|
18 | 18 | package org.openapitools.codegen.java; |
19 | 19 |
|
20 | 20 | import org.junit.jupiter.api.Assertions; |
| 21 | + |
| 22 | +import static org.assertj.core.api.Assertions.assertThat; |
| 23 | +import static org.assertj.core.api.InstanceOfAssertFactories.FILE; |
| 24 | +import static org.assertj.core.api.InstanceOfAssertFactories.type; |
21 | 25 | import static org.openapitools.codegen.TestUtils.assertFileContains; |
22 | 26 | import static org.openapitools.codegen.TestUtils.assertFileNotContains; |
23 | 27 | import static org.openapitools.codegen.TestUtils.validateJavaSourceFiles; |
24 | | -import static org.openapitools.codegen.languages.JavaClientCodegen.USE_ENUM_CASE_INSENSITIVE; |
| 28 | +import static org.openapitools.codegen.languages.JavaClientCodegen.*; |
25 | 29 | import static org.testng.Assert.assertEquals; |
26 | 30 | import static org.testng.Assert.assertTrue; |
27 | 31 | import static org.testng.Assert.fail; |
@@ -3472,4 +3476,66 @@ void testBuilderJavaClient() throws IOException { |
3472 | 3476 | ".name(getName())", |
3473 | 3477 | "hasLegs(getHasLegs())"); |
3474 | 3478 | } |
| 3479 | + |
| 3480 | + /** |
| 3481 | + * Regression test for <a href="https://github.com/OpenAPITools/openapi-generator/issues/6496">#6496</a> |
| 3482 | + */ |
| 3483 | + @Test void doesNotGenerateJacksonToStringSerializerAnnotation_whenLibraryIsGson_andSerializeBigDecimalAsStringIsTrue() throws IOException { |
| 3484 | + File output = Files.createTempDirectory("test").toFile(); |
| 3485 | + output.deleteOnExit(); |
| 3486 | + |
| 3487 | + final CodegenConfigurator configurator = new CodegenConfigurator() |
| 3488 | + .setGeneratorName("java") |
| 3489 | + .setLibrary(JavaClientCodegen.OKHTTP_GSON) |
| 3490 | + .addAdditionalProperty(CodegenConstants.SERIALIZATION_LIBRARY, SERIALIZATION_LIBRARY_GSON) |
| 3491 | + .addAdditionalProperty(CodegenConstants.SERIALIZE_BIG_DECIMAL_AS_STRING, true) |
| 3492 | + .addGlobalProperty(CodegenConstants.MODELS, "FormatTest") |
| 3493 | + .addGlobalProperty(CodegenConstants.MODEL_DOCS, "false") |
| 3494 | + .addGlobalProperty(CodegenConstants.MODEL_TESTS, "false") |
| 3495 | + .setInputSpec("src/test/resources/2_0/java/issue-6496.yaml") |
| 3496 | + .setOutputDir(output.getAbsolutePath().replace("\\", "/")); |
| 3497 | + |
| 3498 | + List<File> files = new DefaultGenerator().opts(configurator.toClientOptInput()).generate(); |
| 3499 | + |
| 3500 | + assertThat(files).hasSize(1).first(FILE).content() |
| 3501 | + .doesNotContain( |
| 3502 | + "@JsonDeserialize(as = LinkedHashSet.class)", |
| 3503 | + "@JsonSerialize(using = ToStringSerializer.class)", |
| 3504 | + "com.fasterxml.jackson.databind.ser.std.ToStringSerializer", |
| 3505 | + "com.fasterxml.jackson.databind.annotation.JsonDeserialize", |
| 3506 | + "com.fasterxml.jackson.databind.annotation.JsonSerialize" |
| 3507 | + ); |
| 3508 | + } |
| 3509 | + |
| 3510 | + /** |
| 3511 | + * Test that fix for <a href="https://github.com/OpenAPITools/openapi-generator/issues/6496">#6496</a> has |
| 3512 | + * no unwanted side effects on the existing feature (Jackson + bigDecimalAsString) |
| 3513 | + */ |
| 3514 | + @Test void generatesJacksonToStringSerializerAnnotation_whenLibraryIsJackson_andSerializeBigDecimalAsStringIsTrue() throws IOException { |
| 3515 | + File output = Files.createTempDirectory("test").toFile(); |
| 3516 | + output.deleteOnExit(); |
| 3517 | + |
| 3518 | + final CodegenConfigurator configurator = new CodegenConfigurator() |
| 3519 | + .setGeneratorName("java") |
| 3520 | + .setLibrary(JavaClientCodegen.NATIVE) |
| 3521 | + .addAdditionalProperty(CodegenConstants.SERIALIZATION_LIBRARY, SERIALIZATION_LIBRARY_JACKSON) |
| 3522 | + .addAdditionalProperty(CodegenConstants.SERIALIZE_BIG_DECIMAL_AS_STRING, true) |
| 3523 | + .addAdditionalProperty(OPENAPI_NULLABLE, false) |
| 3524 | + .addGlobalProperty(CodegenConstants.MODELS, "FormatTest") |
| 3525 | + .addGlobalProperty(CodegenConstants.MODEL_DOCS, "false") |
| 3526 | + .addGlobalProperty(CodegenConstants.MODEL_TESTS, "false") |
| 3527 | + .setInputSpec("src/test/resources/2_0/java/issue-6496.yaml") |
| 3528 | + .setOutputDir(output.getAbsolutePath().replace("\\", "/")); |
| 3529 | + |
| 3530 | + List<File> files = new DefaultGenerator().opts(configurator.toClientOptInput()).generate(); |
| 3531 | + |
| 3532 | + assertThat(files).hasSize(1).first(FILE).content() |
| 3533 | + .contains( |
| 3534 | + "@JsonDeserialize(as = LinkedHashSet.class)", |
| 3535 | + "@JsonSerialize(using = ToStringSerializer.class)", |
| 3536 | + "com.fasterxml.jackson.databind.ser.std.ToStringSerializer", |
| 3537 | + "com.fasterxml.jackson.databind.annotation.JsonDeserialize", |
| 3538 | + "com.fasterxml.jackson.databind.annotation.JsonSerialize" |
| 3539 | + ); |
| 3540 | + } |
3475 | 3541 | } |
0 commit comments