Skip to content

Commit e0227b0

Browse files
committed
fix (JAVA OKHTTP-GSON): don't add oneOf interface as CustomTypeAdapterFactory
1 parent 1d91065 commit e0227b0

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

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
@@ -3737,4 +3737,32 @@ public void testClientWithUseOneOfInterfaceShouldntGenerateOneOfExample_issue_17
37373737

37383738
}
37393739

3740-
}
3740+
@Test
3741+
public void testOkHttpGsonClientWithUseOneOfInterfaceShouldntRegisterInterfaceAsTypeAdapter_issue_17419() {
3742+
// given
3743+
final Path output = newTempFolder();
3744+
final CodegenConfigurator configurator = new CodegenConfigurator()
3745+
.setGeneratorName("java")
3746+
.setLibrary(OKHTTP_GSON)
3747+
.setAdditionalProperties(Map.of("useOneOfInterfaces", "true"))
3748+
.setInputSpec("src/test/resources/3_0/typescript-fetch/oneOf.yaml")
3749+
.setOutputDir(output.toString().replace("\\", "/"));
3750+
3751+
final ClientOptInput input = configurator.toClientOptInput();
3752+
3753+
// when
3754+
List<File> files = new DefaultGenerator().opts(input).generate();
3755+
3756+
// then
3757+
validateJavaSourceFiles(files);
3758+
TestUtils.assertFileNotContains(
3759+
output.resolve("src/main/java/org/openapitools/client/model/TestResponse.java"),
3760+
"CustomTypeAdapterFactory"
3761+
);
3762+
TestUtils.assertFileNotContains(
3763+
output.resolve("src/main/java/org/openapitools/client/JSON.java"),
3764+
"new org.openapitools.client.model.TestResponse.CustomTypeAdapterFactory()"
3765+
);
3766+
}
3767+
3768+
}

0 commit comments

Comments
 (0)