Skip to content

fix(typescript-angular): generate union type for anyOf of primitives - #25559

Open
thekhegay wants to merge 1 commit into
OpenAPITools:masterfrom
thekhegay:fix/ts-angular-anyof-primitives
Open

thekhegay wants to merge 1 commit into
OpenAPITools:masterfrom
thekhegay:fix/ts-angular-anyof-primitives

Conversation

@thekhegay

@thekhegay thekhegay commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

Property like bar: {anyOf: [{type: number}, {type: string}]} gets flattened into FooBar model, and since that model has no own properties typescript-angular renders it as empty export interface FooBar { }
So bar acepts any value, and reading it as number | string fails with TS2322 without cast

model.mustache renders oneOf model as union, but has no such branch for anyOf, so it falls into modelGeneric
Now anyOf model without own properties goes through new modelAnyOf.mustache (like modelOneOf.mustache) and gives export type FooBar = number | string;
anyOf of objects gets merged properties, so hasVars keeps it on modelGeneric and its interface does not change
anyOf of models that extend discriminator parent was empty interface too (their properties go only to allVars), now it also becomes union of these models

Added testAnyOfOfPrimitivesGeneratesUnionType to TypeScriptAngularClientCodegenTest, union check fails on master
No typescript-angular sample spec has anyOf, so regenerated samples (typescript-angular*.yaml configs) have no diff

Fixes #13428

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 codegen so properties with anyOf of primitives generate union types like number | string instead of empty interfaces. Previously these flattened into export interface FooBar { }, which made the property accept any value and caused TS2322 when reading it as the union without a cast. anyOf of objects still merges properties into an interface. Adds modelAnyOf.mustache and a regression test that fails on master.

Written for commit 9c4f6aa. 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] anyOf generates empty interface model

1 participant