feat(typescript-angular): add withHttpResource option for signal-based GET resources

Merged
TH
7d ago
+2968-95

Adds an opt-in withHttpResource option to typescript-angular (Angular 20+; a lower ngVersion is refused).

Every GET operation without a request body gets a <operationId>Resource method next to its Observable method, returning an Angular HttpResourceRef:

readonly pet = inject(PetService).getPetByIdResource(() => ({ petId: this.petId() }));
  • Returning undefined, or leaving a required parameter null/undefined, keeps the resource idle.
  • JSON responses use httpResource, text httpResource.text, binary httpResource.blob, chosen at generation time the same way selectHeaderAccept does.
  • The query/header/auth code moved into a shared partial, so the param codec, credentials (read reactively), Accept, withCredentials, context and transferCache behave exactly like the Observable methods.
  • Options: defaultValue, injector, equal, debugName, context, transferCache.
  • Left out on purpose: writes (Angular recommends resources for reads only), GETs with a body, observe, httpHeaderAccept, parse, and resource signatures in the *Interface files.

With the option off the output is unchanged: regenerating every bin/configs file gives zero diff. Tested with Java unit tests and a new sample build (typescript-angular-v22-provided-in-root/builds/with-http-resource) with an HttpTestingController spec; the generated code was also compiled and run against Angular 20, 21 and 22.

Closes #21263. Related: #22537 — this keeps the Observable methods and doesn't touch existing samples.

PR checklist

  • Read the contribution guidelines.
  • Run the following to build the project and update samples:
    ./mvnw clean package || exit
    ./bin/generate-samples.sh ./bin/configs/*.yaml || exit
    ./bin/utils/export_docs_generators.sh || exit
    
    Commit all changed files.
  • If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request.

@TiFu @taxpon @sebastianhaas @kenisteward @Vrolijkx @macjohnny @topce @akehir @petejohansonxo @amakhrov @davidgamero @mkusaka @joscha @KannaKim


Summary by cubic

Adds an opt-in withHttpResource option to typescript-angular that generates signal-based <operationId>Resource methods next to the existing Observable methods. With the option off, generated output is unchanged; enabling it requires Angular 20+ and rejects lower ngVersion values.

New Features

  • Every GET without a request body gets a <operationId>Resource method returning an Angular HttpResourceRef; JSON, text, and binary responses use httpResource, httpResource.text, and httpResource.blob.
  • The resource stays idle while the params function returns undefined or a required parameter is null/undefined.
  • Query, header, auth, withCredentials, context, and transferCache behavior matches the Observable methods.
  • Supports defaultValue, injector, equal, debugName, context, and transferCache.
  • Methods whose names would collide with another operation are skipped with a generation-time warning.
  • Non-GET operations, GETs with a request body, observe, httpHeaderAccept, and parse remain Observable-only.

Closes #21263.