From 38be3c193e8273c493f13cac093d24930628ec95 Mon Sep 17 00:00:00 2001 From: rk Date: Sat, 24 Oct 2026 12:24:24 +0500 Subject: [PATCH] fix(typescript-angular): generate union for oneOf models with taggedUnions --- .../modelTaggedUnion.mustache | 7 +++ .../TypeScriptAngularClientCodegenTest.java | 19 ++++++++ .../3_0/typescript-angular/issue_20859.yaml | 47 +++++++++++++++++++ 3 files changed, 73 insertions(+) create mode 100644 modules/openapi-generator/src/test/resources/3_0/typescript-angular/issue_20859.yaml diff --git a/modules/openapi-generator/src/main/resources/typescript-angular/modelTaggedUnion.mustache b/modules/openapi-generator/src/main/resources/typescript-angular/modelTaggedUnion.mustache index 8e4507f2c022..38c3a582319f 100644 --- a/modules/openapi-generator/src/main/resources/typescript-angular/modelTaggedUnion.mustache +++ b/modules/openapi-generator/src/main/resources/typescript-angular/modelTaggedUnion.mustache @@ -17,7 +17,14 @@ export interface {{classname}} { {{>modelGenericAdditionalProperties}} {{/parent}} {{^parent}} +{{#oneOf}} +{{#-first}} +{{>modelOneOf}} +{{/-first}} +{{/oneOf}} +{{^oneOf}} {{>modelGeneric}} +{{/oneOf}} {{/parent}} {{/discriminator}} \ No newline at end of file diff --git a/modules/openapi-generator/src/test/java/org/openapitools/codegen/typescript/typescriptangular/TypeScriptAngularClientCodegenTest.java b/modules/openapi-generator/src/test/java/org/openapitools/codegen/typescript/typescriptangular/TypeScriptAngularClientCodegenTest.java index dbece37188b2..4e9b3798a728 100644 --- a/modules/openapi-generator/src/test/java/org/openapitools/codegen/typescript/typescriptangular/TypeScriptAngularClientCodegenTest.java +++ b/modules/openapi-generator/src/test/java/org/openapitools/codegen/typescript/typescriptangular/TypeScriptAngularClientCodegenTest.java @@ -330,6 +330,25 @@ public void testTaggedUnionImports() throws Exception { ); } + @Test + public void testTaggedUnionsOneOfWithoutDiscriminator() throws Exception { + File output = Files.createTempDirectory("test").toFile(); + output.deleteOnExit(); + + final CodegenConfigurator configurator = new CodegenConfigurator() + .setGeneratorName("typescript-angular") + .setInputSpec("src/test/resources/3_0/typescript-angular/issue_20859.yaml") + .addAdditionalProperty(TypeScriptAngularClientCodegen.TAGGED_UNIONS, true) + .setOutputDir(output.getAbsolutePath().replace("\\", "/")); + + new DefaultGenerator().opts(configurator.toClientOptInput()).generate(); + + TestUtils.assertFileContains( + Paths.get(output + "/model/zooInner.ts"), + "export type ZooInner = Cat | Dog;" + ); + } + @Test public void testModelNameMappings() throws Exception { final String specPath = "src/test/resources/2_0/issue_8289.json"; diff --git a/modules/openapi-generator/src/test/resources/3_0/typescript-angular/issue_20859.yaml b/modules/openapi-generator/src/test/resources/3_0/typescript-angular/issue_20859.yaml new file mode 100644 index 000000000000..cf3356f39ab9 --- /dev/null +++ b/modules/openapi-generator/src/test/resources/3_0/typescript-angular/issue_20859.yaml @@ -0,0 +1,47 @@ +openapi: 3.0.0 +info: + title: OpenAPI definition + version: v0 +paths: + /api/test/zoo: + get: + responses: + '200': + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/Zoo' +components: + schemas: + Animal: + type: object + discriminator: + propertyName: type + properties: + type: + type: string + required: + - type + Cat: + allOf: + - $ref: '#/components/schemas/Animal' + - type: object + properties: + purrFrequency: + type: integer + format: int32 + Dog: + allOf: + - $ref: '#/components/schemas/Animal' + - type: object + properties: + barkVolume: + type: integer + format: int32 + Zoo: + type: array + items: + oneOf: + - $ref: '#/components/schemas/Cat' + - $ref: '#/components/schemas/Dog'