Skip to content

Commit bd5eb98

Browse files
committed
Added Issue 20139 test for Spring
1 parent 6fedd29 commit bd5eb98

2 files changed

Lines changed: 26 additions & 0 deletions

File tree

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3606,6 +3606,8 @@ public void givenAdditionalPropertiesNotDefinedAndIsDisallowAdditionalProperties
36063606
codegen.setOutputDir(output.getAbsolutePath());
36073607
codegen.setUseBeanValidation(true);
36083608
codegen.additionalProperties().put(DISALLOW_ADDITIONAL_PROPERTIES_IF_NOT_PRESENT, false);
3609+
3610+
// Only works for these libraries: jersey3, jersey2, feign, feign-hc5, resttemplate, webclient, restclient native
36093611
// The default, okhttp-gson, relies on isAdditionalPropertiesTrue and doesn't use additionalPropertiesType
36103612
codegen.additionalProperties().put(LIBRARY, JERSEY2);
36113613
new DefaultGenerator().opts(new ClientOptInput()

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,12 @@
5858

5959
import static java.util.stream.Collectors.groupingBy;
6060
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;
6163
import static org.openapitools.codegen.TestUtils.*;
6264
import static org.openapitools.codegen.languages.AbstractJavaCodegen.GENERATE_BUILDERS;
6365
import static org.openapitools.codegen.languages.AbstractJavaCodegen.GENERATE_CONSTRUCTOR_WITH_ALL_ARGS;
66+
import static org.openapitools.codegen.languages.JavaClientCodegen.JERSEY2;
6467
import static org.openapitools.codegen.languages.SpringCodegen.*;
6568
import static org.openapitools.codegen.languages.features.DocumentationProviderFeatures.ANNOTATION_LIBRARY;
6669
import static org.openapitools.codegen.languages.features.DocumentationProviderFeatures.DOCUMENTATION_PROVIDER;
@@ -5501,4 +5504,25 @@ public void testEnumFieldShouldBeFinal_issue21018() throws IOException {
55015504
JavaFileAssert.assertThat(files.get("SomeObject.java"))
55025505
.fileContains("private final String value");
55035506
}
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+
}
55045528
}

0 commit comments

Comments
 (0)