Skip to content

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

Open
thekhegay wants to merge 1 commit into
OpenAPITools:masterfrom
thekhegay:typescript-angular-http-resource
Open

thekhegay wants to merge 1 commit into
OpenAPITools:masterfrom
thekhegay:typescript-angular-http-resource

Conversation

@thekhegay

@thekhegay thekhegay commented Sep 19, 2026

Copy link
Copy Markdown

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.

Written for commit a344b41. Summary will update on new commits.

Review in cubic

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 36 files

Tip: cubic can generate docs of your entire codebase and keep them up to date. Try it here.

Re-trigger cubic

…d GET resources

Opt-in, Angular 20+. Every GET operation without a request body gets a
<operation>Resource method next to its Observable method, returning an
Angular httpResource (httpResource.text or httpResource.blob when the
response is text or binary). Writes keep only their Observable method.

The query, header and credential code moves into a partial shared by
both paths, so the output of every existing configuration is unchanged.
Adds a sample build inside typescript-angular-v22-provided-in-root with
an HttpTestingController spec.
@thekhegay
thekhegay force-pushed the typescript-angular-http-resource branch from 5124c05 to a344b41 Compare September 19, 2026 12:14
@thekhegay

Copy link
Copy Markdown
Author

About cubic review:

  • README collision note and null/undefined spec case: fixed in a344b41.
  • git_push.sh and query.params.ts: these come from the shared templates every sample uses, so changing them here would change the output of every generator. Out of scope for this PR.
  • Options-only overload for GETs whose params are all optional: kept (params?, options?). Telling a params function from an options object at runtime would add a dispatch branch for a case getFooResource(undefined, { ... }) already covers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[REQ] Add support for Angular Resource API

1 participant