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

TH
11h ago
+33-1

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.