Skip to content

Commit 122e7c2

Browse files
committed
Add regression test for OpenAPITools#18515
1 parent 66e4264 commit 122e7c2

File tree

1 file changed

+41
-1
lines changed

1 file changed

+41
-1
lines changed

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

+41-1
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060

6161
import static org.assertj.core.api.Assertions.assertThat;
6262
import static org.assertj.core.api.Assertions.entry;
63+
import static org.openapitools.codegen.CodegenConstants.SERIALIZATION_LIBRARY;
6364
import static org.openapitools.codegen.TestUtils.*;
6465
import static org.openapitools.codegen.languages.JavaClientCodegen.*;
6566
import static org.testng.Assert.*;
@@ -112,6 +113,12 @@ public String toString() {
112113
return Arrays.stream(Library.values()).iterator();
113114
}
114115

116+
@DataProvider Iterator<Library> librariesSupportingGson() {
117+
return Arrays.stream(Library.values())
118+
.filter(library -> library.getSupportedSerializers().contains(Serializer.GSON))
119+
.iterator();
120+
}
121+
115122
@Test
116123
public void arraysInRequestBody() {
117124
OpenAPI openAPI = TestUtils.createOpenAPI();
@@ -257,7 +264,7 @@ public void testAdditionalPropertiesPutForConfigValues() throws Exception {
257264
codegen
258265
.additionalProperties()
259266
.put(CodegenConstants.INVOKER_PACKAGE, "xyz.yyyyy.zzzzzzz.iiii.invoker");
260-
codegen.additionalProperties().put(CodegenConstants.SERIALIZATION_LIBRARY, "JACKSON");
267+
codegen.additionalProperties().put(SERIALIZATION_LIBRARY, "JACKSON");
261268
codegen.additionalProperties().put(CodegenConstants.LIBRARY, JavaClientCodegen.JERSEY2);
262269
codegen.processOpts();
263270

@@ -3435,4 +3442,37 @@ void testBuilderJavaClient() throws IOException {
34353442
entry(SERIALIZATION_LIBRARY_JSONB, "true")
34363443
);
34373444
}
3445+
3446+
/**
3447+
* Regression test for <a href="https://github.com/OpenAPITools/openapi-generator/issues/18515">#18515</a>:
3448+
* When GSON is selected as serializer, there should not be any jackson references
3449+
* (except jackson-databind-nullable that is, which is only added when openApiNullable=true)
3450+
*/
3451+
@Test(dataProvider = "librariesSupportingGson") void gsonCodeDoesNotContainJacksonReferences(Library library) {
3452+
final CodegenConfigurator configurator = new CodegenConfigurator()
3453+
.addAdditionalProperty(SERIALIZATION_LIBRARY, Serializer.GSON)
3454+
.addAdditionalProperty(OPENAPI_NULLABLE, "false")
3455+
.setGeneratorName("java")
3456+
.setLibrary(library.getValue())
3457+
.setInputSpec("src/test/resources/3_0/java/autoset_constant.yaml")
3458+
.setOutputDir(newTempFolder().toString());
3459+
var generator = new DefaultGenerator();
3460+
generator.setGenerateMetadata(false);
3461+
3462+
List<File> files = generator.opts(configurator.toClientOptInput()).generate();
3463+
3464+
assertThat(files).allSatisfy(
3465+
file -> assertThat(file).content().doesNotContainIgnoringCase("jackson")
3466+
);
3467+
}
3468+
3469+
private Path newTempFolder() {
3470+
try {
3471+
var tempDir = Files.createTempDirectory("test");
3472+
tempDir.toFile().deleteOnExit();
3473+
return tempDir;
3474+
} catch (IOException e) {
3475+
throw new RuntimeException(e);
3476+
}
3477+
}
34383478
}

0 commit comments

Comments
 (0)