From 2a3194d6e64725bbfa6db113e6476c409361a603 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jose=20Enrique=20Garc=C3=ADa=20Maci=C3=B1eiras?= Date: Sat, 30 Sep 2023 13:34:50 +0200 Subject: [PATCH 1/9] 293 Improve support for Asyncapi ref simple types --- multiapi-engine/pom.xml | 2 +- .../asyncapi/util/MapperContentUtil.java | 14 +- .../plugin/common/tools/SchemaUtil.java | 35 +++++ .../openapi/utils/MapperContentUtil.java | 4 +- .../plugin/openapi/utils/MapperPathUtil.java | 6 +- .../plugin/openapi/utils/OpenApiUtil.java | 21 +-- .../asyncapi/AsyncApiGeneratorFixtures.java | 82 +++++++---- .../asyncapi/AsyncApiGeneratorTest.java | 2 + .../assets/CustomerOrderDTO.java | 35 ++++- .../{ConfigurationDTO.java => ConfigDTO.java} | 28 ++-- .../assets/MailRequestDTO.java | 12 +- .../assets/DataDTO.java | 133 ++++++++++++++++++ .../assets/IClients.java | 8 ++ .../assets/IResponse.java | 8 ++ .../assets/Producer.java | 24 ++++ .../assets/StatusMsgDTO.java | 130 +++++++++++++++++ .../assets/Subscriber.java | 24 ++++ .../event-api.yml | 67 +++++++++ .../{UserDetails.java => Details.java} | 32 ++--- .../assets/payload/UserSignedUp.java | 12 +- scs-multiapi-gradle-plugin/build.gradle | 6 +- scs-multiapi-maven-plugin/pom.xml | 4 +- 22 files changed, 575 insertions(+), 114 deletions(-) create mode 100644 multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/tools/SchemaUtil.java rename multiapi-engine/src/test/resources/asyncapigenerator/testIssueGenerateSupplier/assets/{ConfigurationDTO.java => ConfigDTO.java} (61%) create mode 100644 multiapi-engine/src/test/resources/asyncapigenerator/testIssueSimpleTypeGeneration/assets/DataDTO.java create mode 100644 multiapi-engine/src/test/resources/asyncapigenerator/testIssueSimpleTypeGeneration/assets/IClients.java create mode 100644 multiapi-engine/src/test/resources/asyncapigenerator/testIssueSimpleTypeGeneration/assets/IResponse.java create mode 100644 multiapi-engine/src/test/resources/asyncapigenerator/testIssueSimpleTypeGeneration/assets/Producer.java create mode 100644 multiapi-engine/src/test/resources/asyncapigenerator/testIssueSimpleTypeGeneration/assets/StatusMsgDTO.java create mode 100644 multiapi-engine/src/test/resources/asyncapigenerator/testIssueSimpleTypeGeneration/assets/Subscriber.java create mode 100644 multiapi-engine/src/test/resources/asyncapigenerator/testIssueSimpleTypeGeneration/event-api.yml rename multiapi-engine/src/test/resources/asyncapigenerator/testPropertiesNotGeneratedIssue/assets/payload/{UserDetails.java => Details.java} (71%) diff --git a/multiapi-engine/pom.xml b/multiapi-engine/pom.xml index 655937ab..d0e3f849 100644 --- a/multiapi-engine/pom.xml +++ b/multiapi-engine/pom.xml @@ -4,7 +4,7 @@ com.sngular multiapi-engine - 5.0.1 + 5.0.2 jar diff --git a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/asyncapi/util/MapperContentUtil.java b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/asyncapi/util/MapperContentUtil.java index 0a24ea7f..04bfb3d0 100644 --- a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/asyncapi/util/MapperContentUtil.java +++ b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/asyncapi/util/MapperContentUtil.java @@ -182,7 +182,9 @@ private static List processFieldObject( fieldObjectArrayList.add(processFieldObjectList(totalSchemas, property, model.get(PROPERTIES).path(property), requiredSet.contains(property), prefix, suffix, modelToBuildList, parentPackage)); if (model.get(PROPERTIES).path(property).has(REF)) { - modelToBuildList.add(MapperUtil.getLongRefClass(model.get(PROPERTIES).path(property))); + if (!totalSchemas.containsKey(createKey(parentPackage, property.toUpperCase(), "/"))) { + modelToBuildList.add(MapperUtil.getLongRefClass(model.get(PROPERTIES).path(property))); + } } } } else if (properties.has(ALL_OF)) { @@ -275,14 +277,8 @@ private static SchemaFieldObject processFieldObjectList( fieldObject.setRequired(required); } } else if (ApiTool.hasRef(schema)) { - fieldObject = - SchemaFieldObject - .builder() - .baseName(name) - .dataTypeSimple(MapperUtil.getSimpleType(schema, prefix, suffix)) - .restrictions(new SchemaFieldObjectProperties()) - .build(); - setFieldType(fieldObject, schema, required, prefix, suffix); + final var solvedRef = totalSchemas.get(getComponent(MapperUtil.splitName(ApiTool.getRefValue(schema)))); + fieldObject = processFieldObjectList(totalSchemas, name, solvedRef, required, prefix, suffix, modelToBuildList, modelPackage); } else { fieldObject = SchemaFieldObject .builder() diff --git a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/tools/SchemaUtil.java b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/tools/SchemaUtil.java new file mode 100644 index 00000000..c3e93ad8 --- /dev/null +++ b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/tools/SchemaUtil.java @@ -0,0 +1,35 @@ +package com.sngular.api.generator.plugin.common.tools; + +import java.nio.file.Path; +import java.util.Map; + +import com.fasterxml.jackson.databind.JsonNode; +import com.sngular.api.generator.plugin.openapi.utils.MapperUtil; +import com.sngular.api.generator.plugin.openapi.utils.OpenApiUtil; +import org.apache.commons.lang3.StringUtils; + +public class SchemaUtil { + + protected SchemaUtil() { + } + + public static JsonNode solveRef(final String refValue, final Map schemaMap, final Path rootFilePath) { + JsonNode solvedRef; + if (StringUtils.isNotEmpty(refValue)) { + if (refValue.startsWith("#")) { + final String refSchemaName = MapperUtil.getRefSchemaName(refValue); + solvedRef = schemaMap.get(refSchemaName); + } else { + final var refValueArr = refValue.split("#"); + final var filePath = refValueArr[0]; + solvedRef = OpenApiUtil.getPojoFromRef(rootFilePath.toAbsolutePath(), filePath); + final var refName = MapperUtil.getRefSchemaName(refValueArr[1]); + schemaMap.putAll(ApiTool.getComponentSchemas(solvedRef)); + solvedRef = solvedRef.findValue(refName); + } + } else { + solvedRef = null; + } + return solvedRef; + } +} diff --git a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/openapi/utils/MapperContentUtil.java b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/openapi/utils/MapperContentUtil.java index f7eb28d1..8715dd04 100644 --- a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/openapi/utils/MapperContentUtil.java +++ b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/openapi/utils/MapperContentUtil.java @@ -16,8 +16,10 @@ import java.util.Objects; import java.util.Set; import java.util.function.Consumer; + import com.fasterxml.jackson.databind.JsonNode; import com.sngular.api.generator.plugin.common.tools.ApiTool; +import com.sngular.api.generator.plugin.common.tools.SchemaUtil; import com.sngular.api.generator.plugin.openapi.exception.BadDefinedEnumException; import com.sngular.api.generator.plugin.openapi.model.SchemaFieldObject; import com.sngular.api.generator.plugin.openapi.model.SchemaFieldObjectType; @@ -319,7 +321,7 @@ private static SchemaObject solveRef( final Map compositedSchemas, final List antiLoopList, final SpecFile specFile, final Path baseDir) { - final var referredSchema = OpenApiUtil.solveRef(ApiTool.getRefValue(schema), totalSchemas, baseDir.resolve(specFile.getFilePath()).getParent()); + final var referredSchema = SchemaUtil.solveRef(ApiTool.getRefValue(schema), totalSchemas, baseDir.resolve(specFile.getFilePath()).getParent()); final var schemaObject = toSchemaObject(MapperUtil.getRefSchemaName(schema), totalSchemas, compositedSchemas, antiLoopList, referredSchema, MapperUtil.getRefSchemaName(schema), specFile, baseDir); diff --git a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/openapi/utils/MapperPathUtil.java b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/openapi/utils/MapperPathUtil.java index 2ea7c71f..754a8032 100644 --- a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/openapi/utils/MapperPathUtil.java +++ b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/openapi/utils/MapperPathUtil.java @@ -16,8 +16,10 @@ import java.util.Map.Entry; import java.util.Objects; import java.util.function.BiConsumer; + import com.fasterxml.jackson.databind.JsonNode; import com.sngular.api.generator.plugin.common.tools.ApiTool; +import com.sngular.api.generator.plugin.common.tools.SchemaUtil; import com.sngular.api.generator.plugin.openapi.exception.DuplicatedOperationException; import com.sngular.api.generator.plugin.openapi.exception.InvalidOpenAPIException; import com.sngular.api.generator.plugin.openapi.model.AuthSchemaObject; @@ -374,8 +376,8 @@ private static SchemaFieldObjectType getSchemaType( if (ApiTool.hasRef(schema)) { final String refSchemaPojoName = MapperUtil.getRef(schema, specFile); - final JsonNode refSchema = OpenApiUtil.solveRef(ApiTool.getRefValue(schema), globalObject.getSchemaMap(), - baseDir.resolve(specFile.getFilePath()).getParent()); + final JsonNode refSchema = SchemaUtil.solveRef(ApiTool.getRefValue(schema), globalObject.getSchemaMap(), + baseDir.resolve(specFile.getFilePath()).getParent()); type = getSchemaType(refSchema, refSchemaPojoName, specFile, globalObject, baseDir); } else if (ApiTool.hasAdditionalProperties(schema)) { type = getMapSchemaType(schema, pojoName, specFile, globalObject, baseDir); diff --git a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/openapi/utils/OpenApiUtil.java b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/openapi/utils/OpenApiUtil.java index 494d3c59..04338d9f 100644 --- a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/openapi/utils/OpenApiUtil.java +++ b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/openapi/utils/OpenApiUtil.java @@ -21,6 +21,7 @@ import java.util.Map.Entry; import java.util.Objects; import java.util.Set; + import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.node.JsonNodeFactory; @@ -240,26 +241,6 @@ private static String capLettersAfterSpecialCharacters(final String pathName, fi return javaFileName; } - protected static JsonNode solveRef(final String refValue, final Map schemaMap, final Path rootFilePath) { - JsonNode solvedRef; - if (StringUtils.isNotEmpty(refValue)) { - if (refValue.startsWith("#")) { - final String refSchemaName = MapperUtil.getRefSchemaName(refValue); - solvedRef = schemaMap.get(refSchemaName); - } else { - final var refValueArr = refValue.split("#"); - final var filePath = refValueArr[0]; - solvedRef = getPojoFromRef(rootFilePath.toAbsolutePath(), filePath); - final var refName = MapperUtil.getRefSchemaName(refValueArr[1]); - schemaMap.putAll(ApiTool.getComponentSchemas(solvedRef)); - solvedRef = solvedRef.findValue(refName); - } - } else { - solvedRef = null; - } - return solvedRef; - } - } diff --git a/multiapi-engine/src/test/java/com/sngular/api/generator/plugin/asyncapi/AsyncApiGeneratorFixtures.java b/multiapi-engine/src/test/java/com/sngular/api/generator/plugin/asyncapi/AsyncApiGeneratorFixtures.java index c36b4e33..4cc0264f 100644 --- a/multiapi-engine/src/test/java/com/sngular/api/generator/plugin/asyncapi/AsyncApiGeneratorFixtures.java +++ b/multiapi-engine/src/test/java/com/sngular/api/generator/plugin/asyncapi/AsyncApiGeneratorFixtures.java @@ -6,8 +6,6 @@ package com.sngular.api.generator.plugin.asyncapi; -import static org.assertj.core.api.Assertions.assertThat; - import java.io.File; import java.io.IOException; import java.nio.file.Path; @@ -19,6 +17,7 @@ import com.sngular.api.generator.plugin.asyncapi.parameter.SpecFile; import com.sngular.api.generator.test.utils.TestUtils; import org.apache.commons.collections4.CollectionUtils; +import static org.assertj.core.api.Assertions.assertThat; public class AsyncApiGeneratorFixtures { @@ -68,6 +67,25 @@ public class AsyncApiGeneratorFixtures { .build() ); + final static List TEST_ISSUE_SIMPLE_TYPE_GENERATION = List.of( + SpecFile + .builder() + .filePath("src/test/resources/asyncapigenerator/testIssueSimpleTypeGeneration/event-api.yml") + .consumer(OperationParameterObject.builder() + .ids("response") + .modelNameSuffix("DTO") + .apiPackage("com.sngular.scsplugin.issuesimpletypegeneration.model.event.consumer") + .modelPackage("com.sngular.scsplugin.issuesimpletypegeneration.model.event") + .build()) + .supplier(OperationParameterObject.builder() + .ids("clients") + .modelNameSuffix("DTO") + .apiPackage("com.sngular.scsplugin.issuesimpletypegeneration.model.event.producer") + .modelPackage("com.sngular.scsplugin.issuesimpletypegeneration.model.event") + .build()) + .build() + ); + final static List TEST_CUSTOM_VALIDATORS = List.of( SpecFile .builder() @@ -302,8 +320,6 @@ static Function validateTestFileGeneration() { final String DEFAULT_PRODUCER_FOLDER = DEFAULT_COMMON_FOLDER + "/producer"; - final String DEFAULT_MODEL_SCHEMA_FOLDER = DEFAULT_COMMON_FOLDER; - final String DEFAULT_CUSTOM_VALIDATOR_FOLDER = DEFAULT_COMMON_FOLDER + "/customvalidator"; final String COMMON_PATH = "asyncapigenerator/testFileGeneration/"; @@ -338,16 +354,12 @@ static Function validateTestFileGeneration() { CUSTOM_VALIDATOR_PATH + "NotNullValidator.java" ); - final List expectedModelMessageFiles = List.of( - ASSETS_PATH + "OrderCreatedDTO.java" - ); - final List expectedExceptionFiles = List.of( ASSETS_PATH + "ModelClassException.java"); return (path) -> commonTest(path, expectedConsumerFiles, expectedProducerFiles, DEFAULT_CONSUMER_FOLDER, DEFAULT_PRODUCER_FOLDER, expectedExceptionFiles, DEFAULT_EXCEPTION_API) && - modelTest(path, expectedModelSchemaFiles, DEFAULT_MODEL_SCHEMA_FOLDER) && + modelTest(path, expectedModelSchemaFiles, DEFAULT_COMMON_FOLDER) && customValidatorTest(path, expectedValidatorFiles, DEFAULT_CUSTOM_VALIDATOR_FOLDER); } @@ -375,9 +387,35 @@ static Function validateTestIssueGeneration() { ASSETS_PATH + "StatusMsgDTO.java" ); - final List expectedModelMessageFiles = List.of( - ASSETS_PATH + "DataClientDTO.java", - ASSETS_PATH + "StatusDTO.java" + final List expectedExceptionFiles = List.of(); + + return (path) -> commonTest(path, expectedConsumerFiles, expectedProducerFiles, DEFAULT_CONSUMER_FOLDER, DEFAULT_PRODUCER_FOLDER, + expectedExceptionFiles, null) && + modelTest(path, expectedModelSchemaFiles, DEFAULT_MODEL_SCHEMA_FOLDER); + } + + static Function validateTestIssueSimpleTypeGeneration() { + final String DEFAULT_CONSUMER_FOLDER = "generated/com/sngular/scsplugin/issuesimpletypegeneration/model/event/consumer"; + + final String DEFAULT_PRODUCER_FOLDER = "generated/com/sngular/scsplugin/issuesimpletypegeneration/model/event/producer"; + + final String DEFAULT_MODEL_SCHEMA_FOLDER = "generated/com/sngular/scsplugin/issuesimpletypegeneration/model/event"; + + final String COMMON_PATH = "asyncapigenerator/testIssueSimpleTypeGeneration/"; + + final String ASSETS_PATH = COMMON_PATH + "assets/"; + + final List expectedConsumerFiles = List.of( + ASSETS_PATH + "IResponse.java", + ASSETS_PATH + "Subscriber.java"); + + final List expectedProducerFiles = List.of( + ASSETS_PATH + "IClients.java", + ASSETS_PATH + "Producer.java"); + + final List expectedModelSchemaFiles = List.of( + ASSETS_PATH + "DataDTO.java", + ASSETS_PATH + "StatusMsgDTO.java" ); final List expectedExceptionFiles = List.of(); @@ -455,8 +493,6 @@ static Function validateTestFileGenerationIssue() { final String DEFAULT_PRODUCER_FOLDER = DEFAULT_COMMON_FOLDER + "/producer"; - final String DEFAULT_MODEL_SCHEMA_FOLDER = DEFAULT_COMMON_FOLDER; - final String DEFAULT_CUSTOM_VALIDATOR_FOLDER = DEFAULT_COMMON_FOLDER + "/customvalidator"; final String COMMON_PATH = "asyncapigenerator/testFileGenerationIssue/"; @@ -497,7 +533,7 @@ static Function validateTestFileGenerationIssue() { return (path) -> commonTest(path, expectedConsumerFiles, expectedProducerFiles, DEFAULT_CONSUMER_FOLDER, DEFAULT_PRODUCER_FOLDER, expectedExceptionFiles, DEFAULT_EXCEPTION_API) && - modelTest(path, expectedModelSchemaFiles, DEFAULT_MODEL_SCHEMA_FOLDER) && + modelTest(path, expectedModelSchemaFiles, DEFAULT_COMMON_FOLDER) && customValidatorTest(path, expectedValidatorFiles, DEFAULT_CUSTOM_VALIDATOR_FOLDER); } @@ -598,7 +634,7 @@ static Function validateTestIssueGenerateSupplier() { final String DEFAULT_MODEL_SCHEMA_FOLDER = "generated/company/mail/model"; final List expectedModelSchemaFiles = List.of( - "asyncapigenerator/testIssueGenerateSupplier/assets/ConfigurationDTO.java", + "asyncapigenerator/testIssueGenerateSupplier/assets/ConfigDTO.java", "asyncapigenerator/testIssueGenerateSupplier/assets/MailRequestDTO.java" ); @@ -628,8 +664,6 @@ static Function validateTestModelClassExceptionGeneration() { final String COMMON_PATH = "asyncapigenerator/testModelClassExceptionGeneration/"; - final String DEFAULT_MODEL_SCHEMA_FOLDER = DEFAULT_COMMON_FOLDER ; - final String ASSETS_PATH = COMMON_PATH + "assets/"; final String CUSTOM_VALIDATOR_PATH = COMMON_PATH + "customvalidator/"; @@ -662,7 +696,7 @@ static Function validateTestModelClassExceptionGeneration() { return (path) -> commonTest(path, expectedConsumerFiles, expectedProducerFiles, DEFAULT_CONSUMER_FOLDER, DEFAULT_PRODUCER_FOLDER, expectedExceptionFiles, DEFAULT_EXCEPTION_API) && - modelTest(path, expectedModelSchemaFiles, DEFAULT_MODEL_SCHEMA_FOLDER) && + modelTest(path, expectedModelSchemaFiles, DEFAULT_COMMON_FOLDER) && customValidatorTest(path, expectedValidatorFiles, DEFAULT_CUSTOM_VALIDATOR_FOLDER); } @@ -709,7 +743,7 @@ static Function validateNotGeneratedPropertiesIssue () { final List expectedModelSchemaFiles = List.of( - "asyncapigenerator/testPropertiesNotGeneratedIssue/assets/payload/UserDetails.java", + "asyncapigenerator/testPropertiesNotGeneratedIssue/assets/payload/Details.java", "asyncapigenerator/testPropertiesNotGeneratedIssue/assets/payload/UserSignedUp.java" ); @@ -727,8 +761,6 @@ static Function validateTestFileGenerationWithKafkaBindings() { final String DEFAULT_PRODUCER_FOLDER = DEFAULT_COMMON_FOLDER + "/producer"; - final String DEFAULT_MODEL_SCHEMA_FOLDER = DEFAULT_COMMON_FOLDER; - final String DEFAULT_CUSTOM_VALIDATOR_FOLDER = DEFAULT_COMMON_FOLDER + "/customvalidator"; final String COMMON_PATH = "asyncapigenerator/testFileGenerationWithKafkaBindings/"; @@ -763,12 +795,8 @@ static Function validateTestFileGenerationWithKafkaBindings() { CUSTOM_VALIDATOR_PATH + "NotNullValidator.java" ); - final List expectedModelMessageFiles = List.of( - ASSETS_PATH + "OrderCreatedDTO.java" - ); - return (path) -> commonTest(path, expectedConsumerFiles, expectedProducerFiles, DEFAULT_CONSUMER_FOLDER, DEFAULT_PRODUCER_FOLDER, Collections.emptyList(), null) && - modelTest(path, expectedModelSchemaFiles, DEFAULT_MODEL_SCHEMA_FOLDER) && + modelTest(path, expectedModelSchemaFiles, DEFAULT_COMMON_FOLDER) && customValidatorTest(path, expectedValidatorFiles, DEFAULT_CUSTOM_VALIDATOR_FOLDER); } diff --git a/multiapi-engine/src/test/java/com/sngular/api/generator/plugin/asyncapi/AsyncApiGeneratorTest.java b/multiapi-engine/src/test/java/com/sngular/api/generator/plugin/asyncapi/AsyncApiGeneratorTest.java index 8c76513f..4068e52a 100644 --- a/multiapi-engine/src/test/java/com/sngular/api/generator/plugin/asyncapi/AsyncApiGeneratorTest.java +++ b/multiapi-engine/src/test/java/com/sngular/api/generator/plugin/asyncapi/AsyncApiGeneratorTest.java @@ -55,6 +55,8 @@ static Stream fileSpecToProcess() { AsyncApiGeneratorFixtures.validateTestFileGenerationArrayString()), Arguments.of("TestIssueGenerateSupplier", AsyncApiGeneratorFixtures.TEST_ISSUE_GENERATE_SUPPLIER, AsyncApiGeneratorFixtures.validateTestIssueGenerateSupplier()), + Arguments.of("TestIssueSimpleTypeGenerate", AsyncApiGeneratorFixtures.TEST_ISSUE_SIMPLE_TYPE_GENERATION, + AsyncApiGeneratorFixtures.validateTestIssueSimpleTypeGeneration()), Arguments.of("TestIssueInfiniteLoop", AsyncApiGeneratorFixtures.TEST_ISSUE_INFINITE_LOOP, AsyncApiGeneratorFixtures.validateTestIssueInfiniteLoop()), Arguments.of("TestCustomValidators", AsyncApiGeneratorFixtures.TEST_CUSTOM_VALIDATORS, AsyncApiGeneratorFixtures.validateCustomValidators(SPRING_BOOT_VERSION)), diff --git a/multiapi-engine/src/test/resources/asyncapigenerator/testFileGenerationIssue/assets/CustomerOrderDTO.java b/multiapi-engine/src/test/resources/asyncapigenerator/testFileGenerationIssue/assets/CustomerOrderDTO.java index 25d3e64f..6b7d8038 100644 --- a/multiapi-engine/src/test/resources/asyncapigenerator/testFileGenerationIssue/assets/CustomerOrderDTO.java +++ b/multiapi-engine/src/test/resources/asyncapigenerator/testFileGenerationIssue/assets/CustomerOrderDTO.java @@ -5,6 +5,7 @@ import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder; import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; import io.swagger.v3.oas.annotations.media.Schema; import java.util.List; import java.util.ArrayList; @@ -23,11 +24,32 @@ public class CustomerOrderDTO { @JsonProperty(value ="paymentDetails") private List paymentDetails = new ArrayList(); @JsonProperty(value ="status") - private OrderStatusDTO status; + private Status status; + public enum Status { + DELIVERED("DELIVERED"), + CONFIRMED("CONFIRMED"), + SHIPPED("SHIPPED"); + + private String value; + + Status(String value) { + this.value = value; + } + + @JsonValue + public String getValue() { + return value; + } + + @Override + public String toString() { + return String.valueOf(value); + } + } @JsonProperty(value ="customer") private CustomerDTO customer; - private CustomerOrderDTO(String id, String date, ShippingDetailsDTO shippingDetails, List orderedItems, List paymentDetails, OrderStatusDTO status, CustomerDTO customer) { + private CustomerOrderDTO(String id, String date, ShippingDetailsDTO shippingDetails, List orderedItems, List paymentDetails, Status status, CustomerDTO customer) { this.id = id; this.date = date; this.shippingDetails = shippingDetails; @@ -61,7 +83,7 @@ public static class CustomerOrderDTOBuilder { private ShippingDetailsDTO shippingDetails; private List orderedItems = new ArrayList(); private List paymentDetails = new ArrayList(); - private OrderStatusDTO status; + private Status status; private CustomerDTO customer; public CustomerOrderDTO.CustomerOrderDTOBuilder id(String id) { @@ -104,8 +126,7 @@ public CustomerOrderDTO.CustomerOrderDTOBuilder paymentDetail(PaymentDetailsDTO } return this; } - - public CustomerOrderDTO.CustomerOrderDTOBuilder status(OrderStatusDTO status) { + public CustomerOrderDTO.CustomerOrderDTOBuilder status(Status status) { this.status = status; return this; } @@ -186,10 +207,10 @@ public void setPaymentDetails(List paymentDetails) { * @return status */ @Schema(name = "status", required = false) - public OrderStatusDTO getStatus() { + public Status getStatus() { return status; } - public void setStatus(OrderStatusDTO status) { + public void setStatus(Status status) { this.status = status; } diff --git a/multiapi-engine/src/test/resources/asyncapigenerator/testIssueGenerateSupplier/assets/ConfigurationDTO.java b/multiapi-engine/src/test/resources/asyncapigenerator/testIssueGenerateSupplier/assets/ConfigDTO.java similarity index 61% rename from multiapi-engine/src/test/resources/asyncapigenerator/testIssueGenerateSupplier/assets/ConfigurationDTO.java rename to multiapi-engine/src/test/resources/asyncapigenerator/testIssueGenerateSupplier/assets/ConfigDTO.java index 499c9b32..9a849356 100644 --- a/multiapi-engine/src/test/resources/asyncapigenerator/testIssueGenerateSupplier/assets/ConfigurationDTO.java +++ b/multiapi-engine/src/test/resources/asyncapigenerator/testIssueGenerateSupplier/assets/ConfigDTO.java @@ -7,39 +7,39 @@ import com.fasterxml.jackson.annotation.JsonProperty; import io.swagger.v3.oas.annotations.media.Schema; -@JsonDeserialize(builder = ConfigurationDTO.ConfigurationDTOBuilder.class) -public class ConfigurationDTO { +@JsonDeserialize(builder = ConfigDTO.ConfigDTOBuilder.class) +public class ConfigDTO { @JsonProperty(value ="name") private String name; - private ConfigurationDTO(String name) { + private ConfigDTO(String name) { this.name = name; } - private ConfigurationDTO(ConfigurationDTOBuilder builder) { + private ConfigDTO(ConfigDTOBuilder builder) { this.name = builder.name; } - public static ConfigurationDTO.ConfigurationDTOBuilder builder() { - return new ConfigurationDTO.ConfigurationDTOBuilder(); + public static ConfigDTO.ConfigDTOBuilder builder() { + return new ConfigDTO.ConfigDTOBuilder(); } @JsonPOJOBuilder(buildMethodName = "build", withPrefix = "") - public static class ConfigurationDTOBuilder { + public static class ConfigDTOBuilder { private String name; - public ConfigurationDTO.ConfigurationDTOBuilder name(String name) { + public ConfigDTO.ConfigDTOBuilder name(String name) { this.name = name; return this; } - public ConfigurationDTO build() { - ConfigurationDTO configurationDTO = new ConfigurationDTO(this); - return configurationDTO; + public ConfigDTO build() { + ConfigDTO configDTO = new ConfigDTO(this); + return configDTO; } } @@ -63,8 +63,8 @@ public boolean equals(Object o) { if (o == null || getClass() != o.getClass()) { return false; } - ConfigurationDTO configurationDTO = (ConfigurationDTO) o; - return Objects.equals(this.name, configurationDTO.name); + ConfigDTO configDTO = (ConfigDTO) o; + return Objects.equals(this.name, configDTO.name); } @Override @@ -75,7 +75,7 @@ public int hashCode() { @Override public String toString() { StringBuilder sb = new StringBuilder(); - sb.append("ConfigurationDTO{"); + sb.append("ConfigDTO{"); sb.append(" name:").append(name); sb.append("}"); return sb.toString(); diff --git a/multiapi-engine/src/test/resources/asyncapigenerator/testIssueGenerateSupplier/assets/MailRequestDTO.java b/multiapi-engine/src/test/resources/asyncapigenerator/testIssueGenerateSupplier/assets/MailRequestDTO.java index 631e5016..e87d4045 100644 --- a/multiapi-engine/src/test/resources/asyncapigenerator/testIssueGenerateSupplier/assets/MailRequestDTO.java +++ b/multiapi-engine/src/test/resources/asyncapigenerator/testIssueGenerateSupplier/assets/MailRequestDTO.java @@ -17,9 +17,9 @@ public class MailRequestDTO { @JsonProperty(value ="recipients") private List recipients = new ArrayList(); @JsonProperty(value ="config") - private ConfigurationDTO config; + private ConfigDTO config; - private MailRequestDTO(String sender, List recipients, ConfigurationDTO config) { + private MailRequestDTO(String sender, List recipients, ConfigDTO config) { this.sender = sender; this.recipients = recipients; this.config = config; @@ -42,7 +42,7 @@ public static class MailRequestDTOBuilder { private String sender; private List recipients = new ArrayList(); - private ConfigurationDTO config; + private ConfigDTO config; public MailRequestDTO.MailRequestDTOBuilder sender(String sender) { this.sender = sender; @@ -62,7 +62,7 @@ public MailRequestDTO.MailRequestDTOBuilder recipient(String recipient) { return this; } - public MailRequestDTO.MailRequestDTOBuilder config(ConfigurationDTO config) { + public MailRequestDTO.MailRequestDTOBuilder config(ConfigDTO config) { this.config = config; return this; } @@ -102,10 +102,10 @@ public void setRecipients(List recipients) { * @return config */ @Schema(name = "config", required = false) - public ConfigurationDTO getConfig() { + public ConfigDTO getConfig() { return config; } - public void setConfig(ConfigurationDTO config) { + public void setConfig(ConfigDTO config) { this.config = config; } diff --git a/multiapi-engine/src/test/resources/asyncapigenerator/testIssueSimpleTypeGeneration/assets/DataDTO.java b/multiapi-engine/src/test/resources/asyncapigenerator/testIssueSimpleTypeGeneration/assets/DataDTO.java new file mode 100644 index 00000000..13f11c16 --- /dev/null +++ b/multiapi-engine/src/test/resources/asyncapigenerator/testIssueSimpleTypeGeneration/assets/DataDTO.java @@ -0,0 +1,133 @@ +package com.sngular.scsplugin.issuesimpletypegeneration.model.event; + +import java.util.Objects; + +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder; +import com.fasterxml.jackson.annotation.JsonProperty; +import io.swagger.v3.oas.annotations.media.Schema; + +@JsonDeserialize(builder = DataDTO.DataDTOBuilder.class) +public class DataDTO { + + @JsonProperty(value ="clientId") + private Integer clientId; + @JsonProperty(value ="clientName") + private String clientName; + @JsonProperty(value ="flightNumber") + private String flightNumber; + + private DataDTO(Integer clientId, String clientName, String flightNumber) { + this.clientId = clientId; + this.clientName = clientName; + this.flightNumber = flightNumber; + + } + + private DataDTO(DataDTOBuilder builder) { + this.clientId = builder.clientId; + this.clientName = builder.clientName; + this.flightNumber = builder.flightNumber; + + } + + public static DataDTO.DataDTOBuilder builder() { + return new DataDTO.DataDTOBuilder(); + } + + @JsonPOJOBuilder(buildMethodName = "build", withPrefix = "") + public static class DataDTOBuilder { + + private Integer clientId; + private String clientName; + private String flightNumber; + + public DataDTO.DataDTOBuilder clientId(Integer clientId) { + this.clientId = clientId; + return this; + } + + public DataDTO.DataDTOBuilder clientName(String clientName) { + this.clientName = clientName; + return this; + } + + public DataDTO.DataDTOBuilder flightNumber(String flightNumber) { + this.flightNumber = flightNumber; + return this; + } + + public DataDTO build() { + DataDTO dataDTO = new DataDTO(this); + return dataDTO; + } + } + + /** + * Get clientId + * @return clientId + */ + @Schema(name = "clientId", required = false) + public Integer getClientId() { + return clientId; + } + public void setClientId(Integer clientId) { + this.clientId = clientId; + } + + /** + * Get clientName + * @return clientName + */ + @Schema(name = "clientName", required = false) + public String getClientName() { + return clientName; + } + public void setClientName(String clientName) { + this.clientName = clientName; + } + + /** + * Get flightNumber + * @return flightNumber + */ + @Schema(name = "flightNumber", required = false) + public String getFlightNumber() { + return flightNumber; + } + public void setFlightNumber(String flightNumber) { + this.flightNumber = flightNumber; + } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + DataDTO dataDTO = (DataDTO) o; + return Objects.equals(this.clientId, dataDTO.clientId) && Objects.equals(this.clientName, dataDTO.clientName) && Objects.equals(this.flightNumber, dataDTO.flightNumber); + } + + @Override + public int hashCode() { + return Objects.hash(clientId, clientName, flightNumber); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("DataDTO{"); + sb.append(" clientId:").append(clientId).append(","); + sb.append(" clientName:").append(clientName).append(","); + sb.append(" flightNumber:").append(flightNumber); + sb.append("}"); + return sb.toString(); + } + + + + +} diff --git a/multiapi-engine/src/test/resources/asyncapigenerator/testIssueSimpleTypeGeneration/assets/IClients.java b/multiapi-engine/src/test/resources/asyncapigenerator/testIssueSimpleTypeGeneration/assets/IClients.java new file mode 100644 index 00000000..3d3552de --- /dev/null +++ b/multiapi-engine/src/test/resources/asyncapigenerator/testIssueSimpleTypeGeneration/assets/IClients.java @@ -0,0 +1,8 @@ +package com.sngular.scsplugin.issuesimpletypegeneration.model.event.producer; + +import com.sngular.scsplugin.issuesimpletypegeneration.model.event.DataDTO; + +public interface IClients { + + DataDTO clients(); +} \ No newline at end of file diff --git a/multiapi-engine/src/test/resources/asyncapigenerator/testIssueSimpleTypeGeneration/assets/IResponse.java b/multiapi-engine/src/test/resources/asyncapigenerator/testIssueSimpleTypeGeneration/assets/IResponse.java new file mode 100644 index 00000000..fec198ac --- /dev/null +++ b/multiapi-engine/src/test/resources/asyncapigenerator/testIssueSimpleTypeGeneration/assets/IResponse.java @@ -0,0 +1,8 @@ +package com.sngular.scsplugin.issuesimpletypegeneration.model.event.consumer; + +import com.sngular.scsplugin.issuesimpletypegeneration.model.event.StatusMsgDTO; + +public interface IResponse { + + void response(final StatusMsgDTO value); +} \ No newline at end of file diff --git a/multiapi-engine/src/test/resources/asyncapigenerator/testIssueSimpleTypeGeneration/assets/Producer.java b/multiapi-engine/src/test/resources/asyncapigenerator/testIssueSimpleTypeGeneration/assets/Producer.java new file mode 100644 index 00000000..c5064b3c --- /dev/null +++ b/multiapi-engine/src/test/resources/asyncapigenerator/testIssueSimpleTypeGeneration/assets/Producer.java @@ -0,0 +1,24 @@ +package com.sngular.scsplugin.issuesimpletypegeneration.model.event.producer; + +import java.util.function.Supplier; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import com.sngular.scsplugin.issuesimpletypegeneration.model.event.DataDTO; + +@Configuration +public class Producer { + + private final IClients clients; + + protected Producer(final IClients clients) { + this.clients = clients; + } + + @Bean + public Supplier clients() { + return () -> clients.clients(); + } + + +} diff --git a/multiapi-engine/src/test/resources/asyncapigenerator/testIssueSimpleTypeGeneration/assets/StatusMsgDTO.java b/multiapi-engine/src/test/resources/asyncapigenerator/testIssueSimpleTypeGeneration/assets/StatusMsgDTO.java new file mode 100644 index 00000000..dfeceb10 --- /dev/null +++ b/multiapi-engine/src/test/resources/asyncapigenerator/testIssueSimpleTypeGeneration/assets/StatusMsgDTO.java @@ -0,0 +1,130 @@ +package com.sngular.scsplugin.issuesimpletypegeneration.model.event; + +import java.util.Objects; + +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; +import io.swagger.v3.oas.annotations.media.Schema; + +@JsonDeserialize(builder = StatusMsgDTO.StatusMsgDTOBuilder.class) +public class StatusMsgDTO { + + @JsonProperty(value ="clientId") + private Integer clientId; + @JsonProperty(value ="status") + private Status status; + public enum Status { + OK("OK"), + KO("KO"); + + private String value; + + Status(String value) { + this.value = value; + } + + @JsonValue + public String getValue() { + return value; + } + + @Override + public String toString() { + return String.valueOf(value); + } + } + + private StatusMsgDTO(Integer clientId, Status status) { + this.clientId = clientId; + this.status = status; + + } + + private StatusMsgDTO(StatusMsgDTOBuilder builder) { + this.clientId = builder.clientId; + this.status = builder.status; + + } + + public static StatusMsgDTO.StatusMsgDTOBuilder builder() { + return new StatusMsgDTO.StatusMsgDTOBuilder(); + } + + @JsonPOJOBuilder(buildMethodName = "build", withPrefix = "") + public static class StatusMsgDTOBuilder { + + private Integer clientId; + private Status status; + + public StatusMsgDTO.StatusMsgDTOBuilder clientId(Integer clientId) { + this.clientId = clientId; + return this; + } + public StatusMsgDTO.StatusMsgDTOBuilder status(Status status) { + this.status = status; + return this; + } + + public StatusMsgDTO build() { + StatusMsgDTO statusMsgDTO = new StatusMsgDTO(this); + return statusMsgDTO; + } + } + + /** + * Get clientId + * @return clientId + */ + @Schema(name = "clientId", required = false) + public Integer getClientId() { + return clientId; + } + public void setClientId(Integer clientId) { + this.clientId = clientId; + } + + /** + * Get status + * @return status + */ + @Schema(name = "status", required = false) + public Status getStatus() { + return status; + } + public void setStatus(Status status) { + this.status = status; + } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + StatusMsgDTO statusMsgDTO = (StatusMsgDTO) o; + return Objects.equals(this.clientId, statusMsgDTO.clientId) && Objects.equals(this.status, statusMsgDTO.status); + } + + @Override + public int hashCode() { + return Objects.hash(clientId, status); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("StatusMsgDTO{"); + sb.append(" clientId:").append(clientId).append(","); + sb.append(" status:").append(status); + sb.append("}"); + return sb.toString(); + } + + + + +} diff --git a/multiapi-engine/src/test/resources/asyncapigenerator/testIssueSimpleTypeGeneration/assets/Subscriber.java b/multiapi-engine/src/test/resources/asyncapigenerator/testIssueSimpleTypeGeneration/assets/Subscriber.java new file mode 100644 index 00000000..ffa7383e --- /dev/null +++ b/multiapi-engine/src/test/resources/asyncapigenerator/testIssueSimpleTypeGeneration/assets/Subscriber.java @@ -0,0 +1,24 @@ +package com.sngular.scsplugin.issuesimpletypegeneration.model.event.consumer; + +import java.util.function.Consumer; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import com.sngular.scsplugin.issuesimpletypegeneration.model.event.StatusMsgDTO; + +@Configuration +public class Subscriber { + + private final IResponse response; + + protected Subscriber(final IResponse response) { + this.response = response; + } + + @Bean + public Consumer response() { + return value -> response.response(value); + } + + +} diff --git a/multiapi-engine/src/test/resources/asyncapigenerator/testIssueSimpleTypeGeneration/event-api.yml b/multiapi-engine/src/test/resources/asyncapigenerator/testIssueSimpleTypeGeneration/event-api.yml new file mode 100644 index 00000000..78d1070e --- /dev/null +++ b/multiapi-engine/src/test/resources/asyncapigenerator/testIssueSimpleTypeGeneration/event-api.yml @@ -0,0 +1,67 @@ +asyncapi: 2.5.0 +info: + title: CheckIn Kafka API + version: 1.0.0 + description: | + API de Check In para clientes. + license: + name: Apache 2.0 + url: "https://www.apache.org/licenses/LICENSE-2.0" +servers: + local-kafka: + url: "localhost:9092" + protocol: kafka +channels: + clients: + publish: + operationId: clients + message: + $ref: "#/components/messages/dataClient" + response: + subscribe: + operationId: response + message: + $ref: "#/components/messages/status" +components: + messages: + status: + name: status + title: Envia status + summary: Envia el estado de la solicitud + schemaFormat: application/vnd.aai.asyncapi+json;version=2.0.0 + contentType: application/json + payload: + $ref: "#/components/schemas/statusMsg" + dataClient: + name: dataClient + title: Datos del cliente + summary: Comando que envia los datos del cliente. + schemaFormat: application/vnd.aai.asyncapi+json;version=2.0.0 + contentType: application/json + payload: + $ref: "#/components/schemas/data" + schemas: + statusMsg: + type: object + properties: + clientId: + $ref: '#/components/schemas/clientId' + status: + type: string + enum: + - OK + - KO + data: + type: object + properties: + clientId: + $ref: '#/components/schemas/clientId' + clientName: + description: Nombre del cliente. + type: string + flightNumber: + description: NĂºmero de vuelo. + type: string + clientId: + type: integer + description: Id del cliente. \ No newline at end of file diff --git a/multiapi-engine/src/test/resources/asyncapigenerator/testPropertiesNotGeneratedIssue/assets/payload/UserDetails.java b/multiapi-engine/src/test/resources/asyncapigenerator/testPropertiesNotGeneratedIssue/assets/payload/Details.java similarity index 71% rename from multiapi-engine/src/test/resources/asyncapigenerator/testPropertiesNotGeneratedIssue/assets/payload/UserDetails.java rename to multiapi-engine/src/test/resources/asyncapigenerator/testPropertiesNotGeneratedIssue/assets/payload/Details.java index c11f3892..d1f3314b 100644 --- a/multiapi-engine/src/test/resources/asyncapigenerator/testPropertiesNotGeneratedIssue/assets/payload/UserDetails.java +++ b/multiapi-engine/src/test/resources/asyncapigenerator/testPropertiesNotGeneratedIssue/assets/payload/Details.java @@ -7,8 +7,8 @@ import com.fasterxml.jackson.annotation.JsonProperty; import io.swagger.v3.oas.annotations.media.Schema; -@JsonDeserialize(builder = UserDetails.UserDetailsBuilder.class) -public class UserDetails { +@JsonDeserialize(builder = Details.DetailsBuilder.class) +public class Details { @JsonProperty(value ="firstName") private String firstName; @@ -17,49 +17,49 @@ public class UserDetails { @JsonProperty(value ="email") private String email; - private UserDetails(String firstName, String lastName, String email) { + private Details(String firstName, String lastName, String email) { this.firstName = firstName; this.lastName = lastName; this.email = email; } - private UserDetails(UserDetailsBuilder builder) { + private Details(DetailsBuilder builder) { this.firstName = builder.firstName; this.lastName = builder.lastName; this.email = builder.email; } - public static UserDetails.UserDetailsBuilder builder() { - return new UserDetails.UserDetailsBuilder(); + public static Details.DetailsBuilder builder() { + return new Details.DetailsBuilder(); } @JsonPOJOBuilder(buildMethodName = "build", withPrefix = "") - public static class UserDetailsBuilder { + public static class DetailsBuilder { private String firstName; private String lastName; private String email; - public UserDetails.UserDetailsBuilder firstName(String firstName) { + public Details.DetailsBuilder firstName(String firstName) { this.firstName = firstName; return this; } - public UserDetails.UserDetailsBuilder lastName(String lastName) { + public Details.DetailsBuilder lastName(String lastName) { this.lastName = lastName; return this; } - public UserDetails.UserDetailsBuilder email(String email) { + public Details.DetailsBuilder email(String email) { this.email = email; return this; } - public UserDetails build() { - UserDetails userDetails = new UserDetails(this); - return userDetails; + public Details build() { + Details details = new Details(this); + return details; } } @@ -107,8 +107,8 @@ public boolean equals(Object o) { if (o == null || getClass() != o.getClass()) { return false; } - UserDetails userDetails = (UserDetails) o; - return Objects.equals(this.firstName, userDetails.firstName) && Objects.equals(this.lastName, userDetails.lastName) && Objects.equals(this.email, userDetails.email); + Details details = (Details) o; + return Objects.equals(this.firstName, details.firstName) && Objects.equals(this.lastName, details.lastName) && Objects.equals(this.email, details.email); } @Override @@ -119,7 +119,7 @@ public int hashCode() { @Override public String toString() { StringBuilder sb = new StringBuilder(); - sb.append("UserDetails{"); + sb.append("Details{"); sb.append(" firstName:").append(firstName).append(","); sb.append(" lastName:").append(lastName).append(","); sb.append(" email:").append(email); diff --git a/multiapi-engine/src/test/resources/asyncapigenerator/testPropertiesNotGeneratedIssue/assets/payload/UserSignedUp.java b/multiapi-engine/src/test/resources/asyncapigenerator/testPropertiesNotGeneratedIssue/assets/payload/UserSignedUp.java index 7d1a5833..ec741f71 100644 --- a/multiapi-engine/src/test/resources/asyncapigenerator/testPropertiesNotGeneratedIssue/assets/payload/UserSignedUp.java +++ b/multiapi-engine/src/test/resources/asyncapigenerator/testPropertiesNotGeneratedIssue/assets/payload/UserSignedUp.java @@ -13,9 +13,9 @@ public class UserSignedUp { @JsonProperty(value ="id") private String id; @JsonProperty(value ="details") - private UserDetails details; + private Details details; - private UserSignedUp(String id, UserDetails details) { + private UserSignedUp(String id, Details details) { this.id = id; this.details = details; @@ -35,14 +35,14 @@ public static UserSignedUp.UserSignedUpBuilder builder() { public static class UserSignedUpBuilder { private String id; - private UserDetails details; + private Details details; public UserSignedUp.UserSignedUpBuilder id(String id) { this.id = id; return this; } - public UserSignedUp.UserSignedUpBuilder details(UserDetails details) { + public UserSignedUp.UserSignedUpBuilder details(Details details) { this.details = details; return this; } @@ -70,10 +70,10 @@ public void setId(String id) { * @return details */ @Schema(name = "details", required = false) - public UserDetails getDetails() { + public Details getDetails() { return details; } - public void setDetails(UserDetails details) { + public void setDetails(Details details) { this.details = details; } diff --git a/scs-multiapi-gradle-plugin/build.gradle b/scs-multiapi-gradle-plugin/build.gradle index 2b7b44a5..7a90ad62 100644 --- a/scs-multiapi-gradle-plugin/build.gradle +++ b/scs-multiapi-gradle-plugin/build.gradle @@ -20,7 +20,7 @@ repositories { } group = 'com.sngular' -version = '5.0.1' +version = '5.0.2' def SCSMultiApiPluginGroupId = group def SCSMultiApiPluginVersion = version @@ -30,7 +30,7 @@ dependencies { shadow localGroovy() shadow gradleApi() - implementation 'com.sngular:multiapi-engine:5.0.1' + implementation 'com.sngular:multiapi-engine:5.0.2' testImplementation 'org.assertj:assertj-core:3.24.2' testImplementation 'com.puppycrawl.tools:checkstyle:10.9.1' } @@ -98,7 +98,7 @@ testing { integrationTest(JvmTestSuite) { dependencies { - implementation 'com.sngular:scs-multiapi-gradle-plugin:5.0.0' + implementation 'com.sngular:scs-multiapi-gradle-plugin:5.0.2' implementation 'org.assertj:assertj-core:3.24.2' } diff --git a/scs-multiapi-maven-plugin/pom.xml b/scs-multiapi-maven-plugin/pom.xml index cf94ea96..8a2f62e3 100644 --- a/scs-multiapi-maven-plugin/pom.xml +++ b/scs-multiapi-maven-plugin/pom.xml @@ -4,7 +4,7 @@ com.sngular scs-multiapi-maven-plugin - 5.0.1 + 5.0.2 maven-plugin AsyncApi - OpenApi Code Generator Maven Plugin @@ -243,7 +243,7 @@ com.sngular multiapi-engine - 5.0.1 + 5.0.2 org.apache.maven From 84efc4672bd383e2ca6ae19f07c886101034958a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jose=20Enrique=20Garc=C3=ADa=20Maci=C3=B1eiras?= Date: Mon, 30 Oct 2023 18:24:33 +0100 Subject: [PATCH 2/9] 293 Fix Tests --- README.md | 2 +- .../plugin/asyncapi/AsyncApiGenerator.java | 4 +- .../asyncapi/util/MapperContentUtil.java | 38 +++++++++++-------- .../assets/CustomerOrderDTO.java | 1 + .../{ConfigDTO.java => ConfigurationDTO.java} | 0 .../assets/MailRequestDTO.java | 12 +++--- .../assets/DataDTO.java | 2 - .../assets/StatusMsgDTO.java | 3 +- .../{Details.java => UserDetails.java} | 0 .../assets/payload/UserSignedUp.java | 12 +++--- 10 files changed, 39 insertions(+), 35 deletions(-) rename multiapi-engine/src/test/resources/asyncapigenerator/testIssueGenerateSupplier/assets/{ConfigDTO.java => ConfigurationDTO.java} (100%) rename multiapi-engine/src/test/resources/asyncapigenerator/testPropertiesNotGeneratedIssue/assets/payload/{Details.java => UserDetails.java} (100%) diff --git a/README.md b/README.md index a6c6ec84..842dfb86 100644 --- a/README.md +++ b/README.md @@ -94,7 +94,7 @@ As commented above, they both could be used at the same time, setting a double ``` In the example above, you can see a partial configuration for the plugin with -a double *execution*. This makes neccesary to set an `id` for each execution, +a double *execution*. This makes necessary to set an `id` for each execution, `asyncapi` and `openapi` in this case. In the case that you only want to run one of the goals of the plugin, you only diff --git a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/asyncapi/AsyncApiGenerator.java b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/asyncapi/AsyncApiGenerator.java index 7c51cb9b..ec32b71c 100644 --- a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/asyncapi/AsyncApiGenerator.java +++ b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/asyncapi/AsyncApiGenerator.java @@ -132,8 +132,8 @@ public AsyncApiGenerator(final Integer springBootVersion, final File targetFolde this.processedGeneratedSourcesFolder = processedGeneratedSourcesFolder; this.targetFolder = targetFolder; this.baseDir = baseDir; - templateFactory = new TemplateFactory(); - targetFileFilter = (dir, name) -> name.toLowerCase().contains(targetFolder.toPath().getFileName().toString()); + this.templateFactory = new TemplateFactory(); + this.targetFileFilter = (dir, name) -> name.toLowerCase().contains(targetFolder.toPath().getFileName().toString()); this.springBootVersion = springBootVersion; } diff --git a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/asyncapi/util/MapperContentUtil.java b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/asyncapi/util/MapperContentUtil.java index 04bfb3d0..16b6988a 100644 --- a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/asyncapi/util/MapperContentUtil.java +++ b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/asyncapi/util/MapperContentUtil.java @@ -149,24 +149,25 @@ private static List getFields( schemaCombinatorType = null; if (ApiTool.hasType(model)) { if (OBJECT.equalsIgnoreCase(model.get(TYPE).textValue())) { - fieldObjectArrayList.addAll(processFieldObject(totalSchemas, model, prefix, suffix, modelToBuildList, parentPackage)); + fieldObjectArrayList.addAll(processFieldObject(totalSchemas, model, prefix, suffix, modelToBuildList, parentPackage, null)); } else if (ARRAY.equalsIgnoreCase(model.get(TYPE).textValue())) { - fieldObjectArrayList.add(processFieldObjectList(totalSchemas, "", model, required, prefix, suffix, modelToBuildList, parentPackage)); + fieldObjectArrayList.add(processFieldObjectList(totalSchemas, "", model, required, prefix, suffix, modelToBuildList, parentPackage, null)); } else if ("enum".equalsIgnoreCase(model.get(TYPE).textValue())) { - fieldObjectArrayList.add(processFieldObjectList(totalSchemas, "", model, required, prefix, suffix, modelToBuildList, parentPackage)); + fieldObjectArrayList.add(processFieldObjectList(totalSchemas, "", model, required, prefix, suffix, modelToBuildList, parentPackage, null)); } } else if (ApiTool.hasRef(model)) { - fieldObjectArrayList.addAll(processFieldObject(totalSchemas, totalSchemas.get(MapperUtil.buildKey(MapperUtil.splitName(ApiTool.getRefValue(model)))), prefix, suffix, - modelToBuildList, parentPackage)); + final var splitName = MapperUtil.splitName(ApiTool.getRefValue(model)); + fieldObjectArrayList.addAll(processFieldObject(totalSchemas, totalSchemas.get(MapperUtil.buildKey(splitName)), prefix, suffix, + modelToBuildList, parentPackage, splitName[splitName.length - 1])); } else if (model.elements().hasNext()) { - fieldObjectArrayList.addAll(processFieldObject(totalSchemas, model, prefix, suffix, modelToBuildList, parentPackage)); + fieldObjectArrayList.addAll(processFieldObject(totalSchemas, model, prefix, suffix, modelToBuildList, parentPackage, null)); } return fieldObjectArrayList; } private static List processFieldObject( final Map totalSchemas, final JsonNode model, final String prefix, final String suffix, final Collection modelToBuildList, - final String parentPackage) { + final String parentPackage, final String className) { final Set requiredSet = new HashSet<>(); final var fieldObjectArrayList = new ArrayList(); if (model.has("required")) { @@ -180,7 +181,7 @@ private static List processFieldObject( while (propertiesIt.hasNext()) { final var property = propertiesIt.next(); fieldObjectArrayList.add(processFieldObjectList(totalSchemas, property, model.get(PROPERTIES).path(property), requiredSet.contains(property), prefix, suffix, - modelToBuildList, parentPackage)); + modelToBuildList, parentPackage, null)); if (model.get(PROPERTIES).path(property).has(REF)) { if (!totalSchemas.containsKey(createKey(parentPackage, property.toUpperCase(), "/"))) { modelToBuildList.add(MapperUtil.getLongRefClass(model.get(PROPERTIES).path(property))); @@ -217,10 +218,10 @@ private static SchemaFieldObject solveElement( if (element.has(REF)) { final String schemaName = MapperUtil.getLongRefClass(element); final var schemaToProcess = totalSchemas.get(schemaName.toUpperCase()); - result = processFieldObjectList(totalSchemas, schemaName, schemaToProcess, required, prefix, suffix, modelToBuildList, null); + result = processFieldObjectList(totalSchemas, schemaName, schemaToProcess, required, prefix, suffix, modelToBuildList, null, null); result.setRequired(false); } else { - result = processFieldObjectList(totalSchemas, "", element, required, prefix, suffix, modelToBuildList, null); + result = processFieldObjectList(totalSchemas, "", element, required, prefix, suffix, modelToBuildList, null, null); } return result; } @@ -228,7 +229,7 @@ private static SchemaFieldObject solveElement( @SuppressWarnings("checkstyle:ParameterNumber") private static SchemaFieldObject processFieldObjectList( final Map totalSchemas, final String propertyName, final JsonNode schema, final boolean required, - final String prefix, final String suffix, final Collection modelToBuildList, final String modelPackage) { + final String prefix, final String suffix, final Collection modelToBuildList, final String modelPackage, final String className) { final SchemaFieldObject fieldObject; final var name = schema.has("name") ? schema.get("name").textValue() : propertyName; if (ApiTool.hasType(schema)) { @@ -241,7 +242,7 @@ private static SchemaFieldObject processFieldObjectList( .restrictions(new SchemaFieldObjectProperties()) .dataType(MapperUtil.getSimpleType(schema, prefix, suffix)) .build(); - setFieldType(fieldObject, schema, required, prefix, suffix); + setFieldType(fieldObject, schema, required, prefix, suffix, className); if (StringUtils.isNotEmpty(propertyName) && !totalSchemas.containsKey(propertyName)) { totalSchemas.put(createKey(modelPackage, propertyName.toUpperCase(), "/"), schema); modelToBuildList.add(createKey(modelPackage.toLowerCase(), propertyName, ".")); @@ -277,8 +278,9 @@ private static SchemaFieldObject processFieldObjectList( fieldObject.setRequired(required); } } else if (ApiTool.hasRef(schema)) { - final var solvedRef = totalSchemas.get(getComponent(MapperUtil.splitName(ApiTool.getRefValue(schema)))); - fieldObject = processFieldObjectList(totalSchemas, name, solvedRef, required, prefix, suffix, modelToBuildList, modelPackage); + final var splitName = MapperUtil.splitName(ApiTool.getRefValue(schema)); + final var solvedRef = totalSchemas.get(getComponent(splitName)); + fieldObject = processFieldObjectList(totalSchemas, name, solvedRef, required, prefix, suffix, modelToBuildList, modelPackage, splitName[splitName.length - 1]); } else { fieldObject = SchemaFieldObject .builder() @@ -369,7 +371,7 @@ private static void setFieldProperties(final SchemaFieldObject fieldObject, fina } } - private static void setFieldType(final SchemaFieldObject field, final JsonNode value, final boolean required, final String prefix, final String suffix) { + private static void setFieldType(final SchemaFieldObject field, final JsonNode value, final boolean required, final String prefix, final String suffix, final String className) { field.setRequired(required); if (ApiTool.hasType(value)) { if (ARRAY.equalsIgnoreCase(ApiTool.getType(value))) { @@ -387,7 +389,11 @@ private static void setFieldType(final SchemaFieldObject field, final JsonNode v if (ApiTool.hasRef(value)) { typeObject = MapperUtil.getRef(value, prefix, suffix); } else { - typeObject = MapperUtil.getPojoName(field.getBaseName(), prefix, suffix); + if (StringUtils.isEmpty(className)) { + typeObject = MapperUtil.getPojoName(field.getBaseName(), prefix, suffix); + } else { + typeObject = MapperUtil.getPojoName(className, prefix, suffix); + } } field.setImportClass(getImportClass(typeObject)); field.setDataType(typeObject); diff --git a/multiapi-engine/src/test/resources/asyncapigenerator/testFileGenerationIssue/assets/CustomerOrderDTO.java b/multiapi-engine/src/test/resources/asyncapigenerator/testFileGenerationIssue/assets/CustomerOrderDTO.java index 0efda0a2..fd9e56ee 100644 --- a/multiapi-engine/src/test/resources/asyncapigenerator/testFileGenerationIssue/assets/CustomerOrderDTO.java +++ b/multiapi-engine/src/test/resources/asyncapigenerator/testFileGenerationIssue/assets/CustomerOrderDTO.java @@ -128,6 +128,7 @@ public CustomerOrderDTO.CustomerOrderDTOBuilder paymentDetail(PaymentDetailsDTO } return this; } + public CustomerOrderDTO.CustomerOrderDTOBuilder status(Status status) { this.status = status; return this; diff --git a/multiapi-engine/src/test/resources/asyncapigenerator/testIssueGenerateSupplier/assets/ConfigDTO.java b/multiapi-engine/src/test/resources/asyncapigenerator/testIssueGenerateSupplier/assets/ConfigurationDTO.java similarity index 100% rename from multiapi-engine/src/test/resources/asyncapigenerator/testIssueGenerateSupplier/assets/ConfigDTO.java rename to multiapi-engine/src/test/resources/asyncapigenerator/testIssueGenerateSupplier/assets/ConfigurationDTO.java diff --git a/multiapi-engine/src/test/resources/asyncapigenerator/testIssueGenerateSupplier/assets/MailRequestDTO.java b/multiapi-engine/src/test/resources/asyncapigenerator/testIssueGenerateSupplier/assets/MailRequestDTO.java index 2f2b1fb5..d53cf56f 100644 --- a/multiapi-engine/src/test/resources/asyncapigenerator/testIssueGenerateSupplier/assets/MailRequestDTO.java +++ b/multiapi-engine/src/test/resources/asyncapigenerator/testIssueGenerateSupplier/assets/MailRequestDTO.java @@ -17,9 +17,9 @@ public class MailRequestDTO { @JsonProperty(value ="recipients") private List recipients = new ArrayList(); @JsonProperty(value ="config") - private ConfigDTO config; + private ConfigurationDTO config; - private MailRequestDTO(String sender, List recipients, ConfigDTO config) { + private MailRequestDTO(String sender, List recipients, ConfigurationDTO config) { this.sender = sender; this.recipients = recipients; this.config = config; @@ -42,7 +42,7 @@ public static class MailRequestDTOBuilder { private String sender; private List recipients = new ArrayList(); - private ConfigDTO config; + private ConfigurationDTO config; public MailRequestDTO.MailRequestDTOBuilder sender(String sender) { this.sender = sender; @@ -63,7 +63,7 @@ public MailRequestDTO.MailRequestDTOBuilder recipient(String recipient) { return this; } - public MailRequestDTO.MailRequestDTOBuilder config(ConfigDTO config) { + public MailRequestDTO.MailRequestDTOBuilder config(ConfigurationDTO config) { this.config = config; return this; } @@ -103,10 +103,10 @@ public void setRecipients(List recipients) { * @return config */ @Schema(name = "config", required = false) - public ConfigDTO getConfig() { + public ConfigurationDTO getConfig() { return config; } - public void setConfig(ConfigDTO config) { + public void setConfig(ConfigurationDTO config) { this.config = config; } diff --git a/multiapi-engine/src/test/resources/asyncapigenerator/testIssueSimpleTypeGeneration/assets/DataDTO.java b/multiapi-engine/src/test/resources/asyncapigenerator/testIssueSimpleTypeGeneration/assets/DataDTO.java index 13f11c16..75b2d4d7 100644 --- a/multiapi-engine/src/test/resources/asyncapigenerator/testIssueSimpleTypeGeneration/assets/DataDTO.java +++ b/multiapi-engine/src/test/resources/asyncapigenerator/testIssueSimpleTypeGeneration/assets/DataDTO.java @@ -128,6 +128,4 @@ public String toString() { } - - } diff --git a/multiapi-engine/src/test/resources/asyncapigenerator/testIssueSimpleTypeGeneration/assets/StatusMsgDTO.java b/multiapi-engine/src/test/resources/asyncapigenerator/testIssueSimpleTypeGeneration/assets/StatusMsgDTO.java index dfeceb10..43396cbd 100644 --- a/multiapi-engine/src/test/resources/asyncapigenerator/testIssueSimpleTypeGeneration/assets/StatusMsgDTO.java +++ b/multiapi-engine/src/test/resources/asyncapigenerator/testIssueSimpleTypeGeneration/assets/StatusMsgDTO.java @@ -62,6 +62,7 @@ public StatusMsgDTO.StatusMsgDTOBuilder clientId(Integer clientId) { this.clientId = clientId; return this; } + public StatusMsgDTO.StatusMsgDTOBuilder status(Status status) { this.status = status; return this; @@ -125,6 +126,4 @@ public String toString() { } - - } diff --git a/multiapi-engine/src/test/resources/asyncapigenerator/testPropertiesNotGeneratedIssue/assets/payload/Details.java b/multiapi-engine/src/test/resources/asyncapigenerator/testPropertiesNotGeneratedIssue/assets/payload/UserDetails.java similarity index 100% rename from multiapi-engine/src/test/resources/asyncapigenerator/testPropertiesNotGeneratedIssue/assets/payload/Details.java rename to multiapi-engine/src/test/resources/asyncapigenerator/testPropertiesNotGeneratedIssue/assets/payload/UserDetails.java diff --git a/multiapi-engine/src/test/resources/asyncapigenerator/testPropertiesNotGeneratedIssue/assets/payload/UserSignedUp.java b/multiapi-engine/src/test/resources/asyncapigenerator/testPropertiesNotGeneratedIssue/assets/payload/UserSignedUp.java index 08b61f6e..1017b7b8 100644 --- a/multiapi-engine/src/test/resources/asyncapigenerator/testPropertiesNotGeneratedIssue/assets/payload/UserSignedUp.java +++ b/multiapi-engine/src/test/resources/asyncapigenerator/testPropertiesNotGeneratedIssue/assets/payload/UserSignedUp.java @@ -13,9 +13,9 @@ public class UserSignedUp { @JsonProperty(value ="id") private String id; @JsonProperty(value ="details") - private Details details; + private UserDetails details; - private UserSignedUp(String id, Details details) { + private UserSignedUp(String id, UserDetails details) { this.id = id; this.details = details; @@ -35,14 +35,14 @@ public static UserSignedUp.UserSignedUpBuilder builder() { public static class UserSignedUpBuilder { private String id; - private Details details; + private UserDetails details; public UserSignedUp.UserSignedUpBuilder id(String id) { this.id = id; return this; } - public UserSignedUp.UserSignedUpBuilder details(Details details) { + public UserSignedUp.UserSignedUpBuilder details(UserDetails details) { this.details = details; return this; } @@ -70,10 +70,10 @@ public void setId(String id) { * @return details */ @Schema(name = "details", required = false) - public Details getDetails() { + public UserDetails getDetails() { return details; } - public void setDetails(Details details) { + public void setDetails(UserDetails details) { this.details = details; } From acaa3902a2a2e7735eb0dd4749928601b1b6fe09 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jose=20Enrique=20Garc=C3=ADa=20Maci=C3=B1eiras?= Date: Tue, 31 Oct 2023 15:37:33 +0100 Subject: [PATCH 3/9] 293 Fix Tests --- .../asyncapi/util/MapperContentUtil.java | 9 +++--- .../assets/payload/UserDetails.java | 28 +++++++++---------- 2 files changed, 19 insertions(+), 18 deletions(-) diff --git a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/asyncapi/util/MapperContentUtil.java b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/asyncapi/util/MapperContentUtil.java index 16b6988a..46529a7f 100644 --- a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/asyncapi/util/MapperContentUtil.java +++ b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/asyncapi/util/MapperContentUtil.java @@ -181,7 +181,7 @@ private static List processFieldObject( while (propertiesIt.hasNext()) { final var property = propertiesIt.next(); fieldObjectArrayList.add(processFieldObjectList(totalSchemas, property, model.get(PROPERTIES).path(property), requiredSet.contains(property), prefix, suffix, - modelToBuildList, parentPackage, null)); + modelToBuildList, parentPackage, className)); if (model.get(PROPERTIES).path(property).has(REF)) { if (!totalSchemas.containsKey(createKey(parentPackage, property.toUpperCase(), "/"))) { modelToBuildList.add(MapperUtil.getLongRefClass(model.get(PROPERTIES).path(property))); @@ -243,9 +243,10 @@ private static SchemaFieldObject processFieldObjectList( .dataType(MapperUtil.getSimpleType(schema, prefix, suffix)) .build(); setFieldType(fieldObject, schema, required, prefix, suffix, className); - if (StringUtils.isNotEmpty(propertyName) && !totalSchemas.containsKey(propertyName)) { - totalSchemas.put(createKey(modelPackage, propertyName.toUpperCase(), "/"), schema); - modelToBuildList.add(createKey(modelPackage.toLowerCase(), propertyName, ".")); + final var schemaName = StringUtils.defaultString(className, propertyName); + if (StringUtils.isNotEmpty(schemaName) && !totalSchemas.containsKey(schemaName)) { + totalSchemas.put(createKey(modelPackage, schemaName.toUpperCase(), "/"), schema); + modelToBuildList.add(createKey(modelPackage.toLowerCase(), schemaName, ".")); } } else if (ApiTool.hasItems(schema)) { final var items = ApiTool.getItems(schema); diff --git a/multiapi-engine/src/test/resources/asyncapigenerator/testPropertiesNotGeneratedIssue/assets/payload/UserDetails.java b/multiapi-engine/src/test/resources/asyncapigenerator/testPropertiesNotGeneratedIssue/assets/payload/UserDetails.java index 9ba327eb..7617d4f8 100644 --- a/multiapi-engine/src/test/resources/asyncapigenerator/testPropertiesNotGeneratedIssue/assets/payload/UserDetails.java +++ b/multiapi-engine/src/test/resources/asyncapigenerator/testPropertiesNotGeneratedIssue/assets/payload/UserDetails.java @@ -7,8 +7,8 @@ import com.fasterxml.jackson.annotation.JsonProperty; import io.swagger.v3.oas.annotations.media.Schema; -@JsonDeserialize(builder = Details.DetailsBuilder.class) -public class Details { +@JsonDeserialize(builder = UserDetails.UserDetailsBuilder.class) +public class UserDetails { @JsonProperty(value ="firstName") private String firstName; @@ -17,48 +17,48 @@ public class Details { @JsonProperty(value ="email") private String email; - private Details(String firstName, String lastName, String email) { + private UserDetails(String firstName, String lastName, String email) { this.firstName = firstName; this.lastName = lastName; this.email = email; } - private Details(DetailsBuilder builder) { + private UserDetails(UserDetailsBuilder builder) { this.firstName = builder.firstName; this.lastName = builder.lastName; this.email = builder.email; } - public static Details.DetailsBuilder builder() { - return new Details.DetailsBuilder(); + public static UserDetails.UserDetailsBuilder builder() { + return new UserDetails.UserDetailsBuilder(); } @JsonPOJOBuilder(buildMethodName = "build", withPrefix = "") - public static class DetailsBuilder { + public static class UserDetailsBuilder { private String firstName; private String lastName; private String email; - public Details.DetailsBuilder firstName(String firstName) { + public UserDetails.UserDetailsBuilder firstName(String firstName) { this.firstName = firstName; return this; } - public Details.DetailsBuilder lastName(String lastName) { + public UserDetails.UserDetailsBuilder lastName(String lastName) { this.lastName = lastName; return this; } - public Details.DetailsBuilder email(String email) { + public UserDetails.UserDetailsBuilder email(String email) { this.email = email; return this; } - public Details build() { - Details details = new Details(this); + public UserDetails build() { + UserDetails details = new UserDetails(this); return details; } } @@ -107,7 +107,7 @@ public boolean equals(Object o) { if (o == null || getClass() != o.getClass()) { return false; } - Details details = (Details) o; + UserDetails details = (UserDetails) o; return Objects.equals(this.firstName, details.firstName) && Objects.equals(this.lastName, details.lastName) && Objects.equals(this.email, details.email); } @@ -119,7 +119,7 @@ public int hashCode() { @Override public String toString() { StringBuilder sb = new StringBuilder(); - sb.append("Details{"); + sb.append("UserDetails{"); sb.append(" firstName:").append(firstName).append(","); sb.append(" lastName:").append(lastName).append(","); sb.append(" email:").append(email); From 581ebf92b3c50cd32f562a57bb126c42589ad07e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jose=20Enrique=20Garc=C3=ADa=20Maci=C3=B1eiras?= Date: Tue, 31 Oct 2023 15:47:48 +0100 Subject: [PATCH 4/9] 293 Fix Tests --- .../api/generator/plugin/asyncapi/model/MethodObject.java | 1 + .../api/generator/plugin/asyncapi/template/TemplateFactory.java | 1 + .../api/generator/plugin/common/files/DirectoryFileLocation.java | 1 + .../com/sngular/api/generator/plugin/common/tools/ApiTool.java | 1 + .../sngular/api/generator/plugin/openapi/OpenApiGenerator.java | 1 + .../sngular/api/generator/plugin/openapi/model/GlobalObject.java | 1 + .../generator/plugin/openapi/model/SchemaFieldObjectType.java | 1 + .../api/generator/plugin/openapi/template/TemplateFactory.java | 1 + .../api/generator/plugin/openapi/utils/MapperAuthUtil.java | 1 + 9 files changed, 9 insertions(+) diff --git a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/asyncapi/model/MethodObject.java b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/asyncapi/model/MethodObject.java index 4dbb513d..83baddfe 100644 --- a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/asyncapi/model/MethodObject.java +++ b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/asyncapi/model/MethodObject.java @@ -7,6 +7,7 @@ package com.sngular.api.generator.plugin.asyncapi.model; import java.util.Objects; + import com.sngular.api.generator.plugin.asyncapi.util.BindingTypeEnum; import lombok.Builder; import lombok.Value; diff --git a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/asyncapi/template/TemplateFactory.java b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/asyncapi/template/TemplateFactory.java index 2f30c47b..7ced27b3 100644 --- a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/asyncapi/template/TemplateFactory.java +++ b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/asyncapi/template/TemplateFactory.java @@ -19,6 +19,7 @@ import java.util.Map; import java.util.Objects; import java.util.Set; + import com.sngular.api.generator.plugin.asyncapi.exception.FileSystemException; import com.sngular.api.generator.plugin.asyncapi.exception.NonSupportedBindingException; import com.sngular.api.generator.plugin.asyncapi.model.MethodObject; diff --git a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/files/DirectoryFileLocation.java b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/files/DirectoryFileLocation.java index 119879a1..7fa976e1 100644 --- a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/files/DirectoryFileLocation.java +++ b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/files/DirectoryFileLocation.java @@ -10,6 +10,7 @@ import java.io.IOException; import java.io.InputStream; import java.nio.file.Path; + import com.sngular.api.generator.plugin.asyncapi.exception.FileSystemException; public class DirectoryFileLocation implements FileLocation { diff --git a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/tools/ApiTool.java b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/tools/ApiTool.java index a6e0f472..734b4f54 100644 --- a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/tools/ApiTool.java +++ b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/tools/ApiTool.java @@ -12,6 +12,7 @@ import java.util.Map; import java.util.Map.Entry; import java.util.Objects; + import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.dataformat.yaml.YAMLFactory; diff --git a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/openapi/OpenApiGenerator.java b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/openapi/OpenApiGenerator.java index 3b194a73..23978a4e 100644 --- a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/openapi/OpenApiGenerator.java +++ b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/openapi/OpenApiGenerator.java @@ -18,6 +18,7 @@ import java.util.Objects; import java.util.Set; import java.util.regex.Pattern; + import com.fasterxml.jackson.databind.JsonNode; import com.sngular.api.generator.plugin.PluginConstants; import com.sngular.api.generator.plugin.common.tools.ApiTool; diff --git a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/openapi/model/GlobalObject.java b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/openapi/model/GlobalObject.java index a8d07d3a..478bf081 100644 --- a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/openapi/model/GlobalObject.java +++ b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/openapi/model/GlobalObject.java @@ -11,6 +11,7 @@ import java.util.List; import java.util.Map; import java.util.Optional; + import com.fasterxml.jackson.databind.JsonNode; import lombok.AllArgsConstructor; import lombok.Builder; diff --git a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/openapi/model/SchemaFieldObjectType.java b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/openapi/model/SchemaFieldObjectType.java index de1c0e51..5b8de712 100644 --- a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/openapi/model/SchemaFieldObjectType.java +++ b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/openapi/model/SchemaFieldObjectType.java @@ -9,6 +9,7 @@ import java.util.AbstractMap.SimpleImmutableEntry; import java.util.Map; import java.util.Objects; + import com.sngular.api.generator.plugin.openapi.exception.CodeGenerationException; import lombok.Data; import org.apache.commons.lang3.StringUtils; diff --git a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/openapi/template/TemplateFactory.java b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/openapi/template/TemplateFactory.java index 2025d11c..c7ad9f57 100644 --- a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/openapi/template/TemplateFactory.java +++ b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/openapi/template/TemplateFactory.java @@ -16,6 +16,7 @@ import java.util.Map; import java.util.Objects; import java.util.Set; + import com.sngular.api.generator.plugin.openapi.exception.OverwritingApiFilesException; import com.sngular.api.generator.plugin.openapi.model.AuthObject; import com.sngular.api.generator.plugin.openapi.model.PathObject; diff --git a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/openapi/utils/MapperAuthUtil.java b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/openapi/utils/MapperAuthUtil.java index d8366ba6..b2d26eb7 100644 --- a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/openapi/utils/MapperAuthUtil.java +++ b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/openapi/utils/MapperAuthUtil.java @@ -10,6 +10,7 @@ import java.util.HashSet; import java.util.List; import java.util.Map.Entry; + import com.fasterxml.jackson.databind.JsonNode; import com.sngular.api.generator.plugin.common.tools.ApiTool; import com.sngular.api.generator.plugin.openapi.model.AuthObject; From c242a148d28bd18147bf3be7cd52b72608464fa1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jose=20Enrique=20Garc=C3=ADa=20Maci=C3=B1eiras?= Date: Mon, 13 Nov 2023 08:58:24 +0100 Subject: [PATCH 5/9] 293 Bump maven version --- README.md | 18 +++++----- multiapi-engine/pom.xml | 2 +- .../asyncapi/util/MapperContentUtil.java | 6 ++-- .../plugin/openapi/OpenApiGenerator.java | 27 ++++++++------- .../plugin/openapi/utils/MapperPathUtil.java | 33 +++++++++++-------- scs-multiapi-gradle-plugin/build.gradle | 6 ++-- scs-multiapi-maven-plugin/pom.xml | 4 +-- 7 files changed, 52 insertions(+), 44 deletions(-) diff --git a/README.md b/README.md index 842dfb86..2429dd62 100644 --- a/README.md +++ b/README.md @@ -28,7 +28,7 @@ Maven and Gradle - [Getting Started](#getting-started) - [Initial Considerations](#initial-considerations) - [Usage](#usage) -- [Property Validation](#properties-validation) +- [Property Validation](#property-validation) ## Main Configuration @@ -113,8 +113,8 @@ Apply the plugin in the `build.gradle` file and invoke the task. ```groovy plugins { - id 'java' - id 'com.sngular.scs-multiapi-gradle-plugin' version '5.0.2' + id "java" + id "com.sngular.scs-multiapi-gradle-plugin' version '5.0.2" openapimodel { @@ -466,7 +466,7 @@ public interface Mapper { ```java @Component -public class subscribeOperation implements ISubscribeOperation { +public class SubscribeOperation implements ISubscribeOperation { private final Mapper mapper; @@ -692,12 +692,12 @@ RestClient and the WebClient will be located, if this option is set in any of the specFiles, and the name of the folder where the generated sources will be saved in the api of the project. -| Name | Description | Example | -|-----------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|--------------------------------------| +| Name | Description | Example | +|-----------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------------------------------| | clientPackage | Path where the RestClient and/or WebClient are located | com.sngular.apigenerator.openapi.client | -| [generatedSourcesFolder](#generated-sources-folder) | Name of the folder, inside `target`, where the files will be located. By defaut it's `generated-sources` | generated-sources | -| overwriteModel | Boolean value to decide if you want your models to be overwritten if two or more models have the same name. True means that models will be overwritten and if false is set, it will throw an exception if two models share the same name. It is initialized to false by default | false | -| springBootVersion | The version of spring to target during generation. It's default value is `2`. | 3 +| [generatedSourcesFolder](#generated-sources-folder) | Name of the folder, inside `target`, where the files will be located. By defaut it's `generated-sources` | generated-sources | +| overwriteModel | Boolean value to decide if you want your models to be overwritten if two or more models have the same name. True means that models will be overwritten and if false is set, it will throw an exception if two models share the same name. It is initialized to false by default | false | +| springBootVersion | The version of spring to target during generation. It's default value is `2`. | 3 | We must clarify that the options to make calls are configured under the RestClient or WebClient specifications as indicated above in the configuration diff --git a/multiapi-engine/pom.xml b/multiapi-engine/pom.xml index d0e3f849..cf1ef1ad 100644 --- a/multiapi-engine/pom.xml +++ b/multiapi-engine/pom.xml @@ -4,7 +4,7 @@ com.sngular multiapi-engine - 5.0.2 + 5.1.0 jar diff --git a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/asyncapi/util/MapperContentUtil.java b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/asyncapi/util/MapperContentUtil.java index 46529a7f..008f2d0a 100644 --- a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/asyncapi/util/MapperContentUtil.java +++ b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/asyncapi/util/MapperContentUtil.java @@ -182,10 +182,8 @@ private static List processFieldObject( final var property = propertiesIt.next(); fieldObjectArrayList.add(processFieldObjectList(totalSchemas, property, model.get(PROPERTIES).path(property), requiredSet.contains(property), prefix, suffix, modelToBuildList, parentPackage, className)); - if (model.get(PROPERTIES).path(property).has(REF)) { - if (!totalSchemas.containsKey(createKey(parentPackage, property.toUpperCase(), "/"))) { - modelToBuildList.add(MapperUtil.getLongRefClass(model.get(PROPERTIES).path(property))); - } + if (model.get(PROPERTIES).path(property).has(REF) && !totalSchemas.containsKey(createKey(parentPackage, property.toUpperCase(), "/"))) { + modelToBuildList.add(MapperUtil.getLongRefClass(model.get(PROPERTIES).path(property))); } } } else if (properties.has(ALL_OF)) { diff --git a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/openapi/OpenApiGenerator.java b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/openapi/OpenApiGenerator.java index 23978a4e..c7e71a61 100644 --- a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/openapi/OpenApiGenerator.java +++ b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/openapi/OpenApiGenerator.java @@ -255,19 +255,24 @@ private void processModels( final SpecFile specFile, final String fileModelToSave, final String modelPackage, final Map basicSchemaMap, final boolean overwrite) { final Map builtSchemasMap = new HashMap<>(); - basicSchemaMap.forEach((schemaName, basicSchema) -> { - if (!overwrite && !overwriteModelList.add(schemaName + modelPackage)) { - throw new DuplicateModelClassException(schemaName, modelPackage); - } + basicSchemaMap.forEach((schemaName, basicSchema) -> + processModel(specFile, fileModelToSave, modelPackage, basicSchemaMap, overwrite, schemaName, basicSchema, builtSchemasMap) + ); + } - if (ApiTool.hasRef(basicSchema)) { - final var refSchema = MapperUtil.getRefSchemaName(basicSchema); - builtSchemasMap.putAll(writeModel(specFile, fileModelToSave, refSchema, basicSchemaMap.get(refSchema), basicSchemaMap, builtSchemasMap)); - } else if (!ApiTool.isArray(basicSchema) && !TypeConstants.STRING.equalsIgnoreCase(ApiTool.getType(basicSchema))) { - builtSchemasMap.putAll(writeModel(specFile, fileModelToSave, schemaName, basicSchema, basicSchemaMap, builtSchemasMap)); - } - }); + private void processModel( + final SpecFile specFile, final String fileModelToSave, final String modelPackage, final Map basicSchemaMap, final boolean overwrite, + final String schemaName, final JsonNode basicSchema, final Map builtSchemasMap) { + if (!overwrite && !overwriteModelList.add(schemaName + modelPackage)) { + throw new DuplicateModelClassException(schemaName, modelPackage); + } + if (ApiTool.hasRef(basicSchema)) { + final var refSchema = MapperUtil.getRefSchemaName(basicSchema); + builtSchemasMap.putAll(writeModel(specFile, fileModelToSave, refSchema, basicSchemaMap.get(refSchema), basicSchemaMap, builtSchemasMap)); + } else if (!ApiTool.isArray(basicSchema) && !TypeConstants.STRING.equalsIgnoreCase(ApiTool.getType(basicSchema))) { + builtSchemasMap.putAll(writeModel(specFile, fileModelToSave, schemaName, basicSchema, basicSchemaMap, builtSchemasMap)); + } } private Map writeModel( diff --git a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/openapi/utils/MapperPathUtil.java b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/openapi/utils/MapperPathUtil.java index 754a8032..6165b851 100644 --- a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/openapi/utils/MapperPathUtil.java +++ b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/openapi/utils/MapperPathUtil.java @@ -315,20 +315,25 @@ private static List mapResponseObject(final SpecFile specFile, f private static BiConsumer createResponseObject( final SpecFile specFile, final GlobalObject globalObject, final List responseObjects, final String operationId, final Path baseDir) { - return (responseCode, response) -> { - var realResponse = response; - if (ApiTool.hasRef(response)) { - realResponse = globalObject.getResponseNode(MapperUtil.getRefSchemaName(response)).orElseThrow(); - } - final String operationIdWithCap = operationId.substring(0, 1).toUpperCase() + operationId.substring(1); - final var content = ApiTool.getNode(realResponse, CONTENT); - responseObjects.add(ResponseObject - .builder() - .responseName(responseCode) - .description(StringUtils.defaultIfEmpty(ApiTool.getNodeAsString(realResponse, DESCRIPTION), "")) - .contentObjects(mapContentObject(specFile, content, "InlineResponse" + responseCode + operationIdWithCap, globalObject, baseDir)) - .build()); - }; + return (responseCode, response) -> + buildResponse(specFile, globalObject, responseObjects, operationId, baseDir, responseCode, response); + } + + private static void buildResponse( + final SpecFile specFile, final GlobalObject globalObject, final List responseObjects, final String operationId, final Path baseDir, final String responseCode, + final JsonNode response) { + var realResponse = response; + if (ApiTool.hasRef(response)) { + realResponse = globalObject.getResponseNode(MapperUtil.getRefSchemaName(response)).orElseThrow(); + } + final String operationIdWithCap = operationId.substring(0, 1).toUpperCase() + operationId.substring(1); + final var content = ApiTool.getNode(realResponse, CONTENT); + responseObjects.add(ResponseObject + .builder() + .responseName(responseCode) + .description(StringUtils.defaultIfEmpty(ApiTool.getNodeAsString(realResponse, DESCRIPTION), "")) + .contentObjects(mapContentObject(specFile, content, "InlineResponse" + responseCode + operationIdWithCap, globalObject, baseDir)) + .build()); } private static List mapContentObject( diff --git a/scs-multiapi-gradle-plugin/build.gradle b/scs-multiapi-gradle-plugin/build.gradle index 7a90ad62..06b56d55 100644 --- a/scs-multiapi-gradle-plugin/build.gradle +++ b/scs-multiapi-gradle-plugin/build.gradle @@ -20,7 +20,7 @@ repositories { } group = 'com.sngular' -version = '5.0.2' +version = '5.1.0' def SCSMultiApiPluginGroupId = group def SCSMultiApiPluginVersion = version @@ -30,7 +30,7 @@ dependencies { shadow localGroovy() shadow gradleApi() - implementation 'com.sngular:multiapi-engine:5.0.2' + implementation 'com.sngular:multiapi-engine:5.1.0' testImplementation 'org.assertj:assertj-core:3.24.2' testImplementation 'com.puppycrawl.tools:checkstyle:10.9.1' } @@ -98,7 +98,7 @@ testing { integrationTest(JvmTestSuite) { dependencies { - implementation 'com.sngular:scs-multiapi-gradle-plugin:5.0.2' + implementation 'com.sngular:scs-multiapi-gradle-plugin:5.1.0' implementation 'org.assertj:assertj-core:3.24.2' } diff --git a/scs-multiapi-maven-plugin/pom.xml b/scs-multiapi-maven-plugin/pom.xml index 8a2f62e3..0c301471 100644 --- a/scs-multiapi-maven-plugin/pom.xml +++ b/scs-multiapi-maven-plugin/pom.xml @@ -4,7 +4,7 @@ com.sngular scs-multiapi-maven-plugin - 5.0.2 + 5.1.0 maven-plugin AsyncApi - OpenApi Code Generator Maven Plugin @@ -243,7 +243,7 @@ com.sngular multiapi-engine - 5.0.2 + 5.1.0 org.apache.maven From 02942bc515471357686b4a40ed8afacca942ec93 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jose=20Enrique=20Garc=C3=ADa=20Maci=C3=B1eiras?= Date: Mon, 13 Nov 2023 22:25:31 +0100 Subject: [PATCH 6/9] 303 Fix support for referenced Request Bodies. --- .../sngular/api/generator/plugin/openapi/OpenApiGenerator.java | 1 + 1 file changed, 1 insertion(+) diff --git a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/openapi/OpenApiGenerator.java b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/openapi/OpenApiGenerator.java index c7e71a61..a886023e 100644 --- a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/openapi/OpenApiGenerator.java +++ b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/openapi/OpenApiGenerator.java @@ -260,6 +260,7 @@ private void processModels( ); } + @SuppressWarnings("checkstyle:ParameterNumber") private void processModel( final SpecFile specFile, final String fileModelToSave, final String modelPackage, final Map basicSchemaMap, final boolean overwrite, final String schemaName, final JsonNode basicSchema, final Map builtSchemasMap) { From 3e759bd0a1a08ab7ffc7d4cf42a7af76505910ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jose=20Enrique=20Garc=C3=ADa=20Maci=C3=B1eiras?= Date: Tue, 14 Nov 2023 16:51:13 +0100 Subject: [PATCH 7/9] 303 Fix support for referenced Request Bodies. --- .../asyncapi/util/MapperContentUtil.java | 12 ++++---- .../assets/ConfigurationDTO.java | 28 +++++++++---------- .../assets/payload/UserDetails.java | 8 +++--- 3 files changed, 24 insertions(+), 24 deletions(-) diff --git a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/asyncapi/util/MapperContentUtil.java b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/asyncapi/util/MapperContentUtil.java index 008f2d0a..ffb3dfe7 100644 --- a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/asyncapi/util/MapperContentUtil.java +++ b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/asyncapi/util/MapperContentUtil.java @@ -149,7 +149,7 @@ private static List getFields( schemaCombinatorType = null; if (ApiTool.hasType(model)) { if (OBJECT.equalsIgnoreCase(model.get(TYPE).textValue())) { - fieldObjectArrayList.addAll(processFieldObject(totalSchemas, model, prefix, suffix, modelToBuildList, parentPackage, null)); + fieldObjectArrayList.addAll(processFieldObject(totalSchemas, model, prefix, suffix, modelToBuildList, parentPackage)); } else if (ARRAY.equalsIgnoreCase(model.get(TYPE).textValue())) { fieldObjectArrayList.add(processFieldObjectList(totalSchemas, "", model, required, prefix, suffix, modelToBuildList, parentPackage, null)); } else if ("enum".equalsIgnoreCase(model.get(TYPE).textValue())) { @@ -158,16 +158,16 @@ private static List getFields( } else if (ApiTool.hasRef(model)) { final var splitName = MapperUtil.splitName(ApiTool.getRefValue(model)); fieldObjectArrayList.addAll(processFieldObject(totalSchemas, totalSchemas.get(MapperUtil.buildKey(splitName)), prefix, suffix, - modelToBuildList, parentPackage, splitName[splitName.length - 1])); + modelToBuildList, parentPackage)); } else if (model.elements().hasNext()) { - fieldObjectArrayList.addAll(processFieldObject(totalSchemas, model, prefix, suffix, modelToBuildList, parentPackage, null)); + fieldObjectArrayList.addAll(processFieldObject(totalSchemas, model, prefix, suffix, modelToBuildList, parentPackage)); } return fieldObjectArrayList; } private static List processFieldObject( final Map totalSchemas, final JsonNode model, final String prefix, final String suffix, final Collection modelToBuildList, - final String parentPackage, final String className) { + final String parentPackage) { final Set requiredSet = new HashSet<>(); final var fieldObjectArrayList = new ArrayList(); if (model.has("required")) { @@ -181,7 +181,7 @@ private static List processFieldObject( while (propertiesIt.hasNext()) { final var property = propertiesIt.next(); fieldObjectArrayList.add(processFieldObjectList(totalSchemas, property, model.get(PROPERTIES).path(property), requiredSet.contains(property), prefix, suffix, - modelToBuildList, parentPackage, className)); + modelToBuildList, parentPackage, null)); if (model.get(PROPERTIES).path(property).has(REF) && !totalSchemas.containsKey(createKey(parentPackage, property.toUpperCase(), "/"))) { modelToBuildList.add(MapperUtil.getLongRefClass(model.get(PROPERTIES).path(property))); } @@ -242,7 +242,7 @@ private static SchemaFieldObject processFieldObjectList( .build(); setFieldType(fieldObject, schema, required, prefix, suffix, className); final var schemaName = StringUtils.defaultString(className, propertyName); - if (StringUtils.isNotEmpty(schemaName) && !totalSchemas.containsKey(schemaName)) { + if (StringUtils.isNotEmpty(schemaName) && !totalSchemas.containsKey(createKey(modelPackage, schemaName.toUpperCase(), "/"))) { totalSchemas.put(createKey(modelPackage, schemaName.toUpperCase(), "/"), schema); modelToBuildList.add(createKey(modelPackage.toLowerCase(), schemaName, ".")); } diff --git a/multiapi-engine/src/test/resources/asyncapigenerator/testIssueGenerateSupplier/assets/ConfigurationDTO.java b/multiapi-engine/src/test/resources/asyncapigenerator/testIssueGenerateSupplier/assets/ConfigurationDTO.java index ecf29c89..ea51036d 100644 --- a/multiapi-engine/src/test/resources/asyncapigenerator/testIssueGenerateSupplier/assets/ConfigurationDTO.java +++ b/multiapi-engine/src/test/resources/asyncapigenerator/testIssueGenerateSupplier/assets/ConfigurationDTO.java @@ -7,39 +7,39 @@ import com.fasterxml.jackson.annotation.JsonProperty; import io.swagger.v3.oas.annotations.media.Schema; -@JsonDeserialize(builder = ConfigDTO.ConfigDTOBuilder.class) -public class ConfigDTO { +@JsonDeserialize(builder = ConfigurationDTO.ConfigurationDTOBuilder.class) +public class ConfigurationDTO { @JsonProperty(value ="name") private String name; - private ConfigDTO(String name) { + private ConfigurationDTO(String name) { this.name = name; } - private ConfigDTO(ConfigDTOBuilder builder) { + private ConfigurationDTO(ConfigurationDTOBuilder builder) { this.name = builder.name; } - public static ConfigDTO.ConfigDTOBuilder builder() { - return new ConfigDTO.ConfigDTOBuilder(); + public static ConfigurationDTO.ConfigurationDTOBuilder builder() { + return new ConfigurationDTO.ConfigurationDTOBuilder(); } @JsonPOJOBuilder(buildMethodName = "build", withPrefix = "") - public static class ConfigDTOBuilder { + public static class ConfigurationDTOBuilder { private String name; - public ConfigDTO.ConfigDTOBuilder name(String name) { + public ConfigurationDTO.ConfigurationDTOBuilder name(String name) { this.name = name; return this; } - public ConfigDTO build() { - ConfigDTO configDTO = new ConfigDTO(this); - return configDTO; + public ConfigurationDTO build() { + ConfigurationDTO configurationDTO = new ConfigurationDTO(this); + return configurationDTO; } } @@ -63,8 +63,8 @@ public boolean equals(Object o) { if (o == null || getClass() != o.getClass()) { return false; } - ConfigDTO configDTO = (ConfigDTO) o; - return Objects.equals(this.name, configDTO.name); + ConfigurationDTO configurationDTO = (ConfigurationDTO) o; + return Objects.equals(this.name, configurationDTO.name); } @Override @@ -75,7 +75,7 @@ public int hashCode() { @Override public String toString() { StringBuilder sb = new StringBuilder(); - sb.append("ConfigDTO{"); + sb.append("ConfigurationDTO{"); sb.append(" name:").append(name); sb.append("}"); return sb.toString(); diff --git a/multiapi-engine/src/test/resources/asyncapigenerator/testPropertiesNotGeneratedIssue/assets/payload/UserDetails.java b/multiapi-engine/src/test/resources/asyncapigenerator/testPropertiesNotGeneratedIssue/assets/payload/UserDetails.java index 7617d4f8..a0da46e2 100644 --- a/multiapi-engine/src/test/resources/asyncapigenerator/testPropertiesNotGeneratedIssue/assets/payload/UserDetails.java +++ b/multiapi-engine/src/test/resources/asyncapigenerator/testPropertiesNotGeneratedIssue/assets/payload/UserDetails.java @@ -58,8 +58,8 @@ public UserDetails.UserDetailsBuilder email(String email) { } public UserDetails build() { - UserDetails details = new UserDetails(this); - return details; + UserDetails userDetails = new UserDetails(this); + return userDetails; } } @@ -107,8 +107,8 @@ public boolean equals(Object o) { if (o == null || getClass() != o.getClass()) { return false; } - UserDetails details = (UserDetails) o; - return Objects.equals(this.firstName, details.firstName) && Objects.equals(this.lastName, details.lastName) && Objects.equals(this.email, details.email); + UserDetails userDetails = (UserDetails) o; + return Objects.equals(this.firstName, userDetails.firstName) && Objects.equals(this.lastName, userDetails.lastName) && Objects.equals(this.email, userDetails.email); } @Override From 240ae40056f2d88668adc5570b8dc8344d0b54a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jose=20Enrique=20Garc=C3=ADa=20Maci=C3=B1eiras?= Date: Tue, 14 Nov 2023 16:54:54 +0100 Subject: [PATCH 8/9] 293 Update version on README.md --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 2429dd62..d9f1eeaa 100644 --- a/README.md +++ b/README.md @@ -60,7 +60,7 @@ As commented above, they both could be used at the same time, setting a double com.sngular scs-multiapi-maven-plugin - 5.0.2 + 5.1.0 asyncapi @@ -114,7 +114,7 @@ Apply the plugin in the `build.gradle` file and invoke the task. ```groovy plugins { id "java" - id "com.sngular.scs-multiapi-gradle-plugin' version '5.0.2" + id "com.sngular.scs-multiapi-gradle-plugin' version '5.1.0" openapimodel { @@ -153,7 +153,7 @@ which the plugin is designed. com.sngular scs-multiapi-maven-plugin - 5.0.2 + 5.1.0 generate-sources @@ -576,7 +576,7 @@ file. Here is an example of a basic configuration: com.sngular scs-multiapi-maven-plugin - 5.0.2 + 5.1.0 From d463dc5e4ec7ebcd100d1556808d97df8d33bf66 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jose=20Enrique=20Garc=C3=ADa=20Maci=C3=B1eiras?= Date: Wed, 15 Nov 2023 00:54:40 +0100 Subject: [PATCH 9/9] 293 Codacy complains --- checkstyle.xml | 8 ++++++++ .../generator/plugin/asyncapi/util/MapperContentUtil.java | 1 - .../api/generator/plugin/openapi/OpenApiGenerator.java | 1 - 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/checkstyle.xml b/checkstyle.xml index 506398ae..3d848882 100644 --- a/checkstyle.xml +++ b/checkstyle.xml @@ -405,6 +405,14 @@ + + + + + + + + diff --git a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/asyncapi/util/MapperContentUtil.java b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/asyncapi/util/MapperContentUtil.java index ffb3dfe7..aaafbfe4 100644 --- a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/asyncapi/util/MapperContentUtil.java +++ b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/asyncapi/util/MapperContentUtil.java @@ -224,7 +224,6 @@ private static SchemaFieldObject solveElement( return result; } - @SuppressWarnings("checkstyle:ParameterNumber") private static SchemaFieldObject processFieldObjectList( final Map totalSchemas, final String propertyName, final JsonNode schema, final boolean required, final String prefix, final String suffix, final Collection modelToBuildList, final String modelPackage, final String className) { diff --git a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/openapi/OpenApiGenerator.java b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/openapi/OpenApiGenerator.java index a886023e..c7e71a61 100644 --- a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/openapi/OpenApiGenerator.java +++ b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/openapi/OpenApiGenerator.java @@ -260,7 +260,6 @@ private void processModels( ); } - @SuppressWarnings("checkstyle:ParameterNumber") private void processModel( final SpecFile specFile, final String fileModelToSave, final String modelPackage, final Map basicSchemaMap, final boolean overwrite, final String schemaName, final JsonNode basicSchema, final Map builtSchemasMap) {