Skip to content

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

Merged
wing328 merged 2 commits into
OpenAPITools:masterfrom
thekhegay:typescript-angular-http-resource
Oct 21, 2026
Merged

wing328 merged 2 commits into
OpenAPITools:masterfrom
thekhegay:typescript-angular-http-resource

Conversation

@thekhegay

@thekhegay thekhegay commented Sep 19, 2026 •

Copy link
Copy Markdown
Contributor

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 f16c0ea. Summary will update on new commits.

View guided diff

@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

@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
Contributor 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.

…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 a344b41 to 3fe558b Compare October 20, 2026 08:53

@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 3 files (changes from recent commits).

Tip: Review your code locally with the cubic CLI to iterate faster.

View guided diff | Re-trigger cubic

@bskp

bskp commented Oct 21, 2026

Copy link
Copy Markdown

Great feature! We're waiting for this / considering moving to ng-openapi. Would love to see this PR make it!

@thekhegay

Copy link
Copy Markdown
Contributor Author

@wing328 thanks for running CI. only red one is Samples TS clients and it fails on master too - pom.xml in typescript-angular v18-v21 provided-in-root samples declares exec-maven-plugin twice (line 13 and 100), so maven stops before build

@wing328

wing328 commented Oct 21, 2026

Copy link
Copy Markdown
Member

@thekhegay I've fixed the CI failure via #25343

Can you please merge the latest master into your branch?

I'll then merge it if all the tests pass.

@thekhegay

Copy link
Copy Markdown
Contributor Author

done, merged master in f16c0ea

@wing328
wing328 merged commit 61d14f2 into OpenAPITools:master Oct 21, 2026
29 checks passed
@wing328

wing328 commented Oct 21, 2026

Copy link
Copy Markdown
Member

PR merged. Thanks for the contribution.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[REQ] Add support for Angular Resource API

3 participants