Skip to content

Commit

Permalink
Add regression test for OpenAPITools#18515
Browse files Browse the repository at this point in the history
  • Loading branch information
Philzen committed Jun 2, 2024
1 parent 69c5116 commit 959e68d
Showing 1 changed file with 41 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.entry;
import static org.openapitools.codegen.CodegenConstants.SERIALIZATION_LIBRARY;
import static org.openapitools.codegen.TestUtils.*;
import static org.openapitools.codegen.languages.JavaClientCodegen.*;
import static org.testng.Assert.*;
Expand Down Expand Up @@ -112,6 +113,12 @@ public String toString() {
return Arrays.stream(Library.values()).iterator();
}

@DataProvider Iterator<Library> librariesSupportingGson() {
return Arrays.stream(Library.values())
.filter(library -> library.getSupportedSerializers().contains(Serializer.GSON))
.iterator();
}

@Test
public void arraysInRequestBody() {
OpenAPI openAPI = TestUtils.createOpenAPI();
Expand Down Expand Up @@ -257,7 +264,7 @@ public void testAdditionalPropertiesPutForConfigValues() throws Exception {
codegen
.additionalProperties()
.put(CodegenConstants.INVOKER_PACKAGE, "xyz.yyyyy.zzzzzzz.iiii.invoker");
codegen.additionalProperties().put(CodegenConstants.SERIALIZATION_LIBRARY, "JACKSON");
codegen.additionalProperties().put(SERIALIZATION_LIBRARY, "JACKSON");
codegen.additionalProperties().put(CodegenConstants.LIBRARY, JavaClientCodegen.JERSEY2);
codegen.processOpts();

Expand Down Expand Up @@ -3435,4 +3442,37 @@ void testBuilderJavaClient() throws IOException {
entry(SERIALIZATION_LIBRARY_JSONB, "true")
);
}

/**
* Regression test for <a href="https://github.com/OpenAPITools/openapi-generator/issues/18515">#18515</a>:
* When GSON is selected as serializer, there should not be any jackson references
* (except jackson-databind-nullable that is, which is only added when openApiNullable=true)
*/
@Test(dataProvider = "librariesSupportingGson") void gsonCodeDoesNotContainJacksonReferences(Library library) {
final CodegenConfigurator configurator = new CodegenConfigurator()
.addAdditionalProperty(SERIALIZATION_LIBRARY, Serializer.GSON)
.addAdditionalProperty(OPENAPI_NULLABLE, "false")
.setGeneratorName("java")
.setLibrary(library.getValue())
.setInputSpec("src/test/resources/3_0/java/autoset_constant.yaml")
.setOutputDir(newTempFolder().toString());
var generator = new DefaultGenerator();
generator.setGenerateMetadata(false);

List<File> files = generator.opts(configurator.toClientOptInput()).generate();

assertThat(files).allSatisfy(
file -> assertThat(file).content().doesNotContainIgnoringCase("jackson")
);
}

private Path newTempFolder() {
try {
var tempDir = Files.createTempDirectory("test");
tempDir.toFile().deleteOnExit();
return tempDir;
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}

0 comments on commit 959e68d

Please sign in to comment.