|
16 | 16 | import org.openapitools.codegen.config.CodegenConfigurator; |
17 | 17 | import org.openapitools.codegen.kotlin.KotlinTestUtils; |
18 | 18 | import org.openapitools.codegen.kotlin.assertions.KotlinFileAssert; |
| 19 | +import org.openapitools.codegen.languages.AbstractKotlinCodegen; |
19 | 20 | import org.openapitools.codegen.languages.KotlinSpringServerCodegen; |
20 | 21 | import org.openapitools.codegen.languages.features.CXFServerFeatures; |
21 | 22 | import org.openapitools.codegen.languages.features.DocumentationProviderFeatures; |
@@ -4735,6 +4736,169 @@ public void testCompanionObjectGeneratesCompanionInModel() throws IOException { |
4735 | 4736 | "companion object { }" |
4736 | 4737 | ); |
4737 | 4738 | } |
| 4739 | + |
| 4740 | + @Test |
| 4741 | + public void shouldRefuseJackson3WithoutSpringBoot4() throws IOException { |
| 4742 | + File output = Files.createTempDirectory("test").toFile().getCanonicalFile(); |
| 4743 | + output.deleteOnExit(); |
| 4744 | + |
| 4745 | + final OpenAPI openAPI = TestUtils.parseFlattenSpec("src/test/resources/3_0/petstore.yaml"); |
| 4746 | + final KotlinSpringServerCodegen codegen = new KotlinSpringServerCodegen(); |
| 4747 | + codegen.setOpenAPI(openAPI); |
| 4748 | + codegen.setOutputDir(output.getAbsolutePath()); |
| 4749 | + |
| 4750 | + codegen.additionalProperties().put(KotlinSpringServerCodegen.USE_SPRING_BOOT4, "false"); |
| 4751 | + codegen.additionalProperties().put(AbstractKotlinCodegen.USE_JACKSON_3, "true"); |
| 4752 | + |
| 4753 | + ClientOptInput input = new ClientOptInput(); |
| 4754 | + input.openAPI(openAPI); |
| 4755 | + input.config(codegen); |
| 4756 | + |
| 4757 | + DefaultGenerator generator = new DefaultGenerator(); |
| 4758 | + generator.opts(input); |
| 4759 | + |
| 4760 | + Assertions.assertThatExceptionOfType(IllegalArgumentException.class) |
| 4761 | + .isThrownBy(generator::generate); |
| 4762 | + } |
| 4763 | + |
| 4764 | + @Test |
| 4765 | + public void shouldRefuseSpringBoot3AndSpringBoot4Together() throws IOException { |
| 4766 | + File output = Files.createTempDirectory("test").toFile().getCanonicalFile(); |
| 4767 | + output.deleteOnExit(); |
| 4768 | + |
| 4769 | + final OpenAPI openAPI = TestUtils.parseFlattenSpec("src/test/resources/3_0/petstore.yaml"); |
| 4770 | + final KotlinSpringServerCodegen codegen = new KotlinSpringServerCodegen(); |
| 4771 | + codegen.setOpenAPI(openAPI); |
| 4772 | + codegen.setOutputDir(output.getAbsolutePath()); |
| 4773 | + |
| 4774 | + codegen.additionalProperties().put(KotlinSpringServerCodegen.USE_SPRING_BOOT3, "true"); |
| 4775 | + codegen.additionalProperties().put(KotlinSpringServerCodegen.USE_SPRING_BOOT4, "true"); |
| 4776 | + |
| 4777 | + ClientOptInput input = new ClientOptInput(); |
| 4778 | + input.openAPI(openAPI); |
| 4779 | + input.config(codegen); |
| 4780 | + |
| 4781 | + DefaultGenerator generator = new DefaultGenerator(); |
| 4782 | + generator.opts(input); |
| 4783 | + |
| 4784 | + Assertions.assertThatExceptionOfType(IllegalArgumentException.class) |
| 4785 | + .isThrownBy(generator::generate); |
| 4786 | + } |
| 4787 | + |
| 4788 | + @Test |
| 4789 | + public void shouldRefuseOpenApiNullableWithJackson3() throws IOException { |
| 4790 | + File output = Files.createTempDirectory("test").toFile().getCanonicalFile(); |
| 4791 | + output.deleteOnExit(); |
| 4792 | + |
| 4793 | + final OpenAPI openAPI = TestUtils.parseFlattenSpec("src/test/resources/3_0/petstore.yaml"); |
| 4794 | + final KotlinSpringServerCodegen codegen = new KotlinSpringServerCodegen(); |
| 4795 | + codegen.setOpenAPI(openAPI); |
| 4796 | + codegen.setOutputDir(output.getAbsolutePath()); |
| 4797 | + |
| 4798 | + codegen.additionalProperties().put(KotlinSpringServerCodegen.USE_SPRING_BOOT4, "true"); |
| 4799 | + codegen.additionalProperties().put(AbstractKotlinCodegen.USE_JACKSON_3, "true"); |
| 4800 | + codegen.additionalProperties().put("openApiNullable", "true"); |
| 4801 | + |
| 4802 | + ClientOptInput input = new ClientOptInput(); |
| 4803 | + input.openAPI(openAPI); |
| 4804 | + input.config(codegen); |
| 4805 | + |
| 4806 | + DefaultGenerator generator = new DefaultGenerator(); |
| 4807 | + generator.opts(input); |
| 4808 | + |
| 4809 | + Assertions.assertThatExceptionOfType(IllegalArgumentException.class) |
| 4810 | + .isThrownBy(generator::generate); |
| 4811 | + } |
| 4812 | + |
| 4813 | + @Test |
| 4814 | + public void shouldUseJakartaImportsWithSpringBoot4() throws IOException { |
| 4815 | + File output = Files.createTempDirectory("test").toFile().getCanonicalFile(); |
| 4816 | + output.deleteOnExit(); |
| 4817 | + String outputPath = output.getAbsolutePath().replace('\\', '/'); |
| 4818 | + |
| 4819 | + final OpenAPI openAPI = TestUtils.parseFlattenSpec("src/test/resources/3_0/petstore.yaml"); |
| 4820 | + final KotlinSpringServerCodegen codegen = new KotlinSpringServerCodegen(); |
| 4821 | + codegen.setOpenAPI(openAPI); |
| 4822 | + codegen.setOutputDir(output.getAbsolutePath()); |
| 4823 | + |
| 4824 | + codegen.additionalProperties().put(KotlinSpringServerCodegen.USE_SPRING_BOOT4, "true"); |
| 4825 | + codegen.additionalProperties().put(DOCUMENTATION_PROVIDER, DocumentationProvider.NONE.toCliOptValue()); |
| 4826 | + codegen.additionalProperties().put(ANNOTATION_LIBRARY, AnnotationLibrary.NONE.toCliOptValue()); |
| 4827 | + |
| 4828 | + ClientOptInput input = new ClientOptInput(); |
| 4829 | + input.openAPI(openAPI); |
| 4830 | + input.config(codegen); |
| 4831 | + |
| 4832 | + DefaultGenerator generator = new DefaultGenerator(); |
| 4833 | + generator.setGenerateMetadata(false); |
| 4834 | + generator.opts(input).generate(); |
| 4835 | + |
| 4836 | + Path modelPath = Paths.get(outputPath + "/src/main/kotlin/org/openapitools/model/Pet.kt"); |
| 4837 | + assertFileContains(modelPath, "jakarta.validation"); |
| 4838 | + assertFileNotContains(modelPath, "javax.validation"); |
| 4839 | + } |
| 4840 | + |
| 4841 | + @Test |
| 4842 | + public void shouldGenerateSpringBoot4PomWithJackson3Deps() throws IOException { |
| 4843 | + File output = Files.createTempDirectory("test").toFile().getCanonicalFile(); |
| 4844 | + output.deleteOnExit(); |
| 4845 | + String outputPath = output.getAbsolutePath().replace('\\', '/'); |
| 4846 | + |
| 4847 | + final OpenAPI openAPI = TestUtils.parseFlattenSpec("src/test/resources/3_0/petstore.yaml"); |
| 4848 | + final KotlinSpringServerCodegen codegen = new KotlinSpringServerCodegen(); |
| 4849 | + codegen.setOpenAPI(openAPI); |
| 4850 | + codegen.setOutputDir(output.getAbsolutePath()); |
| 4851 | + |
| 4852 | + codegen.additionalProperties().put(KotlinSpringServerCodegen.USE_SPRING_BOOT4, "true"); |
| 4853 | + codegen.additionalProperties().put(AbstractKotlinCodegen.USE_JACKSON_3, "true"); |
| 4854 | + codegen.additionalProperties().put(DOCUMENTATION_PROVIDER, DocumentationProvider.NONE.toCliOptValue()); |
| 4855 | + codegen.additionalProperties().put(ANNOTATION_LIBRARY, AnnotationLibrary.NONE.toCliOptValue()); |
| 4856 | + |
| 4857 | + ClientOptInput input = new ClientOptInput(); |
| 4858 | + input.openAPI(openAPI); |
| 4859 | + input.config(codegen); |
| 4860 | + |
| 4861 | + DefaultGenerator generator = new DefaultGenerator(); |
| 4862 | + generator.setGenerateMetadata(false); |
| 4863 | + generator.opts(input).generate(); |
| 4864 | + |
| 4865 | + Path pomPath = Paths.get(outputPath + "/pom.xml"); |
| 4866 | + assertFileContains(pomPath, "spring-boot-starter-parent"); |
| 4867 | + assertFileContains(pomPath, "4.0.1"); |
| 4868 | + assertFileContains(pomPath, "tools.jackson.dataformat"); |
| 4869 | + assertFileContains(pomPath, "tools.jackson.module"); |
| 4870 | + assertFileNotContains(pomPath, "jackson-datatype-jsr310"); |
| 4871 | + } |
| 4872 | + |
| 4873 | + @Test |
| 4874 | + public void shouldGenerateSpringBoot4PomWithJackson2Deps() throws IOException { |
| 4875 | + File output = Files.createTempDirectory("test").toFile().getCanonicalFile(); |
| 4876 | + output.deleteOnExit(); |
| 4877 | + String outputPath = output.getAbsolutePath().replace('\\', '/'); |
| 4878 | + |
| 4879 | + final OpenAPI openAPI = TestUtils.parseFlattenSpec("src/test/resources/3_0/petstore.yaml"); |
| 4880 | + final KotlinSpringServerCodegen codegen = new KotlinSpringServerCodegen(); |
| 4881 | + codegen.setOpenAPI(openAPI); |
| 4882 | + codegen.setOutputDir(output.getAbsolutePath()); |
| 4883 | + |
| 4884 | + codegen.additionalProperties().put(KotlinSpringServerCodegen.USE_SPRING_BOOT4, "true"); |
| 4885 | + codegen.additionalProperties().put(AbstractKotlinCodegen.USE_JACKSON_3, "false"); |
| 4886 | + codegen.additionalProperties().put(DOCUMENTATION_PROVIDER, DocumentationProvider.NONE.toCliOptValue()); |
| 4887 | + codegen.additionalProperties().put(ANNOTATION_LIBRARY, AnnotationLibrary.NONE.toCliOptValue()); |
| 4888 | + |
| 4889 | + ClientOptInput input = new ClientOptInput(); |
| 4890 | + input.openAPI(openAPI); |
| 4891 | + input.config(codegen); |
| 4892 | + |
| 4893 | + DefaultGenerator generator = new DefaultGenerator(); |
| 4894 | + generator.setGenerateMetadata(false); |
| 4895 | + generator.opts(input).generate(); |
| 4896 | + |
| 4897 | + Path pomPath = Paths.get(outputPath + "/pom.xml"); |
| 4898 | + assertFileContains(pomPath, "4.0.1"); |
| 4899 | + assertFileContains(pomPath, "com.fasterxml.jackson.dataformat"); |
| 4900 | + assertFileContains(pomPath, "jackson-datatype-jsr310"); |
| 4901 | + } |
4738 | 4902 | } |
4739 | 4903 |
|
4740 | 4904 |
|
0 commit comments