|
22 | 22 | import com.github.javaparser.ast.body.FieldDeclaration;
|
23 | 23 | import com.github.javaparser.ast.expr.Expression;
|
24 | 24 | import com.github.javaparser.ast.expr.MethodCallExpr;
|
25 |
| -import com.github.javaparser.ast.visitor.*; |
| 25 | +import com.github.javaparser.ast.visitor.VoidVisitorAdapter; |
26 | 26 | import com.google.common.collect.ImmutableMap;
|
27 | 27 | import io.swagger.parser.OpenAPIParser;
|
28 | 28 | import io.swagger.v3.oas.models.OpenAPI;
|
|
40 | 40 | import org.openapitools.codegen.java.assertions.JavaFileAssert;
|
41 | 41 | import org.openapitools.codegen.languages.AbstractJavaCodegen;
|
42 | 42 | import org.openapitools.codegen.languages.JavaClientCodegen;
|
43 |
| -import org.openapitools.codegen.languages.RubyClientCodegen; |
44 | 43 | import org.openapitools.codegen.languages.features.BeanValidationFeatures;
|
45 | 44 | import org.openapitools.codegen.languages.features.CXFServerFeatures;
|
46 | 45 | import org.openapitools.codegen.meta.features.SecurityFeature;
|
|
49 | 48 | import org.openapitools.codegen.testutils.ConfigAssert;
|
50 | 49 | import org.testng.Assert;
|
51 | 50 | import org.testng.annotations.DataProvider;
|
52 |
| -import org.testng.annotations.Parameters; |
53 | 51 | import org.testng.annotations.Test;
|
54 | 52 |
|
55 | 53 | import java.io.File;
|
@@ -1791,13 +1789,71 @@ public void testJdkHttpClientWithAndWithoutParentExtension() {
|
1791 | 1789 | List<File> files = generator.opts(configurator.toClientOptInput()).generate();
|
1792 | 1790 |
|
1793 | 1791 | validateJavaSourceFiles(files);
|
1794 |
| - assertThat(files).hasSize(42); |
| 1792 | + assertThat(files).hasSize(48); |
1795 | 1793 | assertThat(output.resolve("src/main/java/xyz/abcdef/model/Child.java"))
|
1796 | 1794 | .content().contains("public class Child extends Person {");
|
1797 | 1795 | assertThat(output.resolve("src/main/java/xyz/abcdef/model/Adult.java"))
|
1798 | 1796 | .content().contains("public class Adult extends Person {");
|
1799 |
| - assertThat(output.resolve("src/main/java/xyz/abcdef/model/SchemaWithTwoParents.java")) |
1800 |
| - .content().contains("public class SchemaWithTwoParents {"); |
| 1797 | + assertThat(output.resolve("src/main/java/xyz/abcdef/model/SchemaWithTwoAllOfRefs.java")) |
| 1798 | + .content().contains("public class SchemaWithTwoAllOfRefs {"); |
| 1799 | + assertThat(output.resolve("src/main/java/xyz/abcdef/model/AnotherChild.java")) |
| 1800 | + .content().contains("public class AnotherChild {"); |
| 1801 | + } |
| 1802 | + |
| 1803 | + @Test |
| 1804 | + public void allOfWithSeveralRefsAndRefAsParentInAllOfNormalizationIsTrue() { |
| 1805 | + final Path output = newTempFolder(); |
| 1806 | + final CodegenConfigurator configurator = new CodegenConfigurator() |
| 1807 | + .setGeneratorName(JAVA_GENERATOR) |
| 1808 | + .addAdditionalProperty(CodegenConstants.API_PACKAGE, "xyz.abcdef.api") |
| 1809 | + .addAdditionalProperty(CodegenConstants.MODEL_PACKAGE, "xyz.abcdef.model") |
| 1810 | + .addAdditionalProperty(CodegenConstants.INVOKER_PACKAGE, "xyz.abcdef.invoker") |
| 1811 | + .addOpenapiNormalizer("REF_AS_PARENT_IN_ALLOF", "true") |
| 1812 | + .setInputSpec("src/test/resources/3_0/allOf_extension_parent.yaml") |
| 1813 | + .setOutputDir(output.toString().replace("\\", "/")); |
| 1814 | + |
| 1815 | + DefaultGenerator generator = new DefaultGenerator(); |
| 1816 | + generator.setGeneratorPropertyDefault(CodegenConstants.MODELS, "true"); |
| 1817 | + generator.setGeneratorPropertyDefault(CodegenConstants.APIS, "true"); |
| 1818 | + List<File> files = generator.opts(configurator.toClientOptInput()).generate(); |
| 1819 | + |
| 1820 | + validateJavaSourceFiles(files); |
| 1821 | + assertThat(files).hasSize(48); |
| 1822 | + assertThat(output.resolve("src/main/java/xyz/abcdef/model/Child.java")) |
| 1823 | + .content().contains("public class Child extends Person {"); |
| 1824 | + assertThat(output.resolve("src/main/java/xyz/abcdef/model/Adult.java")) |
| 1825 | + .content().contains("public class Adult extends Person {"); |
| 1826 | + // The class does not extend a parent since the REF_AS_PARENT_IN_ALLOF normalizer will assign it two parents |
| 1827 | + assertThat(output.resolve("src/main/java/xyz/abcdef/model/SchemaWithTwoAllOfRefsOneIsMarkedAsParent.java")) |
| 1828 | + .content().contains("public class SchemaWithTwoAllOfRefsOneIsMarkedAsParent {"); |
| 1829 | + assertThat(output.resolve("src/main/java/xyz/abcdef/model/AnotherChild.java")) |
| 1830 | + .content().contains("public class AnotherChild extends AnotherPerson {"); |
| 1831 | + } |
| 1832 | + |
| 1833 | + @Test |
| 1834 | + public void allOfWithSeveralRefsButOnlyOneIsMarkedAsParent() { |
| 1835 | + final Path output = newTempFolder(); |
| 1836 | + final CodegenConfigurator configurator = new CodegenConfigurator() |
| 1837 | + .setGeneratorName(JAVA_GENERATOR) |
| 1838 | + .addAdditionalProperty(CodegenConstants.API_PACKAGE, "xyz.abcdef.api") |
| 1839 | + .addAdditionalProperty(CodegenConstants.MODEL_PACKAGE, "xyz.abcdef.model") |
| 1840 | + .addAdditionalProperty(CodegenConstants.INVOKER_PACKAGE, "xyz.abcdef.invoker") |
| 1841 | + .setInputSpec("src/test/resources/3_0/allOf_extension_parent.yaml") |
| 1842 | + .setOutputDir(output.toString().replace("\\", "/")); |
| 1843 | + |
| 1844 | + DefaultGenerator generator = new DefaultGenerator(); |
| 1845 | + generator.setGeneratorPropertyDefault(CodegenConstants.MODELS, "true"); |
| 1846 | + generator.setGeneratorPropertyDefault(CodegenConstants.APIS, "true"); |
| 1847 | + List<File> files = generator.opts(configurator.toClientOptInput()).generate(); |
| 1848 | + |
| 1849 | + validateJavaSourceFiles(files); |
| 1850 | + assertThat(files).hasSize(48); |
| 1851 | + assertThat(output.resolve("src/main/java/xyz/abcdef/model/Child.java")) |
| 1852 | + .content().contains("public class Child extends Person {"); |
| 1853 | + assertThat(output.resolve("src/main/java/xyz/abcdef/model/Adult.java")) |
| 1854 | + .content().contains("public class Adult extends Person {"); |
| 1855 | + assertThat(output.resolve("src/main/java/xyz/abcdef/model/SchemaWithTwoAllOfRefsOneIsMarkedAsParent.java")) |
| 1856 | + .content().contains("public class SchemaWithTwoAllOfRefsOneIsMarkedAsParent extends PersonAExplicitParent {"); |
1801 | 1857 | assertThat(output.resolve("src/main/java/xyz/abcdef/model/AnotherChild.java"))
|
1802 | 1858 | .content().contains("public class AnotherChild {");
|
1803 | 1859 | }
|
@@ -3986,15 +4042,15 @@ public void oneOfWithInnerModelTest() {
|
3986 | 4042 | }
|
3987 | 4043 |
|
3988 | 4044 | @Test
|
3989 |
| - public void testOneOfClassWithAnnotation() throws IOException { |
| 4045 | + public void testOneOfClassWithAnnotation() { |
3990 | 4046 | final Map<String, File> files = generateFromContract("src/test/resources/3_0/java/oneOf-with-annotations.yaml", RESTCLIENT);
|
3991 | 4047 | JavaFileAssert.assertThat(files.get("Fruit.java"))
|
3992 | 4048 | .isNormalClass()
|
3993 | 4049 | .assertTypeAnnotations().containsWithName("SuppressWarnings");
|
3994 | 4050 | }
|
3995 | 4051 |
|
3996 | 4052 | @Test
|
3997 |
| - public void testOneOfInterfaceWithAnnotation() throws IOException { |
| 4053 | + public void testOneOfInterfaceWithAnnotation() { |
3998 | 4054 | final Map<String, File> files = generateFromContract("src/test/resources/3_0/java/oneOf-with-annotations.yaml", RESTCLIENT,
|
3999 | 4055 | Map.of(USE_ONE_OF_INTERFACES, "true"));
|
4000 | 4056 | JavaFileAssert.assertThat(files.get("Fruit.java"))
|
|
0 commit comments