Skip to content

fix(typescript-angular): generate union for oneOf models with taggedUnions - #25557

Open
thekhegay wants to merge 1 commit into
OpenAPITools:masterfrom
thekhegay:fix/ts-angular-tagged-unions-oneof
Open

thekhegay wants to merge 1 commit into
OpenAPITools:masterfrom
thekhegay:fix/ts-angular-tagged-unions-oneof

Conversation

@thekhegay

@thekhegay thekhegay commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

With taggedUnions=true model that is plain oneOf without discriminator is generated as empty interface, for spec from issue zooInner.ts gets export interface ZooInner { } instead of export type ZooInner = Cat | Dog;, so narrowing on z.type fails with TS2339
Without taggedUnions same model is allready union

When option is on model.mustache sends every model except enums and aliases to modelTaggedUnion.mustache, and there branch for model without discriminator and parent renders only modelGeneric
Now that branch picks modelOneOf for oneOf models, same check model.mustache does when option is off, models with discriminator or parent are not touched

Added testTaggedUnionsOneOfWithoutDiscriminator with spec from issue, it fails on master
Client generated from that spec now compiles with strict tsc, narrowing on type included
Sample config with taggedUnions (composed-schemas) has no oneOf, so regenerated typescript-angular samples have no diff

Fixes #20859

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

Fixes typescript-angular generating an empty interface for oneOf models without a discriminator when taggedUnions=true is enabled, instead of a union type like export type ZooInner = Cat | Dog;. This caused type narrowing on z.type to fail with TS2339.

The tagged union template now falls back to the standard oneOf generation for models that have oneOf but no discriminator or parent; models with a discriminator or parent are unchanged. Adds a regression test with the spec from issue #20859.

Written for commit 38be3c1. 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.

No issues found across 3 files

View guided diff | Re-trigger cubic

This branch has not been deployed

No deployments
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.

[BUG][typescript-angular] Tagged unions not working as expected

1 participant