|
40 | 40 | import org.junit.jupiter.api.Assertions; |
41 | 41 | import org.openapitools.codegen.config.CodegenConfigurator; |
42 | 42 | import org.openapitools.codegen.config.GlobalSettings; |
| 43 | +import org.openapitools.codegen.java.assertions.JavaFileAssert; |
43 | 44 | import org.openapitools.codegen.languages.SpringCodegen; |
44 | 45 | import org.openapitools.codegen.model.ModelMap; |
45 | 46 | import org.openapitools.codegen.model.ModelsMap; |
|
55 | 56 | import java.nio.file.Files; |
56 | 57 | import java.util.*; |
57 | 58 | import java.util.concurrent.*; |
| 59 | +import java.util.function.Function; |
58 | 60 | import java.util.stream.Collectors; |
59 | 61 |
|
60 | 62 | import static org.assertj.core.api.Assertions.assertThat; |
@@ -5017,4 +5019,58 @@ public void testQueryIsJsonMimeType() { |
5017 | 5019 |
|
5018 | 5020 | assertTrue(codegenOperation.queryParams.stream().allMatch(p -> p.queryIsJsonMimeType)); |
5019 | 5021 | } |
| 5022 | + |
| 5023 | + @Test(description = "Issue #20213") |
| 5024 | + public void testModelAdditionalPropertiesWithNullableProperty() throws Exception { |
| 5025 | + File output = Files.createTempDirectory("test").toFile(); |
| 5026 | + output.deleteOnExit(); |
| 5027 | + File spring = new File(output, "spring"); |
| 5028 | + |
| 5029 | + final CodegenConfigurator configurator = new CodegenConfigurator() |
| 5030 | + .setGeneratorName("spring") |
| 5031 | + .setInputSpec("src/test/resources/3_1/issue_20213.yaml") |
| 5032 | + .setOutputDir(spring.getAbsolutePath().replace("\\", "/")); |
| 5033 | + |
| 5034 | + final ClientOptInput clientOptInput = configurator.toClientOptInput(); |
| 5035 | + DefaultGenerator generator = new DefaultGenerator(); |
| 5036 | + Map<String, File> files = generator.opts(clientOptInput).generate() |
| 5037 | + .stream().collect(Collectors.toMap(File::getName, Function.identity())); |
| 5038 | + |
| 5039 | + JavaFileAssert.assertThat(files.get("SampleObjectWithAdditionalFalse.java")) |
| 5040 | + .assertProperty("someString") |
| 5041 | + .withType("JsonNullable<String>"); |
| 5042 | + assertFalse(files.containsKey("SampleObjectWithAdditionalFalseSomeString.java")); |
| 5043 | + |
| 5044 | + |
| 5045 | + File tsAngular = new File(output, "ts-angular"); |
| 5046 | + final CodegenConfigurator tsConfigurator = new CodegenConfigurator() |
| 5047 | + .setGeneratorName("typescript-angular") |
| 5048 | + .setInputSpec("src/test/resources/3_1/issue_20213.yaml") |
| 5049 | + .setOutputDir(tsAngular.getAbsolutePath().replace("\\", "/")); |
| 5050 | + |
| 5051 | + final ClientOptInput tsClientOptInput = tsConfigurator.toClientOptInput(); |
| 5052 | + DefaultGenerator tsGenerator = new DefaultGenerator(); |
| 5053 | + Map<String, File> tsFiles = tsGenerator.opts(tsClientOptInput).generate() |
| 5054 | + .stream().collect(Collectors.toMap(File::getName, Function.identity())); |
| 5055 | + |
| 5056 | + System.out.println(Files.readString(tsFiles.get("sampleObjectWithAdditionalFalse.ts").toPath())); |
| 5057 | + TestUtils.assertFileContains(tsFiles.get("sampleObjectWithAdditionalFalse.ts").toPath(), "someString?: string"); |
| 5058 | + assertFalse(tsFiles.containsKey("sampleObjectWithAdditionalFalseSomeString.ts")); |
| 5059 | + |
| 5060 | + File javaClient = new File(output, "java"); |
| 5061 | + final CodegenConfigurator javaClientConfigurator = new CodegenConfigurator() |
| 5062 | + .setGeneratorName("java") |
| 5063 | + .setInputSpec("src/test/resources/3_1/issue_20213.yaml") |
| 5064 | + .setOutputDir(javaClient.getAbsolutePath().replace("\\", "/")); |
| 5065 | + |
| 5066 | + final ClientOptInput javaClientClientOptInput = javaClientConfigurator.toClientOptInput(); |
| 5067 | + DefaultGenerator javaClientGenerator = new DefaultGenerator(); |
| 5068 | + Map<String, File> javaClientFiles = javaClientGenerator.opts(javaClientClientOptInput).generate() |
| 5069 | + .stream().collect(Collectors.toMap(File::getName, Function.identity())); |
| 5070 | + |
| 5071 | + JavaFileAssert.assertThat(javaClientFiles.get("SampleObjectWithAdditionalFalse.java")) |
| 5072 | + .assertProperty("someString") |
| 5073 | + .withType("String"); |
| 5074 | + assertFalse(javaClientFiles.containsKey("SampleObjectWithAdditionalFalseSomeString.java")); |
| 5075 | + } |
5020 | 5076 | } |
0 commit comments