Skip to content

Commit 197c047

Browse files
committed
fix (JAVA OKHTTP-GSON): don't add oneOf interface as CustomTypeAdapterFactory
1 parent 23c9a07 commit 197c047

2 files changed

Lines changed: 31 additions & 1 deletion

File tree

modules/openapi-generator/src/main/resources/Java/libraries/okhttp-gson/JSON.mustache

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,9 @@ public class JSON {
131131
{{#model}}
132132
{{^isEnum}}
133133
{{^hasChildren}}
134+
{{^vendorExtensions.x-is-one-of-interface}}
134135
gsonBuilder.registerTypeAdapterFactory(new {{modelPackage}}.{{{classname}}}.CustomTypeAdapterFactory());
136+
{{/vendorExtensions.x-is-one-of-interface}}
135137
{{/hasChildren}}
136138
{{/isEnum}}
137139
{{/model}}

modules/openapi-generator/src/test/java/org/openapitools/codegen/java/JavaClientCodegenTest.java

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4452,4 +4452,32 @@ public void testClientWithUseOneOfInterfaceShouldntGenerateOneOfExample_issue_17
44524452

44534453
}
44544454

4455-
}
4455+
@Test
4456+
public void testOkHttpGsonClientWithUseOneOfInterfaceShouldntRegisterInterfaceAsTypeAdapter_issue_17419() {
4457+
// given
4458+
final Path output = newTempFolder();
4459+
final CodegenConfigurator configurator = new CodegenConfigurator()
4460+
.setGeneratorName("java")
4461+
.setLibrary(OKHTTP_GSON)
4462+
.setAdditionalProperties(Map.of("useOneOfInterfaces", "true"))
4463+
.setInputSpec("src/test/resources/3_0/typescript-fetch/oneOf.yaml")
4464+
.setOutputDir(output.toString().replace("\\", "/"));
4465+
4466+
final ClientOptInput input = configurator.toClientOptInput();
4467+
4468+
// when
4469+
List<File> files = new DefaultGenerator().opts(input).generate();
4470+
4471+
// then
4472+
validateJavaSourceFiles(files);
4473+
TestUtils.assertFileNotContains(
4474+
output.resolve("src/main/java/org/openapitools/client/model/TestResponse.java"),
4475+
"CustomTypeAdapterFactory"
4476+
);
4477+
TestUtils.assertFileNotContains(
4478+
output.resolve("src/main/java/org/openapitools/client/JSON.java"),
4479+
"new org.openapitools.client.model.TestResponse.CustomTypeAdapterFactory()"
4480+
);
4481+
}
4482+
4483+
}

0 commit comments

Comments
 (0)