|
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; |
@@ -4706,6 +4707,169 @@ public void testDeprecatedAnnotationOnController() throws IOException { |
4706 | 4707 | "@Deprecated(message=\"Operation is deprecated\") @RequestMapping(" |
4707 | 4708 | ); |
4708 | 4709 | } |
| 4710 | + |
| 4711 | + @Test |
| 4712 | + public void shouldRefuseJackson3WithoutSpringBoot4() throws IOException { |
| 4713 | + File output = Files.createTempDirectory("test").toFile().getCanonicalFile(); |
| 4714 | + output.deleteOnExit(); |
| 4715 | + |
| 4716 | + final OpenAPI openAPI = TestUtils.parseFlattenSpec("src/test/resources/3_0/petstore.yaml"); |
| 4717 | + final KotlinSpringServerCodegen codegen = new KotlinSpringServerCodegen(); |
| 4718 | + codegen.setOpenAPI(openAPI); |
| 4719 | + codegen.setOutputDir(output.getAbsolutePath()); |
| 4720 | + |
| 4721 | + codegen.additionalProperties().put(KotlinSpringServerCodegen.USE_SPRING_BOOT4, "false"); |
| 4722 | + codegen.additionalProperties().put(AbstractKotlinCodegen.USE_JACKSON_3, "true"); |
| 4723 | + |
| 4724 | + ClientOptInput input = new ClientOptInput(); |
| 4725 | + input.openAPI(openAPI); |
| 4726 | + input.config(codegen); |
| 4727 | + |
| 4728 | + DefaultGenerator generator = new DefaultGenerator(); |
| 4729 | + generator.opts(input); |
| 4730 | + |
| 4731 | + Assertions.assertThatExceptionOfType(IllegalArgumentException.class) |
| 4732 | + .isThrownBy(generator::generate); |
| 4733 | + } |
| 4734 | + |
| 4735 | + @Test |
| 4736 | + public void shouldRefuseSpringBoot3AndSpringBoot4Together() throws IOException { |
| 4737 | + File output = Files.createTempDirectory("test").toFile().getCanonicalFile(); |
| 4738 | + output.deleteOnExit(); |
| 4739 | + |
| 4740 | + final OpenAPI openAPI = TestUtils.parseFlattenSpec("src/test/resources/3_0/petstore.yaml"); |
| 4741 | + final KotlinSpringServerCodegen codegen = new KotlinSpringServerCodegen(); |
| 4742 | + codegen.setOpenAPI(openAPI); |
| 4743 | + codegen.setOutputDir(output.getAbsolutePath()); |
| 4744 | + |
| 4745 | + codegen.additionalProperties().put(KotlinSpringServerCodegen.USE_SPRING_BOOT3, "true"); |
| 4746 | + codegen.additionalProperties().put(KotlinSpringServerCodegen.USE_SPRING_BOOT4, "true"); |
| 4747 | + |
| 4748 | + ClientOptInput input = new ClientOptInput(); |
| 4749 | + input.openAPI(openAPI); |
| 4750 | + input.config(codegen); |
| 4751 | + |
| 4752 | + DefaultGenerator generator = new DefaultGenerator(); |
| 4753 | + generator.opts(input); |
| 4754 | + |
| 4755 | + Assertions.assertThatExceptionOfType(IllegalArgumentException.class) |
| 4756 | + .isThrownBy(generator::generate); |
| 4757 | + } |
| 4758 | + |
| 4759 | + @Test |
| 4760 | + public void shouldRefuseOpenApiNullableWithJackson3() throws IOException { |
| 4761 | + File output = Files.createTempDirectory("test").toFile().getCanonicalFile(); |
| 4762 | + output.deleteOnExit(); |
| 4763 | + |
| 4764 | + final OpenAPI openAPI = TestUtils.parseFlattenSpec("src/test/resources/3_0/petstore.yaml"); |
| 4765 | + final KotlinSpringServerCodegen codegen = new KotlinSpringServerCodegen(); |
| 4766 | + codegen.setOpenAPI(openAPI); |
| 4767 | + codegen.setOutputDir(output.getAbsolutePath()); |
| 4768 | + |
| 4769 | + codegen.additionalProperties().put(KotlinSpringServerCodegen.USE_SPRING_BOOT4, "true"); |
| 4770 | + codegen.additionalProperties().put(AbstractKotlinCodegen.USE_JACKSON_3, "true"); |
| 4771 | + codegen.additionalProperties().put("openApiNullable", "true"); |
| 4772 | + |
| 4773 | + ClientOptInput input = new ClientOptInput(); |
| 4774 | + input.openAPI(openAPI); |
| 4775 | + input.config(codegen); |
| 4776 | + |
| 4777 | + DefaultGenerator generator = new DefaultGenerator(); |
| 4778 | + generator.opts(input); |
| 4779 | + |
| 4780 | + Assertions.assertThatExceptionOfType(IllegalArgumentException.class) |
| 4781 | + .isThrownBy(generator::generate); |
| 4782 | + } |
| 4783 | + |
| 4784 | + @Test |
| 4785 | + public void shouldUseJakartaImportsWithSpringBoot4() throws IOException { |
| 4786 | + File output = Files.createTempDirectory("test").toFile().getCanonicalFile(); |
| 4787 | + output.deleteOnExit(); |
| 4788 | + String outputPath = output.getAbsolutePath().replace('\\', '/'); |
| 4789 | + |
| 4790 | + final OpenAPI openAPI = TestUtils.parseFlattenSpec("src/test/resources/3_0/petstore.yaml"); |
| 4791 | + final KotlinSpringServerCodegen codegen = new KotlinSpringServerCodegen(); |
| 4792 | + codegen.setOpenAPI(openAPI); |
| 4793 | + codegen.setOutputDir(output.getAbsolutePath()); |
| 4794 | + |
| 4795 | + codegen.additionalProperties().put(KotlinSpringServerCodegen.USE_SPRING_BOOT4, "true"); |
| 4796 | + codegen.additionalProperties().put(DOCUMENTATION_PROVIDER, DocumentationProvider.NONE.toCliOptValue()); |
| 4797 | + codegen.additionalProperties().put(ANNOTATION_LIBRARY, AnnotationLibrary.NONE.toCliOptValue()); |
| 4798 | + |
| 4799 | + ClientOptInput input = new ClientOptInput(); |
| 4800 | + input.openAPI(openAPI); |
| 4801 | + input.config(codegen); |
| 4802 | + |
| 4803 | + DefaultGenerator generator = new DefaultGenerator(); |
| 4804 | + generator.setGenerateMetadata(false); |
| 4805 | + generator.opts(input).generate(); |
| 4806 | + |
| 4807 | + Path modelPath = Paths.get(outputPath + "/src/main/kotlin/org/openapitools/model/Pet.kt"); |
| 4808 | + assertFileContains(modelPath, "jakarta.validation"); |
| 4809 | + assertFileNotContains(modelPath, "javax.validation"); |
| 4810 | + } |
| 4811 | + |
| 4812 | + @Test |
| 4813 | + public void shouldGenerateSpringBoot4PomWithJackson3Deps() throws IOException { |
| 4814 | + File output = Files.createTempDirectory("test").toFile().getCanonicalFile(); |
| 4815 | + output.deleteOnExit(); |
| 4816 | + String outputPath = output.getAbsolutePath().replace('\\', '/'); |
| 4817 | + |
| 4818 | + final OpenAPI openAPI = TestUtils.parseFlattenSpec("src/test/resources/3_0/petstore.yaml"); |
| 4819 | + final KotlinSpringServerCodegen codegen = new KotlinSpringServerCodegen(); |
| 4820 | + codegen.setOpenAPI(openAPI); |
| 4821 | + codegen.setOutputDir(output.getAbsolutePath()); |
| 4822 | + |
| 4823 | + codegen.additionalProperties().put(KotlinSpringServerCodegen.USE_SPRING_BOOT4, "true"); |
| 4824 | + codegen.additionalProperties().put(AbstractKotlinCodegen.USE_JACKSON_3, "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 pomPath = Paths.get(outputPath + "/pom.xml"); |
| 4837 | + assertFileContains(pomPath, "spring-boot-starter-parent"); |
| 4838 | + assertFileContains(pomPath, "4.0.1"); |
| 4839 | + assertFileContains(pomPath, "tools.jackson.dataformat"); |
| 4840 | + assertFileContains(pomPath, "tools.jackson.module"); |
| 4841 | + assertFileNotContains(pomPath, "jackson-datatype-jsr310"); |
| 4842 | + } |
| 4843 | + |
| 4844 | + @Test |
| 4845 | + public void shouldGenerateSpringBoot4PomWithJackson2Deps() throws IOException { |
| 4846 | + File output = Files.createTempDirectory("test").toFile().getCanonicalFile(); |
| 4847 | + output.deleteOnExit(); |
| 4848 | + String outputPath = output.getAbsolutePath().replace('\\', '/'); |
| 4849 | + |
| 4850 | + final OpenAPI openAPI = TestUtils.parseFlattenSpec("src/test/resources/3_0/petstore.yaml"); |
| 4851 | + final KotlinSpringServerCodegen codegen = new KotlinSpringServerCodegen(); |
| 4852 | + codegen.setOpenAPI(openAPI); |
| 4853 | + codegen.setOutputDir(output.getAbsolutePath()); |
| 4854 | + |
| 4855 | + codegen.additionalProperties().put(KotlinSpringServerCodegen.USE_SPRING_BOOT4, "true"); |
| 4856 | + codegen.additionalProperties().put(AbstractKotlinCodegen.USE_JACKSON_3, "false"); |
| 4857 | + codegen.additionalProperties().put(DOCUMENTATION_PROVIDER, DocumentationProvider.NONE.toCliOptValue()); |
| 4858 | + codegen.additionalProperties().put(ANNOTATION_LIBRARY, AnnotationLibrary.NONE.toCliOptValue()); |
| 4859 | + |
| 4860 | + ClientOptInput input = new ClientOptInput(); |
| 4861 | + input.openAPI(openAPI); |
| 4862 | + input.config(codegen); |
| 4863 | + |
| 4864 | + DefaultGenerator generator = new DefaultGenerator(); |
| 4865 | + generator.setGenerateMetadata(false); |
| 4866 | + generator.opts(input).generate(); |
| 4867 | + |
| 4868 | + Path pomPath = Paths.get(outputPath + "/pom.xml"); |
| 4869 | + assertFileContains(pomPath, "4.0.1"); |
| 4870 | + assertFileContains(pomPath, "com.fasterxml.jackson.dataformat"); |
| 4871 | + assertFileContains(pomPath, "jackson-datatype-jsr310"); |
| 4872 | + } |
4709 | 4873 | } |
4710 | 4874 |
|
4711 | 4875 |
|
0 commit comments