|
60 | 60 |
|
61 | 61 | import static org.assertj.core.api.Assertions.assertThat;
|
62 | 62 | import static org.assertj.core.api.Assertions.entry;
|
| 63 | +import static org.openapitools.codegen.CodegenConstants.SERIALIZATION_LIBRARY; |
63 | 64 | import static org.openapitools.codegen.TestUtils.*;
|
64 | 65 | import static org.openapitools.codegen.languages.JavaClientCodegen.*;
|
65 | 66 | import static org.testng.Assert.*;
|
@@ -112,6 +113,12 @@ public String toString() {
|
112 | 113 | return Arrays.stream(Library.values()).iterator();
|
113 | 114 | }
|
114 | 115 |
|
| 116 | + @DataProvider Iterator<Library> librariesSupportingGson() { |
| 117 | + return Arrays.stream(Library.values()) |
| 118 | + .filter(library -> library.getSupportedSerializers().contains(Serializer.GSON)) |
| 119 | + .iterator(); |
| 120 | + } |
| 121 | + |
115 | 122 | @Test
|
116 | 123 | public void arraysInRequestBody() {
|
117 | 124 | OpenAPI openAPI = TestUtils.createOpenAPI();
|
@@ -257,7 +264,7 @@ public void testAdditionalPropertiesPutForConfigValues() throws Exception {
|
257 | 264 | codegen
|
258 | 265 | .additionalProperties()
|
259 | 266 | .put(CodegenConstants.INVOKER_PACKAGE, "xyz.yyyyy.zzzzzzz.iiii.invoker");
|
260 |
| - codegen.additionalProperties().put(CodegenConstants.SERIALIZATION_LIBRARY, "JACKSON"); |
| 267 | + codegen.additionalProperties().put(SERIALIZATION_LIBRARY, "JACKSON"); |
261 | 268 | codegen.additionalProperties().put(CodegenConstants.LIBRARY, JavaClientCodegen.JERSEY2);
|
262 | 269 | codegen.processOpts();
|
263 | 270 |
|
@@ -3435,4 +3442,37 @@ void testBuilderJavaClient() throws IOException {
|
3435 | 3442 | entry(SERIALIZATION_LIBRARY_JSONB, "true")
|
3436 | 3443 | );
|
3437 | 3444 | }
|
| 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 | + } |
3438 | 3478 | }
|
0 commit comments