|
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 {
|
@@ -5738,4 +5739,72 @@ public void testOneOfInterfaceWithAnnotation() throws IOException {
|
5738 | 5739 | .isInterface()
|
5739 | 5740 | .assertTypeAnnotations().containsWithName("SuppressWarnings");
|
5740 | 5741 | }
|
| 5742 | + |
| 5743 | + @Test |
| 5744 | + public void annotationLibraryDoesNotCauseImportConflictsInSpring() throws IOException { |
| 5745 | + Map<String, Object> properties = new HashMap<>(); |
| 5746 | + properties.put("documentationProvider", "source"); |
| 5747 | + properties.put("annotationLibrary", "none"); |
| 5748 | + |
| 5749 | + File output = Files.createTempDirectory("test").toFile(); |
| 5750 | + output.deleteOnExit(); |
| 5751 | + |
| 5752 | + final OpenAPI openAPI = TestUtils.parseFlattenSpec("src/test/resources/3_0/java/native/issue21991.yaml"); |
| 5753 | + |
| 5754 | + SpringCodegen codegen = new SpringCodegen(); |
| 5755 | + codegen.setLibrary(SPRING_BOOT); |
| 5756 | + codegen.setOpenAPI(openAPI); |
| 5757 | + codegen.setOutputDir(output.getAbsolutePath()); |
| 5758 | + codegen.additionalProperties().putAll(properties); |
| 5759 | + |
| 5760 | + ClientOptInput input = new ClientOptInput() |
| 5761 | + .openAPI(openAPI) |
| 5762 | + .config(codegen); |
| 5763 | + |
| 5764 | + DefaultGenerator generator = new DefaultGenerator(); |
| 5765 | + |
| 5766 | + Map<String, File> files = generator.opts(input).generate().stream() |
| 5767 | + .collect(Collectors.toMap(File::getName, Function.identity())); |
| 5768 | + |
| 5769 | + File apiFile = files.get("Schema.java"); |
| 5770 | + assertNotNull(apiFile); |
| 5771 | + |
| 5772 | + JavaFileAssert.assertThat(apiFile).fileDoesNotContain( |
| 5773 | + "import io.swagger.v3.oas.annotations.media.Schema;" |
| 5774 | + ); |
| 5775 | + } |
| 5776 | + |
| 5777 | + @Test |
| 5778 | + public void annotationLibraryDoesNotCauseImportConflictsInSpringWithAnnotationLibrary() throws IOException { |
| 5779 | + Map<String, Object> properties = new HashMap<>(); |
| 5780 | + properties.put("documentationProvider", "source"); |
| 5781 | + properties.put("annotationLibrary", "swagger2"); |
| 5782 | + |
| 5783 | + File output = Files.createTempDirectory("test").toFile(); |
| 5784 | + output.deleteOnExit(); |
| 5785 | + |
| 5786 | + final OpenAPI openAPI = TestUtils.parseFlattenSpec("src/test/resources/3_0/java/native/issue21991.yaml"); |
| 5787 | + |
| 5788 | + SpringCodegen codegen = new SpringCodegen(); |
| 5789 | + codegen.setOpenAPI(openAPI); |
| 5790 | + codegen.setLibrary(SPRING_BOOT); |
| 5791 | + codegen.setOutputDir(output.getAbsolutePath()); |
| 5792 | + codegen.additionalProperties().putAll(properties); |
| 5793 | + |
| 5794 | + ClientOptInput input = new ClientOptInput() |
| 5795 | + .openAPI(openAPI) |
| 5796 | + .config(codegen); |
| 5797 | + |
| 5798 | + DefaultGenerator generator = new DefaultGenerator(); |
| 5799 | + |
| 5800 | + Map<String, File> files = generator.opts(input).generate().stream() |
| 5801 | + .collect(Collectors.toMap(File::getName, Function.identity())); |
| 5802 | + |
| 5803 | + File apiFile = files.get("Schema.java"); |
| 5804 | + assertNotNull(apiFile); |
| 5805 | + |
| 5806 | + JavaFileAssert.assertThat(apiFile).fileContains( |
| 5807 | + "import io.swagger.v3.oas.annotations.media.Schema;" |
| 5808 | + ); |
| 5809 | + } |
5741 | 5810 | }
|
0 commit comments