|
58 | 58 |
|
59 | 59 | import static java.util.stream.Collectors.groupingBy; |
60 | 60 | import static org.assertj.core.api.Assertions.assertThat; |
| 61 | +import static org.openapitools.codegen.CodegenConstants.DISALLOW_ADDITIONAL_PROPERTIES_IF_NOT_PRESENT; |
| 62 | +import static org.openapitools.codegen.CodegenConstants.LIBRARY; |
61 | 63 | import static org.openapitools.codegen.TestUtils.*; |
62 | 64 | import static org.openapitools.codegen.languages.AbstractJavaCodegen.GENERATE_BUILDERS; |
63 | 65 | import static org.openapitools.codegen.languages.AbstractJavaCodegen.GENERATE_CONSTRUCTOR_WITH_ALL_ARGS; |
| 66 | +import static org.openapitools.codegen.languages.JavaClientCodegen.JERSEY2; |
64 | 67 | import static org.openapitools.codegen.languages.SpringCodegen.*; |
65 | 68 | import static org.openapitools.codegen.languages.features.DocumentationProviderFeatures.ANNOTATION_LIBRARY; |
66 | 69 | import static org.openapitools.codegen.languages.features.DocumentationProviderFeatures.DOCUMENTATION_PROVIDER; |
@@ -5501,4 +5504,25 @@ public void testEnumFieldShouldBeFinal_issue21018() throws IOException { |
5501 | 5504 | JavaFileAssert.assertThat(files.get("SomeObject.java")) |
5502 | 5505 | .fileContains("private final String value"); |
5503 | 5506 | } |
| 5507 | + |
| 5508 | + @Test(description = "Issue #20139") |
| 5509 | + public void givenAdditionalPropertiesNotDefinedAndIsDisallowAdditionalPropertiesIfNotPresentIsFalseWhenGenerateModelThenAdditionalPropertiesTypeIsObject() throws Exception { |
| 5510 | + File output = Files.createTempDirectory("test").toFile().getCanonicalFile(); |
| 5511 | + output.deleteOnExit(); |
| 5512 | + |
| 5513 | + SpringCodegen codegen = new SpringCodegen(); |
| 5514 | + codegen.setOutputDir(output.getAbsolutePath()); |
| 5515 | + codegen.setUseBeanValidation(true); |
| 5516 | + codegen.additionalProperties().put(DISALLOW_ADDITIONAL_PROPERTIES_IF_NOT_PRESENT, false); |
| 5517 | + new DefaultGenerator().opts(new ClientOptInput() |
| 5518 | + .openAPI(TestUtils.parseSpec("src/test/resources/2_0/issue_20139.yaml")) |
| 5519 | + .config(codegen)) |
| 5520 | + .generate(); |
| 5521 | + |
| 5522 | + String outputPath = output.getAbsolutePath() + "/src/main/java/org/openapitools"; |
| 5523 | + Path jsonWebKey = Paths.get(outputPath + "/model/JsonWebKey.java"); |
| 5524 | + JavaFileAssert.assertThat(jsonWebKey) |
| 5525 | + .assertProperty("additionalProperties") |
| 5526 | + .withType("Map<String, Object>"); |
| 5527 | + } |
5504 | 5528 | } |
0 commit comments