Skip to content

Commit 0e96c72

Browse files
Revert "Merge branch 'fix-nested-oneof'"
This reverts commit 4a46c59, reversing changes made to 37bad16.
1 parent ad666bd commit 0e96c72

4 files changed

Lines changed: 1 addition & 146 deletions

File tree

modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/TypeScriptFetchClientCodegen.java

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -460,22 +460,6 @@ public Map<String, ModelsMap> postProcessAllModels(Map<String, ModelsMap> objs)
460460
}
461461
}
462462

463-
// Build a set of classnames that are oneOf models (union types)
464-
Set<String> oneOfModelNames = allModels.stream()
465-
.filter(m -> !m.oneOf.isEmpty())
466-
.map(m -> m.classname)
467-
.collect(Collectors.toSet());
468-
469-
// Mark models whose parent is a oneOf model — these cannot use
470-
// "interface X extends Parent" because TypeScript does not allow
471-
// an interface to extend a union type. They use
472-
// "type X = Parent & { ... }" instead.
473-
for (ExtendedCodegenModel m : allModels) {
474-
if (m.parent != null && oneOfModelNames.contains(m.parent)) {
475-
m.parentIsOneOf = true;
476-
}
477-
}
478-
479463
for (ExtendedCodegenModel rootModel : allModels) {
480464
for (String curImport : rootModel.imports) {
481465
boolean isModelImport = false;
@@ -1561,8 +1545,6 @@ public class ExtendedCodegenModel extends CodegenModel {
15611545
public Set<CodegenProperty> oneOfPrimitives = new HashSet<>();
15621546
@Getter @Setter
15631547
public CodegenDiscriminator.MappedModel selfReferencingDiscriminatorMapping;
1564-
@Getter @Setter
1565-
public boolean parentIsOneOf; // true when this model's parent is a oneOf union type
15661548

15671549
public boolean isEntity; // Is a model containing an "id" property marked as isUniqueId
15681550
public String returnPassthrough;

modules/openapi-generator/src/main/resources/typescript-fetch/modelGenericInterfaces.mustache

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,9 @@
11
/**
22
* {{#lambda.indented_star_1}}{{{unescapedDescription}}}{{/lambda.indented_star_1}}
33
* @export
4-
{{^parentIsOneOf}}
54
* @interface {{classname}}
65
*/
76
export interface {{classname}} {{#parent}}extends {{{.}}} {{/parent}}{
8-
{{/parentIsOneOf}}
9-
{{#parentIsOneOf}}
10-
*/
11-
export type {{classname}} = {{{parent}}} & {
12-
{{/parentIsOneOf}}
137
{{#additionalPropertiesType}}
148
[key: string]: {{{additionalPropertiesType}}}{{#hasVars}} | any{{/hasVars}};
159
{{/additionalPropertiesType}}
@@ -24,7 +18,7 @@ export type {{classname}} = {{{parent}}} & {
2418
*/
2519
{{#isReadOnly}}readonly {{/isReadOnly}}{{name}}{{^required}}?{{/required}}: {{{datatypeWithEnum}}}{{#isNullable}} | null{{/isNullable}};
2620
{{/vars}}
27-
}{{#parentIsOneOf}};{{/parentIsOneOf}}{{#hasEnums}}
21+
}{{#hasEnums}}
2822

2923
{{#vars}}
3024
{{#isEnum}}

modules/openapi-generator/src/test/java/org/openapitools/codegen/typescript/fetch/TypeScriptFetchClientCodegenTest.java

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -563,43 +563,6 @@ public void testRequestOptsNotInInterfaceWhenDisabled() throws IOException {
563563
assertThat(classSection).contains("async addPetRequestOpts(");
564564
}
565565

566-
/**
567-
* When a oneOf variant uses allOf to reference another oneOf (nested discriminated unions),
568-
* the child model must be generated as a type alias with intersection rather than an
569-
* interface with extends, because TypeScript does not allow interfaces to extend union types.
570-
*/
571-
@Test(description = "Verify nested oneOf generates type alias instead of interface extends")
572-
public void testNestedOneOfGeneratesTypeAliasForOneOfParent() throws IOException {
573-
File output = generate(
574-
Collections.emptyMap(),
575-
"src/test/resources/3_0/typescript-fetch/nested-oneOf.yaml"
576-
);
577-
578-
// OuterComposed's parent is Inner (a oneOf union type), so it must use
579-
// "type OuterComposed = Inner & { ... }" instead of "interface OuterComposed extends Inner"
580-
Path outerComposed = Paths.get(output + "/models/OuterComposed.ts");
581-
TestUtils.assertFileExists(outerComposed);
582-
TestUtils.assertFileContains(outerComposed, "export type OuterComposed = Inner & {");
583-
TestUtils.assertFileNotContains(outerComposed, "export interface OuterComposed extends Inner");
584-
585-
// Inner should still be a proper oneOf union type with discriminator dispatch
586-
Path inner = Paths.get(output + "/models/Inner.ts");
587-
TestUtils.assertFileExists(inner);
588-
TestUtils.assertFileContains(inner, "export type Inner = { innerDiscriminator: 'a' } & InnerA | { innerDiscriminator: 'b' } & InnerB");
589-
TestUtils.assertFileContains(inner, "switch (json['innerDiscriminator'])");
590-
591-
// Outer should dispatch on outerDiscriminator, including the composed variant
592-
Path outer = Paths.get(output + "/models/Outer.ts");
593-
TestUtils.assertFileExists(outer);
594-
TestUtils.assertFileContains(outer, "switch (json['outerDiscriminator'])");
595-
TestUtils.assertFileContains(outer, "case 'composed':");
596-
597-
// Regular models (not extending a oneOf parent) should still use interface
598-
Path outerPlain = Paths.get(output + "/models/OuterPlain.ts");
599-
TestUtils.assertFileExists(outerPlain);
600-
TestUtils.assertFileContains(outerPlain, "export interface OuterPlain {");
601-
}
602-
603566
private static File generate(
604567
Map<String, Object> properties
605568
) throws IOException {

modules/openapi-generator/src/test/resources/3_0/typescript-fetch/nested-oneOf.yaml

Lines changed: 0 additions & 84 deletions
This file was deleted.

0 commit comments

Comments
 (0)