diff --git a/modules/openapi-generator/src/test/java/org/openapitools/codegen/DefaultCodegenTest.java b/modules/openapi-generator/src/test/java/org/openapitools/codegen/DefaultCodegenTest.java index daaea9a2637..1c0631f98cc 100644 --- a/modules/openapi-generator/src/test/java/org/openapitools/codegen/DefaultCodegenTest.java +++ b/modules/openapi-generator/src/test/java/org/openapitools/codegen/DefaultCodegenTest.java @@ -2592,9 +2592,9 @@ public class DefaultCodegenTest { DefaultGenerator generator = new DefaultGenerator(); List files = generator.opts(clientOptInput).generate(); - TestUtils.ensureDoesNotContainsFile(files, output, "src/main/java/org/openapitools/client/model/FreeFormWithValidation.java"); - TestUtils.ensureDoesNotContainsFile(files, output, "src/main/java/org/openapitools/client/model/FreeFormInterface.java"); - TestUtils.ensureDoesNotContainsFile(files, output, "src/main/java/org/openapitools/client/model/FreeForm.java"); + TestUtils.ensureDoesNotContainFile(files, output, "src/main/java/org/openapitools/client/model/FreeFormWithValidation.java"); + TestUtils.ensureDoesNotContainFile(files, output, "src/main/java/org/openapitools/client/model/FreeFormInterface.java"); + TestUtils.ensureDoesNotContainFile(files, output, "src/main/java/org/openapitools/client/model/FreeForm.java"); output.deleteOnExit(); } diff --git a/modules/openapi-generator/src/test/java/org/openapitools/codegen/DefaultGeneratorTest.java b/modules/openapi-generator/src/test/java/org/openapitools/codegen/DefaultGeneratorTest.java index b456a5f73fa..ae5f43ab69a 100644 --- a/modules/openapi-generator/src/test/java/org/openapitools/codegen/DefaultGeneratorTest.java +++ b/modules/openapi-generator/src/test/java/org/openapitools/codegen/DefaultGeneratorTest.java @@ -86,29 +86,29 @@ public class DefaultGeneratorTest { TestUtils.ensureContainsFile(files, output, "build.gradle"); Assert.assertTrue(new File(output, "build.gradle").exists()); - TestUtils.ensureDoesNotContainsFile(files, output, "api/openapi.yaml"); + TestUtils.ensureDoesNotContainFile(files, output, "api/openapi.yaml"); Assert.assertFalse(new File(output, "api").exists()); - TestUtils.ensureDoesNotContainsFile(files, output, ".github/workflows/"); + TestUtils.ensureDoesNotContainFile(files, output, ".github/workflows/"); Assert.assertFalse(new File(output, ".github").exists()); // Check excluded files - TestUtils.ensureDoesNotContainsFile(files, output, ".travis.yml"); + TestUtils.ensureDoesNotContainFile(files, output, ".travis.yml"); Assert.assertFalse(new File(output, ".travis.yml").exists()); - TestUtils.ensureDoesNotContainsFile(files, output, "build.sbt"); + TestUtils.ensureDoesNotContainFile(files, output, "build.sbt"); Assert.assertFalse(new File(output, "build.sbt").exists()); - TestUtils.ensureDoesNotContainsFile(files, output, "src/main/AndroidManifest.xml"); + TestUtils.ensureDoesNotContainFile(files, output, "src/main/AndroidManifest.xml"); Assert.assertFalse(new File(output, "src/main/AndroidManifest.xml").exists()); - TestUtils.ensureDoesNotContainsFile(files, output, "pom.xml"); + TestUtils.ensureDoesNotContainFile(files, output, "pom.xml"); Assert.assertFalse(new File(output, "pom.xml").exists()); - TestUtils.ensureDoesNotContainsFile(files, output, "src/test/java/org/openapitools/client/model/CategoryTest.java"); + TestUtils.ensureDoesNotContainFile(files, output, "src/test/java/org/openapitools/client/model/CategoryTest.java"); Assert.assertFalse(new File(output, "src/test/java/org/openapitools/client/model/CategoryTest.java").exists()); - TestUtils.ensureDoesNotContainsFile(files, output, "src/main/java/org/openapitools/client/api/UserApi.java"); + TestUtils.ensureDoesNotContainFile(files, output, "src/main/java/org/openapitools/client/api/UserApi.java"); Assert.assertFalse(new File(output, "src/main/java/org/openapitools/client/api/UserApi.java").exists()); } finally { output.deleteOnExit(); @@ -162,7 +162,7 @@ public class DefaultGeneratorTest { TestUtils.ensureContainsFile(files, output, "src/main/java/org/openapitools/client/api/PetApi.java"); Assert.assertTrue(new File(output, "src/main/java/org/openapitools/client/api/PetApi.java").exists()); - TestUtils.ensureDoesNotContainsFile(files, output, apiTestRelativePath); + TestUtils.ensureDoesNotContainFile(files, output, apiTestRelativePath); Assert.assertTrue(apiTestFile.exists()); String apiTestContents = Files.readAllLines(apiTestFile.toPath()).get(0); Assert.assertEquals(apiTestContents, "empty", "Expected test file to retain original contents."); @@ -171,7 +171,7 @@ public class DefaultGeneratorTest { TestUtils.ensureContainsFile(files, output, "src/main/java/org/openapitools/client/model/Category.java"); Assert.assertTrue(new File(output, "src/test/java/org/openapitools/client/model/CategoryTest.java").exists()); - TestUtils.ensureDoesNotContainsFile(files, output, modelTestRelativePath); + TestUtils.ensureDoesNotContainFile(files, output, modelTestRelativePath); Assert.assertTrue(modelTestFile.exists()); String modelTestContents = Files.readAllLines(modelTestFile.toPath()).get(0); Assert.assertEquals(modelTestContents, "empty", "Expected test file to retain original contents."); @@ -827,19 +827,19 @@ public class DefaultGeneratorTest { // Check not generated cause backwards compatibility files String ft1FileName = "src/main/java/org/openapitools/model/FT1.java"; - TestUtils.ensureDoesNotContainsFile(files, output, ft1FileName); + TestUtils.ensureDoesNotContainFile(files, output, ft1FileName); Assert.assertFalse(new File(output, ft1FileName).exists()); String ft2FileName = "src/main/java/org/openapitools/model/FT2.java"; - TestUtils.ensureDoesNotContainsFile(files, output, ft2FileName); + TestUtils.ensureDoesNotContainFile(files, output, ft2FileName); Assert.assertFalse(new File(output, ft2FileName).exists()); String ft3FileName = "src/main/java/org/openapitools/model/FT3.java"; - TestUtils.ensureDoesNotContainsFile(files, output, ft3FileName); + TestUtils.ensureDoesNotContainFile(files, output, ft3FileName); Assert.assertFalse(new File(output, ft3FileName).exists()); String bttFileName = "src/main/java/org/openapitools/model/BTT.java"; - TestUtils.ensureDoesNotContainsFile(files, output, bttFileName); + TestUtils.ensureDoesNotContainFile(files, output, bttFileName); Assert.assertFalse(new File(output, bttFileName).exists()); } finally { diff --git a/modules/openapi-generator/src/test/java/org/openapitools/codegen/TestUtils.java b/modules/openapi-generator/src/test/java/org/openapitools/codegen/TestUtils.java index cbce02b1417..72288ac05af 100644 --- a/modules/openapi-generator/src/test/java/org/openapitools/codegen/TestUtils.java +++ b/modules/openapi-generator/src/test/java/org/openapitools/codegen/TestUtils.java @@ -98,7 +98,7 @@ public class TestUtils { assertTrue(generatedFiles.contains(path.toFile()), "File '" + path.toAbsolutePath() + "' was not found in the list of generated files"); } - public static void ensureDoesNotContainsFile(List generatedFiles, File root, String filename) { + public static void ensureDoesNotContainFile(List generatedFiles, File root, String filename) { Path path = root.toPath().resolve(filename); assertFalse(generatedFiles.contains(path.toFile()), "File '" + path.toAbsolutePath() + "' was found in the list of generated files"); } @@ -217,7 +217,7 @@ public class TestUtils { .containsWithName("javax.persistence.Entity") .containsWithNameAndAttributes("javax.persistence.Table", ImmutableMap.of("name", "\"employees\"")) .toType() - .hasProperty("assignments") + .assertProperty("assignments") .assertPropertyAnnotations() .containsWithNameAndAttributes("javax.persistence.OneToMany", ImmutableMap.of("mappedBy", "\"employee\"")) .toProperty() @@ -227,17 +227,17 @@ public class TestUtils { .assertTypeAnnotations() .containsWithName("javax.persistence.MappedSuperclass") .toType() - .hasProperty("id") + .assertProperty("id") .assertPropertyAnnotations() .containsWithName("javax.persistence.Id") .toProperty() .toType() - .hasProperty("email") + .assertProperty("email") .assertPropertyAnnotations() .containsWithName("org.hibernate.annotations.Formula") .toProperty() .toType() - .hasProperty("hasAcceptedTerms") + .assertProperty("hasAcceptedTerms") .assertPropertyAnnotations() .containsWithName("javax.persistence.Transient") .toProperty() @@ -248,13 +248,13 @@ public class TestUtils { .containsWithName("javax.persistence.Entity") .containsWithNameAndAttributes("javax.persistence.Table", ImmutableMap.of("name", "\"survey_groups\"")) .toType() - .hasProperty("assignments") + .assertProperty("assignments") .assertPropertyAnnotations() .containsWithName("javax.persistence.OneToMany") .containsWithNameAndAttributes("javax.persistence.JoinColumn", ImmutableMap.of("name", "\"survey_group_id\"")) .toProperty() .toType() - .hasProperty("disabled") + .assertProperty("disabled") .assertPropertyAnnotations() .containsWithNameAndAttributes("javax.persistence.Column", ImmutableMap.of("nullable", "false")) .toProperty() @@ -265,7 +265,7 @@ public class TestUtils { .containsWithName("javax.persistence.MappedSuperclass") .containsWithName("javax.persistence.EntityListeners") .toType() - .hasProperty("id") + .assertProperty("id") .assertPropertyAnnotations() .containsWithName("javax.persistence.Id") .containsWithNameAndAttributes("javax.persistence.GeneratedValue", ImmutableMap.of("generator", "\"UUID\"")) @@ -273,39 +273,39 @@ public class TestUtils { .containsWithNameAndAttributes("javax.persistence.Column", ImmutableMap.of("name", "\"id\"","updatable", "false","nullable", "false")) .toProperty() .toType() - .hasProperty("createdDate") + .assertProperty("createdDate") .assertPropertyAnnotations() .containsWithName("org.springframework.data.annotation.CreatedDate") .toProperty() .toType() - .hasProperty("createdBy") + .assertProperty("createdBy") .assertPropertyAnnotations() .containsWithName("org.springframework.data.annotation.CreatedBy") .toProperty() .toType() - .hasProperty("modifiedDate") + .assertProperty("modifiedDate") .assertPropertyAnnotations() .containsWithName("org.springframework.data.annotation.LastModifiedDate") .toProperty() .toType() - .hasProperty("modifiedBy") + .assertProperty("modifiedBy") .assertPropertyAnnotations() .containsWithName("org.springframework.data.annotation.LastModifiedBy") .toProperty() .toType() - .hasProperty("opportunityId") + .assertProperty("opportunityId") .assertPropertyAnnotations() .containsWithNameAndAttributes("javax.persistence.Column", ImmutableMap.of("unique", "true")) .toProperty() .toType() - .hasProperty("submissionStatus") + .assertProperty("submissionStatus") .assertPropertyAnnotations() .containsWithName("javax.persistence.Transient") .toProperty() .toType(); JavaFileAssert.assertThat(java.nio.file.Paths.get(baseOutputPath + "/CompanyDto.java")) - .hasProperty("priceCategory") + .assertProperty("priceCategory") .assertPropertyAnnotations() .containsWithNameAndAttributes("IgnoreForRoles", ImmutableMap.of("value", "\"MEDIA_ADMIN\"")); } @@ -319,4 +319,16 @@ public class TestUtils { objs.setModels(modelMaps); return objs; } + + public static Path newTempFolder() { + final Path tempDir; + try { + tempDir = Files.createTempDirectory("test"); + } catch (IOException e) { + throw new RuntimeException(e); + } + tempDir.toFile().deleteOnExit(); + + return tempDir; + } } diff --git a/modules/openapi-generator/src/test/java/org/openapitools/codegen/config/MergedSpecBuilderTest.java b/modules/openapi-generator/src/test/java/org/openapitools/codegen/config/MergedSpecBuilderTest.java index a7d6db4c0f4..f3feed5c126 100644 --- a/modules/openapi-generator/src/test/java/org/openapitools/codegen/config/MergedSpecBuilderTest.java +++ b/modules/openapi-generator/src/test/java/org/openapitools/codegen/config/MergedSpecBuilderTest.java @@ -77,8 +77,8 @@ public class MergedSpecBuilderTest { .assertMethodAnnotations() .containsWithNameAndAttributes("RequestMapping", ImmutableMap.of("value", "\"/spec1/complex/{param1}/path\"")) .toMethod() - .hasParameter("param1") - .withType("String") + .assertParameter("param1") + .hasType("String") .assertParameterAnnotations() .containsWithNameAndAttributes("PathVariable", ImmutableMap.of("value", "\"param1\"")); @@ -92,4 +92,4 @@ public class MergedSpecBuilderTest { .assertMethod("getSpec2Field").hasReturnType("BigDecimal"); } -} \ No newline at end of file +} diff --git a/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/JavaClientCodegenTest.java b/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/JavaClientCodegenTest.java index 942315f1534..bab653d55f1 100644 --- a/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/JavaClientCodegenTest.java +++ b/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/JavaClientCodegenTest.java @@ -60,6 +60,7 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.entry; import static org.assertj.core.api.InstanceOfAssertFactories.FILE; import static org.openapitools.codegen.CodegenConstants.SERIALIZATION_LIBRARY; +import static org.openapitools.codegen.TestUtils.newTempFolder; import static org.openapitools.codegen.TestUtils.validateJavaSourceFiles; import static org.openapitools.codegen.languages.JavaClientCodegen.*; import static org.testng.Assert.*; @@ -1537,13 +1538,13 @@ public class JavaClientCodegenTest { .stream().collect(Collectors.toMap(File::getName, Function.identity())); JavaFileAssert.assertThat(files.get("DefaultValuesType.java")) - .hasProperty("stringDefault") + .assertProperty("stringDefault") .asString().endsWith("= new ArrayList<>();"); JavaFileAssert.assertThat(files.get("DefaultValuesType.java")) - .hasProperty("stringDefault2") + .assertProperty("stringDefault2") .asString().endsWith("= new ArrayList<>(Arrays.asList(\"Hallo\", \"Huhu\"));"); JavaFileAssert.assertThat(files.get("DefaultValuesType.java")) - .hasProperty("objectDefault") + .assertProperty("objectDefault") .asString().endsWith("= new ArrayList<>();"); } @@ -1624,11 +1625,11 @@ public class JavaClientCodegenTest { JavaFileAssert.assertThat(files.get("DefaultApi.java")) .assertMethod("operationWithHttpInfo") - .hasParameter("requestBody") + .assertParameter("requestBody") .assertParameterAnnotations() .containsWithName("NotNull") .toParameter().toMethod() - .hasParameter("xNonNullHeaderParameter") + .assertParameter("xNonNullHeaderParameter") .assertParameterAnnotations() .containsWithName("NotNull"); } @@ -2024,8 +2025,8 @@ public class JavaClientCodegenTest { JavaFileAssert.assertThat(files.get("AbstractOpenApiSchema.java")) .assertTypeAnnotations() - .doesNotContainsWithName("annotation1") - .doesNotContainsWithName("annotation2"); + .doesNotContainWithName("annotation1") + .doesNotContainWithName("annotation2"); JavaFileAssert.assertThat(files.get("Animal.java")) .assertTypeAnnotations() .containsWithName("annotation1") @@ -2679,16 +2680,6 @@ public class JavaClientCodegenTest { "com.fasterxml.jackson.databind.annotation.JsonSerialize" ); } - - static private Path newTempFolder() { - try { - var tempDir = Files.createTempDirectory("test"); - tempDir.toFile().deleteOnExit(); - return tempDir; - } catch (IOException e) { - throw new RuntimeException(e); - } - } /** * General XML annotations test (both JAXB and Jackson) @@ -2698,28 +2689,24 @@ public class JavaClientCodegenTest { * - Microprofile generator missing Jackson annotations and namespaces */ @Test(dataProvider = "librariesSupportingJackson") - void shouldGenerateCorrectXmlAnnotations(Library library) throws IOException { + void shouldGenerateCorrectXmlAnnotations(Library library) { // Arrange - final String TEST_SPEC = "src/test/resources/3_0/java/xml-annotations-test.yaml"; - final Path output = newTempFolder(); - - JavaClientCodegen codegen = new JavaClientCodegen(); - codegen.setLibrary(library.getValue()); - codegen.setSerializationLibrary("jackson"); - codegen.setWithXml(true); - codegen.setOutputDir(output.toString()); - - DefaultGenerator generator = new DefaultGenerator(); - generator.setGeneratorPropertyDefault(CodegenConstants.MODELS, "true"); - generator.setGeneratorPropertyDefault(CodegenConstants.MODEL_TESTS, "false"); - generator.setGeneratorPropertyDefault(CodegenConstants.MODEL_DOCS, "false"); - generator.setGenerateMetadata(false); + final CodegenConfigurator config = new CodegenConfigurator() + .addAdditionalProperty(CodegenConstants.WITH_XML, true) + .addAdditionalProperty(SERIALIZATION_LIBRARY, "jackson") + .addGlobalProperty(CodegenConstants.MODELS, "Pet") + .addGlobalProperty(CodegenConstants.MODEL_DOCS, null) + .addGlobalProperty(CodegenConstants.MODEL_TESTS, null) + .setGeneratorName("java") + .setInputSpec("src/test/resources/3_0/java/xml-annotations-test.yaml") + .setLibrary(library.value) + .setOutputDir(newTempFolder().toString()); // Act - generator.opts(new ClientOptInput().config(codegen).openAPI(TestUtils.parseSpec(TEST_SPEC))).generate(); + final List files = new DefaultGenerator().opts(config.toClientOptInput()).generate(); // Assert - JavaFileAssert.assertThat(output.resolve("src/main/java/org/openapitools/client/model/Pet.java").toFile()) + JavaFileAssert.assertThat(files.get(0)) .assertTypeAnnotations() .containsWithNameAndAttributes("XmlAccessorType", Map.of("value", "XmlAccessType.FIELD")) .containsWithNameAndAttributes("XmlRootElement", Map.of("name", "\"Pet\"", "namespace", "\"urn:jacksonxml\"")) @@ -2727,116 +2714,116 @@ public class JavaClientCodegenTest { .toType() // ↓ test custom-name on wrapper element (https://swagger.io/docs/specification/data-models/representing-xml/#:~:text=Use%20xml/name%20to%20give%20different%20names) - .hasProperty("tags").assertPropertyAnnotations() - .doesNotContainsWithName("XmlAttribute") + .assertProperty("tags").assertPropertyAnnotations() + .doesNotContainWithName("XmlAttribute") .containsWithNameAndAttributes("XmlElement", Map.of("name", "\"Tag\"")) .containsWithNameAndAttributes("XmlElementWrapper", Map.of("name", "\"TagList\"")) .toProperty().toType() - .assertMethod("getTags").assertMethodAnnotations() - .containsWithNameAndAttributes("JacksonXmlProperty", Map.of("localName", "\"Tag\"")) - .containsWithNameAndAttributes("JacksonXmlElementWrapper", Map.of("localName", "\"TagList\"", "useWrapping", "true")) - .toMethod().toFileAssert() + .assertMethod("getTags") + .hasAnnotation("JacksonXmlProperty", Map.of("localName", "\"Tag\"")) + .hasAnnotation("JacksonXmlElementWrapper", Map.of("localName", "\"TagList\"", "useWrapping", "true")) + .toFileAssert() // ↓ custom internal xml-array element name, non-wrapped (1st example in https://spec.openapis.org/oas/v3.0.0#xml-arrays) - .hasProperty("friends").assertPropertyAnnotations() - .doesNotContainsWithName("XmlAttribute") - .doesNotContainsWithName("XmlElementWrapper") + .assertProperty("friends").assertPropertyAnnotations() + .doesNotContainWithName("XmlAttribute") + .doesNotContainWithName("XmlElementWrapper") .containsWithNameAndAttributes("XmlElement", Map.of("name", "\"friend-pet\"")) .toProperty().toType() - .assertMethod("getFriends").assertMethodAnnotations() - .containsWithNameAndAttributes("JacksonXmlProperty", Map.of("localName", "\"friend-pet\"")) - .containsWithNameAndAttributes("JacksonXmlElementWrapper", Map.of("useWrapping", "false")) - .toMethod().toFileAssert() + .assertMethod("getFriends") + .hasAnnotation("JacksonXmlProperty", Map.of("localName", "\"friend-pet\"")) + .hasAnnotation("JacksonXmlElementWrapper", Map.of("useWrapping", "false")) + .toFileAssert() // ↓ test custom element name (https://swagger.io/docs/specification/data-models/representing-xml/#:~:text=Change%20Element%20Names) - .hasProperty("status").assertPropertyAnnotations() - .doesNotContainsWithName("XmlAttribute") - .doesNotContainsWithName("XmlElementWrapper") + .assertProperty("status").assertPropertyAnnotations() + .doesNotContainWithName("XmlAttribute") + .doesNotContainWithName("XmlElementWrapper") .containsWithNameAndAttributes("XmlElement", Map.of("name", "\"PetStatus\"")) .toProperty().toType() - .assertMethod("getStatus").assertMethodAnnotations() - .doesNotContainsWithName("JacksonXmlElementWrapper") - .containsWithNameAndAttributes("JacksonXmlProperty", Map.of("localName", "\"PetStatus\"")) - .toMethod().toFileAssert() + .assertMethod("getStatus") + .doesNotHaveAnnotation("JacksonXmlElementWrapper") + .hasAnnotation("JacksonXmlProperty", Map.of("localName", "\"PetStatus\"")) + .toFileAssert() // ↓ test same-name wrapping element (https://swagger.io/docs/specification/data-models/representing-xml/#:~:text=Wrapping%20Arrays) // maps to 3rd example in https://spec.openapis.org/oas/v3.0.0#xml-arrays - .hasProperty("photoUrls").assertPropertyAnnotations() - .doesNotContainsWithName("XmlAttribute") + .assertProperty("photoUrls").assertPropertyAnnotations() + .doesNotContainWithName("XmlAttribute") .containsWithNameAndAttributes("XmlElement", Map.of("name", "\"photoUrls\"")) .containsWithNameAndAttributes("XmlElementWrapper", Map.of("name", "\"photoUrls\"")) .toProperty().toType() - .assertMethod("getPhotoUrls").assertMethodAnnotations() - .containsWithNameAndAttributes("JacksonXmlProperty", Map.of("localName", "\"photoUrls\"")) - .containsWithNameAndAttributes("JacksonXmlElementWrapper", Map.of("localName", "\"photoUrls\"", "useWrapping", "true")) - .toMethod().toFileAssert() + .assertMethod("getPhotoUrls") + .hasAnnotation("JacksonXmlProperty", Map.of("localName", "\"photoUrls\"")) + .hasAnnotation("JacksonXmlElementWrapper", Map.of("localName", "\"photoUrls\"", "useWrapping", "true")) + .toFileAssert() // ↓ test attribute generation (https://swagger.io/docs/specification/data-models/representing-xml/#:~:text=Convert%20Property%20to%20an%20Attribute) - .hasProperty("name").assertPropertyAnnotations() - .doesNotContainsWithName("XmlElement") - .doesNotContainsWithName("XmlElementWrapper") + .assertProperty("name").assertPropertyAnnotations() + .doesNotContainWithName("XmlElement") + .doesNotContainWithName("XmlElementWrapper") .containsWithNameAndAttributes("XmlAttribute", Map.of("name", "\"name\"")) .toProperty().toType() - .assertMethod("getName").assertMethodAnnotations() - .doesNotContainsWithName("JacksonXmlElementWrapper") - .containsWithNameAndAttributes("JacksonXmlProperty", Map.of("isAttribute", "true", "localName", "\"name\"")) - .toMethod().toFileAssert() + .assertMethod("getName") + .doesNotHaveAnnotation("JacksonXmlElementWrapper") + .hasAnnotation("JacksonXmlProperty", Map.of("isAttribute", "true", "localName", "\"name\"")) + .toFileAssert() // ↓ test XML namespace and prefix (https://swagger.io/docs/specification/data-models/representing-xml/#:~:text=Prefixes%20and%20Namespaces) - .hasProperty("id").assertPropertyAnnotations() - .doesNotContainsWithName("XmlAttribute") - .doesNotContainsWithName("XmlElementWrapper") + .assertProperty("id").assertPropertyAnnotations() + .doesNotContainWithName("XmlAttribute") + .doesNotContainWithName("XmlElementWrapper") .containsWithNameAndAttributes("XmlElement", Map.of("name", "\"id\"", "namespace", "\"http://example.com/schema\"")) .toProperty().toType() - .assertMethod("getId").assertMethodAnnotations() - .doesNotContainsWithName("JacksonXmlElementWrapper") - .containsWithNameAndAttributes("JacksonXmlProperty", Map.of("localName", "\"id\"", "namespace", "\"http://example.com/schema\"")) - .toMethod().toFileAssert() + .assertMethod("getId") + .doesNotHaveAnnotation("JacksonXmlElementWrapper") + .hasAnnotation("JacksonXmlProperty", Map.of("localName", "\"id\"", "namespace", "\"http://example.com/schema\"")) + .toFileAssert() // ↓ external xml-array element name only (last example in https://spec.openapis.org/oas/v3.0.0#xml-arrays) - .hasProperty("foods").assertPropertyAnnotations() - .doesNotContainsWithName("XmlAttribute") + .assertProperty("foods").assertPropertyAnnotations() + .doesNotContainWithName("XmlAttribute") .containsWithNameAndAttributes("XmlElement", Map.of("name", "\"yummy-yummy\"")) .containsWithNameAndAttributes("XmlElementWrapper", Map.of("name", "\"yummy-yummy\"")) .toProperty().toType() - .assertMethod("getFoods").assertMethodAnnotations() - .containsWithNameAndAttributes("JacksonXmlProperty", Map.of("localName", "\"yummy-yummy\"")) - .containsWithNameAndAttributes("JacksonXmlElementWrapper", Map.of("localName", "\"yummy-yummy\"")) - .toMethod().toFileAssert() + .assertMethod("getFoods") + .hasAnnotation("JacksonXmlProperty", Map.of("localName", "\"yummy-yummy\"")) + .hasAnnotation("JacksonXmlElementWrapper", Map.of("localName", "\"yummy-yummy\"")) + .toFileAssert() // ↓ internal xml-array element name (4th example in https://spec.openapis.org/oas/v3.0.0#xml-arrays) - .hasProperty("colors").assertPropertyAnnotations() - .doesNotContainsWithName("XmlAttribute") + .assertProperty("colors").assertPropertyAnnotations() + .doesNotContainWithName("XmlAttribute") .containsWithNameAndAttributes("XmlElement", Map.of("name", "\"color\"")) .containsWithNameAndAttributes("XmlElementWrapper", Map.of("name", "\"colors\"")) .toProperty().toType() - .assertMethod("getColors").assertMethodAnnotations() - .containsWithNameAndAttributes("JacksonXmlProperty", Map.of("localName", "\"color\"")) - .containsWithNameAndAttributes("JacksonXmlElementWrapper", Map.of("localName", "\"colors\"")) - .toMethod().toFileAssert() + .assertMethod("getColors") + .hasAnnotation("JacksonXmlProperty", Map.of("localName", "\"color\"")) + .hasAnnotation("JacksonXmlElementWrapper", Map.of("localName", "\"colors\"")) + .toFileAssert() // ↓ ignored external xml-array element name, non-wrapped (2nd example in https://spec.openapis.org/oas/v3.0.0#xml-arrays) - .hasProperty("categories").assertPropertyAnnotations() - .doesNotContainsWithName("XmlAttribute") - .doesNotContainsWithName("XmlElementWrapper") + .assertProperty("categories").assertPropertyAnnotations() + .doesNotContainWithName("XmlAttribute") + .doesNotContainWithName("XmlElementWrapper") .containsWithNameAndAttributes("XmlElement", Map.of("name", "\"Category\"")) .toProperty().toType() - .assertMethod("getCategories").assertMethodAnnotations() - .containsWithNameAndAttributes("JacksonXmlProperty", Map.of("localName", "\"Category\"")) + .assertMethod("getCategories") + .hasAnnotation("JacksonXmlProperty", Map.of("localName", "\"Category\"")) // ↓ specific regression test for #2417: (useWrapping=false) needs to be present - .containsWithNameAndAttributes("JacksonXmlElementWrapper", Map.of("useWrapping", "false")) - .toMethod().toFileAssert() + .hasAnnotation("JacksonXmlElementWrapper", Map.of("useWrapping", "false")) + .toFileAssert() // ↓ test custom-name on wrapper AND children (https://swagger.io/docs/specification/data-models/representing-xml/#:~:text=Use%20xml/name%20to%20give%20different%20names) // maps to 5th example in https://spec.openapis.org/oas/v3.0.0#xml-arrays - .hasProperty("activities").assertPropertyAnnotations() - .doesNotContainsWithName("XmlAttribute") + .assertProperty("activities").assertPropertyAnnotations() + .doesNotContainWithName("XmlAttribute") .containsWithNameAndAttributes("XmlElement", Map.of("name", "\"item\"")) .containsWithNameAndAttributes("XmlElementWrapper", Map.of("name", "\"activities-array\"")) .toProperty().toType() - .assertMethod("getActivities").assertMethodAnnotations() - .containsWithNameAndAttributes("JacksonXmlProperty", Map.of("localName", "\"item\"")) - .containsWithNameAndAttributes("JacksonXmlElementWrapper", Map.of("localName", "\"activities-array\"")); + .assertMethod("getActivities") + .hasAnnotation("JacksonXmlProperty", Map.of("localName", "\"item\"")) + .hasAnnotation("JacksonXmlElementWrapper", Map.of("localName", "\"activities-array\"")); } /** @@ -2845,99 +2832,94 @@ public class JavaClientCodegenTest { @Test(dataProvider = "librariesNotSupportingJackson") void shouldGenerateCorrectJaxbAnnotations(Library library) { // Arrange - final String TEST_SPEC = "src/test/resources/3_0/java/xml-annotations-test.yaml"; - final Path output = newTempFolder(); - - JavaClientCodegen codegen = new JavaClientCodegen(); - codegen.setLibrary(library.getValue()); - codegen.setSerializationLibrary("jackson"); - codegen.setWithXml(true); - codegen.setOutputDir(output.toString()); - - DefaultGenerator generator = new DefaultGenerator(); - generator.setGeneratorPropertyDefault(CodegenConstants.MODELS, "true"); - generator.setGeneratorPropertyDefault(CodegenConstants.MODEL_TESTS, "false"); - generator.setGeneratorPropertyDefault(CodegenConstants.MODEL_DOCS, "false"); - generator.setGenerateMetadata(false); + final CodegenConfigurator config = new CodegenConfigurator() + .addAdditionalProperty(CodegenConstants.WITH_XML, true) + .addGlobalProperty(CodegenConstants.MODELS, "Pet") + .addGlobalProperty(CodegenConstants.MODEL_DOCS, null) + .addGlobalProperty(CodegenConstants.MODEL_TESTS, null) + .setGeneratorName("java") + .setLibrary(library.value) + .setInputSpec("src/test/resources/3_0/java/xml-annotations-test.yaml") + .setOutputDir(newTempFolder().toString()); // Act - generator.opts(new ClientOptInput().config(codegen).openAPI(TestUtils.parseSpec(TEST_SPEC))).generate(); + final List files = new DefaultGenerator().opts(config.toClientOptInput()).generate(); // Assert - JavaFileAssert.assertThat(output.resolve("src/main/java/org/openapitools/client/model/Pet.java").toFile()) + JavaFileAssert.assertThat(files.get(0)) .assertTypeAnnotations() .containsWithNameAndAttributes("XmlRootElement", Map.of("name", "\"Pet\"", "namespace", "\"urn:jacksonxml\"")) .containsWithNameAndAttributes("XmlAccessorType", Map.of("value", "XmlAccessType.FIELD")) .toType() // ↓ test custom-name on wrapper element (https://swagger.io/docs/specification/data-models/representing-xml/#:~:text=Use%20xml/name%20to%20give%20different%20names) - .hasProperty("tags").assertPropertyAnnotations() - .doesNotContainsWithName("XmlAttribute") + .assertProperty("tags").assertPropertyAnnotations() + .doesNotContainWithName("XmlAttribute") .containsWithNameAndAttributes("XmlElement", Map.of("name", "\"Tag\"")) .containsWithNameAndAttributes("XmlElementWrapper", Map.of("name", "\"TagList\"")) .toProperty().toType() // ↓ custom internal xml-array element name, non-wrapped (1st example in https://spec.openapis.org/oas/v3.0.0#xml-arrays) - .hasProperty("friends").assertPropertyAnnotations() - .doesNotContainsWithName("XmlAttribute") - .doesNotContainsWithName("XmlElementWrapper") + .assertProperty("friends").assertPropertyAnnotations() + .doesNotContainWithName("XmlAttribute") + .doesNotContainWithName("XmlElementWrapper") .containsWithNameAndAttributes("XmlElement", Map.of("name", "\"friend-pet\"")) .toProperty().toType() // ↓ test custom element name (https://swagger.io/docs/specification/data-models/representing-xml/#:~:text=Change%20Element%20Names) - .hasProperty("status").assertPropertyAnnotations() - .doesNotContainsWithName("XmlAttribute") - .doesNotContainsWithName("XmlElementWrapper") + .assertProperty("status").assertPropertyAnnotations() + .doesNotContainWithName("XmlAttribute") + .doesNotContainWithName("XmlElementWrapper") .containsWithNameAndAttributes("XmlElement", Map.of("name", "\"PetStatus\"")) .toProperty().toType() // ↓ test same-name wrapping element (https://swagger.io/docs/specification/data-models/representing-xml/#:~:text=Wrapping%20Arrays) // maps to 3rd example in https://spec.openapis.org/oas/v3.0.0#xml-arrays - .hasProperty("photoUrls").assertPropertyAnnotations() - .doesNotContainsWithName("XmlAttribute") + .assertProperty("photoUrls").assertPropertyAnnotations() + .doesNotContainWithName("XmlAttribute") .containsWithNameAndAttributes("XmlElement", Map.of("name", "\"photoUrls\"")) .containsWithNameAndAttributes("XmlElementWrapper", Map.of("name", "\"photoUrls\"")) .toProperty().toType() // ↓ test attribute generation (https://swagger.io/docs/specification/data-models/representing-xml/#:~:text=Convert%20Property%20to%20an%20Attribute) - .hasProperty("name").assertPropertyAnnotations() - .doesNotContainsWithName("XmlElement") - .doesNotContainsWithName("XmlElementWrapper") + .assertProperty("name").assertPropertyAnnotations() + .doesNotContainWithName("XmlElement") + .doesNotContainWithName("XmlElementWrapper") .containsWithNameAndAttributes("XmlAttribute", Map.of("name", "\"name\"")) .toProperty().toType() // ↓ test XML namespace and prefix (https://swagger.io/docs/specification/data-models/representing-xml/#:~:text=Prefixes%20and%20Namespaces) - .hasProperty("id").assertPropertyAnnotations() - .doesNotContainsWithName("XmlAttribute") - .doesNotContainsWithName("XmlElementWrapper") + .assertProperty("id").assertPropertyAnnotations() + .doesNotContainWithName("XmlAttribute") + .doesNotContainWithName("XmlElementWrapper") .containsWithNameAndAttributes("XmlElement", Map.of("name", "\"id\"", "namespace", "\"http://example.com/schema\"")) .toProperty().toType() // ↓ external xml-array element name only (last example in https://spec.openapis.org/oas/v3.0.0#xml-arrays) - .hasProperty("foods").assertPropertyAnnotations() - .doesNotContainsWithName("XmlAttribute") + .assertProperty("foods").assertPropertyAnnotations() + .doesNotContainWithName("XmlAttribute") .containsWithNameAndAttributes("XmlElement", Map.of("name", "\"yummy-yummy\"")) .containsWithNameAndAttributes("XmlElementWrapper", Map.of("name", "\"yummy-yummy\"")) .toProperty().toType() // ↓ internal xml-array element name (4th example in https://spec.openapis.org/oas/v3.0.0#xml-arrays) - .hasProperty("colors").assertPropertyAnnotations() - .doesNotContainsWithName("XmlAttribute") + .assertProperty("colors").assertPropertyAnnotations() + .doesNotContainWithName("XmlAttribute") .containsWithNameAndAttributes("XmlElement", Map.of("name", "\"color\"")) .containsWithNameAndAttributes("XmlElementWrapper", Map.of("name", "\"colors\"")) .toProperty().toType() // ↓ ignored external xml-array element name, non-wrapped (2nd example in https://spec.openapis.org/oas/v3.0.0#xml-arrays) - .hasProperty("categories").assertPropertyAnnotations() - .doesNotContainsWithName("XmlAttribute") - .doesNotContainsWithName("XmlElementWrapper") + .assertProperty("categories").assertPropertyAnnotations() + .doesNotContainWithName("XmlAttribute") + .doesNotContainWithName("XmlElementWrapper") .containsWithNameAndAttributes("XmlElement", Map.of("name", "\"Category\"")) .toProperty().toType() // ↓ test custom-name on wrapper AND children (https://swagger.io/docs/specification/data-models/representing-xml/#:~:text=Use%20xml/name%20to%20give%20different%20names) // maps to 5th example in https://spec.openapis.org/oas/v3.0.0#xml-arrays - .hasProperty("activities").assertPropertyAnnotations() - .doesNotContainsWithName("XmlAttribute") + .assertProperty("activities").assertPropertyAnnotations() + .doesNotContainWithName("XmlAttribute") .containsWithNameAndAttributes("XmlElement", Map.of("name", "\"item\"")) .containsWithNameAndAttributes("XmlElementWrapper", Map.of("name", "\"activities-array\"")); } diff --git a/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/JavaValidationArrayPrimitivesTest.java b/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/JavaValidationArrayPrimitivesTest.java index 9626647b9fc..06bccb329d7 100644 --- a/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/JavaValidationArrayPrimitivesTest.java +++ b/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/JavaValidationArrayPrimitivesTest.java @@ -39,73 +39,73 @@ public class JavaValidationArrayPrimitivesTest { private static Consumer> assertWithValidationWithoutJsonNullable() { return files -> JavaFileAssert.assertThat(files.get("Foo.java")) .isNormalClass() - .hasProperty("stringPattern") + .assertProperty("stringPattern") .withType("Set<@Pattern(regexp = \"[a-z]\") String>") .toType() - .hasProperty("stringMaxMinLength") + .assertProperty("stringMaxMinLength") .withType("Set<@Size(min = 1, max = 10) String>") .toType() - .hasProperty("stringMinLength") + .assertProperty("stringMinLength") .withType("List<@Size(min = 1) String>") .toType() - .hasProperty("stringMaxLength") + .assertProperty("stringMaxLength") .withType("Set<@Size(max = 1) String>") .toType() - .hasProperty("stringEmail") + .assertProperty("stringEmail") .withType("List<@Email String>") .toType() - .hasProperty("intMinMax") + .assertProperty("intMinMax") .withType("List<@Min(1) @Max(10) Integer>") .toType() - .hasProperty("intMin") + .assertProperty("intMin") .withType("List<@Min(1) Integer>") .toType() - .hasProperty("intMax") + .assertProperty("intMax") .withType("List<@Max(10) Integer>") .toType() - .hasProperty("numberMinMax") + .assertProperty("numberMinMax") .withType("List<@DecimalMin(value = \"1\", inclusive = true) @DecimalMax(value = \"10\", inclusive = true) BigDecimal>") .toType() - .hasProperty("numberMin") + .assertProperty("numberMin") .withType("List<@DecimalMin(value = \"1\", inclusive = true) BigDecimal>") .toType() - .hasProperty("numberMax") + .assertProperty("numberMax") .withType("List<@DecimalMax(value = \"10\", inclusive = true) BigDecimal>") .toType() - .hasProperty("stringPatternWithMin") + .assertProperty("stringPatternWithMin") .withType("Set<@Pattern(regexp = \"^\\\\d{3}-\\\\d{2}-\\\\d{4}$\") @Size(min = 10) String>") .toType() - .hasProperty("stringPatternNullable") + .assertProperty("stringPatternNullable") .withType("Set<@Pattern(regexp = \"^\\\\d{3}-\\\\d{2}-\\\\d{4}$\") String>") .toType() - .hasProperty("stringMaxMinLengthNullable") + .assertProperty("stringMaxMinLengthNullable") .withType("Set<@Size(min = 1, max = 10) String>") .toType() - .hasProperty("stringMinLengthNullable") + .assertProperty("stringMinLengthNullable") .withType("List<@Size(min = 1) String>") .toType() - .hasProperty("stringMaxLengthNullable") + .assertProperty("stringMaxLengthNullable") .withType("Set<@Size(max = 1) String>") .toType() - .hasProperty("stringNumbers") + .assertProperty("stringNumbers") .withType("Set<@DecimalMin(value = \"1\", inclusive = true) @DecimalMax(value = \"10\", inclusive = true) BigDecimal>") .toType() - .hasProperty("intMinMaxNullable") + .assertProperty("intMinMaxNullable") .withType("List<@Min(1) @Max(10) Integer>") .toType() - .hasProperty("intMinNullable") + .assertProperty("intMinNullable") .withType("List<@Min(1) Integer>") .toType() - .hasProperty("intMaxNullable") + .assertProperty("intMaxNullable") .withType("List<@Max(10) Integer>") .toType() - .hasProperty("numberMinMaxNullable") + .assertProperty("numberMinMaxNullable") .withType("List<@DecimalMin(value = \"1\", inclusive = true) @DecimalMax(value = \"10\", inclusive = true) BigDecimal>") .toType() - .hasProperty("numberMinNullable") + .assertProperty("numberMinNullable") .withType("List<@DecimalMin(value = \"1\", inclusive = true) BigDecimal>") .toType() - .hasProperty("numberMaxNullable") + .assertProperty("numberMaxNullable") .withType("List<@DecimalMax(value = \"10\", inclusive = false) BigDecimal>") .toType(); } @@ -113,76 +113,76 @@ public class JavaValidationArrayPrimitivesTest { private static Consumer> assertWithValidationWithJsonNullable() { return files -> JavaFileAssert.assertThat(files.get("Foo.java")) .isNormalClass() - .hasProperty("category") + .assertProperty("category") .withType("List<@Pattern(regexp = \"^[a-zA-Z0-9 .:!()-]$\") @Size(max = 50) String>") .toType() - .hasProperty("stringPattern") + .assertProperty("stringPattern") .withType("Set<@Pattern(regexp = \"[a-z]\") String>") .toType() - .hasProperty("stringMaxMinLength") + .assertProperty("stringMaxMinLength") .withType("Set<@Size(min = 1, max = 10) String>") .toType() - .hasProperty("stringMinLength") + .assertProperty("stringMinLength") .withType("List<@Size(min = 1) String>") .toType() - .hasProperty("stringMaxLength") + .assertProperty("stringMaxLength") .withType("Set<@Size(max = 1) String>") .toType() - .hasProperty("stringEmail") + .assertProperty("stringEmail") .withType("List<@Email String>") .toType() - .hasProperty("intMinMax") + .assertProperty("intMinMax") .withType("List<@Min(1) @Max(10) Integer>") .toType() - .hasProperty("intMin") + .assertProperty("intMin") .withType("List<@Min(1) Integer>") .toType() - .hasProperty("intMax") + .assertProperty("intMax") .withType("List<@Max(10) Integer>") .toType() - .hasProperty("numberMinMax") + .assertProperty("numberMinMax") .withType("List<@DecimalMin(value = \"1\", inclusive = true) @DecimalMax(value = \"10\", inclusive = true) BigDecimal>") .toType() - .hasProperty("numberMin") + .assertProperty("numberMin") .withType("List<@DecimalMin(value = \"1\", inclusive = true) BigDecimal>") .toType() - .hasProperty("numberMax") + .assertProperty("numberMax") .withType("List<@DecimalMax(value = \"10\", inclusive = true) BigDecimal>") .toType() - .hasProperty("stringPatternWithMin") + .assertProperty("stringPatternWithMin") .withType("JsonNullable>") .toType() - .hasProperty("stringPatternNullable") + .assertProperty("stringPatternNullable") .withType("JsonNullable>") .toType() - .hasProperty("stringMaxMinLengthNullable") + .assertProperty("stringMaxMinLengthNullable") .withType("JsonNullable>") .toType() - .hasProperty("stringMinLengthNullable") + .assertProperty("stringMinLengthNullable") .withType("JsonNullable>") .toType() - .hasProperty("stringMaxLengthNullable") + .assertProperty("stringMaxLengthNullable") .withType("JsonNullable>") .toType() - .hasProperty("stringNumbers") + .assertProperty("stringNumbers") .withType("Set<@DecimalMin(value = \"1\", inclusive = true) @DecimalMax(value = \"10\", inclusive = true) BigDecimal>") .toType() - .hasProperty("intMinMaxNullable") + .assertProperty("intMinMaxNullable") .withType("JsonNullable>") .toType() - .hasProperty("intMinNullable") + .assertProperty("intMinNullable") .withType("JsonNullable>") .toType() - .hasProperty("intMaxNullable") + .assertProperty("intMaxNullable") .withType("JsonNullable>") .toType() - .hasProperty("numberMinMaxNullable") + .assertProperty("numberMinMaxNullable") .withType("JsonNullable>") .toType() - .hasProperty("numberMinNullable") + .assertProperty("numberMinNullable") .withType("JsonNullable>") .toType() - .hasProperty("numberMaxNullable") + .assertProperty("numberMaxNullable") .withType("JsonNullable>") .toType(); } @@ -231,70 +231,70 @@ public class JavaValidationArrayPrimitivesTest { private static Consumer> assertWithoutValidationWithoutJsonNullable() { return files -> JavaFileAssert.assertThat(files.get("Foo.java")) .isNormalClass() - .hasProperty("stringPattern") + .assertProperty("stringPattern") .withType("Set") .toType() - .hasProperty("stringMaxMinLength") + .assertProperty("stringMaxMinLength") .withType("Set") .toType() - .hasProperty("stringMinLength") + .assertProperty("stringMinLength") .withType("List") .toType() - .hasProperty("stringMaxLength") + .assertProperty("stringMaxLength") .withType("Set") .toType() - .hasProperty("stringEmail") + .assertProperty("stringEmail") .withType("List") .toType() - .hasProperty("intMinMax") + .assertProperty("intMinMax") .withType("List") .toType() - .hasProperty("intMin") + .assertProperty("intMin") .withType("List") .toType() - .hasProperty("intMax") + .assertProperty("intMax") .withType("List") .toType() - .hasProperty("numberMinMax") + .assertProperty("numberMinMax") .withType("List") .toType() - .hasProperty("numberMin") + .assertProperty("numberMin") .withType("List") .toType() - .hasProperty("numberMax") + .assertProperty("numberMax") .withType("List") .toType() - .hasProperty("stringPatternWithMin") + .assertProperty("stringPatternWithMin") .withType("Set") .toType() - .hasProperty("stringPatternNullable") + .assertProperty("stringPatternNullable") .withType("Set") .toType() - .hasProperty("stringMaxMinLengthNullable") + .assertProperty("stringMaxMinLengthNullable") .withType("Set") .toType() - .hasProperty("stringMinLengthNullable") + .assertProperty("stringMinLengthNullable") .withType("List") .toType() - .hasProperty("stringMaxLengthNullable") + .assertProperty("stringMaxLengthNullable") .withType("Set") .toType() - .hasProperty("intMinMaxNullable") + .assertProperty("intMinMaxNullable") .withType("List") .toType() - .hasProperty("intMinNullable") + .assertProperty("intMinNullable") .withType("List") .toType() - .hasProperty("intMaxNullable") + .assertProperty("intMaxNullable") .withType("List") .toType() - .hasProperty("numberMinMaxNullable") + .assertProperty("numberMinMaxNullable") .withType("List") .toType() - .hasProperty("numberMinNullable") + .assertProperty("numberMinNullable") .withType("List") .toType() - .hasProperty("numberMaxNullable") + .assertProperty("numberMaxNullable") .withType("List") .toType(); } @@ -302,70 +302,70 @@ public class JavaValidationArrayPrimitivesTest { private static Consumer> assertWithoutValidationWithJsonNullable() { return files -> JavaFileAssert.assertThat(files.get("Foo.java")) .isNormalClass() - .hasProperty("stringPattern") + .assertProperty("stringPattern") .withType("Set") .toType() - .hasProperty("stringMaxMinLength") + .assertProperty("stringMaxMinLength") .withType("Set") .toType() - .hasProperty("stringMinLength") + .assertProperty("stringMinLength") .withType("List") .toType() - .hasProperty("stringMaxLength") + .assertProperty("stringMaxLength") .withType("Set") .toType() - .hasProperty("stringEmail") + .assertProperty("stringEmail") .withType("List") .toType() - .hasProperty("intMinMax") + .assertProperty("intMinMax") .withType("List") .toType() - .hasProperty("intMin") + .assertProperty("intMin") .withType("List") .toType() - .hasProperty("intMax") + .assertProperty("intMax") .withType("List") .toType() - .hasProperty("numberMinMax") + .assertProperty("numberMinMax") .withType("List") .toType() - .hasProperty("numberMin") + .assertProperty("numberMin") .withType("List") .toType() - .hasProperty("numberMax") + .assertProperty("numberMax") .withType("List") .toType() - .hasProperty("stringPatternWithMin") + .assertProperty("stringPatternWithMin") .withType("JsonNullable>") .toType() - .hasProperty("stringPatternNullable") + .assertProperty("stringPatternNullable") .withType("JsonNullable>") .toType() - .hasProperty("stringMaxMinLengthNullable") + .assertProperty("stringMaxMinLengthNullable") .withType("JsonNullable>") .toType() - .hasProperty("stringMinLengthNullable") + .assertProperty("stringMinLengthNullable") .withType("JsonNullable>") .toType() - .hasProperty("stringMaxLengthNullable") + .assertProperty("stringMaxLengthNullable") .withType("JsonNullable>") .toType() - .hasProperty("intMinMaxNullable") + .assertProperty("intMinMaxNullable") .withType("JsonNullable>") .toType() - .hasProperty("intMinNullable") + .assertProperty("intMinNullable") .withType("JsonNullable>") .toType() - .hasProperty("intMaxNullable") + .assertProperty("intMaxNullable") .withType("JsonNullable>") .toType() - .hasProperty("numberMinMaxNullable") + .assertProperty("numberMinMaxNullable") .withType("JsonNullable>") .toType() - .hasProperty("numberMinNullable") + .assertProperty("numberMinNullable") .withType("JsonNullable>") .toType() - .hasProperty("numberMaxNullable") + .assertProperty("numberMaxNullable") .withType("JsonNullable>") .toType(); } diff --git a/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/assertions/AbstractAnnotationAssert.java b/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/assertions/AbstractAnnotationsAssert.java similarity index 91% rename from modules/openapi-generator/src/test/java/org/openapitools/codegen/java/assertions/AbstractAnnotationAssert.java rename to modules/openapi-generator/src/test/java/org/openapitools/codegen/java/assertions/AbstractAnnotationsAssert.java index 921f5ac5051..ccda2854b2e 100644 --- a/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/assertions/AbstractAnnotationAssert.java +++ b/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/assertions/AbstractAnnotationsAssert.java @@ -17,9 +17,9 @@ import com.github.javaparser.ast.nodeTypes.NodeWithSimpleName; import com.google.common.collect.ImmutableMap; @CanIgnoreReturnValue -public abstract class AbstractAnnotationAssert> extends ListAssert { +public abstract class AbstractAnnotationsAssert> extends ListAssert { - protected AbstractAnnotationAssert(final List annotationExpr) { + protected AbstractAnnotationsAssert(final List annotationExpr) { super(annotationExpr); } @@ -36,7 +36,7 @@ public abstract class AbstractAnnotationAssert annotation.getNameAsString().equals(name)); diff --git a/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/assertions/AbstractMethodAssert.java b/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/assertions/AbstractMethodAssert.java new file mode 100644 index 00000000000..1217d87933a --- /dev/null +++ b/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/assertions/AbstractMethodAssert.java @@ -0,0 +1,152 @@ +package org.openapitools.codegen.java.assertions; + +import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration; +import com.github.javaparser.ast.body.MethodDeclaration; +import com.github.javaparser.ast.nodeTypes.NodeWithName; +import org.assertj.core.api.AbstractAssert; +import org.assertj.core.api.Assertions; +import org.assertj.core.util.CanIgnoreReturnValue; + +import java.util.Arrays; +import java.util.Map; +import java.util.stream.Collectors; + +@CanIgnoreReturnValue +public abstract class AbstractMethodAssert> extends AbstractAssert, MethodDeclaration> { + + protected final String methodSignature; + + protected AbstractMethodAssert(MethodDeclaration methodDeclaration, Class selfType) { + super(methodDeclaration, selfType); + this.methodSignature = methodDeclaration.getDeclarationAsString(); + } + + public abstract JavaFileAssert toFileAssert(); + public abstract AbstractAnnotationsAssert assertMethodAnnotations(); + + public ACTUAL hasReturnType(final String returnType) { + Assertions.assertThat(actual.getType().toString()) + .isEqualTo(returnType); + return myself(); + } + + public ACTUAL hasAnnotation(String annotation) { + assertMethodAnnotations().containsWithName(annotation); + return myself(); + } + + public ACTUAL hasAnnotation(String annotation, final Map attributes) { + assertMethodAnnotations().containsWithNameAndAttributes(annotation, attributes); + return myself(); + } + + public ACTUAL doesNotHaveAnnotation(String annotation) { + assertMethodAnnotations().doesNotContainWithName(annotation); + return myself(); + } + + public ACTUAL doesNotHaveParameter(final String paramName) { + Assertions.assertThat(actual.getParameterByName(paramName)) + .withFailMessage("Method %s shouldn't have parameter %s, but it does", methodSignature, paramName) + .isEmpty(); + return myself(); + } + + public ACTUAL doesNotHaveParameters() { + Assertions.assertThat(actual.getParameters()) + .withFailMessage("Method %s shouldn't have parameter, but it does", methodSignature) + .isEmpty(); + return myself(); + } + + public ACTUAL bodyContainsLines(final String... lines) { + Assertions.assertThat(isWithImplementation()) + .withFailMessage("Method %s is abstract", methodSignature) + .isTrue(); + final String actualBody = actual.getTokenRange() + .orElseThrow(() -> new IllegalStateException("Not-abstract method doesn't have body")) + .toString(); + Assertions.assertThat(actualBody) + .withFailMessage( + "Method's %s body should contains lines\n====\n%s\n====\nbut actually was\n====\n%s\n====", + methodSignature, Arrays.stream(lines).collect(Collectors.joining(System.lineSeparator())), actualBody + ) + .contains(lines); + + return myself(); + } + + public ACTUAL bodyNotContainsLines(final String... lines) { + Assertions.assertThat(isWithImplementation()) + .withFailMessage("Method %s is abstract", methodSignature) + .isTrue(); + final String actualBody = actual.getTokenRange() + .orElseThrow(() -> new IllegalStateException("Not-abstract method doesn't have body")) + .toString(); + Assertions.assertThat(actualBody) + .withFailMessage( + "Method's %s body shouldn't contains lines\n====\n%s\n====\nbut actually was\n====\n%s\n====", + methodSignature, Arrays.stream(lines).collect(Collectors.joining(System.lineSeparator())), actualBody + ) + .doesNotContain(lines); + + return myself(); + } + + public ACTUAL doesNotHaveImplementation() { + Assertions.assertThat(isWithImplementation()) + .withFailMessage("Method %s should be abstract", methodSignature) + .isFalse(); + return myself(); + } + + public ACTUAL doesNotHaveComment() { + Assertions.assertThat(actual.getJavadocComment()) + .withFailMessage("Method %s shouldn't contains comment, but it does", methodSignature) + .isEmpty(); + return myself(); + } + + @SuppressWarnings("OptionalGetWithoutIsPresent") + public ACTUAL commentContainsLines(final String... lines) { + Assertions.assertThat(actual.getJavadocComment()) + .withFailMessage("Method %s should contains comment, but it doesn't", methodSignature) + .isPresent(); + + final String actualComment = actual.getJavadocComment().get().getContent(); + Assertions.assertThat(actualComment) + .withFailMessage( + "Method's %s comment should contains lines\n====\n%s\n====\nbut actually was\n====%s\n====", + methodSignature, Arrays.stream(lines).collect(Collectors.joining(System.lineSeparator())), actualComment + ) + .contains(lines); + + return myself(); + } + + public ACTUAL noneOfParameterHasAnnotation(final String annotationName) { + actual.getParameters() + .forEach( + param -> Assertions.assertThat(param.getAnnotations()) + .withFailMessage("Parameter %s contains annotation %s while it shouldn't", param.getNameAsString(), annotationName) + .extracting(NodeWithName::getNameAsString) + .doesNotContain(annotationName) + ); + + return myself(); + } + + private boolean isWithImplementation() { + final boolean isInterface = actual.getParentNode() + .filter(ClassOrInterfaceDeclaration.class::isInstance) + .map(ClassOrInterfaceDeclaration.class::cast) + .map(ClassOrInterfaceDeclaration::isInterface) + .orElse(false); + return !(actual.isAbstract() || (isInterface && !actual.isDefault())); + } + + @SuppressWarnings("unchecked") + private ACTUAL myself() { + return (ACTUAL) this; + } +} diff --git a/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/assertions/ConstructorAssert.java b/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/assertions/ConstructorAssert.java index c0296c5cea6..dfe465caba4 100644 --- a/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/assertions/ConstructorAssert.java +++ b/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/assertions/ConstructorAssert.java @@ -27,10 +27,11 @@ public class ConstructorAssert extends AbstractAssert parameter = actual.getParameterByName(paramName); Assertions.assertThat(parameter) @@ -67,6 +68,7 @@ public class ConstructorAssert extends AbstractAssert { + + private final JavaFileAssert parent; + private final ClassOrInterfaceDeclaration innerClass; + + protected InnerClassAssert(final JavaFileAssert fileAssert, final ClassOrInterfaceDeclaration bodyDeclaration) { + super(bodyDeclaration, InnerClassAssert.class); + parent = fileAssert; + innerClass = bodyDeclaration; + } + + public JavaFileAssert toFileAssert() { + return parent; + } + + // TODO this effectively duplicates JavaFileAssert.assertMethod, could be moved into a common + // intermediate base class (which would then easily implement property, type & constructor + // assertions for inner classes + public MethodAssert assertMethod(final String methodName, final String... paramTypes) { + + final List methods = paramTypes.length == 0 + ? innerClass.getMethodsByName(methodName) + : innerClass.getMethodsBySignature(methodName, paramTypes); + + final String failMessage = (methods.isEmpty() + ? "No methods matching `%s(%s)` exist" + : "There are " + methods.size() + " methods matching `%s(%s)`") + + " in inner class `" + innerClass.getName() + "`"; + + Assertions.assertThat(methods) + .withFailMessage(failMessage, methodName, Arrays.toString(paramTypes).replaceAll("\\[]", "")) + .hasSize(1); + + return new MethodAssert(this, methods.get(0)); + } + + public static class MethodAssert extends AbstractMethodAssert { + + private final InnerClassAssert innerClassAssert; + + MethodAssert(InnerClassAssert innerClassAssert, MethodDeclaration methodDeclaration) { + super(methodDeclaration, MethodAssert.class); + this.innerClassAssert = innerClassAssert; + } + + public MethodAnnotationsAssert assertMethodAnnotations() { + return new MethodAnnotationsAssert(this, actual.getAnnotations()); + } + + public InnerClassAssert toInnerClassAssert() { + return innerClassAssert; + } + + public JavaFileAssert toFileAssert() { + return innerClassAssert.toFileAssert(); + } + } + + public static class MethodAnnotationsAssert extends AbstractAnnotationsAssert { + + private final MethodAssert parent; + + protected MethodAnnotationsAssert(MethodAssert methodAssert, List annotationExpr) { + super(annotationExpr); + parent = methodAssert; + } + + public InnerClassAssert toInnerClassAssert() { + return parent.innerClassAssert; + } + + public MethodAssert toMethod() { + return parent; + } + } +} diff --git a/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/assertions/JavaFileAssert.java b/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/assertions/JavaFileAssert.java index 007eb2c40e9..b8ebae768c2 100644 --- a/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/assertions/JavaFileAssert.java +++ b/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/assertions/JavaFileAssert.java @@ -1,5 +1,14 @@ package org.openapitools.codegen.java.assertions; +import com.github.javaparser.StaticJavaParser; +import com.github.javaparser.ast.CompilationUnit; +import com.github.javaparser.ast.body.*; +import com.github.javaparser.ast.nodeTypes.NodeWithName; +import com.github.javaparser.ast.nodeTypes.modifiers.NodeWithAbstractModifier; +import org.assertj.core.api.AbstractAssert; +import org.assertj.core.api.Assertions; +import org.assertj.core.util.CanIgnoreReturnValue; + import java.io.File; import java.io.IOException; import java.nio.file.Path; @@ -8,19 +17,6 @@ import java.util.List; import java.util.Optional; import java.util.stream.Collectors; -import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration; -import com.github.javaparser.ast.body.ConstructorDeclaration; -import org.assertj.core.api.AbstractAssert; -import org.assertj.core.api.Assertions; -import org.assertj.core.util.CanIgnoreReturnValue; - -import com.github.javaparser.StaticJavaParser; -import com.github.javaparser.ast.CompilationUnit; -import com.github.javaparser.ast.body.FieldDeclaration; -import com.github.javaparser.ast.body.MethodDeclaration; -import com.github.javaparser.ast.nodeTypes.NodeWithName; -import com.github.javaparser.ast.nodeTypes.modifiers.NodeWithAbstractModifier; - @CanIgnoreReturnValue public class JavaFileAssert extends AbstractAssert { @@ -41,11 +37,7 @@ public class JavaFileAssert extends AbstractAssert methods = paramTypes.length == 0 ? actual.getType(0).getMethodsByName(methodName) : actual.getType(0).getMethodsBySignature(methodName, paramTypes); @@ -98,7 +90,23 @@ public class JavaFileAssert extends AbstractAssert innerClass = actual.getType(0).getMembers().stream() + .filter(BodyDeclaration::isClassOrInterfaceDeclaration) + .map(clazz -> (ClassOrInterfaceDeclaration) clazz) + .filter(clazz -> clazz.isInnerClass() || clazz.isStatic() && clazz.getNameAsString().equals(className)) + .findFirst(); + Assertions.assertThat(innerClass) + .withFailMessage("No inner class with name %s found", className) + .isPresent(); + + return new InnerClassAssert(this, innerClass.get ()); + } + + @SuppressWarnings("OptionalGetWithoutIsPresent") public ConstructorAssert assertConstructor(final String... paramTypes) { Optional constructorDeclaration = actual.getType(0).getConstructorByParameterTypes(paramTypes); Assertions.assertThat(constructorDeclaration) @@ -108,7 +116,7 @@ public class JavaFileAssert extends AbstractAssert constructorDeclaration = actual.getType(0).getConstructorByParameterTypes(paramTypes); Assertions.assertThat(constructorDeclaration) .withFailMessage("Found constructor with parameter(s) %s", Arrays.toString(paramTypes)) @@ -117,7 +125,8 @@ public class JavaFileAssert extends AbstractAssert fieldOptional = actual.getType(0).getMembers().stream() .filter(FieldDeclaration.class::isInstance) .map(FieldDeclaration.class::cast) @@ -161,7 +170,7 @@ public class JavaFileAssert extends AbstractAssert new IllegalStateException("Empty file")) .toString(); @@ -175,8 +184,7 @@ public class JavaFileAssert extends AbstractAssert { +public class MethodAnnotationsAssert extends AbstractAnnotationsAssert { private final MethodAssert methodAssert; private final ConstructorAssert constructorAssert; - protected MethodAnnotationAssert(final MethodAssert methodAssert, final List annotationExpr) { + protected MethodAnnotationsAssert(final MethodAssert methodAssert, final List annotationExpr) { super(annotationExpr); this.methodAssert = methodAssert; this.constructorAssert = null; } - protected MethodAnnotationAssert(final ConstructorAssert constructorAssert, final List annotationExpr) { + protected MethodAnnotationsAssert(final ConstructorAssert constructorAssert, final List annotationExpr) { super(annotationExpr); this.constructorAssert = constructorAssert; this.methodAssert = null; diff --git a/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/assertions/MethodAssert.java b/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/assertions/MethodAssert.java index cdfb564ff75..bdd4f776e76 100644 --- a/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/assertions/MethodAssert.java +++ b/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/assertions/MethodAssert.java @@ -1,148 +1,38 @@ package org.openapitools.codegen.java.assertions; -import java.util.Arrays; -import java.util.Optional; -import java.util.stream.Collectors; - -import org.assertj.core.api.AbstractAssert; -import org.assertj.core.api.Assertions; -import org.assertj.core.util.CanIgnoreReturnValue; - -import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration; import com.github.javaparser.ast.body.MethodDeclaration; import com.github.javaparser.ast.body.Parameter; -import com.github.javaparser.ast.nodeTypes.NodeWithName; +import org.assertj.core.api.Assertions; -@CanIgnoreReturnValue -public class MethodAssert extends AbstractAssert { +import java.util.Optional; + +public class MethodAssert extends AbstractMethodAssert { private final JavaFileAssert fileAssert; - private final String methodSignature; MethodAssert(final JavaFileAssert fileAssert, final MethodDeclaration methodDeclaration) { super(methodDeclaration, MethodAssert.class); this.fileAssert = fileAssert; - this.methodSignature = methodDeclaration.getDeclarationAsString(); } public JavaFileAssert toFileAssert() { return fileAssert; } - public MethodAnnotationAssert assertMethodAnnotations() { - return new MethodAnnotationAssert(this, actual.getAnnotations()); + public MethodAnnotationsAssert assertMethodAnnotations() { + return new MethodAnnotationsAssert(this, actual.getAnnotations()); } - public MethodAssert hasReturnType(final String returnType) { - Assertions.assertThat(actual.getType().toString()) - .isEqualTo(returnType); - return this; - } - - public ParameterAssert hasParameter(final String paramName) { + // TODO move into base class so inner class method parameters can be asserted + // (may need some more Generics Kung-Fu applied to the ParameterAssert class, + // alternatively the f) + @SuppressWarnings("OptionalGetWithoutIsPresent") + public ParameterAssert assertParameter(final String paramName) { final Optional parameter = actual.getParameterByName(paramName); Assertions.assertThat(parameter) .withFailMessage("Method %s should have parameter %s, but it doesn't", methodSignature, paramName) .isPresent(); + return new ParameterAssert(this, parameter.get()); } - - public MethodAssert doesNotHaveParameter(final String paramName) { - Assertions.assertThat(actual.getParameterByName(paramName)) - .withFailMessage("Method %s shouldn't have parameter %s, but it does", methodSignature, paramName) - .isEmpty(); - return this; - } - - public MethodAssert doesNotHaveParameters() { - Assertions.assertThat(actual.getParameters()) - .withFailMessage("Method %s shouldn't have parameter, but it does", methodSignature) - .isEmpty(); - return this; - } - - public MethodAssert bodyContainsLines(final String... lines) { - Assertions.assertThat(isWithImplementation()) - .withFailMessage("Method %s is abstract", methodSignature) - .isTrue(); - final String actualBody = actual.getTokenRange() - .orElseThrow(() -> new IllegalStateException("Not-abstract method doesn't have body")) - .toString(); - Assertions.assertThat(actualBody) - .withFailMessage( - "Method's %s body should contains lines\n====\n%s\n====\nbut actually was\n====\n%s\n====", - methodSignature, Arrays.stream(lines).collect(Collectors.joining(System.lineSeparator())), actualBody - ) - .contains(lines); - - return this; - } - - public MethodAssert bodyNotContainsLines(final String... lines) { - Assertions.assertThat(isWithImplementation()) - .withFailMessage("Method %s is abstract", methodSignature) - .isTrue(); - final String actualBody = actual.getTokenRange() - .orElseThrow(() -> new IllegalStateException("Not-abstract method doesn't have body")) - .toString(); - Assertions.assertThat(actualBody) - .withFailMessage( - "Method's %s body shouldn't contains lines\n====\n%s\n====\nbut actually was\n====\n%s\n====", - methodSignature, Arrays.stream(lines).collect(Collectors.joining(System.lineSeparator())), actualBody - ) - .doesNotContain(lines); - - return this; - } - - public MethodAssert doesNotHaveImplementation() { - Assertions.assertThat(isWithImplementation()) - .withFailMessage("Method %s should be abstract", methodSignature) - .isFalse(); - return this; - } - - public MethodAssert doesNotHaveComment() { - Assertions.assertThat(actual.getJavadocComment()) - .withFailMessage("Method %s shouldn't contains comment, but it does", methodSignature) - .isEmpty(); - return this; - } - - public MethodAssert commentContainsLines(final String... lines) { - Assertions.assertThat(actual.getJavadocComment()) - .withFailMessage("Method %s should contains comment, but it doesn't", methodSignature) - .isPresent(); - final String actualComment = actual.getJavadocComment().get().getContent(); - Assertions.assertThat(actualComment) - .withFailMessage( - "Method's %s comment should contains lines\n====\n%s\n====\nbut actually was\n====%s\n====", - methodSignature, Arrays.stream(lines).collect(Collectors.joining(System.lineSeparator())), actualComment - ) - .contains(lines); - - return this; - } - - public MethodAssert noneOfParameterHasAnnotation(final String annotationName) { - actual.getParameters() - .forEach( - param -> Assertions.assertThat(param.getAnnotations()) - .withFailMessage("Parameter %s contains annotation %s while it shouldn't", param.getNameAsString(), annotationName) - .extracting(NodeWithName::getNameAsString) - .doesNotContain(annotationName) - ); - - return this; - } - - private boolean isWithImplementation() { - final boolean isInterface = actual.getParentNode() - .filter(ClassOrInterfaceDeclaration.class::isInstance) - .map(ClassOrInterfaceDeclaration.class::cast) - .map(ClassOrInterfaceDeclaration::isInterface) - .orElse(false); - return !(actual.isAbstract() || (isInterface && !actual.isDefault())); - } - } diff --git a/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/assertions/ParameterAnnotationAssert.java b/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/assertions/ParameterAnnotationsAssert.java similarity index 65% rename from modules/openapi-generator/src/test/java/org/openapitools/codegen/java/assertions/ParameterAnnotationAssert.java rename to modules/openapi-generator/src/test/java/org/openapitools/codegen/java/assertions/ParameterAnnotationsAssert.java index 184943bd4da..bf3cdbcb952 100644 --- a/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/assertions/ParameterAnnotationAssert.java +++ b/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/assertions/ParameterAnnotationsAssert.java @@ -7,11 +7,11 @@ import org.assertj.core.util.CanIgnoreReturnValue; import com.github.javaparser.ast.expr.AnnotationExpr; @CanIgnoreReturnValue -public class ParameterAnnotationAssert extends AbstractAnnotationAssert { +public class ParameterAnnotationsAssert extends AbstractAnnotationsAssert { private final ParameterAssert parameterAssert; - protected ParameterAnnotationAssert(final ParameterAssert parameterAssert, final List annotationExpr) { + protected ParameterAnnotationsAssert(final ParameterAssert parameterAssert, final List annotationExpr) { super(annotationExpr); this.parameterAssert = parameterAssert; } diff --git a/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/assertions/ParameterAssert.java b/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/assertions/ParameterAssert.java index adf73c7063a..a878ad2cd9b 100644 --- a/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/assertions/ParameterAssert.java +++ b/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/assertions/ParameterAssert.java @@ -38,14 +38,14 @@ public class ParameterAssert extends ObjectAssert { return constructorAssert; } - public ParameterAssert withType(final String expectedType) { + public ParameterAssert hasType(final String expectedType) { Assertions.assertThat(actual.getTypeAsString()) .withFailMessage("Expected parameter to have type %s, but was %s", expectedType, actual.getTypeAsString()) .isEqualTo(expectedType); return this; } - public ParameterAnnotationAssert assertParameterAnnotations() { - return new ParameterAnnotationAssert(this, actual.getAnnotations()); + public ParameterAnnotationsAssert assertParameterAnnotations() { + return new ParameterAnnotationsAssert(this, actual.getAnnotations()); } } diff --git a/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/assertions/PropertyAnnotationAssert.java b/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/assertions/PropertyAnnotationsAssert.java similarity index 65% rename from modules/openapi-generator/src/test/java/org/openapitools/codegen/java/assertions/PropertyAnnotationAssert.java rename to modules/openapi-generator/src/test/java/org/openapitools/codegen/java/assertions/PropertyAnnotationsAssert.java index 92636a90730..25b09f31116 100644 --- a/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/assertions/PropertyAnnotationAssert.java +++ b/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/assertions/PropertyAnnotationsAssert.java @@ -7,11 +7,11 @@ import org.assertj.core.util.CanIgnoreReturnValue; import com.github.javaparser.ast.expr.AnnotationExpr; @CanIgnoreReturnValue -public class PropertyAnnotationAssert extends AbstractAnnotationAssert { +public class PropertyAnnotationsAssert extends AbstractAnnotationsAssert { private final PropertyAssert propertyAssert; - protected PropertyAnnotationAssert(final PropertyAssert propertyAssert, final List annotationExpr) { + protected PropertyAnnotationsAssert(final PropertyAssert propertyAssert, final List annotationExpr) { super(annotationExpr); this.propertyAssert = propertyAssert; } diff --git a/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/assertions/PropertyAssert.java b/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/assertions/PropertyAssert.java index 9cf733a05a8..d75727c8bc8 100644 --- a/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/assertions/PropertyAssert.java +++ b/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/assertions/PropertyAssert.java @@ -27,7 +27,7 @@ public class PropertyAssert extends ObjectAssert { return this; } - public PropertyAnnotationAssert assertPropertyAnnotations() { - return new PropertyAnnotationAssert(this, actual.getAnnotations()); + public PropertyAnnotationsAssert assertPropertyAnnotations() { + return new PropertyAnnotationsAssert(this, actual.getAnnotations()); } } diff --git a/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/assertions/TypeAnnotationAssert.java b/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/assertions/TypeAnnotationsAssert.java similarity index 65% rename from modules/openapi-generator/src/test/java/org/openapitools/codegen/java/assertions/TypeAnnotationAssert.java rename to modules/openapi-generator/src/test/java/org/openapitools/codegen/java/assertions/TypeAnnotationsAssert.java index f8418510049..8da97accd1b 100644 --- a/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/assertions/TypeAnnotationAssert.java +++ b/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/assertions/TypeAnnotationsAssert.java @@ -7,11 +7,11 @@ import org.assertj.core.util.CanIgnoreReturnValue; import com.github.javaparser.ast.expr.AnnotationExpr; @CanIgnoreReturnValue -public class TypeAnnotationAssert extends AbstractAnnotationAssert { +public class TypeAnnotationsAssert extends AbstractAnnotationsAssert { private final JavaFileAssert fileAssert; - protected TypeAnnotationAssert(final JavaFileAssert fileAssert, final List annotationExpr) { + protected TypeAnnotationsAssert(final JavaFileAssert fileAssert, final List annotationExpr) { super(annotationExpr); this.fileAssert = fileAssert; } diff --git a/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/jaxrs/JavaJAXRSCXFCDIServerCodegenTest.java b/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/jaxrs/JavaJAXRSCXFCDIServerCodegenTest.java index 6dc31e2bd48..2f528391173 100644 --- a/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/jaxrs/JavaJAXRSCXFCDIServerCodegenTest.java +++ b/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/jaxrs/JavaJAXRSCXFCDIServerCodegenTest.java @@ -48,53 +48,53 @@ public class JavaJAXRSCXFCDIServerCodegenTest extends JavaJaxrsBaseTest { JavaFileAssert.assertThat(files.get("TestHeadersApi.java")) .assertMethod("headersTest") - .hasParameter("headerNumber").withType("BigDecimal") + .assertParameter("headerNumber").hasType("BigDecimal") .assertParameterAnnotations() .containsWithNameAndAttributes("ApiParam", ImmutableMap.of("defaultValue", "\"11.2\"")) .toParameter().toMethod() - .hasParameter("headerString").withType("String") + .assertParameter("headerString").hasType("String") .assertParameterAnnotations() .containsWithNameAndAttributes("ApiParam", ImmutableMap.of("defaultValue", "\"qwerty\"")) .toParameter().toMethod() - .hasParameter("headerStringWrapped").withType("String") + .assertParameter("headerStringWrapped").hasType("String") .assertParameterAnnotations() .containsWithNameAndAttributes("ApiParam", ImmutableMap.of("defaultValue", "\"qwerty\"")) .toParameter().toMethod() - .hasParameter("headerStringQuotes").withType("String") + .assertParameter("headerStringQuotes").hasType("String") .assertParameterAnnotations() .containsWithNameAndAttributes("ApiParam", ImmutableMap.of("defaultValue", "\"qwerty\\\"with quotes\\\" test\"")) .toParameter().toMethod() - .hasParameter("headerStringQuotesWrapped").withType("String") + .assertParameter("headerStringQuotesWrapped").hasType("String") .assertParameterAnnotations() .containsWithNameAndAttributes("ApiParam", ImmutableMap.of("defaultValue", "\"qwerty\\\"with quotes\\\" test\"")) .toParameter().toMethod() - .hasParameter("headerBoolean").withType("Boolean") + .assertParameter("headerBoolean").hasType("Boolean") .assertParameterAnnotations() .containsWithNameAndAttributes("ApiParam", ImmutableMap.of("defaultValue", "\"true\"")); JavaFileAssert.assertThat(files.get("TestQueryParamsApi.java")) .assertMethod("queryParamsTest") - .hasParameter("queryNumber").withType("BigDecimal") + .assertParameter("queryNumber").hasType("BigDecimal") .assertParameterAnnotations() .containsWithNameAndAttributes("ApiParam", ImmutableMap.of("defaultValue", "\"11.2\"")) .toParameter().toMethod() - .hasParameter("queryString").withType("String") + .assertParameter("queryString").hasType("String") .assertParameterAnnotations() .containsWithNameAndAttributes("ApiParam", ImmutableMap.of("defaultValue", "\"qwerty\"")) .toParameter().toMethod() - .hasParameter("queryStringWrapped").withType("String") + .assertParameter("queryStringWrapped").hasType("String") .assertParameterAnnotations() .containsWithNameAndAttributes("ApiParam", ImmutableMap.of("defaultValue", "\"qwerty\"")) .toParameter().toMethod() - .hasParameter("queryStringQuotes").withType("String") + .assertParameter("queryStringQuotes").hasType("String") .assertParameterAnnotations() .containsWithNameAndAttributes("ApiParam", ImmutableMap.of("defaultValue", "\"qwerty\\\"with quotes\\\" test\"")) .toParameter().toMethod() - .hasParameter("queryStringQuotesWrapped").withType("String") + .assertParameter("queryStringQuotesWrapped").hasType("String") .assertParameterAnnotations() .containsWithNameAndAttributes("ApiParam", ImmutableMap.of("defaultValue", "\"qwerty\\\"with quotes\\\" test\"")) .toParameter().toMethod() - .hasParameter("queryBoolean").withType("Boolean") + .assertParameter("queryBoolean").hasType("Boolean") .assertParameterAnnotations() .containsWithNameAndAttributes("ApiParam", ImmutableMap.of("defaultValue", "\"true\"")); } diff --git a/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/jaxrs/JavaJAXRSSpecServerCodegenTest.java b/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/jaxrs/JavaJAXRSSpecServerCodegenTest.java index dfd2e33fd4c..1a6427fc2db 100644 --- a/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/jaxrs/JavaJAXRSSpecServerCodegenTest.java +++ b/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/jaxrs/JavaJAXRSSpecServerCodegenTest.java @@ -293,7 +293,7 @@ public class JavaJAXRSSpecServerCodegenTest extends JavaJaxrsBaseTest { List files = generator.opts(clientOptInput).generate(); validateJavaSourceFiles(files); - TestUtils.ensureDoesNotContainsFile(files, output, "src/main/openapi/openapi.yaml"); + TestUtils.ensureDoesNotContainFile(files, output, "src/main/openapi/openapi.yaml"); output.deleteOnExit(); } @@ -660,53 +660,53 @@ public class JavaJAXRSSpecServerCodegenTest extends JavaJaxrsBaseTest { JavaFileAssert.assertThat(files.get("TestHeadersApi.java")) .assertMethod("headersTest") - .hasParameter("headerNumber").withType("BigDecimal") + .assertParameter("headerNumber").hasType("BigDecimal") .assertParameterAnnotations() .containsWithNameAndAttributes("DefaultValue", ImmutableMap.of("value", "\"11.2\"")) .toParameter().toMethod() - .hasParameter("headerString").withType("String") + .assertParameter("headerString").hasType("String") .assertParameterAnnotations() .containsWithNameAndAttributes("DefaultValue", ImmutableMap.of("value", "\"qwerty\"")) .toParameter().toMethod() - .hasParameter("headerStringWrapped").withType("String") + .assertParameter("headerStringWrapped").hasType("String") .assertParameterAnnotations() .containsWithNameAndAttributes("DefaultValue", ImmutableMap.of("value", "\"qwerty\"")) .toParameter().toMethod() - .hasParameter("headerStringQuotes").withType("String") + .assertParameter("headerStringQuotes").hasType("String") .assertParameterAnnotations() .containsWithNameAndAttributes("DefaultValue", ImmutableMap.of("value", "\"qwerty\\\"with quotes\\\" test\"")) .toParameter().toMethod() - .hasParameter("headerStringQuotesWrapped").withType("String") + .assertParameter("headerStringQuotesWrapped").hasType("String") .assertParameterAnnotations() .containsWithNameAndAttributes("DefaultValue", ImmutableMap.of("value", "\"qwerty\\\"with quotes\\\" test\"")) .toParameter().toMethod() - .hasParameter("headerBoolean").withType("Boolean") + .assertParameter("headerBoolean").hasType("Boolean") .assertParameterAnnotations() .containsWithNameAndAttributes("DefaultValue", ImmutableMap.of("value", "\"true\"")); JavaFileAssert.assertThat(files.get("TestQueryParamsApi.java")) .assertMethod("queryParamsTest") - .hasParameter("queryNumber").withType("BigDecimal") + .assertParameter("queryNumber").hasType("BigDecimal") .assertParameterAnnotations() .containsWithNameAndAttributes("DefaultValue", ImmutableMap.of("value", "\"11.2\"")) .toParameter().toMethod() - .hasParameter("queryString").withType("String") + .assertParameter("queryString").hasType("String") .assertParameterAnnotations() .containsWithNameAndAttributes("DefaultValue", ImmutableMap.of("value", "\"qwerty\"")) .toParameter().toMethod() - .hasParameter("queryStringWrapped").withType("String") + .assertParameter("queryStringWrapped").hasType("String") .assertParameterAnnotations() .containsWithNameAndAttributes("DefaultValue", ImmutableMap.of("value", "\"qwerty\"")) .toParameter().toMethod() - .hasParameter("queryStringQuotes").withType("String") + .assertParameter("queryStringQuotes").hasType("String") .assertParameterAnnotations() .containsWithNameAndAttributes("DefaultValue", ImmutableMap.of("value", "\"qwerty\\\"with quotes\\\" test\"")) .toParameter().toMethod() - .hasParameter("queryStringQuotesWrapped").withType("String") + .assertParameter("queryStringQuotesWrapped").hasType("String") .assertParameterAnnotations() .containsWithNameAndAttributes("DefaultValue", ImmutableMap.of("value", "\"qwerty\\\"with quotes\\\" test\"")) .toParameter().toMethod() - .hasParameter("queryBoolean").withType("Boolean") + .assertParameter("queryBoolean").hasType("Boolean") .assertParameterAnnotations() .containsWithNameAndAttributes("DefaultValue", ImmutableMap.of("value", "\"true\"")); } @@ -731,9 +731,9 @@ public class JavaJAXRSSpecServerCodegenTest extends JavaJaxrsBaseTest { JavaFileAssert.assertThat(files.get("ComplexObject.java")) .fileContains("private @Valid List dates") - .fileDoesNotContains("private @Valid SymbolTypeEnum symbolType") - .fileDoesNotContains("@Valid String") - .fileDoesNotContains("@Valid Double"); + .fileDoesNotContain("private @Valid SymbolTypeEnum symbolType") + .fileDoesNotContain("@Valid String") + .fileDoesNotContain("@Valid Double"); } @Test @@ -921,7 +921,7 @@ public class JavaJAXRSSpecServerCodegenTest extends JavaJaxrsBaseTest { .collect(Collectors.toMap(File::getName, Function.identity())); JavaFileAssert.assertThat(files.get("ReadonlyAndRequiredProperties.java")) - .hasProperty("requiredYesReadonlyYes") + .assertProperty("requiredYesReadonlyYes") .toType() .assertMethod("getRequiredYesReadonlyYes") .assertMethodAnnotations() @@ -931,7 +931,7 @@ public class JavaJAXRSSpecServerCodegenTest extends JavaJaxrsBaseTest { .containsWithNameAndAttributes("JsonProperty", ImmutableMap.of("value", "\"requiredYesReadonlyYes\"")) .toMethod() .toFileAssert() - .hasProperty("requiredYesReadonlyNo") + .assertProperty("requiredYesReadonlyNo") .toType() .assertMethod("getRequiredYesReadonlyNo") .assertMethodAnnotations() diff --git a/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/jaxrs/JavaJaxrsResteasyServerCodegenModelTest.java b/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/jaxrs/JavaJaxrsResteasyServerCodegenModelTest.java index 2d075457c9d..025d1d94d9f 100644 --- a/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/jaxrs/JavaJaxrsResteasyServerCodegenModelTest.java +++ b/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/jaxrs/JavaJaxrsResteasyServerCodegenModelTest.java @@ -97,53 +97,53 @@ public class JavaJaxrsResteasyServerCodegenModelTest extends JavaJaxrsBaseTest { JavaFileAssert.assertThat(files.get("TestHeadersApi.java")) .assertMethod("headersTest") - .hasParameter("headerNumber").withType("BigDecimal") + .assertParameter("headerNumber").hasType("BigDecimal") .assertParameterAnnotations() .containsWithNameAndAttributes("ApiParam", ImmutableMap.of("defaultValue", "\"11.2\"")) .toParameter().toMethod() - .hasParameter("headerString").withType("String") + .assertParameter("headerString").hasType("String") .assertParameterAnnotations() .containsWithNameAndAttributes("ApiParam", ImmutableMap.of("defaultValue", "\"qwerty\"")) .toParameter().toMethod() - .hasParameter("headerStringWrapped").withType("String") + .assertParameter("headerStringWrapped").hasType("String") .assertParameterAnnotations() .containsWithNameAndAttributes("ApiParam", ImmutableMap.of("defaultValue", "\"qwerty\"")) .toParameter().toMethod() - .hasParameter("headerStringQuotes").withType("String") + .assertParameter("headerStringQuotes").hasType("String") .assertParameterAnnotations() .containsWithNameAndAttributes("ApiParam", ImmutableMap.of("defaultValue", "\"qwerty\\\"with quotes\\\" test\"")) .toParameter().toMethod() - .hasParameter("headerStringQuotesWrapped").withType("String") + .assertParameter("headerStringQuotesWrapped").hasType("String") .assertParameterAnnotations() .containsWithNameAndAttributes("ApiParam", ImmutableMap.of("defaultValue", "\"qwerty\\\"with quotes\\\" test\"")) .toParameter().toMethod() - .hasParameter("headerBoolean").withType("Boolean") + .assertParameter("headerBoolean").hasType("Boolean") .assertParameterAnnotations() .containsWithNameAndAttributes("ApiParam", ImmutableMap.of("defaultValue", "\"true\"")); JavaFileAssert.assertThat(files.get("TestQueryParamsApi.java")) .assertMethod("queryParamsTest") - .hasParameter("queryNumber").withType("BigDecimal") + .assertParameter("queryNumber").hasType("BigDecimal") .assertParameterAnnotations() .containsWithNameAndAttributes("DefaultValue", ImmutableMap.of("value", "\"11.2\"")) .toParameter().toMethod() - .hasParameter("queryString").withType("String") + .assertParameter("queryString").hasType("String") .assertParameterAnnotations() .containsWithNameAndAttributes("DefaultValue", ImmutableMap.of("value", "\"qwerty\"")) .toParameter().toMethod() - .hasParameter("queryStringWrapped").withType("String") + .assertParameter("queryStringWrapped").hasType("String") .assertParameterAnnotations() .containsWithNameAndAttributes("DefaultValue", ImmutableMap.of("value", "\"qwerty\"")) .toParameter().toMethod() - .hasParameter("queryStringQuotes").withType("String") + .assertParameter("queryStringQuotes").hasType("String") .assertParameterAnnotations() .containsWithNameAndAttributes("DefaultValue", ImmutableMap.of("value", "\"qwerty\\\"with quotes\\\" test\"")) .toParameter().toMethod() - .hasParameter("queryStringQuotesWrapped").withType("String") + .assertParameter("queryStringQuotesWrapped").hasType("String") .assertParameterAnnotations() .containsWithNameAndAttributes("DefaultValue", ImmutableMap.of("value", "\"qwerty\\\"with quotes\\\" test\"")) .toParameter().toMethod() - .hasParameter("queryBoolean").withType("Boolean") + .assertParameter("queryBoolean").hasType("Boolean") .assertParameterAnnotations() .containsWithNameAndAttributes("DefaultValue", ImmutableMap.of("value", "\"true\"")); } diff --git a/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/jaxrs/JavaJerseyServerCodegenTest.java b/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/jaxrs/JavaJerseyServerCodegenTest.java index 8bfc4b12815..84ae0f65c3f 100644 --- a/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/jaxrs/JavaJerseyServerCodegenTest.java +++ b/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/jaxrs/JavaJerseyServerCodegenTest.java @@ -250,53 +250,53 @@ public class JavaJerseyServerCodegenTest extends JavaJaxrsBaseTest { JavaFileAssert.assertThat(files.get("TestHeadersApi.java")) .assertMethod("headersTest") - .hasParameter("headerNumber").withType("BigDecimal") + .assertParameter("headerNumber").hasType("BigDecimal") .assertParameterAnnotations() .containsWithNameAndAttributes("ApiParam", ImmutableMap.of("defaultValue", "\"11.2\"")) .toParameter().toMethod() - .hasParameter("headerString").withType("String") + .assertParameter("headerString").hasType("String") .assertParameterAnnotations() .containsWithNameAndAttributes("ApiParam", ImmutableMap.of("defaultValue", "\"qwerty\"")) .toParameter().toMethod() - .hasParameter("headerStringWrapped").withType("String") + .assertParameter("headerStringWrapped").hasType("String") .assertParameterAnnotations() .containsWithNameAndAttributes("ApiParam", ImmutableMap.of("defaultValue", "\"qwerty\"")) .toParameter().toMethod() - .hasParameter("headerStringQuotes").withType("String") + .assertParameter("headerStringQuotes").hasType("String") .assertParameterAnnotations() .containsWithNameAndAttributes("ApiParam", ImmutableMap.of("defaultValue", "\"qwerty\\\"with quotes\\\" test\"")) .toParameter().toMethod() - .hasParameter("headerStringQuotesWrapped").withType("String") + .assertParameter("headerStringQuotesWrapped").hasType("String") .assertParameterAnnotations() .containsWithNameAndAttributes("ApiParam", ImmutableMap.of("defaultValue", "\"qwerty\\\"with quotes\\\" test\"")) .toParameter().toMethod() - .hasParameter("headerBoolean").withType("Boolean") + .assertParameter("headerBoolean").hasType("Boolean") .assertParameterAnnotations() .containsWithNameAndAttributes("ApiParam", ImmutableMap.of("defaultValue", "\"true\"")); JavaFileAssert.assertThat(files.get("TestQueryParamsApi.java")) .assertMethod("queryParamsTest") - .hasParameter("queryNumber").withType("BigDecimal") + .assertParameter("queryNumber").hasType("BigDecimal") .assertParameterAnnotations() .containsWithNameAndAttributes("ApiParam", ImmutableMap.of("defaultValue", "\"11.2\"")) .toParameter().toMethod() - .hasParameter("queryString").withType("String") + .assertParameter("queryString").hasType("String") .assertParameterAnnotations() .containsWithNameAndAttributes("ApiParam", ImmutableMap.of("defaultValue", "\"qwerty\"")) .toParameter().toMethod() - .hasParameter("queryStringWrapped").withType("String") + .assertParameter("queryStringWrapped").hasType("String") .assertParameterAnnotations() .containsWithNameAndAttributes("ApiParam", ImmutableMap.of("defaultValue", "\"qwerty\"")) .toParameter().toMethod() - .hasParameter("queryStringQuotes").withType("String") + .assertParameter("queryStringQuotes").hasType("String") .assertParameterAnnotations() .containsWithNameAndAttributes("ApiParam", ImmutableMap.of("defaultValue", "\"qwerty\\\"with quotes\\\" test\"")) .toParameter().toMethod() - .hasParameter("queryStringQuotesWrapped").withType("String") + .assertParameter("queryStringQuotesWrapped").hasType("String") .assertParameterAnnotations() .containsWithNameAndAttributes("ApiParam", ImmutableMap.of("defaultValue", "\"qwerty\\\"with quotes\\\" test\"")) .toParameter().toMethod() - .hasParameter("queryBoolean").withType("Boolean") + .assertParameter("queryBoolean").hasType("Boolean") .assertParameterAnnotations() .containsWithNameAndAttributes("ApiParam", ImmutableMap.of("defaultValue", "\"true\"")); } diff --git a/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/micronaut/JavaMicronautClientCodegenTest.java b/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/micronaut/JavaMicronautClientCodegenTest.java index d3e50f79700..e6c7bc263f8 100644 --- a/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/micronaut/JavaMicronautClientCodegenTest.java +++ b/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/micronaut/JavaMicronautClientCodegenTest.java @@ -3,18 +3,21 @@ package org.openapitools.codegen.java.micronaut; import io.swagger.v3.oas.models.OpenAPI; import io.swagger.v3.oas.models.info.Info; import io.swagger.v3.oas.models.servers.Server; -import org.openapitools.codegen.*; +import org.openapitools.codegen.CliOption; +import org.openapitools.codegen.CodegenConstants; +import org.openapitools.codegen.DefaultGenerator; +import org.openapitools.codegen.config.CodegenConfigurator; import org.openapitools.codegen.java.assertions.JavaFileAssert; import org.openapitools.codegen.languages.JavaMicronautClientCodegen; import org.testng.Assert; import org.testng.annotations.Test; -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Path; +import java.io.File; +import java.util.List; import java.util.Map; import static java.util.stream.Collectors.groupingBy; +import static org.openapitools.codegen.TestUtils.newTempFolder; import static org.testng.Assert.assertEquals; @@ -323,27 +326,22 @@ public class JavaMicronautClientCodegenTest extends AbstractMicronautCodegenTest * Includes regression tests for: * - Correct Jackson annotation when `wrapped: false` */ - @Test public void shouldGenerateCorrectXmlAnnotations() throws IOException { + @Test public void shouldGenerateCorrectXmlAnnotations() { // Arrange - final String TEST_SPEC = "src/test/resources/3_0/java/xml-annotations-test.yaml"; - final Path output = Files.createTempDirectory("test-xml-annotations_"); - output.toFile().deleteOnExit(); - - JavaMicronautClientCodegen codegen = new JavaMicronautClientCodegen(); - codegen.setWithXml(true); - codegen.setOutputDir(output.toString()); - - DefaultGenerator generator = new DefaultGenerator(); - generator.setGeneratorPropertyDefault(CodegenConstants.MODELS, "true"); - generator.setGeneratorPropertyDefault(CodegenConstants.MODEL_TESTS, "false"); - generator.setGeneratorPropertyDefault(CodegenConstants.MODEL_DOCS, "false"); - generator.setGenerateMetadata(false); - + final CodegenConfigurator config = new CodegenConfigurator() + .addAdditionalProperty(CodegenConstants.WITH_XML, true) + .addGlobalProperty(CodegenConstants.MODELS, "Pet") + .addGlobalProperty(CodegenConstants.MODEL_DOCS, null) + .addGlobalProperty(CodegenConstants.MODEL_TESTS, null) + .setGeneratorName(JavaMicronautClientCodegen.NAME) + .setInputSpec("src/test/resources/3_0/java/xml-annotations-test.yaml") + .setOutputDir(newTempFolder().toString()); + // Act - generator.opts(new ClientOptInput().config(codegen).openAPI(TestUtils.parseSpec(TEST_SPEC))).generate(); + final List files = new DefaultGenerator().opts(config.toClientOptInput()).generate(); // Assert - JavaFileAssert.assertThat(output.resolve("src/main/java/org/openapitools/model/Pet.java").toFile()) + JavaFileAssert.assertThat(files.get(0)) .assertTypeAnnotations() .containsWithNameAndAttributes("JacksonXmlRootElement", Map.of("localName", "\"Pet\"", "namespace", "\"urn:jacksonxml\"")) .containsWithNameAndAttributes("XmlRootElement", Map.of("name", "\"Pet\"", "namespace", "\"urn:jacksonxml\"")) @@ -351,115 +349,115 @@ public class JavaMicronautClientCodegenTest extends AbstractMicronautCodegenTest .toType() // ↓ test custom-name on wrapper element (https://swagger.io/docs/specification/data-models/representing-xml/#:~:text=Use%20xml/name%20to%20give%20different%20names) - .hasProperty("tags").assertPropertyAnnotations() - .doesNotContainsWithName("XmlAttribute") + .assertProperty("tags").assertPropertyAnnotations() + .doesNotContainWithName("XmlAttribute") .containsWithNameAndAttributes("XmlElement", Map.of("name", "\"Tag\"")) .containsWithNameAndAttributes("XmlElementWrapper", Map.of("name", "\"TagList\"")) .toProperty().toType() - .assertMethod("getTags").assertMethodAnnotations() - .containsWithNameAndAttributes("JacksonXmlProperty", Map.of("localName", "\"Tag\"")) - .containsWithNameAndAttributes("JacksonXmlElementWrapper", Map.of("localName", "\"TagList\"", "useWrapping", "true")) - .toMethod().toFileAssert() + .assertMethod("getTags") + .hasAnnotation("JacksonXmlProperty", Map.of("localName", "\"Tag\"")) + .hasAnnotation("JacksonXmlElementWrapper", Map.of("localName", "\"TagList\"", "useWrapping", "true")) + .toFileAssert() // ↓ custom internal xml-array element name, non-wrapped (1st example in https://spec.openapis.org/oas/v3.0.0#xml-arrays) - .hasProperty("friends").assertPropertyAnnotations() - .doesNotContainsWithName("XmlAttribute") - .doesNotContainsWithName("XmlElementWrapper") + .assertProperty("friends").assertPropertyAnnotations() + .doesNotContainWithName("XmlAttribute") + .doesNotContainWithName("XmlElementWrapper") .containsWithNameAndAttributes("XmlElement", Map.of("name", "\"friend-pet\"")) .toProperty().toType() - .assertMethod("getFriends").assertMethodAnnotations() - .containsWithNameAndAttributes("JacksonXmlProperty", Map.of("localName", "\"friend-pet\"")) - .containsWithNameAndAttributes("JacksonXmlElementWrapper", Map.of("useWrapping", "false")) - .toMethod().toFileAssert() + .assertMethod("getFriends") + .hasAnnotation("JacksonXmlProperty", Map.of("localName", "\"friend-pet\"")) + .hasAnnotation("JacksonXmlElementWrapper", Map.of("useWrapping", "false")) + .toFileAssert() // ↓ test custom element name (https://swagger.io/docs/specification/data-models/representing-xml/#:~:text=Change%20Element%20Names) - .hasProperty("status").assertPropertyAnnotations() - .doesNotContainsWithName("XmlAttribute") - .doesNotContainsWithName("XmlElementWrapper") + .assertProperty("status").assertPropertyAnnotations() + .doesNotContainWithName("XmlAttribute") + .doesNotContainWithName("XmlElementWrapper") .containsWithNameAndAttributes("XmlElement", Map.of("name", "\"PetStatus\"")) .toProperty().toType() - .assertMethod("getStatus").assertMethodAnnotations() - .doesNotContainsWithName("JacksonXmlElementWrapper") - .containsWithNameAndAttributes("JacksonXmlProperty", Map.of("localName", "\"PetStatus\"")) - .toMethod().toFileAssert() + .assertMethod("getStatus") + .doesNotHaveAnnotation("JacksonXmlElementWrapper") + .hasAnnotation("JacksonXmlProperty", Map.of("localName", "\"PetStatus\"")) + .toFileAssert() // ↓ test same-name wrapping element (https://swagger.io/docs/specification/data-models/representing-xml/#:~:text=Wrapping%20Arrays) // maps to 3rd example in https://spec.openapis.org/oas/v3.0.0#xml-arrays - .hasProperty("photoUrls").assertPropertyAnnotations() - .doesNotContainsWithName("XmlAttribute") + .assertProperty("photoUrls").assertPropertyAnnotations() + .doesNotContainWithName("XmlAttribute") .containsWithNameAndAttributes("XmlElement", Map.of("name", "\"photoUrls\"")) .containsWithNameAndAttributes("XmlElementWrapper", Map.of("name", "\"photoUrls\"")) .toProperty().toType() - .assertMethod("getPhotoUrls").assertMethodAnnotations() - .containsWithNameAndAttributes("JacksonXmlProperty", Map.of("localName", "\"photoUrls\"")) - .containsWithNameAndAttributes("JacksonXmlElementWrapper", Map.of("localName", "\"photoUrls\"", "useWrapping", "true")) - .toMethod().toFileAssert() + .assertMethod("getPhotoUrls") + .hasAnnotation("JacksonXmlProperty", Map.of("localName", "\"photoUrls\"")) + .hasAnnotation("JacksonXmlElementWrapper", Map.of("localName", "\"photoUrls\"", "useWrapping", "true")) + .toFileAssert() // ↓ test attribute generation (https://swagger.io/docs/specification/data-models/representing-xml/#:~:text=Convert%20Property%20to%20an%20Attribute) - .hasProperty("name").assertPropertyAnnotations() - .doesNotContainsWithName("XmlElement") - .doesNotContainsWithName("XmlElementWrapper") + .assertProperty("name").assertPropertyAnnotations() + .doesNotContainWithName("XmlElement") + .doesNotContainWithName("XmlElementWrapper") .containsWithNameAndAttributes("XmlAttribute", Map.of("name", "\"name\"")) .toProperty().toType() - .assertMethod("getName").assertMethodAnnotations() - .doesNotContainsWithName("JacksonXmlElementWrapper") - .containsWithNameAndAttributes("JacksonXmlProperty", Map.of("isAttribute", "true", "localName", "\"name\"")) - .toMethod().toFileAssert() + .assertMethod("getName") + .doesNotHaveAnnotation("JacksonXmlElementWrapper") + .hasAnnotation("JacksonXmlProperty", Map.of("isAttribute", "true", "localName", "\"name\"")) + .toFileAssert() // ↓ test XML namespace and prefix (https://swagger.io/docs/specification/data-models/representing-xml/#:~:text=Prefixes%20and%20Namespaces) - .hasProperty("id").assertPropertyAnnotations() - .doesNotContainsWithName("XmlAttribute") - .doesNotContainsWithName("XmlElementWrapper") + .assertProperty("id").assertPropertyAnnotations() + .doesNotContainWithName("XmlAttribute") + .doesNotContainWithName("XmlElementWrapper") .containsWithNameAndAttributes("XmlElement", Map.of("name", "\"id\"", "namespace", "\"http://example.com/schema\"")) .toProperty().toType() - .assertMethod("getId").assertMethodAnnotations() - .doesNotContainsWithName("JacksonXmlElementWrapper") - .containsWithNameAndAttributes("JacksonXmlProperty", Map.of("localName", "\"id\"", "namespace", "\"http://example.com/schema\"")) - .toMethod().toFileAssert() + .assertMethod("getId") + .doesNotHaveAnnotation("JacksonXmlElementWrapper") + .hasAnnotation("JacksonXmlProperty", Map.of("localName", "\"id\"", "namespace", "\"http://example.com/schema\"")) + .toFileAssert() // ↓ external xml-array element name only (last example in https://spec.openapis.org/oas/v3.0.0#xml-arrays) - .hasProperty("foods").assertPropertyAnnotations() - .doesNotContainsWithName("XmlAttribute") + .assertProperty("foods").assertPropertyAnnotations() + .doesNotContainWithName("XmlAttribute") .containsWithNameAndAttributes("XmlElement", Map.of("name", "\"yummy-yummy\"")) .containsWithNameAndAttributes("XmlElementWrapper", Map.of("name", "\"yummy-yummy\"")) .toProperty().toType() - .assertMethod("getFoods").assertMethodAnnotations() - .containsWithNameAndAttributes("JacksonXmlProperty", Map.of("localName", "\"yummy-yummy\"")) - .containsWithNameAndAttributes("JacksonXmlElementWrapper", Map.of("localName", "\"yummy-yummy\"")) - .toMethod().toFileAssert() + .assertMethod("getFoods") + .hasAnnotation("JacksonXmlProperty", Map.of("localName", "\"yummy-yummy\"")) + .hasAnnotation("JacksonXmlElementWrapper", Map.of("localName", "\"yummy-yummy\"")) + .toFileAssert() // ↓ internal xml-array element name (4th example in https://spec.openapis.org/oas/v3.0.0#xml-arrays) - .hasProperty("colors").assertPropertyAnnotations() - .doesNotContainsWithName("XmlAttribute") + .assertProperty("colors").assertPropertyAnnotations() + .doesNotContainWithName("XmlAttribute") .containsWithNameAndAttributes("XmlElement", Map.of("name", "\"color\"")) .containsWithNameAndAttributes("XmlElementWrapper", Map.of("name", "\"colors\"")) .toProperty().toType() - .assertMethod("getColors").assertMethodAnnotations() - .containsWithNameAndAttributes("JacksonXmlProperty", Map.of("localName", "\"color\"")) - .containsWithNameAndAttributes("JacksonXmlElementWrapper", Map.of("localName", "\"colors\"")) - .toMethod().toFileAssert() + .assertMethod("getColors") + .hasAnnotation("JacksonXmlProperty", Map.of("localName", "\"color\"")) + .hasAnnotation("JacksonXmlElementWrapper", Map.of("localName", "\"colors\"")) + .toFileAssert() // ↓ ignored external xml-array element name, non-wrapped (2nd example in https://spec.openapis.org/oas/v3.0.0#xml-arrays) - .hasProperty("categories").assertPropertyAnnotations() - .doesNotContainsWithName("XmlAttribute") - .doesNotContainsWithName("XmlElementWrapper") + .assertProperty("categories").assertPropertyAnnotations() + .doesNotContainWithName("XmlAttribute") + .doesNotContainWithName("XmlElementWrapper") .containsWithNameAndAttributes("XmlElement", Map.of("name", "\"Category\"")) .toProperty().toType() - .assertMethod("getCategories").assertMethodAnnotations() - .containsWithNameAndAttributes("JacksonXmlProperty", Map.of("localName", "\"Category\"")) + .assertMethod("getCategories") + .hasAnnotation("JacksonXmlProperty", Map.of("localName", "\"Category\"")) // ↓ specific regression test for #2417: (useWrapping=false) needs to be present - .containsWithNameAndAttributes("JacksonXmlElementWrapper", Map.of("useWrapping", "false")) - .toMethod().toFileAssert() + .hasAnnotation("JacksonXmlElementWrapper", Map.of("useWrapping", "false")) + .toFileAssert() // ↓ test custom-name on wrapper AND children (https://swagger.io/docs/specification/data-models/representing-xml/#:~:text=Use%20xml/name%20to%20give%20different%20names) // maps to 5th example in https://spec.openapis.org/oas/v3.0.0#xml-arrays - .hasProperty("activities").assertPropertyAnnotations() - .doesNotContainsWithName("XmlAttribute") + .assertProperty("activities").assertPropertyAnnotations() + .doesNotContainWithName("XmlAttribute") .containsWithNameAndAttributes("XmlElement", Map.of("name", "\"item\"")) .containsWithNameAndAttributes("XmlElementWrapper", Map.of("name", "\"activities-array\"")) .toProperty().toType() - .assertMethod("getActivities").assertMethodAnnotations() - .containsWithNameAndAttributes("JacksonXmlProperty", Map.of("localName", "\"item\"")) - .containsWithNameAndAttributes("JacksonXmlElementWrapper", Map.of("localName", "\"activities-array\"")); + .assertMethod("getActivities") + .hasAnnotation("JacksonXmlProperty", Map.of("localName", "\"item\"")) + .hasAnnotation("JacksonXmlElementWrapper", Map.of("localName", "\"activities-array\"")); } } diff --git a/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/micronaut/JavaMicronautServerCodegenTest.java b/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/micronaut/JavaMicronautServerCodegenTest.java index e2b79e245d0..0102e24b602 100644 --- a/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/micronaut/JavaMicronautServerCodegenTest.java +++ b/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/micronaut/JavaMicronautServerCodegenTest.java @@ -3,18 +3,22 @@ package org.openapitools.codegen.java.micronaut; import io.swagger.v3.oas.models.OpenAPI; import io.swagger.v3.oas.models.info.Info; import io.swagger.v3.oas.models.servers.Server; -import org.openapitools.codegen.*; +import org.openapitools.codegen.CliOption; +import org.openapitools.codegen.CodegenConstants; +import org.openapitools.codegen.DefaultGenerator; +import org.openapitools.codegen.TestUtils; +import org.openapitools.codegen.config.CodegenConfigurator; import org.openapitools.codegen.java.assertions.JavaFileAssert; import org.openapitools.codegen.languages.JavaMicronautServerCodegen; import org.testng.Assert; import org.testng.annotations.Test; -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Path; +import java.io.File; +import java.util.List; import java.util.Map; import static java.util.stream.Collectors.groupingBy; +import static org.openapitools.codegen.TestUtils.newTempFolder; import static org.testng.Assert.assertEquals; public class JavaMicronautServerCodegenTest extends AbstractMicronautCodegenTest { @@ -352,27 +356,22 @@ public class JavaMicronautServerCodegenTest extends AbstractMicronautCodegenTest * Includes regression tests for: * - Correct Jackson annotation when `wrapped: false` */ - @Test public void shouldGenerateCorrectXmlAnnotations() throws IOException { + @Test public void shouldGenerateCorrectXmlAnnotations() { // Arrange - final String TEST_SPEC = "src/test/resources/3_0/java/xml-annotations-test.yaml"; - final Path output = Files.createTempDirectory("test-xml-annotations_"); - output.toFile().deleteOnExit(); - - JavaMicronautServerCodegen codegen = new JavaMicronautServerCodegen(); - codegen.setWithXml(true); - codegen.setOutputDir(output.toString()); - - DefaultGenerator generator = new DefaultGenerator(); - generator.setGeneratorPropertyDefault(CodegenConstants.MODELS, "true"); - generator.setGeneratorPropertyDefault(CodegenConstants.MODEL_TESTS, "false"); - generator.setGeneratorPropertyDefault(CodegenConstants.MODEL_DOCS, "false"); - generator.setGenerateMetadata(false); + final CodegenConfigurator config = new CodegenConfigurator() + .addAdditionalProperty(CodegenConstants.WITH_XML, true) + .addGlobalProperty(CodegenConstants.MODELS, "Pet") + .addGlobalProperty(CodegenConstants.MODEL_DOCS, null) + .addGlobalProperty(CodegenConstants.MODEL_TESTS, null) + .setGeneratorName(JavaMicronautServerCodegen.NAME) + .setInputSpec("src/test/resources/3_0/java/xml-annotations-test.yaml") + .setOutputDir(newTempFolder().toString()); // Act - generator.opts(new ClientOptInput().config(codegen).openAPI(TestUtils.parseSpec(TEST_SPEC))).generate(); + final List files = new DefaultGenerator().opts(config.toClientOptInput()).generate(); // Assert - JavaFileAssert.assertThat(output.resolve("src/main/java/org/openapitools/model/Pet.java").toFile()) + JavaFileAssert.assertThat(files.get(0)) .assertTypeAnnotations() .containsWithNameAndAttributes("JacksonXmlRootElement", Map.of("localName", "\"Pet\"", "namespace", "\"urn:jacksonxml\"")) .containsWithNameAndAttributes("XmlRootElement", Map.of("name", "\"Pet\"", "namespace", "\"urn:jacksonxml\"")) @@ -380,115 +379,115 @@ public class JavaMicronautServerCodegenTest extends AbstractMicronautCodegenTest .toType() // ↓ test custom-name on wrapper element (https://swagger.io/docs/specification/data-models/representing-xml/#:~:text=Use%20xml/name%20to%20give%20different%20names) - .hasProperty("tags").assertPropertyAnnotations() - .doesNotContainsWithName("XmlAttribute") + .assertProperty("tags").assertPropertyAnnotations() + .doesNotContainWithName("XmlAttribute") .containsWithNameAndAttributes("XmlElement", Map.of("name", "\"Tag\"")) .containsWithNameAndAttributes("XmlElementWrapper", Map.of("name", "\"TagList\"")) .toProperty().toType() - .assertMethod("getTags").assertMethodAnnotations() - .containsWithNameAndAttributes("JacksonXmlProperty", Map.of("localName", "\"Tag\"")) - .containsWithNameAndAttributes("JacksonXmlElementWrapper", Map.of("localName", "\"TagList\"", "useWrapping", "true")) - .toMethod().toFileAssert() + .assertMethod("getTags") + .hasAnnotation("JacksonXmlProperty", Map.of("localName", "\"Tag\"")) + .hasAnnotation("JacksonXmlElementWrapper", Map.of("localName", "\"TagList\"", "useWrapping", "true")) + .toFileAssert() // ↓ custom internal xml-array element name, non-wrapped (1st example in https://spec.openapis.org/oas/v3.0.0#xml-arrays) - .hasProperty("friends").assertPropertyAnnotations() - .doesNotContainsWithName("XmlAttribute") - .doesNotContainsWithName("XmlElementWrapper") + .assertProperty("friends").assertPropertyAnnotations() + .doesNotContainWithName("XmlAttribute") + .doesNotContainWithName("XmlElementWrapper") .containsWithNameAndAttributes("XmlElement", Map.of("name", "\"friend-pet\"")) .toProperty().toType() - .assertMethod("getFriends").assertMethodAnnotations() - .containsWithNameAndAttributes("JacksonXmlProperty", Map.of("localName", "\"friend-pet\"")) - .containsWithNameAndAttributes("JacksonXmlElementWrapper", Map.of("useWrapping", "false")) - .toMethod().toFileAssert() + .assertMethod("getFriends") + .hasAnnotation("JacksonXmlProperty", Map.of("localName", "\"friend-pet\"")) + .hasAnnotation("JacksonXmlElementWrapper", Map.of("useWrapping", "false")) + .toFileAssert() // ↓ test custom element name (https://swagger.io/docs/specification/data-models/representing-xml/#:~:text=Change%20Element%20Names) - .hasProperty("status").assertPropertyAnnotations() - .doesNotContainsWithName("XmlAttribute") - .doesNotContainsWithName("XmlElementWrapper") + .assertProperty("status").assertPropertyAnnotations() + .doesNotContainWithName("XmlAttribute") + .doesNotContainWithName("XmlElementWrapper") .containsWithNameAndAttributes("XmlElement", Map.of("name", "\"PetStatus\"")) .toProperty().toType() - .assertMethod("getStatus").assertMethodAnnotations() - .doesNotContainsWithName("JacksonXmlElementWrapper") - .containsWithNameAndAttributes("JacksonXmlProperty", Map.of("localName", "\"PetStatus\"")) - .toMethod().toFileAssert() + .assertMethod("getStatus") + .doesNotHaveAnnotation("JacksonXmlElementWrapper") + .hasAnnotation("JacksonXmlProperty", Map.of("localName", "\"PetStatus\"")) + .toFileAssert() // ↓ test same-name wrapping element (https://swagger.io/docs/specification/data-models/representing-xml/#:~:text=Wrapping%20Arrays) // maps to 3rd example in https://spec.openapis.org/oas/v3.0.0#xml-arrays - .hasProperty("photoUrls").assertPropertyAnnotations() - .doesNotContainsWithName("XmlAttribute") + .assertProperty("photoUrls").assertPropertyAnnotations() + .doesNotContainWithName("XmlAttribute") .containsWithNameAndAttributes("XmlElement", Map.of("name", "\"photoUrls\"")) .containsWithNameAndAttributes("XmlElementWrapper", Map.of("name", "\"photoUrls\"")) .toProperty().toType() - .assertMethod("getPhotoUrls").assertMethodAnnotations() - .containsWithNameAndAttributes("JacksonXmlProperty", Map.of("localName", "\"photoUrls\"")) - .containsWithNameAndAttributes("JacksonXmlElementWrapper", Map.of("localName", "\"photoUrls\"", "useWrapping", "true")) - .toMethod().toFileAssert() + .assertMethod("getPhotoUrls") + .hasAnnotation("JacksonXmlProperty", Map.of("localName", "\"photoUrls\"")) + .hasAnnotation("JacksonXmlElementWrapper", Map.of("localName", "\"photoUrls\"", "useWrapping", "true")) + .toFileAssert() // ↓ test attribute generation (https://swagger.io/docs/specification/data-models/representing-xml/#:~:text=Convert%20Property%20to%20an%20Attribute) - .hasProperty("name").assertPropertyAnnotations() - .doesNotContainsWithName("XmlElement") - .doesNotContainsWithName("XmlElementWrapper") + .assertProperty("name").assertPropertyAnnotations() + .doesNotContainWithName("XmlElement") + .doesNotContainWithName("XmlElementWrapper") .containsWithNameAndAttributes("XmlAttribute", Map.of("name", "\"name\"")) .toProperty().toType() - .assertMethod("getName").assertMethodAnnotations() - .doesNotContainsWithName("JacksonXmlElementWrapper") - .containsWithNameAndAttributes("JacksonXmlProperty", Map.of("isAttribute", "true", "localName", "\"name\"")) - .toMethod().toFileAssert() + .assertMethod("getName") + .doesNotHaveAnnotation("JacksonXmlElementWrapper") + .hasAnnotation("JacksonXmlProperty", Map.of("isAttribute", "true", "localName", "\"name\"")) + .toFileAssert() // ↓ test XML namespace and prefix (https://swagger.io/docs/specification/data-models/representing-xml/#:~:text=Prefixes%20and%20Namespaces) - .hasProperty("id").assertPropertyAnnotations() - .doesNotContainsWithName("XmlAttribute") - .doesNotContainsWithName("XmlElementWrapper") + .assertProperty("id").assertPropertyAnnotations() + .doesNotContainWithName("XmlAttribute") + .doesNotContainWithName("XmlElementWrapper") .containsWithNameAndAttributes("XmlElement", Map.of("name", "\"id\"", "namespace", "\"http://example.com/schema\"")) .toProperty().toType() - .assertMethod("getId").assertMethodAnnotations() - .doesNotContainsWithName("JacksonXmlElementWrapper") - .containsWithNameAndAttributes("JacksonXmlProperty", Map.of("localName", "\"id\"", "namespace", "\"http://example.com/schema\"")) - .toMethod().toFileAssert() + .assertMethod("getId") + .doesNotHaveAnnotation("JacksonXmlElementWrapper") + .hasAnnotation("JacksonXmlProperty", Map.of("localName", "\"id\"", "namespace", "\"http://example.com/schema\"")) + .toFileAssert() // ↓ external xml-array element name only (last example in https://spec.openapis.org/oas/v3.0.0#xml-arrays) - .hasProperty("foods").assertPropertyAnnotations() - .doesNotContainsWithName("XmlAttribute") + .assertProperty("foods").assertPropertyAnnotations() + .doesNotContainWithName("XmlAttribute") .containsWithNameAndAttributes("XmlElement", Map.of("name", "\"yummy-yummy\"")) .containsWithNameAndAttributes("XmlElementWrapper", Map.of("name", "\"yummy-yummy\"")) .toProperty().toType() - .assertMethod("getFoods").assertMethodAnnotations() - .containsWithNameAndAttributes("JacksonXmlProperty", Map.of("localName", "\"yummy-yummy\"")) - .containsWithNameAndAttributes("JacksonXmlElementWrapper", Map.of("localName", "\"yummy-yummy\"")) - .toMethod().toFileAssert() + .assertMethod("getFoods") + .hasAnnotation("JacksonXmlProperty", Map.of("localName", "\"yummy-yummy\"")) + .hasAnnotation("JacksonXmlElementWrapper", Map.of("localName", "\"yummy-yummy\"")) + .toFileAssert() // ↓ internal xml-array element name (4th example in https://spec.openapis.org/oas/v3.0.0#xml-arrays) - .hasProperty("colors").assertPropertyAnnotations() - .doesNotContainsWithName("XmlAttribute") + .assertProperty("colors").assertPropertyAnnotations() + .doesNotContainWithName("XmlAttribute") .containsWithNameAndAttributes("XmlElement", Map.of("name", "\"color\"")) .containsWithNameAndAttributes("XmlElementWrapper", Map.of("name", "\"colors\"")) .toProperty().toType() - .assertMethod("getColors").assertMethodAnnotations() - .containsWithNameAndAttributes("JacksonXmlProperty", Map.of("localName", "\"color\"")) - .containsWithNameAndAttributes("JacksonXmlElementWrapper", Map.of("localName", "\"colors\"")) - .toMethod().toFileAssert() + .assertMethod("getColors") + .hasAnnotation("JacksonXmlProperty", Map.of("localName", "\"color\"")) + .hasAnnotation("JacksonXmlElementWrapper", Map.of("localName", "\"colors\"")) + .toFileAssert() // ↓ ignored external xml-array element name, non-wrapped (2nd example in https://spec.openapis.org/oas/v3.0.0#xml-arrays) - .hasProperty("categories").assertPropertyAnnotations() - .doesNotContainsWithName("XmlAttribute") - .doesNotContainsWithName("XmlElementWrapper") + .assertProperty("categories").assertPropertyAnnotations() + .doesNotContainWithName("XmlAttribute") + .doesNotContainWithName("XmlElementWrapper") .containsWithNameAndAttributes("XmlElement", Map.of("name", "\"Category\"")) .toProperty().toType() - .assertMethod("getCategories").assertMethodAnnotations() - .containsWithNameAndAttributes("JacksonXmlProperty", Map.of("localName", "\"Category\"")) + .assertMethod("getCategories") + .hasAnnotation("JacksonXmlProperty", Map.of("localName", "\"Category\"")) // ↓ specific regression test for #2417: (useWrapping=false) needs to be present - .containsWithNameAndAttributes("JacksonXmlElementWrapper", Map.of("useWrapping", "false")) - .toMethod().toFileAssert() + .hasAnnotation("JacksonXmlElementWrapper", Map.of("useWrapping", "false")) + .toFileAssert() // ↓ test custom-name on wrapper AND children (https://swagger.io/docs/specification/data-models/representing-xml/#:~:text=Use%20xml/name%20to%20give%20different%20names) // maps to 5th example in https://spec.openapis.org/oas/v3.0.0#xml-arrays - .hasProperty("activities").assertPropertyAnnotations() - .doesNotContainsWithName("XmlAttribute") + .assertProperty("activities").assertPropertyAnnotations() + .doesNotContainWithName("XmlAttribute") .containsWithNameAndAttributes("XmlElement", Map.of("name", "\"item\"")) .containsWithNameAndAttributes("XmlElementWrapper", Map.of("name", "\"activities-array\"")) .toProperty().toType() - .assertMethod("getActivities").assertMethodAnnotations() - .containsWithNameAndAttributes("JacksonXmlProperty", Map.of("localName", "\"item\"")) - .containsWithNameAndAttributes("JacksonXmlElementWrapper", Map.of("localName", "\"activities-array\"")); + .assertMethod("getActivities") + .hasAnnotation("JacksonXmlProperty", Map.of("localName", "\"item\"")) + .hasAnnotation("JacksonXmlElementWrapper", Map.of("localName", "\"activities-array\"")); } } diff --git a/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/spring/SpringCodegenTest.java b/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/spring/SpringCodegenTest.java index 21ae7fdb8e4..e00f2b6bb72 100644 --- a/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/spring/SpringCodegenTest.java +++ b/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/spring/SpringCodegenTest.java @@ -57,8 +57,7 @@ import java.util.stream.Collectors; import static java.util.stream.Collectors.groupingBy; import static org.assertj.core.api.Assertions.assertThat; -import static org.openapitools.codegen.TestUtils.assertFileContains; -import static org.openapitools.codegen.TestUtils.assertFileNotContains; +import static org.openapitools.codegen.TestUtils.*; import static org.openapitools.codegen.languages.AbstractJavaCodegen.GENERATE_BUILDERS; import static org.openapitools.codegen.languages.AbstractJavaCodegen.GENERATE_CONSTRUCTOR_WITH_ALL_ARGS; import static org.openapitools.codegen.languages.SpringCodegen.*; @@ -126,26 +125,26 @@ public class SpringCodegenTest { "value", "\"/zebras\"" )) .toMethod() - .hasParameter("limit").withType("BigDecimal") + .assertParameter("limit").hasType("BigDecimal") .assertParameterAnnotations() .containsWithName("Valid") .containsWithNameAndAttributes("Parameter", ImmutableMap.of("name", "\"limit\"")) .containsWithNameAndAttributes("RequestParam", ImmutableMap.of("required", "false", "value", "\"limit\"")) .toParameter() .toMethod() - .hasParameter("animalParams").withType("AnimalParams") + .assertParameter("animalParams").hasType("AnimalParams") .toMethod() .commentContainsLines("GET /zebras", "@param limit (optional)") .bodyContainsLines("return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED)"); JavaFileAssert.assertThat(Paths.get(outputPath + "/src/main/java/org/openapitools/model/AnimalParams.java")) .hasImports("org.springframework.format.annotation.DateTimeFormat") - .hasProperty("born").withType("LocalDate") + .assertProperty("born").withType("LocalDate") .assertPropertyAnnotations() .containsWithNameAndAttributes("DateTimeFormat", ImmutableMap.of("iso", "DateTimeFormat.ISO.DATE")) .toProperty() .toType() - .hasProperty("lastSeen").withType("OffsetDateTime") + .assertProperty("lastSeen").withType("OffsetDateTime") .assertPropertyAnnotations() .containsWithNameAndAttributes("DateTimeFormat", ImmutableMap.of("iso", "DateTimeFormat.ISO.DATE_TIME")) .toProperty().toType() @@ -204,26 +203,26 @@ public class SpringCodegenTest { "value", "\"/zebras\"" )) .toMethod() - .hasParameter("limit").withType("Optional") + .assertParameter("limit").hasType("Optional") .assertParameterAnnotations() .containsWithName("Valid") .containsWithNameAndAttributes("Parameter", ImmutableMap.of("name", "\"limit\"")) .containsWithNameAndAttributes("RequestParam", ImmutableMap.of("required", "false", "value", "\"limit\"")) .toParameter() .toMethod() - .hasParameter("animalParams").withType("Optional") + .assertParameter("animalParams").hasType("Optional") .toMethod() .commentContainsLines("GET /zebras", "@param limit (optional)") .bodyContainsLines("return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED)"); JavaFileAssert.assertThat(Paths.get(outputPath + "/src/main/java/org/openapitools/model/AnimalParams.java")) .hasImports("org.springframework.format.annotation.DateTimeFormat") - .hasProperty("born").withType("Optional") + .assertProperty("born").withType("Optional") .assertPropertyAnnotations() .containsWithNameAndAttributes("DateTimeFormat", ImmutableMap.of("iso", "DateTimeFormat.ISO.DATE")) .toProperty() .toType() - .hasProperty("lastSeen").withType("Optional") + .assertProperty("lastSeen").withType("Optional") .assertPropertyAnnotations() .containsWithNameAndAttributes("DateTimeFormat", ImmutableMap.of("iso", "DateTimeFormat.ISO.DATE_TIME")) .toProperty().toType() @@ -259,13 +258,13 @@ public class SpringCodegenTest { JavaFileAssert.assertThat(Paths.get(outputPath + "/src/main/java/org/openapitools/api/ElephantsApi.java")) .assertMethod("getElephants", "String", "BigDecimal") - .hasParameter("userToken") + .assertParameter("userToken") .assertParameterAnnotations() .containsWithNameAndAttributes("CookieValue", ImmutableMap.of("name", "\"userToken\"")); JavaFileAssert.assertThat(Paths.get(outputPath + "/src/main/java/org/openapitools/api/ZebrasApi.java")) .assertMethod("getZebras", "String") - .hasParameter("userToken") + .assertParameter("userToken") .assertParameterAnnotations() .containsWithNameAndAttributes("CookieValue", ImmutableMap.of("name", "\"userToken\"")); @@ -367,14 +366,14 @@ public class SpringCodegenTest { JavaFileAssert.assertThat(Paths.get(outputPath + "/src/main/java/org/openapitools/api/ElephantsApi.java")) .hasImports("org.springframework.format.annotation.DateTimeFormat") .assertMethod("getElephants", "LocalDate") - .hasParameter("startDate") + .assertParameter("startDate") .assertParameterAnnotations() .containsWithNameAndAttributes("DateTimeFormat", ImmutableMap.of("iso", "DateTimeFormat.ISO.DATE")); JavaFileAssert.assertThat(Paths.get(outputPath + "/src/main/java/org/openapitools/api/ZebrasApi.java")) .hasImports("org.springframework.format.annotation.DateTimeFormat") .assertMethod("getZebras", "OffsetDateTime") - .hasParameter("startDateTime") + .assertParameter("startDateTime") .assertParameterAnnotations() .containsWithNameAndAttributes("DateTimeFormat", ImmutableMap.of("iso", "DateTimeFormat.ISO.DATE_TIME")); } @@ -425,11 +424,11 @@ public class SpringCodegenTest { JavaFileAssert.assertThat(Paths.get(outputPath + "/src/main/java/org/openapitools/api/ExampleApi.java")) .assertMethod("exampleApiGet", "String", "Format") - .hasParameter("query") + .assertParameter("query") .assertParameterAnnotations() .containsWithNameAndAttributes("RequestParam", ImmutableMap.of("value", "\"query\"")) .toParameter().toMethod() - .hasParameter("format") + .assertParameter("format") .assertParameterAnnotations() .containsWithNameAndAttributes("RequestParam", ImmutableMap.of("value", "\"format\"")); } @@ -462,7 +461,7 @@ public class SpringCodegenTest { JavaFileAssert.assertThat(Paths.get(outputPath + "/src/main/java/org/openapitools/api/ExampleApi.java")) .assertMethod("exampleApiGet", "OffsetDateTime") - .hasParameter("start") + .assertParameter("start") .assertParameterAnnotations() .containsWithNameAndAttributes("RequestParam", ImmutableMap.of("value", "\"start\"")) .containsWithNameAndAttributes("DateTimeFormat", ImmutableMap.of("iso", "DateTimeFormat.ISO.DATE_TIME")); @@ -637,7 +636,7 @@ public class SpringCodegenTest { JavaFileAssert.assertThat(Paths.get(outputPath + "/src/main/java/org/openapitools/api/ExampleApi.java")) .fileContains("@RequestBody(required = false") .assertMethod("exampleApiPost", "ExampleApiPostRequest") - .hasParameter("exampleApiPostRequest") + .assertParameter("exampleApiPostRequest") .assertParameterAnnotations() .containsWithNameAndAttributes("RequestBody", ImmutableMap.of("required", "false")); } @@ -681,12 +680,12 @@ public class SpringCodegenTest { // Check that the delegate handles the array JavaFileAssert.assertThat(files.get("MultipartArrayApiDelegate.java")) .assertMethod("multipartArray", "List") - .hasParameter("files").withType("List"); + .assertParameter("files").hasType("List"); // Check that the api handles the array JavaFileAssert.assertThat(files.get("MultipartArrayApi.java")) .assertMethod("multipartArray", "List") - .hasParameter("files").withType("List") + .assertParameter("files").hasType("List") .assertParameterAnnotations() .containsWithNameAndAttributes("ApiParam", ImmutableMap.of("value", "\"Many files\"")) .containsWithNameAndAttributes("RequestPart", ImmutableMap.of("value", "\"files\"", "required", "false")); @@ -701,7 +700,7 @@ public class SpringCodegenTest { // Check that the api handles the single file JavaFileAssert.assertThat(files.get("MultipartSingleApi.java")) .assertMethod("multipartSingle", "MultipartFile") - .hasParameter("file").withType("MultipartFile") + .assertParameter("file").hasType("MultipartFile") .assertParameterAnnotations() .containsWithNameAndAttributes("ApiParam", ImmutableMap.of("value", "\"One file\"")) .containsWithNameAndAttributes("RequestPart", ImmutableMap.of("value", "\"file\"", "required", "false")); @@ -709,21 +708,21 @@ public class SpringCodegenTest { // Check that api validates mixed multipart request JavaFileAssert.assertThat(files.get("MultipartMixedApi.java")) .assertMethod("multipartMixed", "MultipartMixedStatus", "MultipartFile", "MultipartMixedRequestMarker", "List") - .hasParameter("status").withType("MultipartMixedStatus") + .assertParameter("status").hasType("MultipartMixedStatus") .assertParameterAnnotations() .containsWithName("Valid") .containsWithNameAndAttributes("ApiParam", ImmutableMap.of("value", "\"\"")) .containsWithNameAndAttributes("RequestParam", ImmutableMap.of("value", "\"status\"", "required", "true")) .toParameter().toMethod() - .hasParameter("file").withType("MultipartFile") + .assertParameter("file").hasType("MultipartFile") .assertParameterAnnotations() .containsWithNameAndAttributes("RequestPart", ImmutableMap.of("value", "\"file\"", "required", "true")) .toParameter().toMethod() - .hasParameter("marker").withType("MultipartMixedRequestMarker") + .assertParameter("marker").hasType("MultipartMixedRequestMarker") .assertParameterAnnotations() .containsWithNameAndAttributes("RequestPart", ImmutableMap.of("value", "\"marker\"", "required", "false")) .toParameter().toMethod() - .hasParameter("statusArray").withType("List") + .assertParameter("statusArray").hasType("List") .assertParameterAnnotations() .containsWithNameAndAttributes("RequestPart", ImmutableMap.of("value", "\"statusArray\"", "required", "false")); } @@ -735,21 +734,21 @@ public class SpringCodegenTest { final Map files = generateFiles(codegen, "src/test/resources/3_0/spring/petstore-with-fake-endpoints-models-for-testing.yaml"); JavaFileAssert.assertThat(files.get("AdditionalPropertiesAnyType.java")) - .hasProperty("additionalProperties").withType("Map") + .assertProperty("additionalProperties").withType("Map") .toType() .assertMethod("putAdditionalProperty", "String", "Object") .toFileAssert() .assertMethod("getAdditionalProperty", "String").hasReturnType("Object"); JavaFileAssert.assertThat(files.get("AdditionalPropertiesArray.java")) - .hasProperty("additionalProperties").withType("Map") + .assertProperty("additionalProperties").withType("Map") .toType() .assertMethod("putAdditionalProperty", "String", "List") .toFileAssert() .assertMethod("getAdditionalProperty", "String").hasReturnType("List"); JavaFileAssert.assertThat(files.get("AdditionalPropertiesInteger.java")) - .hasProperty("additionalProperties").withType("Map") + .assertProperty("additionalProperties").withType("Map") .toType() .assertMethod("putAdditionalProperty", "String", "Integer") .toFileAssert() @@ -921,34 +920,34 @@ public class SpringCodegenTest { JavaFileAssert.assertThat(files.get("ResponseTest.java")) .isNormalClass() .hasImports("javax.validation.Valid") - .hasProperty("details") + .assertProperty("details") .withType( "Map" ) .toType() - .hasProperty("response") + .assertProperty("response") .withType( "JsonNullable>" ) .toType() - .hasProperty("nullableDtos") + .assertProperty("nullableDtos") .withType( "JsonNullable>" ) .toType() - .hasProperty("dtos") + .assertProperty("dtos") .withType( "Set<@Valid ResponseTest2>" ) .toType() - .hasProperty("listNullableDtos") + .assertProperty("listNullableDtos") .withType( "JsonNullable>" ) .toType() - .hasProperty("listDtos") + .assertProperty("listDtos") .withType( "List<@Valid ResponseTest2>" ) .toType() - .hasProperty("nullableStrings") + .assertProperty("nullableStrings") .withType( "JsonNullable>" ) .toType() - .hasProperty("strings") + .assertProperty("strings") .withType( "Set" ) .toType() - .hasProperty("nullableInts") + .assertProperty("nullableInts") .withType( "JsonNullable>" ) .toType() - .hasProperty("ints") + .assertProperty("ints") .withType( "Set" ); } @@ -982,65 +981,65 @@ public class SpringCodegenTest { .isNormalClass() .hasImports("jakarta.validation.Valid") .hasImports("jakarta.validation.constraints") - .hasProperty("stringPattern") + .assertProperty("stringPattern") .withType( "Set<@Pattern(regexp = \"[a-z]\") String>" ) .toType() - .hasProperty("stringMaxMinLength") + .assertProperty("stringMaxMinLength") .withType( "Set<@Size(min = 1, max = 10) String>" ) .toType() - .hasProperty("stringMinLength") + .assertProperty("stringMinLength") .withType( "List<@Size(min = 1) String>" ) .toType() - .hasProperty("stringMaxLength") + .assertProperty("stringMaxLength") .withType( "Set<@Size(max = 1) String>" ) .toType() - .hasProperty("intMinMax") + .assertProperty("intMinMax") .withType( "List<@Min(1) @Max(10) Integer>" ) .toType() - .hasProperty("intMin") + .assertProperty("intMin") .withType( "List<@Min(1) Integer>" ) .toType() - .hasProperty("intMax") + .assertProperty("intMax") .withType( "List<@Max(10) Integer>" ) .toType() - .hasProperty("numberMinMax") + .assertProperty("numberMinMax") .withType( "List<@DecimalMin(value = \"1\", inclusive = true) @DecimalMax(value = \"10\", inclusive = true) BigDecimal>" ) .toType() - .hasProperty("numberMin") + .assertProperty("numberMin") .withType( "List<@DecimalMin(value = \"1\", inclusive = true) BigDecimal>" ) .toType() - .hasProperty("numberMax") + .assertProperty("numberMax") .withType( "List<@DecimalMax(value = \"10\", inclusive = true) BigDecimal>" ) .toType() - .hasProperty("stringPatternNullable") + .assertProperty("stringPatternNullable") .withType( "JsonNullable>" ) .toType() - .hasProperty("stringMaxMinLengthNullable") + .assertProperty("stringMaxMinLengthNullable") .withType( "JsonNullable>" ) .toType() - .hasProperty("stringMinLengthNullable") + .assertProperty("stringMinLengthNullable") .withType( "JsonNullable>" ) .toType() - .hasProperty("stringMaxLengthNullable") + .assertProperty("stringMaxLengthNullable") .withType( "JsonNullable>" ) .toType() - .hasProperty("intMinMaxNullable") + .assertProperty("intMinMaxNullable") .withType( "JsonNullable>" ) .toType() - .hasProperty("intMinNullable") + .assertProperty("intMinNullable") .withType( "JsonNullable>" ) .toType() - .hasProperty("intMaxNullable") + .assertProperty("intMaxNullable") .withType( "JsonNullable>" ) .toType() - .hasProperty("numberMinMaxNullable") + .assertProperty("numberMinMaxNullable") .withType( "JsonNullable>" ) .toType() - .hasProperty("numberMinNullable") + .assertProperty("numberMinNullable") .withType( "JsonNullable>" ) .toType() - .hasProperty("numberMaxNullable") + .assertProperty("numberMaxNullable") .withType( "JsonNullable>" ) .toType() ; @@ -1272,7 +1271,7 @@ public class SpringCodegenTest { if (performBeanValidation) javaFileAssert.hasImports("org.hibernate.validator.constraints"); JavaFileAssert.assertThat(Paths.get(outputPath + "/src/main/java/org/openapitools/model/PersonWithEmail.java")) .fileContains(contains) - .fileDoesNotContains(notContains); + .fileDoesNotContain(notContains); } @Test @@ -1303,10 +1302,10 @@ public class SpringCodegenTest { JavaFileAssert.assertThat(Paths.get(outputPath + "/src/main/java/org/openapitools/api/SomeApi.java")) .fileContains("Mono>") - .fileDoesNotContains("Mono"); + .fileDoesNotContain("Mono"); JavaFileAssert.assertThat(Paths.get(outputPath + "/src/main/java/org/openapitools/api/SomeApiDelegate.java")) .fileContains("Mono>") - .fileDoesNotContains("Mono"); + .fileDoesNotContain("Mono"); } @Test @@ -1638,7 +1637,7 @@ public class SpringCodegenTest { JavaFileAssert.assertThat(Paths.get(outputPath + "/src/main/java/org/openapitools/model/Dummy.java")) .fileContains( "status") - .fileDoesNotContains("@NotNull"); + .fileDoesNotContain("@NotNull"); } @Test @@ -1711,7 +1710,7 @@ public class SpringCodegenTest { assertFileContains(Paths.get(outputPath + "/src/main/java/org/openapitools/model/FooRefOrValue.java"), "public interface FooRefOrValue"); // previous bugs JavaFileAssert.assertThat(Paths.get(outputPath + "/src/main/java/org/openapitools/model/BarRef.java")) - .fileDoesNotContains( "atTypesuper.hashCode", "private String atBaseType"); + .fileDoesNotContain("atTypesuper.hashCode", "private String atBaseType"); // imports for inherited properties assertFileContains(Paths.get(outputPath + "/src/main/java/org/openapitools/model/PizzaSpeziale.java"), "import java.math.BigDecimal"); } @@ -2024,53 +2023,53 @@ public class SpringCodegenTest { JavaFileAssert.assertThat(files.get("TestHeadersApi.java")) .assertMethod("headersTest") - .hasParameter("headerNumber").withType("BigDecimal") + .assertParameter("headerNumber").hasType("BigDecimal") .assertParameterAnnotations() .containsWithNameAndAttributes("RequestHeader", ImmutableMap.of("defaultValue", "\"11.2\"")) .toParameter().toMethod() - .hasParameter("headerString").withType("String") + .assertParameter("headerString").hasType("String") .assertParameterAnnotations() .containsWithNameAndAttributes("RequestHeader", ImmutableMap.of("defaultValue", "\"qwerty\"")) .toParameter().toMethod() - .hasParameter("headerStringWrapped").withType("String") + .assertParameter("headerStringWrapped").hasType("String") .assertParameterAnnotations() .containsWithNameAndAttributes("RequestHeader", ImmutableMap.of("defaultValue", "\"qwerty\"")) .toParameter().toMethod() - .hasParameter("headerStringQuotes").withType("String") + .assertParameter("headerStringQuotes").hasType("String") .assertParameterAnnotations() .containsWithNameAndAttributes("RequestHeader", ImmutableMap.of("defaultValue", "\"qwerty\\\"with quotes\\\" test\"")) .toParameter().toMethod() - .hasParameter("headerStringQuotesWrapped").withType("String") + .assertParameter("headerStringQuotesWrapped").hasType("String") .assertParameterAnnotations() .containsWithNameAndAttributes("RequestHeader", ImmutableMap.of("defaultValue", "\"qwerty\\\"with quotes\\\" test\"")) .toParameter().toMethod() - .hasParameter("headerBoolean").withType("Boolean") + .assertParameter("headerBoolean").hasType("Boolean") .assertParameterAnnotations() .containsWithNameAndAttributes("RequestHeader", ImmutableMap.of("defaultValue", "\"true\"")); JavaFileAssert.assertThat(files.get("TestQueryParamsApi.java")) .assertMethod("queryParamsTest") - .hasParameter("queryNumber").withType("BigDecimal") + .assertParameter("queryNumber").hasType("BigDecimal") .assertParameterAnnotations() .containsWithNameAndAttributes("RequestParam", ImmutableMap.of("defaultValue", "\"11.2\"")) .toParameter().toMethod() - .hasParameter("queryString").withType("String") + .assertParameter("queryString").hasType("String") .assertParameterAnnotations() .containsWithNameAndAttributes("RequestParam", ImmutableMap.of("defaultValue", "\"qwerty\"")) .toParameter().toMethod() - .hasParameter("queryStringWrapped").withType("String") + .assertParameter("queryStringWrapped").hasType("String") .assertParameterAnnotations() .containsWithNameAndAttributes("RequestParam", ImmutableMap.of("defaultValue", "\"qwerty\"")) .toParameter().toMethod() - .hasParameter("queryStringQuotes").withType("String") + .assertParameter("queryStringQuotes").hasType("String") .assertParameterAnnotations() .containsWithNameAndAttributes("RequestParam", ImmutableMap.of("defaultValue", "\"qwerty\\\"with quotes\\\" test\"")) .toParameter().toMethod() - .hasParameter("queryStringQuotesWrapped").withType("String") + .assertParameter("queryStringQuotesWrapped").hasType("String") .assertParameterAnnotations() .containsWithNameAndAttributes("RequestParam", ImmutableMap.of("defaultValue", "\"qwerty\\\"with quotes\\\" test\"")) .toParameter().toMethod() - .hasParameter("queryBoolean").withType("Boolean") + .assertParameter("queryBoolean").hasType("Boolean") .assertParameterAnnotations() .containsWithNameAndAttributes("RequestParam", ImmutableMap.of("defaultValue", "\"true\"")); } @@ -2225,7 +2224,7 @@ public class SpringCodegenTest { JavaFileAssert.assertThat(files.get("PetApi.java")) .hasImports("org.springdoc.api.annotations.ParameterObject") .assertMethod("findPetsByStatus") - .hasParameter("pageable").withType("Pageable") + .assertParameter("pageable").hasType("Pageable") .assertParameterAnnotations() .containsWithName("ParameterObject"); @@ -2237,7 +2236,7 @@ public class SpringCodegenTest { JavaFileAssert.assertThat(files.get("PetApi.java")) .hasImports("org.springdoc.core.annotations.ParameterObject", "org.springframework.data.domain.Pageable") .assertMethod("findPetsByStatus") - .hasParameter("pageable").withType("Pageable") + .assertParameter("pageable").hasType("Pageable") .assertParameterAnnotations() .containsWithName("ParameterObject"); } @@ -2257,7 +2256,7 @@ public class SpringCodegenTest { .hasImports("org.openapitools.model.Pageable") .hasNoImports("org.springframework.data.domain.Pageable", "org.springdoc.core.annotations.ParameterObject") .assertMethod("findPageable") - .hasParameter("pageable").withType("Pageable"); + .assertParameter("pageable").hasType("Pageable"); } @Test @@ -2274,22 +2273,22 @@ public class SpringCodegenTest { JavaFileAssert.assertThat(files.get("SearchApi.java")) .assertMethod("defaultList") - .hasParameter("orderBy") + .assertParameter("orderBy") .assertParameterAnnotations() .containsWithNameAndAttributes("RequestParam", ImmutableMap.of("defaultValue", "\"updatedAt:DESC,createdAt:DESC\"")) .toParameter().toMethod().toFileAssert() .assertMethod("defaultSet") - .hasParameter("orderBy") + .assertParameter("orderBy") .assertParameterAnnotations() .containsWithNameAndAttributes("RequestParam", ImmutableMap.of("defaultValue", "\"updatedAt:DESC,createdAt:DESC\"")) .toParameter().toMethod().toFileAssert() .assertMethod("emptyDefaultList") - .hasParameter("orderBy") + .assertParameter("orderBy") .assertParameterAnnotations() .containsWithNameAndAttributes("RequestParam", ImmutableMap.of("defaultValue", "\"\"")) .toParameter().toMethod().toFileAssert() .assertMethod("emptyDefaultSet") - .hasParameter("orderBy") + .assertParameter("orderBy") .assertParameterAnnotations() .containsWithNameAndAttributes("RequestParam", ImmutableMap.of("defaultValue", "\"\"")); } @@ -2367,7 +2366,7 @@ public class SpringCodegenTest { JavaFileAssert.assertThat(files.get("SomeMethodApi.java")) .assertMethod("methodWithValidation") - .hasParameter("headerOne") + .assertParameter("headerOne") .assertParameterAnnotations() .containsWithName("RequestHeader") .containsWithName("NotNull") @@ -2378,7 +2377,7 @@ public class SpringCodegenTest { .containsWithNameAndAttributes("Pattern", ImmutableMap.of("regexp", "\"\\\\d+\"")) .toParameter() .toMethod() - .hasParameter("headerTwo") + .assertParameter("headerTwo") .assertParameterAnnotations() .containsWithName("RequestHeader") .containsWithName("NotNull") @@ -2605,7 +2604,7 @@ public class SpringCodegenTest { JavaFileAssert.assertThat(files.get("AddApi.java")) .assertMethod("addPost") - .hasParameter("body") + .assertParameter("body") .assertParameterAnnotations() .containsWithNameAndAttributes("Min", ImmutableMap.of("value", "2")); } @@ -2653,7 +2652,7 @@ public class SpringCodegenTest { } @Test - public void contractWithoutEnumDoesNotContainsEnumConverter() throws IOException { + public void contractWithoutEnumDoesNotContainEnumConverter() throws IOException { Map output = generateFromContract("src/test/resources/3_0/generic.yaml", SPRING_BOOT); assertThat(output).doesNotContainKey("EnumConverterConfiguration.java"); @@ -2711,7 +2710,7 @@ public class SpringCodegenTest { Map.of(GENERATE_CONSTRUCTOR_WITH_ALL_ARGS, "false") ); - JavaFileAssert.assertThat(output.get("ObjectWithNoRequiredParameter.java")).assertNoConstructor("String"); + JavaFileAssert.assertThat(output.get("ObjectWithNoRequiredParameter.java")).hasNoConstructor("String"); JavaFileAssert.assertThat(output.get("ObjectWithRequiredParameter.java")).assertConstructor(); JavaFileAssert.assertThat(output.get("ObjectWithRequiredParameter.java")).assertConstructor("String", "String") @@ -2822,25 +2821,25 @@ public class SpringCodegenTest { .collect(Collectors.toMap(File::getName, Function.identity())); JavaFileAssert.assertThat(files.get("ResponseObjectWithDifferentFieldNames.java")) - .hasProperty("normalPropertyName") + .assertProperty("normalPropertyName") .assertPropertyAnnotations() - .doesNotContainsWithName("JsonProperty") - .doesNotContainsWithName("JacksonXmlProperty") + .doesNotContainWithName("JsonProperty") + .doesNotContainWithName("JacksonXmlProperty") .toProperty().toType() - .hasProperty("UPPER_CASE_PROPERTY_SNAKE") + .assertProperty("UPPER_CASE_PROPERTY_SNAKE") .assertPropertyAnnotations() - .doesNotContainsWithName("JsonProperty") - .doesNotContainsWithName("JacksonXmlProperty") + .doesNotContainWithName("JsonProperty") + .doesNotContainWithName("JacksonXmlProperty") .toProperty().toType() - .hasProperty("lowerCasePropertyDashes") + .assertProperty("lowerCasePropertyDashes") .assertPropertyAnnotations() - .doesNotContainsWithName("JsonProperty") - .doesNotContainsWithName("JacksonXmlProperty") + .doesNotContainWithName("JsonProperty") + .doesNotContainWithName("JacksonXmlProperty") .toProperty().toType() - .hasProperty("propertyNameWithSpaces") + .assertProperty("propertyNameWithSpaces") .assertPropertyAnnotations() - .doesNotContainsWithName("JsonProperty") - .doesNotContainsWithName("JacksonXmlProperty") + .doesNotContainWithName("JsonProperty") + .doesNotContainWithName("JacksonXmlProperty") .toProperty().toType() .assertMethod("getNormalPropertyName") .assertMethodAnnotations() @@ -3066,7 +3065,7 @@ public class SpringCodegenTest { .hasNoImports("org.springframework.stereotype.Controller") .assertTypeAnnotations() .containsWithName("RestController") - .doesNotContainsWithName("Controller"); + .doesNotContainWithName("Controller"); } @Test @@ -3104,7 +3103,7 @@ public class SpringCodegenTest { .hasNoImports("org.springframework.web.bind.annotation.RestController") .assertTypeAnnotations() .containsWithName("Controller") - .doesNotContainsWithName("RestController"); + .doesNotContainWithName("RestController"); } @Test @@ -3356,29 +3355,29 @@ public class SpringCodegenTest { .assertMethod("alias") .hasReturnType("Animal") .bodyContainsLines("this.alias = JsonNullable.of(alias);", "return this;") - .hasParameter("alias") - .withType("String") + .assertParameter("alias") + .hasType("String") .toMethod() .toFileAssert() // Setter method assertions .assertMethod("setAlias") .hasReturnType("void") - .hasParameter("alias") - .withType("JsonNullable"); + .assertParameter("alias") + .hasType("JsonNullable"); JavaFileAssert.assertThat(Paths.get(outputPath + "/src/main/java/org/openapitools/model/Zebra.java")) // Fluent method assertions .assertMethod("alias") .hasReturnType("Zebra") .bodyContainsLines("super.alias(alias);", "return this;") - .hasParameter("alias") - .withType("String") + .assertParameter("alias") + .hasType("String") .toMethod() .toFileAssert() // No overridden setter on child object - .assertNoMethod("setAlias"); + .hasNoMethod("setAlias"); } @Test @@ -3412,96 +3411,96 @@ public class SpringCodegenTest { .hasImports("jakarta.validation.Valid") .hasImports("jakarta.validation.constraints") - .hasProperty("name") + .assertProperty("name") .withType( "String" ) .toType() - .hasProperty("age") + .assertProperty("age") .withType( "JsonNullable" ) .toType() - .hasProperty("alias") + .assertProperty("alias") .withType( "JsonNullable" ) .toType() - .hasProperty("color") + .assertProperty("color") .withType( "String" ) .toType() - .hasProperty("names") + .assertProperty("names") .withType( "List" ) .toType() - .hasProperty("colors") + .assertProperty("colors") .withType( "JsonNullable>" ) .toType() - .hasProperty("stringPattern") + .assertProperty("stringPattern") .withType( "String" ) .toType() - .hasProperty("stringMaxMinLength") + .assertProperty("stringMaxMinLength") .withType( "String" ) .toType() - .hasProperty("stringMinLength") + .assertProperty("stringMinLength") .withType( "String" ) .toType() - .hasProperty("stringMaxLength") + .assertProperty("stringMaxLength") .withType( "String" ) .toType() - .hasProperty("stringEmail") + .assertProperty("stringEmail") .withType( "String" ) .toType() - .hasProperty("intMinMax") + .assertProperty("intMinMax") .withType( "Integer" ) .toType() - .hasProperty("intMin") + .assertProperty("intMin") .withType( "Integer" ) .toType() - .hasProperty("intMax") + .assertProperty("intMax") .withType( "Integer" ) .toType() - .hasProperty("numberMinMax") + .assertProperty("numberMinMax") .withType( "BigDecimal" ) .toType() - .hasProperty("numberMin") + .assertProperty("numberMin") .withType( "BigDecimal" ) .toType() - .hasProperty("numberMax") + .assertProperty("numberMax") .withType( "BigDecimal" ) .toType() - .hasProperty("stringDefault") + .assertProperty("stringDefault") .withType( "String" ) .toType() .fileContains("stringDefault = \"ABC\"") - .hasProperty("zebra") + .assertProperty("zebra") .withType( "Zebra" ) .toType() - .hasProperty("stringPatternNullable") + .assertProperty("stringPatternNullable") .withType( "JsonNullable<@Pattern(regexp = \"[a-z]\") String>" ) .toType() - .hasProperty("stringMaxMinLengthNullable") + .assertProperty("stringMaxMinLengthNullable") .withType( "JsonNullable<@Size(min = 1, max = 10) String>" ) .toType() - .hasProperty("stringMinLengthNullable") + .assertProperty("stringMinLengthNullable") .withType( "JsonNullable<@Size(min = 1) String>" ) .toType() - .hasProperty("stringMaxLengthNullable") + .assertProperty("stringMaxLengthNullable") .withType( "JsonNullable<@Size(max = 1) String>" ) .toType() - .hasProperty("intMinMaxNullable") + .assertProperty("intMinMaxNullable") .withType( "JsonNullable<@Min(1) @Max(10) Integer>" ) .toType() - .hasProperty("intMinNullable") + .assertProperty("intMinNullable") .withType( "JsonNullable<@Min(1) Integer>" ) .toType() - .hasProperty("intMaxNullable") + .assertProperty("intMaxNullable") .withType( "JsonNullable<@Max(10) Integer>" ) .toType() - .hasProperty("numberMinMaxNullable") + .assertProperty("numberMinMaxNullable") .withType( "JsonNullable<@DecimalMin(\"1\") @DecimalMax(\"10\") BigDecimal>" ) .toType() - .hasProperty("numberMinNullable") + .assertProperty("numberMinNullable") .withType( "JsonNullable<@DecimalMin(\"1\") BigDecimal>" ) .toType() - .hasProperty("numberMaxNullable") + .assertProperty("numberMaxNullable") .withType( "JsonNullable<@DecimalMax(\"10\") BigDecimal>" ) .toType() - .hasProperty("stringDefaultNullable") + .assertProperty("stringDefaultNullable") .withType( "JsonNullable<@Size(max = 1) String>" ) .toType() .fileContains("stringDefaultNullable = JsonNullable.undefined();") @@ -3509,15 +3508,15 @@ public class SpringCodegenTest { .assertMethod("name") .hasReturnType("Animal") .bodyContainsLines("this.name = name;", "return this;") - .hasParameter("name") - .withType("String") + .assertParameter("name") + .hasType("String") .toMethod() .toFileAssert() // Setter method assertions .assertMethod("setName") .hasReturnType("void") - .hasParameter("name") - .withType("String") + .assertParameter("name") + .hasType("String") .toMethod() .toFileAssert() // Getter method assertions @@ -3529,15 +3528,15 @@ public class SpringCodegenTest { .assertMethod("colors") .hasReturnType("Animal") .bodyContainsLines("this.colors = JsonNullable.of(colors);", "return this;") - .hasParameter("colors") - .withType("List") + .assertParameter("colors") + .hasType("List") .toMethod() .toFileAssert() // Setter method assertions .assertMethod("setColors") .hasReturnType("void") - .hasParameter("colors") - .withType("JsonNullable>") + .assertParameter("colors") + .hasType("JsonNullable>") .toMethod() .toFileAssert() // Getter method assertions @@ -3549,15 +3548,15 @@ public class SpringCodegenTest { .assertMethod("names") .hasReturnType("Animal") .bodyContainsLines("this.names = names;", "return this;") - .hasParameter("names") - .withType("List") + .assertParameter("names") + .hasType("List") .toMethod() .toFileAssert() // Setter method assertions .assertMethod("setNames") .hasReturnType("void") - .hasParameter("names") - .withType("List") + .assertParameter("names") + .hasType("List") .toMethod() .toFileAssert() // Getter method assertions @@ -3628,96 +3627,96 @@ public class SpringCodegenTest { .hasImports("jakarta.validation.Valid") .hasImports("jakarta.validation.constraints") - .hasProperty("name") + .assertProperty("name") .withType( "String" ) .toType() - .hasProperty("age") + .assertProperty("age") .withType( "JsonNullable" ) .toType() - .hasProperty("alias") + .assertProperty("alias") .withType( "JsonNullable" ) .toType() - .hasProperty("color") + .assertProperty("color") .withType( "Optional" ) .toType() - .hasProperty("names") + .assertProperty("names") .withType( "List" ) .toType() - .hasProperty("colors") + .assertProperty("colors") .withType( "JsonNullable>" ) .toType() - .hasProperty("stringPattern") + .assertProperty("stringPattern") .withType( "Optional<@Pattern(regexp = \"[a-z]\") String>" ) .toType() - .hasProperty("stringMaxMinLength") + .assertProperty("stringMaxMinLength") .withType( "Optional<@Size(min = 1, max = 10) String>" ) .toType() - .hasProperty("stringMinLength") + .assertProperty("stringMinLength") .withType( "Optional<@Size(min = 1) String>" ) .toType() - .hasProperty("stringMaxLength") + .assertProperty("stringMaxLength") .withType( "Optional<@Size(max = 1) String>" ) .toType() - .hasProperty("stringEmail") + .assertProperty("stringEmail") .withType( "Optional<@jakarta.validation.constraints.Email String>" ) .toType() - .hasProperty("intMinMax") + .assertProperty("intMinMax") .withType( "Optional<@Min(1) @Max(10) Integer>" ) .toType() - .hasProperty("intMin") + .assertProperty("intMin") .withType( "Optional<@Min(1) Integer>" ) .toType() - .hasProperty("intMax") + .assertProperty("intMax") .withType( "Optional<@Max(10) Integer>" ) .toType() - .hasProperty("numberMinMax") + .assertProperty("numberMinMax") .withType( "Optional<@DecimalMin(\"1\") @DecimalMax(\"10\") BigDecimal>" ) .toType() - .hasProperty("numberMin") + .assertProperty("numberMin") .withType( "Optional<@DecimalMin(\"1\") BigDecimal>" ) .toType() - .hasProperty("numberMax") + .assertProperty("numberMax") .withType( "Optional<@DecimalMax(\"10\") BigDecimal>" ) .toType() - .hasProperty("stringDefault") + .assertProperty("stringDefault") .withType( "Optional<@Size(max = 1) String>" ) .toType() .fileContains("stringDefault = Optional.of(\"ABC\")") - .hasProperty("zebra") + .assertProperty("zebra") .withType( "Optional" ) .toType() - .hasProperty("stringPatternNullable") + .assertProperty("stringPatternNullable") .withType( "JsonNullable<@Pattern(regexp = \"[a-z]\") String>" ) .toType() - .hasProperty("stringMaxMinLengthNullable") + .assertProperty("stringMaxMinLengthNullable") .withType( "JsonNullable<@Size(min = 1, max = 10) String>" ) .toType() - .hasProperty("stringMinLengthNullable") + .assertProperty("stringMinLengthNullable") .withType( "JsonNullable<@Size(min = 1) String>" ) .toType() - .hasProperty("stringMaxLengthNullable") + .assertProperty("stringMaxLengthNullable") .withType( "JsonNullable<@Size(max = 1) String>" ) .toType() - .hasProperty("intMinMaxNullable") + .assertProperty("intMinMaxNullable") .withType( "JsonNullable<@Min(1) @Max(10) Integer>" ) .toType() - .hasProperty("intMinNullable") + .assertProperty("intMinNullable") .withType( "JsonNullable<@Min(1) Integer>" ) .toType() - .hasProperty("intMaxNullable") + .assertProperty("intMaxNullable") .withType( "JsonNullable<@Max(10) Integer>" ) .toType() - .hasProperty("numberMinMaxNullable") + .assertProperty("numberMinMaxNullable") .withType( "JsonNullable<@DecimalMin(\"1\") @DecimalMax(\"10\") BigDecimal>" ) .toType() - .hasProperty("numberMinNullable") + .assertProperty("numberMinNullable") .withType( "JsonNullable<@DecimalMin(\"1\") BigDecimal>" ) .toType() - .hasProperty("numberMaxNullable") + .assertProperty("numberMaxNullable") .withType( "JsonNullable<@DecimalMax(\"10\") BigDecimal>" ) .toType() - .hasProperty("stringDefaultNullable") + .assertProperty("stringDefaultNullable") .withType( "JsonNullable<@Size(max = 1) String>" ) .toType() .fileContains("stringDefaultNullable = JsonNullable.undefined();") @@ -3725,15 +3724,15 @@ public class SpringCodegenTest { .assertMethod("name") .hasReturnType("Animal") .bodyContainsLines("this.name = name;", "return this;") - .hasParameter("name") - .withType("String") + .assertParameter("name") + .hasType("String") .toMethod() .toFileAssert() // Setter method assertions .assertMethod("setName") .hasReturnType("void") - .hasParameter("name") - .withType("String") + .assertParameter("name") + .hasType("String") .toMethod() .toFileAssert() // Getter method assertions @@ -3745,15 +3744,15 @@ public class SpringCodegenTest { .assertMethod("colors") .hasReturnType("Animal") .bodyContainsLines("this.colors = JsonNullable.of(colors);", "return this;") - .hasParameter("colors") - .withType("List") + .assertParameter("colors") + .hasType("List") .toMethod() .toFileAssert() // Setter method assertions .assertMethod("setColors") .hasReturnType("void") - .hasParameter("colors") - .withType("JsonNullable>") + .assertParameter("colors") + .hasType("JsonNullable>") .toMethod() .toFileAssert() // Getter method assertions @@ -3765,15 +3764,15 @@ public class SpringCodegenTest { .assertMethod("names") .hasReturnType("Animal") .bodyContainsLines("this.names = names;", "return this;") - .hasParameter("names") - .withType("List") + .assertParameter("names") + .hasType("List") .toMethod() .toFileAssert() // Setter method assertions .assertMethod("setNames") .hasReturnType("void") - .hasParameter("names") - .withType("List") + .assertParameter("names") + .hasType("List") .toMethod() .toFileAssert() // Getter method assertions @@ -3844,96 +3843,96 @@ public class SpringCodegenTest { .hasImports("jakarta.validation.Valid") .hasImports("jakarta.validation.constraints") - .hasProperty("name") + .assertProperty("name") .withType( "String" ) .toType() - .hasProperty("age") + .assertProperty("age") .withType( "Integer" ) .toType() - .hasProperty("alias") + .assertProperty("alias") .withType( "String" ) .toType() - .hasProperty("color") + .assertProperty("color") .withType( "String" ) .toType() - .hasProperty("names") + .assertProperty("names") .withType( "List" ) .toType() - .hasProperty("colors") + .assertProperty("colors") .withType( "List" ) .toType() - .hasProperty("stringPattern") + .assertProperty("stringPattern") .withType( "String" ) .toType() - .hasProperty("stringMaxMinLength") + .assertProperty("stringMaxMinLength") .withType( "String" ) .toType() - .hasProperty("stringMinLength") + .assertProperty("stringMinLength") .withType( "String" ) .toType() - .hasProperty("stringMaxLength") + .assertProperty("stringMaxLength") .withType( "String" ) .toType() - .hasProperty("stringEmail") + .assertProperty("stringEmail") .withType( "String" ) .toType() - .hasProperty("intMinMax") + .assertProperty("intMinMax") .withType( "Integer" ) .toType() - .hasProperty("intMin") + .assertProperty("intMin") .withType( "Integer" ) .toType() - .hasProperty("intMax") + .assertProperty("intMax") .withType( "Integer" ) .toType() - .hasProperty("numberMinMax") + .assertProperty("numberMinMax") .withType( "BigDecimal" ) .toType() - .hasProperty("numberMin") + .assertProperty("numberMin") .withType( "BigDecimal" ) .toType() - .hasProperty("numberMax") + .assertProperty("numberMax") .withType( "BigDecimal" ) .toType() - .hasProperty("stringDefault") + .assertProperty("stringDefault") .withType( "String" ) .toType() .fileContains("stringDefault = \"ABC\"") - .hasProperty("zebra") + .assertProperty("zebra") .withType( "Zebra" ) .toType() - .hasProperty("stringPatternNullable") + .assertProperty("stringPatternNullable") .withType( "String" ) .toType() - .hasProperty("stringMaxMinLengthNullable") + .assertProperty("stringMaxMinLengthNullable") .withType( "String" ) .toType() - .hasProperty("stringMinLengthNullable") + .assertProperty("stringMinLengthNullable") .withType( "String" ) .toType() - .hasProperty("stringMaxLengthNullable") + .assertProperty("stringMaxLengthNullable") .withType( "String" ) .toType() - .hasProperty("intMinMaxNullable") + .assertProperty("intMinMaxNullable") .withType( "Integer" ) .toType() - .hasProperty("intMinNullable") + .assertProperty("intMinNullable") .withType( "Integer" ) .toType() - .hasProperty("intMaxNullable") + .assertProperty("intMaxNullable") .withType( "Integer" ) .toType() - .hasProperty("numberMinMaxNullable") + .assertProperty("numberMinMaxNullable") .withType( "BigDecimal" ) .toType() - .hasProperty("numberMinNullable") + .assertProperty("numberMinNullable") .withType( "BigDecimal" ) .toType() - .hasProperty("numberMaxNullable") + .assertProperty("numberMaxNullable") .withType( "BigDecimal" ) .toType() - .hasProperty("stringDefaultNullable") + .assertProperty("stringDefaultNullable") .withType( "String" ) .toType() .fileContains("stringDefaultNullable = null;") @@ -3941,15 +3940,15 @@ public class SpringCodegenTest { .assertMethod("name") .hasReturnType("Animal") .bodyContainsLines("this.name = name;", "return this;") - .hasParameter("name") - .withType("String") + .assertParameter("name") + .hasType("String") .toMethod() .toFileAssert() // Setter method assertions .assertMethod("setName") .hasReturnType("void") - .hasParameter("name") - .withType("String") + .assertParameter("name") + .hasType("String") .toMethod() .toFileAssert() // Getter method assertions @@ -3961,15 +3960,15 @@ public class SpringCodegenTest { .assertMethod("age") .hasReturnType("Animal") .bodyContainsLines("this.age = age;", "return this;") - .hasParameter("age") - .withType("Integer") + .assertParameter("age") + .hasType("Integer") .toMethod() .toFileAssert() // Setter method assertions .assertMethod("setAge") .hasReturnType("void") - .hasParameter("age") - .withType("Integer") + .assertParameter("age") + .hasType("Integer") .toMethod() .toFileAssert() // Getter method assertions @@ -3981,15 +3980,15 @@ public class SpringCodegenTest { .assertMethod("colors") .hasReturnType("Animal") .bodyContainsLines("this.colors = colors;", "return this;") - .hasParameter("colors") - .withType("List") + .assertParameter("colors") + .hasType("List") .toMethod() .toFileAssert() // Setter method assertions .assertMethod("setColors") .hasReturnType("void") - .hasParameter("colors") - .withType("List") + .assertParameter("colors") + .hasType("List") .toMethod() .toFileAssert() // Getter method assertions @@ -4001,15 +4000,15 @@ public class SpringCodegenTest { .assertMethod("names") .hasReturnType("Animal") .bodyContainsLines("this.names = names;", "return this;") - .hasParameter("names") - .withType("List") + .assertParameter("names") + .hasType("List") .toMethod() .toFileAssert() // Setter method assertions .assertMethod("setNames") .hasReturnType("void") - .hasParameter("names") - .withType("List") + .assertParameter("names") + .hasType("List") .toMethod() .toFileAssert() // Getter method assertions @@ -4079,96 +4078,96 @@ public class SpringCodegenTest { .hasImports("jakarta.validation.Valid") .hasImports("jakarta.validation.constraints") - .hasProperty("name") + .assertProperty("name") .withType( "String" ) .toType() - .hasProperty("age") + .assertProperty("age") .withType( "Integer" ) .toType() - .hasProperty("alias") + .assertProperty("alias") .withType( "String" ) .toType() - .hasProperty("color") + .assertProperty("color") .withType( "String" ) .toType() - .hasProperty("names") + .assertProperty("names") .withType( "List" ) .toType() - .hasProperty("colors") + .assertProperty("colors") .withType( "List" ) .toType() - .hasProperty("stringPattern") + .assertProperty("stringPattern") .withType( "String" ) .toType() - .hasProperty("stringMaxMinLength") + .assertProperty("stringMaxMinLength") .withType( "String" ) .toType() - .hasProperty("stringMinLength") + .assertProperty("stringMinLength") .withType( "String" ) .toType() - .hasProperty("stringMaxLength") + .assertProperty("stringMaxLength") .withType( "String" ) .toType() - .hasProperty("stringEmail") + .assertProperty("stringEmail") .withType( "String" ) .toType() - .hasProperty("intMinMax") + .assertProperty("intMinMax") .withType( "Integer" ) .toType() - .hasProperty("intMin") + .assertProperty("intMin") .withType( "Integer" ) .toType() - .hasProperty("intMax") + .assertProperty("intMax") .withType( "Integer" ) .toType() - .hasProperty("numberMinMax") + .assertProperty("numberMinMax") .withType( "BigDecimal" ) .toType() - .hasProperty("numberMin") + .assertProperty("numberMin") .withType( "BigDecimal" ) .toType() - .hasProperty("numberMax") + .assertProperty("numberMax") .withType( "BigDecimal" ) .toType() - .hasProperty("stringDefault") + .assertProperty("stringDefault") .withType( "String" ) .toType() .fileContains("stringDefault = \"ABC\"") - .hasProperty("zebra") + .assertProperty("zebra") .withType( "Zebra" ) .toType() - .hasProperty("stringPatternNullable") + .assertProperty("stringPatternNullable") .withType( "String" ) .toType() - .hasProperty("stringMaxMinLengthNullable") + .assertProperty("stringMaxMinLengthNullable") .withType( "String" ) .toType() - .hasProperty("stringMinLengthNullable") + .assertProperty("stringMinLengthNullable") .withType( "String" ) .toType() - .hasProperty("stringMaxLengthNullable") + .assertProperty("stringMaxLengthNullable") .withType( "String" ) .toType() - .hasProperty("intMinMaxNullable") + .assertProperty("intMinMaxNullable") .withType( "Integer" ) .toType() - .hasProperty("intMinNullable") + .assertProperty("intMinNullable") .withType( "Integer" ) .toType() - .hasProperty("intMaxNullable") + .assertProperty("intMaxNullable") .withType( "Integer" ) .toType() - .hasProperty("numberMinMaxNullable") + .assertProperty("numberMinMaxNullable") .withType( "BigDecimal" ) .toType() - .hasProperty("numberMinNullable") + .assertProperty("numberMinNullable") .withType( "BigDecimal" ) .toType() - .hasProperty("numberMaxNullable") + .assertProperty("numberMaxNullable") .withType( "BigDecimal" ) .toType() - .hasProperty("stringDefaultNullable") + .assertProperty("stringDefaultNullable") .withType( "String" ) .toType() .fileContains("stringDefaultNullable = null;") @@ -4176,15 +4175,15 @@ public class SpringCodegenTest { .assertMethod("name") .hasReturnType("Animal") .bodyContainsLines("this.name = name;", "return this;") - .hasParameter("name") - .withType("String") + .assertParameter("name") + .hasType("String") .toMethod() .toFileAssert() // Setter method assertions .assertMethod("setName") .hasReturnType("void") - .hasParameter("name") - .withType("String") + .assertParameter("name") + .hasType("String") .toMethod() .toFileAssert() // Getter method assertions @@ -4196,15 +4195,15 @@ public class SpringCodegenTest { .assertMethod("age") .hasReturnType("Animal") .bodyContainsLines("this.age = age;", "return this;") - .hasParameter("age") - .withType("Integer") + .assertParameter("age") + .hasType("Integer") .toMethod() .toFileAssert() // Setter method assertions .assertMethod("setAge") .hasReturnType("void") - .hasParameter("age") - .withType("Integer") + .assertParameter("age") + .hasType("Integer") .toMethod() .toFileAssert() // Getter method assertions @@ -4216,15 +4215,15 @@ public class SpringCodegenTest { .assertMethod("colors") .hasReturnType("Animal") .bodyContainsLines("this.colors = colors;", "return this;") - .hasParameter("colors") - .withType("List") + .assertParameter("colors") + .hasType("List") .toMethod() .toFileAssert() // Setter method assertions .assertMethod("setColors") .hasReturnType("void") - .hasParameter("colors") - .withType("List") + .assertParameter("colors") + .hasType("List") .toMethod() .toFileAssert() // Getter method assertions @@ -4236,15 +4235,15 @@ public class SpringCodegenTest { .assertMethod("names") .hasReturnType("Animal") .bodyContainsLines("this.names = names;", "return this;") - .hasParameter("names") - .withType("List") + .assertParameter("names") + .hasType("List") .toMethod() .toFileAssert() // Setter method assertions .assertMethod("setNames") .hasReturnType("void") - .hasParameter("names") - .withType("List") + .assertParameter("names") + .hasType("List") .toMethod() .toFileAssert() // Getter method assertions @@ -4304,15 +4303,15 @@ public class SpringCodegenTest { javaFileAssert.assertMethod(expectedName) .hasReturnType("Animal") .bodyContainsLines("this."+expectedName+" = "+wrapperType+".of("+expectedName+");", "return this;") - .hasParameter(expectedName) - .withType(type) + .assertParameter(expectedName) + .hasType(type) .toMethod() .toFileAssert() // Setter method assertions .assertMethod("set"+methodName) .hasReturnType("void") - .hasParameter(expectedName) - .withType(wrapperType+"<"+type+">") + .assertParameter(expectedName) + .hasType(wrapperType+"<"+type+">") .toMethod() .toFileAssert() // Getter method assertions @@ -4327,15 +4326,15 @@ public class SpringCodegenTest { javaFileAssert.assertMethod(expectedName) .hasReturnType("Animal") .bodyContainsLines("this."+expectedName+" = "+ expectedName + ";", "return this;") - .hasParameter(expectedName) - .withType(type) + .assertParameter(expectedName) + .hasType(type) .toMethod() .toFileAssert() // Setter method assertions .assertMethod("set"+methodName) .hasReturnType("void") - .hasParameter(expectedName) - .withType(type) + .assertParameter(expectedName) + .hasType(type) .toMethod() .toFileAssert() // Getter method assertions @@ -4638,20 +4637,20 @@ public class SpringCodegenTest { additionalProperties.put(INTERFACE_ONLY, "true"); Map output = generateFromContract("src/test/resources/3_0/petstore.yaml", SPRING_BOOT, additionalProperties); JavaFileAssert.assertThat(output.get("Pet.java")) - .assertNoConstructor() - .assertNoMethod("toString") - .assertNoMethod("hashCode") - .assertNoMethod("equals") - .assertNoMethod("getId") - .assertNoMethod("setId") - .assertNoMethod("getName") - .assertNoMethod("setName") + .hasNoConstructor() + .hasNoMethod("toString") + .hasNoMethod("hashCode") + .hasNoMethod("equals") + .hasNoMethod("getId") + .hasNoMethod("setId") + .hasNoMethod("getName") + .hasNoMethod("setName") ; additionalProperties.put(AbstractJavaCodegen.ADDITIONAL_MODEL_TYPE_ANNOTATIONS, "@lombok.ToString"); output = generateFromContract("src/test/resources/3_0/petstore.yaml", SPRING_BOOT, additionalProperties); JavaFileAssert.assertThat(output.get("Pet.java")) .assertConstructor().toFileAssert() - .assertNoMethod("toString") + .hasNoMethod("toString") .assertMethod("hashCode") .toFileAssert() .assertMethod("equals") @@ -4702,7 +4701,7 @@ public class SpringCodegenTest { .fileContains("public SimpleObject.Builder additionalProperties(Map additionalProperties) {", "SimpleObject.Builder nullableObject(String nullableObject) {", "SimpleObject.Builder nb(BigDecimal nb) {") - .fileDoesNotContains("SimpleObject.Builder nullableObject(JsonNullable nullableObject) {"); + .fileDoesNotContain("SimpleObject.Builder nullableObject(JsonNullable nullableObject) {"); } @Test @@ -4807,10 +4806,10 @@ public class SpringCodegenTest { .fileContains("Set stringSet") .fileContains("private Set stringDefaultSet = new LinkedHashSet<>(Arrays.asList(\"A\", \"B\"));") .fileContains("private Set stringEmptyDefaultSet = new LinkedHashSet<>();") - .fileDoesNotContains("private List<@Valid TagDto> tags = new ArrayList<>()") - .fileDoesNotContains("private Set<@Valid TagDto> tagsUnique = new LinkedHashSet<>()") - .fileDoesNotContains("private List stringList = new ArrayList<>()") - .fileDoesNotContains("private Set stringSet = new LinkedHashSet<>()"); + .fileDoesNotContain("private List<@Valid TagDto> tags = new ArrayList<>()") + .fileDoesNotContain("private Set<@Valid TagDto> tagsUnique = new LinkedHashSet<>()") + .fileDoesNotContain("private List stringList = new ArrayList<>()") + .fileDoesNotContain("private Set stringSet = new LinkedHashSet<>()"); } @Test @@ -4826,14 +4825,14 @@ public class SpringCodegenTest { Map files = generateFromContract("src/test/resources/bugs/issue_17768.yaml", SPRING_BOOT, additionalProperties); JavaFileAssert.assertThat(files.get("TestApiDelegate.java")) .assertMethod("updatePost") - .hasParameter("updateRequest") - .withType("Optional") + .assertParameter("updateRequest") + .hasType("Optional") .toMethod() .toFileAssert(); JavaFileAssert.assertThat(files.get("TestApi.java")) .assertMethod("updatePost") - .hasParameter("updateRequest") - .withType("Optional") + .assertParameter("updateRequest") + .hasType("Optional") .toMethod() .toFileAssert(); } @@ -4868,26 +4867,21 @@ public class SpringCodegenTest { * Includes regression tests for: * - Correct Jackson annotation when `wrapped: false` */ - @Test void shouldGenerateCorrectXmlAnnotations() throws IOException { + @Test void shouldGenerateCorrectXmlAnnotations() { // Arrange - final String TEST_SPEC = "src/test/resources/3_0/java/xml-annotations-test.yaml"; - final Path output = Files.createTempDirectory("test-xml-annotations_"); - output.toFile().deleteOnExit(); - - SpringCodegen codegen = new SpringCodegen(); - codegen.setLibrary(SPRING_BOOT); - codegen.setWithXml(true); - codegen.setOutputDir(output.toString()); - - DefaultGenerator generator = new DefaultGenerator(); - generator.setGeneratorPropertyDefault(CodegenConstants.MODELS, "true"); - generator.setGenerateMetadata(false); + final CodegenConfigurator config = new CodegenConfigurator() + .addAdditionalProperty(CodegenConstants.WITH_XML, true) + .addGlobalProperty(CodegenConstants.MODELS, "Pet") + .setGeneratorName("spring") + .setInputSpec("src/test/resources/3_0/java/xml-annotations-test.yaml") + .setLibrary(SPRING_BOOT) + .setOutputDir(newTempFolder().toString()); // Act - generator.opts(new ClientOptInput().config(codegen).openAPI(TestUtils.parseSpec(TEST_SPEC))).generate(); + final List files = new DefaultGenerator().opts(config.toClientOptInput()).generate(); // Assert - JavaFileAssert.assertThat(output.resolve("src/main/java/org/openapitools/model/Pet.java").toFile()) + JavaFileAssert.assertThat(files.get(0)) .assertTypeAnnotations() .containsWithNameAndAttributes("JacksonXmlRootElement", Map.of("localName", "\"Pet\"", "namespace", "\"urn:jacksonxml\"")) .containsWithNameAndAttributes("XmlRootElement", Map.of("name", "\"Pet\"", "namespace", "\"urn:jacksonxml\"")) @@ -4895,98 +4889,95 @@ public class SpringCodegenTest { .toType() // ↓ test custom-name on wrapper element (https://swagger.io/docs/specification/data-models/representing-xml/#:~:text=Use%20xml/name%20to%20give%20different%20names) - .assertMethod("getTags").assertMethodAnnotations() - .doesNotContainsWithName("XmlAttribute") - .containsWithNameAndAttributes("XmlElement", Map.of("name", "\"Tag\"")) - .containsWithNameAndAttributes("XmlElementWrapper", Map.of("name", "\"TagList\"")) - .containsWithNameAndAttributes("JacksonXmlProperty", Map.of("localName", "\"Tag\"")) - .containsWithNameAndAttributes("JacksonXmlElementWrapper", Map.of("localName", "\"TagList\"", "useWrapping", "true")) - .toMethod().toFileAssert() + .assertMethod("getTags") + .doesNotHaveAnnotation("XmlAttribute") + .hasAnnotation("XmlElement", Map.of("name", "\"Tag\"")) + .hasAnnotation("XmlElementWrapper", Map.of("name", "\"TagList\"")) + .hasAnnotation("JacksonXmlProperty", Map.of("localName", "\"Tag\"")) + .hasAnnotation("JacksonXmlElementWrapper", Map.of("localName", "\"TagList\"", "useWrapping", "true")) + .toFileAssert() // ↓ custom internal xml-array element name, non-wrapped (1st example in https://spec.openapis.org/oas/v3.0.0#xml-arrays) - .assertMethod("getFriends").assertMethodAnnotations() - .doesNotContainsWithName("XmlAttribute") - .doesNotContainsWithName("XmlElementWrapper") - .containsWithNameAndAttributes("XmlElement", Map.of("name", "\"friend-pet\"")) - .containsWithNameAndAttributes("JacksonXmlProperty", Map.of("localName", "\"friend-pet\"")) - .containsWithNameAndAttributes("JacksonXmlElementWrapper", Map.of("useWrapping", "false")) - .toMethod().toFileAssert() + .assertMethod("getFriends") + .doesNotHaveAnnotation("XmlAttribute") + .doesNotHaveAnnotation("XmlElementWrapper") + .hasAnnotation("XmlElement", Map.of("name", "\"friend-pet\"")) + .hasAnnotation("JacksonXmlProperty", Map.of("localName", "\"friend-pet\"")) + .hasAnnotation("JacksonXmlElementWrapper", Map.of("useWrapping", "false")) + .toFileAssert() // ↓ test custom element name (https://swagger.io/docs/specification/data-models/representing-xml/#:~:text=Change%20Element%20Names) - .assertMethod("getStatus").assertMethodAnnotations() - .doesNotContainsWithName("XmlAttribute") - .doesNotContainsWithName("XmlElementWrapper") - .containsWithNameAndAttributes("XmlElement", Map.of("name", "\"PetStatus\"")) - .doesNotContainsWithName("JacksonXmlElementWrapper") - .containsWithNameAndAttributes("JacksonXmlProperty", Map.of("localName", "\"PetStatus\"")) - .toMethod().toFileAssert() + .assertMethod("getStatus") + .doesNotHaveAnnotation("XmlAttribute") + .doesNotHaveAnnotation("XmlElementWrapper") + .hasAnnotation("XmlElement", Map.of("name", "\"PetStatus\"")) + .doesNotHaveAnnotation("JacksonXmlElementWrapper") + .hasAnnotation("JacksonXmlProperty", Map.of("localName", "\"PetStatus\"")) + .toFileAssert() // ↓ test same-name wrapping element (https://swagger.io/docs/specification/data-models/representing-xml/#:~:text=Wrapping%20Arrays) // maps to 3rd example in https://spec.openapis.org/oas/v3.0.0#xml-arrays - .assertMethod("getPhotoUrls").assertMethodAnnotations() - .doesNotContainsWithName("XmlAttribute") - .containsWithNameAndAttributes("XmlElement", Map.of("name", "\"photoUrls\"")) - .containsWithNameAndAttributes("XmlElementWrapper", Map.of("name", "\"photoUrls\"")) - .containsWithNameAndAttributes("JacksonXmlProperty", Map.of("localName", "\"photoUrls\"")) - .containsWithNameAndAttributes("JacksonXmlElementWrapper", Map.of("localName", "\"photoUrls\"", "useWrapping", "true")) - .toMethod().toFileAssert() + .assertMethod("getPhotoUrls") + .doesNotHaveAnnotation("XmlAttribute") + .hasAnnotation("XmlElement", Map.of("name", "\"photoUrls\"")) + .hasAnnotation("XmlElementWrapper", Map.of("name", "\"photoUrls\"")) + .hasAnnotation("JacksonXmlProperty", Map.of("localName", "\"photoUrls\"")) + .hasAnnotation("JacksonXmlElementWrapper", Map.of("localName", "\"photoUrls\"", "useWrapping", "true")) + .toFileAssert() // ↓ test attribute generation (https://swagger.io/docs/specification/data-models/representing-xml/#:~:text=Convert%20Property%20to%20an%20Attribute) - .assertMethod("getName").assertMethodAnnotations() - .doesNotContainsWithName("XmlElement") - .doesNotContainsWithName("XmlElementWrapper") - .containsWithNameAndAttributes("XmlAttribute", Map.of("name", "\"name\"")) - .doesNotContainsWithName("JacksonXmlElementWrapper") - .containsWithNameAndAttributes( - "JacksonXmlProperty", - Map.of("isAttribute", "true", "localName", "\"name\"") - ) - .toMethod().toFileAssert() + .assertMethod("getName") + .doesNotHaveAnnotation("XmlElement") + .doesNotHaveAnnotation("XmlElementWrapper") + .hasAnnotation("XmlAttribute", Map.of("name", "\"name\"")) + .doesNotHaveAnnotation("JacksonXmlElementWrapper") + .hasAnnotation("JacksonXmlProperty", Map.of("isAttribute", "true", "localName", "\"name\"")) + .toFileAssert() // ↓ test XML namespace and prefix (https://swagger.io/docs/specification/data-models/representing-xml/#:~:text=Prefixes%20and%20Namespaces) - .assertMethod("getId").assertMethodAnnotations() - .doesNotContainsWithName("XmlAttribute") - .doesNotContainsWithName("XmlElementWrapper") - .containsWithNameAndAttributes("XmlElement", Map.of("name", "\"id\"", "namespace", "\"http://example.com/schema\"")) - .doesNotContainsWithName("JacksonXmlElementWrapper") - .containsWithNameAndAttributes("JacksonXmlProperty", Map.of("localName", "\"id\"", "namespace", "\"http://example.com/schema\"")) - .toMethod().toFileAssert() + .assertMethod("getId") + .doesNotHaveAnnotation("XmlAttribute") + .doesNotHaveAnnotation("XmlElementWrapper") + .hasAnnotation("XmlElement", Map.of("name", "\"id\"", "namespace", "\"http://example.com/schema\"")) + .doesNotHaveAnnotation("JacksonXmlElementWrapper") + .hasAnnotation("JacksonXmlProperty", Map.of("localName", "\"id\"", "namespace", "\"http://example.com/schema\"")) + .toFileAssert() // ↓ external xml-array element name only (last example in https://spec.openapis.org/oas/v3.0.0#xml-arrays) - .assertMethod("getFoods").assertMethodAnnotations() - .doesNotContainsWithName("XmlAttribute") - .containsWithNameAndAttributes("XmlElement", Map.of("name", "\"yummy-yummy\"")) - .containsWithNameAndAttributes("XmlElementWrapper", Map.of("name", "\"yummy-yummy\"")) - .containsWithNameAndAttributes("JacksonXmlProperty", Map.of("localName", "\"yummy-yummy\"")) - .containsWithNameAndAttributes("JacksonXmlElementWrapper", Map.of("localName", "\"yummy-yummy\"")) - .toMethod().toFileAssert() + .assertMethod("getFoods") + .doesNotHaveAnnotation("XmlAttribute") + .hasAnnotation("XmlElement", Map.of("name", "\"yummy-yummy\"")) + .hasAnnotation("XmlElementWrapper", Map.of("name", "\"yummy-yummy\"")) + .hasAnnotation("JacksonXmlProperty", Map.of("localName", "\"yummy-yummy\"")) + .hasAnnotation("JacksonXmlElementWrapper", Map.of("localName", "\"yummy-yummy\"")) + .toFileAssert() // ↓ internal xml-array element name (4th example in https://spec.openapis.org/oas/v3.0.0#xml-arrays) - .assertMethod("getColors").assertMethodAnnotations() - .doesNotContainsWithName("XmlAttribute") - .containsWithNameAndAttributes("XmlElement", Map.of("name", "\"color\"")) - .containsWithNameAndAttributes("XmlElementWrapper", Map.of("name", "\"colors\"")) - .containsWithNameAndAttributes("JacksonXmlProperty", Map.of("localName", "\"color\"")) - .containsWithNameAndAttributes("JacksonXmlElementWrapper", Map.of("localName", "\"colors\"")) - .toMethod().toFileAssert() + .assertMethod("getColors") + .doesNotHaveAnnotation("XmlAttribute") + .hasAnnotation("XmlElement", Map.of("name", "\"color\"")) + .hasAnnotation("XmlElementWrapper", Map.of("name", "\"colors\"")) + .hasAnnotation("JacksonXmlProperty", Map.of("localName", "\"color\"")) + .hasAnnotation("JacksonXmlElementWrapper", Map.of("localName", "\"colors\"")) + .toFileAssert() // ↓ ignored external xml-array element name, non-wrapped (2nd example in https://spec.openapis.org/oas/v3.0.0#xml-arrays) - .assertMethod("getCategories").assertMethodAnnotations() - .doesNotContainsWithName("XmlAttribute") - .doesNotContainsWithName("XmlElementWrapper") - .containsWithNameAndAttributes("XmlElement", Map.of("name", "\"Category\"")) - .containsWithNameAndAttributes("JacksonXmlProperty", Map.of("localName", "\"Category\"")) + .assertMethod("getCategories") + .doesNotHaveAnnotation("XmlAttribute") + .doesNotHaveAnnotation("XmlElementWrapper") + .hasAnnotation("XmlElement", Map.of("name", "\"Category\"")) + .hasAnnotation("JacksonXmlProperty", Map.of("localName", "\"Category\"")) // ↓ specific regression test for #2417: (useWrapping=false) needs to be present - .containsWithNameAndAttributes("JacksonXmlElementWrapper", Map.of("useWrapping", "false")) - .toMethod().toFileAssert() + .hasAnnotation("JacksonXmlElementWrapper", Map.of("useWrapping", "false")) + .toFileAssert() // ↓ test custom-name on wrapper AND children (https://swagger.io/docs/specification/data-models/representing-xml/#:~:text=Use%20xml/name%20to%20give%20different%20names) // maps to 5th example in https://spec.openapis.org/oas/v3.0.0#xml-arrays - .assertMethod("getActivities").assertMethodAnnotations() - .doesNotContainsWithName("XmlAttribute") - .containsWithNameAndAttributes("XmlElement", Map.of("name", "\"item\"")) - .containsWithNameAndAttributes("XmlElementWrapper", Map.of("name", "\"activities-array\"")) - .containsWithNameAndAttributes("JacksonXmlProperty", Map.of("localName", "\"item\"")) - .containsWithNameAndAttributes("JacksonXmlElementWrapper", Map.of("localName", "\"activities-array\"")); + .assertMethod("getActivities") + .doesNotHaveAnnotation("XmlAttribute") + .hasAnnotation("XmlElement", Map.of("name", "\"item\"")) + .hasAnnotation("XmlElementWrapper", Map.of("name", "\"activities-array\"")) + .hasAnnotation("JacksonXmlProperty", Map.of("localName", "\"item\"")) + .hasAnnotation("JacksonXmlElementWrapper", Map.of("localName", "\"activities-array\"")); } } diff --git a/modules/openapi-generator/src/test/java/org/openapitools/codegen/languages/JavaPKMSTServerCodegenTest.java b/modules/openapi-generator/src/test/java/org/openapitools/codegen/languages/JavaPKMSTServerCodegenTest.java index 25dbd04093f..e4db32d175f 100644 --- a/modules/openapi-generator/src/test/java/org/openapitools/codegen/languages/JavaPKMSTServerCodegenTest.java +++ b/modules/openapi-generator/src/test/java/org/openapitools/codegen/languages/JavaPKMSTServerCodegenTest.java @@ -1,17 +1,17 @@ package org.openapitools.codegen.languages; -import org.openapitools.codegen.ClientOptInput; import org.openapitools.codegen.CodegenConstants; import org.openapitools.codegen.DefaultGenerator; -import org.openapitools.codegen.TestUtils; +import org.openapitools.codegen.config.CodegenConfigurator; import org.openapitools.codegen.java.assertions.JavaFileAssert; import org.testng.annotations.Test; -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Path; +import java.io.File; +import java.util.List; import java.util.Map; +import static org.openapitools.codegen.TestUtils.newTempFolder; + public class JavaPKMSTServerCodegenTest { /** @@ -20,27 +20,22 @@ public class JavaPKMSTServerCodegenTest { * Includes regression tests for: * - Correct Jackson annotation when `wrapped: false` */ - @Test public void shouldGenerateCorrectXmlAnnotations() throws IOException { + @Test public void shouldGenerateCorrectXmlAnnotations() { // Arrange - final String TEST_SPEC = "src/test/resources/3_0/java/xml-annotations-test.yaml"; - final Path output = Files.createTempDirectory("test-xml-annotations_"); - output.toFile().deleteOnExit(); - - JavaPKMSTServerCodegen codegen = new JavaPKMSTServerCodegen(); - codegen.setWithXml(true); - codegen.setOutputDir(output.toString()); - - DefaultGenerator generator = new DefaultGenerator(); - generator.setGeneratorPropertyDefault(CodegenConstants.MODELS, "true"); - generator.setGeneratorPropertyDefault(CodegenConstants.MODEL_TESTS, "false"); - generator.setGeneratorPropertyDefault(CodegenConstants.MODEL_DOCS, "false"); - generator.setGenerateMetadata(false); + final CodegenConfigurator config = new CodegenConfigurator() + .addAdditionalProperty(CodegenConstants.WITH_XML, true) + .addGlobalProperty(CodegenConstants.MODELS, "Pet") + .addGlobalProperty(CodegenConstants.MODEL_DOCS, null) + .addGlobalProperty(CodegenConstants.MODEL_TESTS, null) + .setGeneratorName("java-pkmst") + .setInputSpec("src/test/resources/3_0/java/xml-annotations-test.yaml") + .setOutputDir(newTempFolder().toString()); // Act - generator.opts(new ClientOptInput().config(codegen).openAPI(TestUtils.parseSpec(TEST_SPEC))).generate(); + final List files = new DefaultGenerator().opts(config.toClientOptInput()).generate(); // Assert - JavaFileAssert.assertThat(output.resolve("src/main/java/com/prokarma/pkmst/model/Pet.java").toFile()) + JavaFileAssert.assertThat(files.get(0)) .assertTypeAnnotations() .containsWithNameAndAttributes("JacksonXmlRootElement", Map.of("localName", "\"Pet\"", "namespace", "\"urn:jacksonxml\"")) .containsWithNameAndAttributes("XmlRootElement", Map.of("name", "\"Pet\"", "namespace", "\"urn:jacksonxml\"")) @@ -48,56 +43,56 @@ public class JavaPKMSTServerCodegenTest { .toType() // ↓ test custom-name on wrapper element (https://swagger.io/docs/specification/data-models/representing-xml/#:~:text=Use%20xml/name%20to%20give%20different%20names) - .hasProperty("tags").assertPropertyAnnotations() + .assertProperty("tags").assertPropertyAnnotations() .containsWithNameAndAttributes("JacksonXmlProperty", Map.of("localName", "\"Tag\"")) .containsWithNameAndAttributes("JacksonXmlElementWrapper", Map.of("localName", "\"TagList\"", "useWrapping", "true")) .toProperty().toType() // ↓ custom internal xml-array element name, non-wrapped (1st example in https://spec.openapis.org/oas/v3.0.0#xml-arrays) - .hasProperty("friends").assertPropertyAnnotations() + .assertProperty("friends").assertPropertyAnnotations() .containsWithNameAndAttributes("JacksonXmlProperty", Map.of("localName", "\"friend-pet\"")) .containsWithNameAndAttributes("JacksonXmlElementWrapper", Map.of("useWrapping", "false")) .toProperty().toType() // ↓ test custom element name (https://swagger.io/docs/specification/data-models/representing-xml/#:~:text=Change%20Element%20Names) - .hasProperty("status").assertPropertyAnnotations() - .doesNotContainsWithName("JacksonXmlElementWrapper") + .assertProperty("status").assertPropertyAnnotations() + .doesNotContainWithName("JacksonXmlElementWrapper") .containsWithNameAndAttributes("JacksonXmlProperty", Map.of("localName", "\"PetStatus\"")) .toProperty().toType() // ↓ test same-name wrapping element (https://swagger.io/docs/specification/data-models/representing-xml/#:~:text=Wrapping%20Arrays) // maps to 3rd example in https://spec.openapis.org/oas/v3.0.0#xml-arrays - .hasProperty("photoUrls").assertPropertyAnnotations() + .assertProperty("photoUrls").assertPropertyAnnotations() .containsWithNameAndAttributes("JacksonXmlProperty", Map.of("localName", "\"photoUrls\"")) .containsWithNameAndAttributes("JacksonXmlElementWrapper", Map.of("localName", "\"photoUrls\"", "useWrapping", "true")) .toProperty().toType() // ↓ test attribute generation (https://swagger.io/docs/specification/data-models/representing-xml/#:~:text=Convert%20Property%20to%20an%20Attribute) - .hasProperty("name").assertPropertyAnnotations() - .doesNotContainsWithName("JacksonXmlElementWrapper") + .assertProperty("name").assertPropertyAnnotations() + .doesNotContainWithName("JacksonXmlElementWrapper") .containsWithNameAndAttributes("JacksonXmlProperty", Map.of("isAttribute", "true", "localName", "\"name\"")) .toProperty().toType() // ↓ test XML namespace and prefix (https://swagger.io/docs/specification/data-models/representing-xml/#:~:text=Prefixes%20and%20Namespaces) - .hasProperty("id").assertPropertyAnnotations() - .doesNotContainsWithName("JacksonXmlElementWrapper") + .assertProperty("id").assertPropertyAnnotations() + .doesNotContainWithName("JacksonXmlElementWrapper") .containsWithNameAndAttributes("JacksonXmlProperty", Map.of("localName", "\"id\"", "namespace", "\"http://example.com/schema\"")) .toProperty().toType() // ↓ external xml-array element name only (last example in https://spec.openapis.org/oas/v3.0.0#xml-arrays) - .hasProperty("foods").assertPropertyAnnotations() + .assertProperty("foods").assertPropertyAnnotations() .containsWithNameAndAttributes("JacksonXmlProperty", Map.of("localName", "\"yummy-yummy\"")) .containsWithNameAndAttributes("JacksonXmlElementWrapper", Map.of("localName", "\"yummy-yummy\"")) .toProperty().toType() // ↓ internal xml-array element name (4th example in https://spec.openapis.org/oas/v3.0.0#xml-arrays) - .hasProperty("colors").assertPropertyAnnotations() + .assertProperty("colors").assertPropertyAnnotations() .containsWithNameAndAttributes("JacksonXmlProperty", Map.of("localName", "\"color\"")) .containsWithNameAndAttributes("JacksonXmlElementWrapper", Map.of("localName", "\"colors\"")) .toProperty().toType() // ↓ ignored external xml-array element name, non-wrapped (2nd example in https://spec.openapis.org/oas/v3.0.0#xml-arrays) - .hasProperty("categories").assertPropertyAnnotations() + .assertProperty("categories").assertPropertyAnnotations() .containsWithNameAndAttributes("JacksonXmlProperty", Map.of("localName", "\"Category\"")) // ↓ specific regression test for #2417: (useWrapping=false) needs to be present .containsWithNameAndAttributes("JacksonXmlElementWrapper", Map.of("useWrapping", "false")) @@ -105,8 +100,8 @@ public class JavaPKMSTServerCodegenTest { // ↓ test custom-name on wrapper AND children (https://swagger.io/docs/specification/data-models/representing-xml/#:~:text=Use%20xml/name%20to%20give%20different%20names) // maps to 5th example in https://spec.openapis.org/oas/v3.0.0#xml-arrays - .hasProperty("activities").assertPropertyAnnotations() + .assertProperty("activities").assertPropertyAnnotations() .containsWithNameAndAttributes("JacksonXmlProperty", Map.of("localName", "\"item\"")) .containsWithNameAndAttributes("JacksonXmlElementWrapper", Map.of("localName", "\"activities-array\"")); } -} \ No newline at end of file +}