|
65 | 65 | import static org.openapitools.codegen.languages.features.DocumentationProviderFeatures.ANNOTATION_LIBRARY;
|
66 | 66 | import static org.openapitools.codegen.languages.features.DocumentationProviderFeatures.DOCUMENTATION_PROVIDER;
|
67 | 67 | import static org.testng.Assert.assertEquals;
|
| 68 | +import static org.testng.Assert.assertNotNull; |
68 | 69 | import static org.testng.Assert.fail;
|
69 | 70 |
|
70 | 71 | public class SpringCodegenTest {
|
@@ -5759,4 +5760,72 @@ public void testApiVersion() throws IOException {
|
5759 | 5760 | .assertMethodAnnotations()
|
5760 | 5761 | .containsWithNameAndDoesContainAttributes("RequestMapping", List.of("version"));
|
5761 | 5762 | }
|
| 5763 | + |
| 5764 | + @Test |
| 5765 | + public void annotationLibraryDoesNotCauseImportConflictsInSpring() throws IOException { |
| 5766 | + Map<String, Object> properties = new HashMap<>(); |
| 5767 | + properties.put("documentationProvider", "source"); |
| 5768 | + properties.put("annotationLibrary", "none"); |
| 5769 | + |
| 5770 | + File output = Files.createTempDirectory("test").toFile(); |
| 5771 | + output.deleteOnExit(); |
| 5772 | + |
| 5773 | + final OpenAPI openAPI = TestUtils.parseFlattenSpec("src/test/resources/3_0/java/native/issue21991.yaml"); |
| 5774 | + |
| 5775 | + SpringCodegen codegen = new SpringCodegen(); |
| 5776 | + codegen.setLibrary(SPRING_BOOT); |
| 5777 | + codegen.setOpenAPI(openAPI); |
| 5778 | + codegen.setOutputDir(output.getAbsolutePath()); |
| 5779 | + codegen.additionalProperties().putAll(properties); |
| 5780 | + |
| 5781 | + ClientOptInput input = new ClientOptInput() |
| 5782 | + .openAPI(openAPI) |
| 5783 | + .config(codegen); |
| 5784 | + |
| 5785 | + DefaultGenerator generator = new DefaultGenerator(); |
| 5786 | + |
| 5787 | + Map<String, File> files = generator.opts(input).generate().stream() |
| 5788 | + .collect(Collectors.toMap(File::getName, Function.identity())); |
| 5789 | + |
| 5790 | + File apiFile = files.get("Schema.java"); |
| 5791 | + assertNotNull(apiFile); |
| 5792 | + |
| 5793 | + JavaFileAssert.assertThat(apiFile).fileDoesNotContain( |
| 5794 | + "import io.swagger.v3.oas.annotations.media.Schema;" |
| 5795 | + ); |
| 5796 | + } |
| 5797 | + |
| 5798 | + @Test |
| 5799 | + public void annotationLibraryDoesNotCauseImportConflictsInSpringWithAnnotationLibrary() throws IOException { |
| 5800 | + Map<String, Object> properties = new HashMap<>(); |
| 5801 | + properties.put("documentationProvider", "source"); |
| 5802 | + properties.put("annotationLibrary", "swagger2"); |
| 5803 | + |
| 5804 | + File output = Files.createTempDirectory("test").toFile(); |
| 5805 | + output.deleteOnExit(); |
| 5806 | + |
| 5807 | + final OpenAPI openAPI = TestUtils.parseFlattenSpec("src/test/resources/3_0/java/native/issue21991.yaml"); |
| 5808 | + |
| 5809 | + SpringCodegen codegen = new SpringCodegen(); |
| 5810 | + codegen.setOpenAPI(openAPI); |
| 5811 | + codegen.setLibrary(SPRING_BOOT); |
| 5812 | + codegen.setOutputDir(output.getAbsolutePath()); |
| 5813 | + codegen.additionalProperties().putAll(properties); |
| 5814 | + |
| 5815 | + ClientOptInput input = new ClientOptInput() |
| 5816 | + .openAPI(openAPI) |
| 5817 | + .config(codegen); |
| 5818 | + |
| 5819 | + DefaultGenerator generator = new DefaultGenerator(); |
| 5820 | + |
| 5821 | + Map<String, File> files = generator.opts(input).generate().stream() |
| 5822 | + .collect(Collectors.toMap(File::getName, Function.identity())); |
| 5823 | + |
| 5824 | + File apiFile = files.get("Schema.java"); |
| 5825 | + assertNotNull(apiFile); |
| 5826 | + |
| 5827 | + JavaFileAssert.assertThat(apiFile).fileContains( |
| 5828 | + "import io.swagger.v3.oas.annotations.media.Schema;" |
| 5829 | + ); |
| 5830 | + } |
5762 | 5831 | }
|
0 commit comments