feat(typescript-angular): add withHttpResource option for signal-based GET resources
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, texthttpResource.text, binaryhttpResource.blob, chosen at generation time the same wayselectHeaderAcceptdoes. - The query/header/auth code moved into a shared partial, so the param codec, credentials (read reactively), Accept,
withCredentials,contextandtransferCachebehave 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*Interfacefiles.
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:
Commit all changed files../mvnw clean package || exit ./bin/generate-samples.sh ./bin/configs/*.yaml || exit ./bin/utils/export_docs_generators.sh || exit - 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>Resourcemethod returning an AngularHttpResourceRef; JSON, text, and binary responses usehttpResource,httpResource.text, andhttpResource.blob. - The resource stays idle while the params function returns
undefinedor a required parameter isnull/undefined. - Query, header, auth,
withCredentials,context, andtransferCachebehavior matches the Observable methods. - Supports
defaultValue,injector,equal,debugName,context, andtransferCache. - 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, andparseremain Observable-only.
Closes #21263.