From e51827e4c183fea96ab1194b2e050837343e7250 Mon Sep 17 00:00:00 2001 From: "joseenrique.garcia" Date: Tue, 6 Aug 2024 23:34:48 +0200 Subject: [PATCH 01/26] Fix test --- .../plugin/asyncapi/AsyncApiGenerator.java | 63 +- .../plugin/asyncapi/model/MethodObject.java | 1 + .../asyncapi/model/SchemaFieldObject.java | 40 - .../plugin/asyncapi/model/SchemaObject.java | 61 -- .../parameter/OperationParameterObject.java | 40 +- .../asyncapi/template/ClassTemplate.java | 2 +- .../asyncapi/template/TemplateFactory.java | 8 +- .../asyncapi/util/MapperContentUtil.java | 473 +---------- .../plugin/asyncapi/util/MapperUtil.java | 174 ---- .../asyncapi/util/ReferenceProcessor.java | 1 + .../plugin/common/model/CommonSpecFile.java | 43 + .../common/model/SchemaFieldObject.java | 28 + .../model/SchemaFieldObjectProperties.java | 2 +- .../model/SchemaFieldObjectType.java | 2 +- .../plugin/common/model/SchemaObject.java | 56 ++ .../plugin/common/model/TimeType.java | 6 - .../model/TypeConstants.java | 2 +- .../plugin/common/tools/ApiTool.java | 2 +- .../utils => common/tools}/MapperUtil.java | 81 +- .../plugin/common/tools/ModelBuilder.java | 738 +++++++++++++++++ .../plugin/common/tools/SchemaUtil.java | 5 +- .../plugin/openapi/OpenApiGenerator.java | 16 +- .../plugin/openapi/model/ContentObject.java | 2 + .../plugin/openapi/model/ParameterObject.java | 1 + .../openapi/model/SchemaFieldObject.java | 39 - .../model/SchemaFieldObjectProperties.java | 101 --- .../plugin/openapi/model/SchemaObject.java | 72 -- .../plugin/openapi/parameter/SpecFile.java | 30 +- .../openapi/template/TemplateFactory.java | 6 +- .../openapi/utils/MapperContentUtil.java | 754 +----------------- .../plugin/openapi/utils/MapperPathUtil.java | 4 + .../plugin/openapi/utils/OpenApiUtil.java | 6 +- .../templates/asyncapi/templateSchema.ftlh | 251 +++--- .../asyncapi/templateSchemaWithLombok.ftlh | 260 +++--- .../templates/openapi/templateSchema.ftlh | 102 ++- .../openapi/OpenApiGeneratorFixtures.java | 2 +- .../assets/payload/SomeOtherObject.java | 51 +- .../testCustomValidators/assets/DataDTO.java | 108 +-- .../assets/CreateOrderMapper.java | 51 +- .../testFileGeneration/assets/OrderDTO.java | 66 +- .../assets/OrderLineDTO.java | 54 +- .../assets/OrderLineMapper.java | 54 +- .../assets/OrderMapper.java | 66 +- .../assets/OrderProductDTO.java | 65 +- .../assets/OrderProductMapper.java | 65 +- .../assets/WaiterMapper.java | 56 +- .../assets/ObjectArrayDTO.java | 55 +- .../assets/CustomerDTO.java | 113 +-- .../assets/CustomerEventPayloadDTO.java | 54 +- .../assets/CustomerOrderDTO.java | 133 ++- .../assets/CustomerOrderEventPayloadDTO.java | 58 +- .../assets/OrderedItemDTO.java | 55 +- .../assets/PaymentDetailsDTO.java | 4 - .../assets/ShippingDetailsDTO.java | 4 - .../testIssueGeneration/assets/DataDTO.java | 56 +- .../assets/StatusMsgDTO.java | 54 +- .../assets/MailRequestInfiniteDTO.java | 56 +- .../assets/DataDTO.java | 56 +- .../assets/StatusMsgDTO.java | 54 +- .../assets/CreateOrderEventDTO.java | 51 +- .../assets/OrderDTO.java | 64 +- .../assets/OrderLineDTO.java | 54 +- .../assets/OrderProductDTO.java | 65 +- .../assets/WaiterDTO.java | 56 +- .../assets/payload/SomeOtherObject.java | 51 +- .../assets/payload/UserSignedUpPayload.java | 101 +-- .../testNoSchemas/assets/TestMsg.java | 4 - .../testNoSchemas/assets/Thing.java | 4 - .../assets/payload/UserDetails.java | 54 +- .../assets/payload/UserSignedUp.java | 50 +- .../assets/CreateOrderDTO.java | 51 +- .../assets/OrderDTO.java | 72 +- .../assets/WaiterDTO.java | 58 +- .../assets/CreateOrderDTO.java | 51 +- .../assets/OrderDTO.java | 68 +- .../assets/OrderLineDTO.java | 52 +- .../assets/WaiterDTO.java | 58 +- .../assets/input/model/Data.java | 4 - .../assets/input/model/Input.java | 11 - .../assets/output/model/Data.java | 49 +- .../assets/output/model/Output.java | 73 +- 81 files changed, 2283 insertions(+), 3680 deletions(-) delete mode 100644 multiapi-engine/src/main/java/com/sngular/api/generator/plugin/asyncapi/model/SchemaFieldObject.java delete mode 100644 multiapi-engine/src/main/java/com/sngular/api/generator/plugin/asyncapi/model/SchemaObject.java delete mode 100644 multiapi-engine/src/main/java/com/sngular/api/generator/plugin/asyncapi/util/MapperUtil.java create mode 100644 multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/model/CommonSpecFile.java create mode 100644 multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/model/SchemaFieldObject.java rename multiapi-engine/src/main/java/com/sngular/api/generator/plugin/{asyncapi => common}/model/SchemaFieldObjectProperties.java (97%) rename multiapi-engine/src/main/java/com/sngular/api/generator/plugin/{openapi => common}/model/SchemaFieldObjectType.java (99%) create mode 100644 multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/model/SchemaObject.java delete mode 100644 multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/model/TimeType.java rename multiapi-engine/src/main/java/com/sngular/api/generator/plugin/{openapi => common}/model/TypeConstants.java (98%) rename multiapi-engine/src/main/java/com/sngular/api/generator/plugin/{openapi/utils => common/tools}/MapperUtil.java (62%) create mode 100644 multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/tools/ModelBuilder.java delete mode 100644 multiapi-engine/src/main/java/com/sngular/api/generator/plugin/openapi/model/SchemaFieldObject.java delete mode 100644 multiapi-engine/src/main/java/com/sngular/api/generator/plugin/openapi/model/SchemaFieldObjectProperties.java delete mode 100644 multiapi-engine/src/main/java/com/sngular/api/generator/plugin/openapi/model/SchemaObject.java 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 e64d4777..85d8b203 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 @@ -6,24 +6,6 @@ package com.sngular.api.generator.plugin.asyncapi; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.FilenameFilter; -import java.io.IOException; -import java.io.InputStream; -import java.nio.file.Path; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; -import java.util.Objects; -import java.util.regex.Pattern; - import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.dataformat.yaml.YAMLFactory; @@ -32,20 +14,20 @@ import com.sngular.api.generator.plugin.asyncapi.model.ProcessBindingsResult; import com.sngular.api.generator.plugin.asyncapi.model.ProcessBindingsResult.ProcessBindingsResultBuilder; import com.sngular.api.generator.plugin.asyncapi.model.ProcessMethodResult; -import com.sngular.api.generator.plugin.asyncapi.model.SchemaObject; import com.sngular.api.generator.plugin.asyncapi.parameter.OperationParameterObject; import com.sngular.api.generator.plugin.asyncapi.parameter.SpecFile; import com.sngular.api.generator.plugin.asyncapi.template.TemplateFactory; import com.sngular.api.generator.plugin.asyncapi.util.BindingTypeEnum; import com.sngular.api.generator.plugin.asyncapi.util.FactoryTypeEnum; import com.sngular.api.generator.plugin.asyncapi.util.MapperContentUtil; -import com.sngular.api.generator.plugin.asyncapi.util.MapperUtil; import com.sngular.api.generator.plugin.asyncapi.util.ReferenceProcessor; import com.sngular.api.generator.plugin.common.files.ClasspathFileLocation; import com.sngular.api.generator.plugin.common.files.DirectoryFileLocation; import com.sngular.api.generator.plugin.common.files.FileLocation; -import com.sngular.api.generator.plugin.common.model.TimeType; +import com.sngular.api.generator.plugin.common.model.CommonSpecFile; +import com.sngular.api.generator.plugin.common.model.SchemaObject; import com.sngular.api.generator.plugin.common.tools.ApiTool; +import com.sngular.api.generator.plugin.common.tools.MapperUtil; import com.sngular.api.generator.plugin.exception.InvalidAPIException; import freemarker.template.TemplateException; import lombok.extern.slf4j.Slf4j; @@ -54,6 +36,12 @@ import org.apache.commons.lang3.tuple.ImmutablePair; import org.apache.commons.lang3.tuple.Pair; +import java.io.*; +import java.nio.file.Path; +import java.util.*; +import java.util.Map.Entry; +import java.util.regex.Pattern; + @Slf4j public class AsyncApiGenerator { @@ -133,7 +121,7 @@ public AsyncApiGenerator(final Integer springBootVersion, final File targetFolde this.springBootVersion = springBootVersion; } - public static Pair resolveYmlLocation(final String ymlFilePath) throws FileNotFoundException { + private static Pair resolveYmlLocation(final String ymlFilePath) throws FileNotFoundException { final InputStream classPathInput = AsyncApiGenerator.class.getClassLoader().getResourceAsStream(ymlFilePath); final InputStream ymlFile; @@ -166,13 +154,13 @@ public final void processFileSpec(final List specsListFile) { try { final JsonNode openApi = om.readTree(ymlFile); - final JsonNode internalNode = openApi.get(CHANNELS); + final JsonNode channelList = openApi.get(CHANNELS); final Map totalSchemas = getAllSchemas(ymlParent, openApi); - final Iterator> iter = internalNode.fields(); + final Iterator> channelListIt = channelList.fields(); setUpTemplate(fileParameter, springBootVersion); - while (iter.hasNext()) { + while (channelListIt.hasNext()) { - final Map.Entry entry = iter.next(); + final Map.Entry entry = channelListIt.next(); final JsonNode channel = entry.getValue(); @@ -194,7 +182,7 @@ private void checkRequiredOrCombinatorExists(final SchemaObject schema, final bo if ("anyOf".equals(schema.getSchemaCombinator()) || "oneOf".equals(schema.getSchemaCombinator())) { generateExceptionTemplate = true; } else if (Objects.nonNull(schema.getFieldObjectList()) && !useLombok) { - final var fieldListIt = schema.getFieldObjectList().listIterator(); + final var fieldListIt = schema.getFieldObjectList().iterator(); if (fieldListIt.hasNext()) { do { final var field = fieldListIt.next(); @@ -266,16 +254,19 @@ private void processOperation( final String operationId, final JsonNode channelPayload, final Map totalSchemas) throws IOException, TemplateException { if (isValidOperation(fileParameter.getConsumer(), operationId, channel, SUBSCRIBE, true)) { final var operationObject = fileParameter.getConsumer(); + operationObject.setFilePath(fileParameter.getFilePath()); checkClassPackageDuplicate(operationObject.getClassNamePostfix(), operationObject.getApiPackage()); processSubscribeMethod(channelPayload, operationObject, ymlParent, totalSchemas); addProcessedClassesAndPackagesToGlobalVariables(operationObject.getClassNamePostfix(), operationObject.getApiPackage(), CONSUMER_CLASS_NAME); } else if (isValidOperation(fileParameter.getSupplier(), operationId, channel, PUBLISH, Objects.isNull(fileParameter.getStreamBridge()))) { final var operationObject = fileParameter.getSupplier(); + operationObject.setFilePath(fileParameter.getFilePath()); checkClassPackageDuplicate(operationObject.getClassNamePostfix(), operationObject.getApiPackage()); processSupplierMethod(channelPayload, operationObject, ymlParent, totalSchemas); addProcessedClassesAndPackagesToGlobalVariables(operationObject.getClassNamePostfix(), operationObject.getApiPackage(), SUPPLIER_CLASS_NAME); } else if (isValidOperation(fileParameter.getStreamBridge(), operationId, channel, PUBLISH, Objects.isNull(fileParameter.getSupplier()))) { final var operationObject = fileParameter.getStreamBridge(); + operationObject.setFilePath(fileParameter.getFilePath()); checkClassPackageDuplicate(operationObject.getClassNamePostfix(), operationObject.getApiPackage()); processStreamBridgeMethod(channelPayload, operationObject, ymlParent, entry.getKey(), totalSchemas); addProcessedClassesAndPackagesToGlobalVariables(operationObject.getClassNamePostfix(), operationObject.getApiPackage(), STREAM_BRIDGE_CLASS_NAME); @@ -471,8 +462,7 @@ private void fillTemplateFactory( final JsonNode schemaToBuild = processedMethod.getPayload(); if (shouldBuild(schemaToBuild)) { final var schemaObjectIt = - MapperContentUtil.mapComponentToSchemaObject(totalSchemas, className, schemaToBuild, null, operationObject.getModelNameSuffix(), parentPackage, modelPackage, - operationObject.getFormats(), operationObject.getUseTimeType()).iterator(); + MapperContentUtil.mapComponentToSchemaObject(totalSchemas, className, schemaToBuild, parentPackage, operationObject, this.baseDir.toPath()).iterator(); if (schemaObjectIt.hasNext()) { final var filePath = writeSchemaObject(operationObject.isUseLombokModelAnnotation(), operationObject.getModelPackage(), keyClassName, schemaObjectIt.next()); @@ -523,7 +513,7 @@ private ProcessMethodResult processMethod( } else if (message.has(PAYLOAD)) { payloadInfo = processPayload(operationObject, ApiTool.getName(message), ApiTool.getNode(message, PAYLOAD), ymlParent); if (ApiTool.hasNode(message, BINDINGS)) { - processBindings(processBindingsResultBuilder, operationObject.getClassNamePostfix(), operationObject.getModelNameSuffix(), message, operationObject.getUseTimeType()); + processBindings(processBindingsResultBuilder, message, operationObject); } } else { throw new InvalidAsyncAPIException(operationId); @@ -556,7 +546,7 @@ private Pair processMethodRef( final var message = totalSchemas.get(MapperUtil.buildKey(MapperUtil.splitName(messageRef))); if (ApiTool.hasNode(message, BINDINGS)) { - processBindings(bindingsResult, operationObject.getClassNamePostfix(), operationObject.getModelNameSuffix(), message, operationObject.getUseTimeType()); + processBindings(bindingsResult, message, operationObject); } return processPayload(operationObject, MapperUtil.getRefClass(method), ApiTool.getNode(message, PAYLOAD), ymlParent); } @@ -613,22 +603,21 @@ private String processExternalRef(final String modelPackage, final FileLocation } } - private void processBindings(final ProcessBindingsResultBuilder bindingsResult, final String prefix, final String suffix, final JsonNode message, - final TimeType useTimeType) { + private void processBindings(final ProcessBindingsResultBuilder bindingsResult, final JsonNode message, + final CommonSpecFile commonSpecFile) { if (message.has(BINDINGS)) { final var bindingsNode = message.get(BINDINGS); if (bindingsNode.has(KAFKA)) { - processKafkaBindings(bindingsResult, prefix, suffix, bindingsNode.get(KAFKA), useTimeType); + processKafkaBindings(bindingsResult, bindingsNode.get(KAFKA), commonSpecFile); } else { bindingsResult.bindingType(BindingTypeEnum.NONBINDING.getValue()); } } } - private void processKafkaBindings(final ProcessBindingsResultBuilder bindingsResult, final String prefix, final String suffix, final JsonNode kafkaBindings, - final TimeType useTimeType) { + private void processKafkaBindings(final ProcessBindingsResultBuilder bindingsResult, final JsonNode kafkaBindings, final CommonSpecFile specFile) { if (kafkaBindings.has(KEY)) { - bindingsResult.bindings(MapperUtil.getSimpleType(ApiTool.getNode(kafkaBindings, "key"), prefix, suffix, useTimeType)) + bindingsResult.bindings(MapperUtil.getSimpleType(ApiTool.getNode(kafkaBindings, "key"), specFile)) .bindingType(BindingTypeEnum.KAFKA.getValue()); } } 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 83baddfe..6222580f 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 @@ -9,6 +9,7 @@ import java.util.Objects; import com.sngular.api.generator.plugin.asyncapi.util.BindingTypeEnum; +import com.sngular.api.generator.plugin.common.model.SchemaObject; import lombok.Builder; import lombok.Value; import org.apache.commons.lang3.StringUtils; diff --git a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/asyncapi/model/SchemaFieldObject.java b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/asyncapi/model/SchemaFieldObject.java deleted file mode 100644 index b3eb12c6..00000000 --- a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/asyncapi/model/SchemaFieldObject.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * This Source Code Form is subject to the terms of the Mozilla Public - * * License, v. 2.0. If a copy of the MPL was not distributed with this - * * file, You can obtain one at https://mozilla.org/MPL/2.0/. - */ - -package com.sngular.api.generator.plugin.asyncapi.model; - -import java.util.List; - -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Builder.Default; -import lombok.Data; -import lombok.NoArgsConstructor; - -@Data -@Builder -@NoArgsConstructor -@AllArgsConstructor -public class SchemaFieldObject { - - private String baseName; - - private String dataTypeSimple; - - @Default - private SchemaFieldObjectProperties restrictions = new SchemaFieldObjectProperties(); - - private String dataType; - - private String importClass; - - private boolean required; - - private List enumValues; - - private Object constValue; - -} diff --git a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/asyncapi/model/SchemaObject.java b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/asyncapi/model/SchemaObject.java deleted file mode 100644 index ed66182f..00000000 --- a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/asyncapi/model/SchemaObject.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * This Source Code Form is subject to the terms of the Mozilla Public - * * License, v. 2.0. If a copy of the MPL was not distributed with this - * * file, You can obtain one at https://mozilla.org/MPL/2.0/. - */ - -package com.sngular.api.generator.plugin.asyncapi.model; - -import java.util.ArrayList; -import java.util.List; - -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Data; -import lombok.NoArgsConstructor; - -@Data -@Builder -@NoArgsConstructor -@AllArgsConstructor -public class SchemaObject { - - private String schemaName; - - private String className; - - private List importList; - - private List fieldObjectList; - - private String schemaCombinator; - - private String parentPackage; - - public static final class SchemaObjectBuilder { - - private final List importList = new ArrayList<>(); - - private final List fieldObjectList = new ArrayList<>(); - - public SchemaObjectBuilder importList(final List importList) { - this.importList.addAll(importList); - return this; - } - - public SchemaObjectBuilder importItem(final String importItem) { - this.importList.add(importItem); - return this; - } - - public SchemaObjectBuilder fieldObjectList(final List fieldObjectList) { - this.fieldObjectList.addAll(fieldObjectList); - return this; - } - - public SchemaObjectBuilder fieldObject(final SchemaFieldObject fieldObject) { - this.fieldObjectList.add(fieldObject); - return this; - } - } -} diff --git a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/asyncapi/parameter/OperationParameterObject.java b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/asyncapi/parameter/OperationParameterObject.java index f831c476..1dec6a89 100644 --- a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/asyncapi/parameter/OperationParameterObject.java +++ b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/asyncapi/parameter/OperationParameterObject.java @@ -13,53 +13,29 @@ package com.sngular.api.generator.plugin.asyncapi.parameter; -import java.util.List; -import java.util.Map; - -import com.sngular.api.generator.plugin.common.model.TimeType; -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Builder.Default; -import lombok.Data; -import lombok.NoArgsConstructor; +import com.sngular.api.generator.plugin.common.model.CommonSpecFile; +import lombok.*; +import lombok.experimental.SuperBuilder; import org.apache.commons.lang3.StringUtils; +import java.util.List; + @Data -@Builder +@SuperBuilder @NoArgsConstructor @AllArgsConstructor -public final class OperationParameterObject { +@EqualsAndHashCode(callSuper = true) +public final class OperationParameterObject extends CommonSpecFile { private String ids; - private String apiPackage; - - private String modelPackage; - - private String modelNameSuffix; - private String classNamePostfix; - private boolean useLombokModelAnnotation; - - @Builder.Default - private String dateTimeFormat = "yyyy-MM-dd'T'HH:mm:ss"; - - @Builder.Default - private String dateFormat = "yyyy-MM-dd"; - - @Default - private TimeType useTimeType = TimeType.LOCAL; - @SuppressWarnings("unused") private List operationIds; public List getOperationIds() { return StringUtils.isEmpty(ids) ? List.of() : List.of(ids.replace(" ", "").split(",")); } - - public Map getFormats() { - return Map.of("DATE_TIME", dateTimeFormat, "DATE", dateFormat); - } } diff --git a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/asyncapi/template/ClassTemplate.java b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/asyncapi/template/ClassTemplate.java index 073f257c..c84524d0 100644 --- a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/asyncapi/template/ClassTemplate.java +++ b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/asyncapi/template/ClassTemplate.java @@ -8,7 +8,7 @@ import java.nio.file.Path; -import com.sngular.api.generator.plugin.asyncapi.model.SchemaObject; +import com.sngular.api.generator.plugin.common.model.SchemaObject; 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 7ced27b3..46a054a2 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 @@ -23,10 +23,10 @@ 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; -import com.sngular.api.generator.plugin.asyncapi.model.SchemaFieldObject; -import com.sngular.api.generator.plugin.asyncapi.model.SchemaObject; import com.sngular.api.generator.plugin.asyncapi.util.BindingTypeEnum; -import com.sngular.api.generator.plugin.asyncapi.util.MapperUtil; +import com.sngular.api.generator.plugin.common.model.SchemaFieldObject; +import com.sngular.api.generator.plugin.common.model.SchemaObject; +import com.sngular.api.generator.plugin.common.tools.MapperUtil; import com.sngular.api.generator.plugin.exception.GeneratorTemplateException; import freemarker.template.Configuration; import freemarker.template.Template; @@ -82,6 +82,8 @@ public TemplateFactory() { cfg.setDefaultEncoding("UTF-8"); cfg.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER); cfg.setLogTemplateExceptions(true); + cfg.setAPIBuiltinEnabled(true); + } private void fillTemplate(final String filePathToSave, final String className, final String templateName, final Map root) throws IOException, TemplateException { 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 1533b615..0a1d3642 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 @@ -7,480 +7,39 @@ package com.sngular.api.generator.plugin.asyncapi.util; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.HashSet; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; -import java.util.Objects; -import java.util.Queue; -import java.util.Set; -import java.util.concurrent.ConcurrentLinkedQueue; - import com.fasterxml.jackson.databind.JsonNode; -import com.sngular.api.generator.plugin.asyncapi.exception.BadDefinedEnumException; -import com.sngular.api.generator.plugin.asyncapi.exception.NonSupportedSchemaException; -import com.sngular.api.generator.plugin.asyncapi.model.SchemaFieldObject; -import com.sngular.api.generator.plugin.asyncapi.model.SchemaFieldObjectProperties; -import com.sngular.api.generator.plugin.asyncapi.model.SchemaObject; -import com.sngular.api.generator.plugin.common.model.TimeType; -import com.sngular.api.generator.plugin.common.tools.ApiTool; -import org.apache.commons.lang3.StringUtils; -import org.apache.commons.text.WordUtils; - -public class MapperContentUtil { - - public static final String OBJECT = "object"; - - public static final String ONE_OF = "oneOf"; - - public static final String PROPERTIES = "properties"; - - public static final String REF = "$ref"; - - public static final String TYPE = "type"; - - public static final String ALL_OF = "allOf"; +import com.sngular.api.generator.plugin.common.model.CommonSpecFile; +import com.sngular.api.generator.plugin.common.model.SchemaObject; +import com.sngular.api.generator.plugin.common.tools.ModelBuilder; - public static final String ANY_OF = "anyOf"; +import java.nio.file.Path; +import java.util.*; - private static final String ARRAY = "array"; - - private static final String BIG_DECIMAL = "BigDecimal"; +public class MapperContentUtil { - private static final String LOCAL_DATE = "LocalDate"; + private static final String ADDITIONAL_PROPERTY_NAME = "AdditionalProperty"; - private static final String LOCAL_DATE_TIME = "LocalDateTime"; + private static final String ADDITIONAL_PROPERTIES = "additionalProperties"; - private static final String ZONED_DATE_TIME = "ZonedDateTime"; + private static final String ANY_OF_COMBINATOR = "anyOf"; - private static final String MAP = "map"; + private static final String ONE_OF_COMBINATOR = "oneOf"; - private static String schemaCombinatorType; + private static final String ALL_OF_COMBINATOR = "allOf"; private MapperContentUtil() {} public static List mapComponentToSchemaObject( - final Map totalSchemas, final String component, final JsonNode model, - final String prefix, final String suffix, final String parentPackage, - final String modelPackage, final Map formats, final TimeType useTimeType) { + final Map totalSchemas, final String className, final JsonNode model, + final String parentPackage, final CommonSpecFile specFile, final Path baseDir) { final List schemasList = new ArrayList<>(); if (Objects.nonNull(model)) { - final Queue modelToBuildList = new ConcurrentLinkedQueue<>(); - final List alreadyBuilt = new ArrayList<>(); - schemasList.add(buildSchemaObject(totalSchemas, component, model, prefix, suffix, modelToBuildList, parentPackage, modelPackage, formats, useTimeType)); - while (!modelToBuildList.isEmpty()) { - - final var modelToBuild = modelToBuildList.remove(); - if (!alreadyBuilt.contains(modelToBuild)) { - final var path = MapperUtil.splitName(modelToBuild); - final var nexElement = buildSchemaObject(totalSchemas, modelToBuild, totalSchemas.get(getComponent(path)), - prefix, suffix, modelToBuildList, getParentName(path), modelPackage, formats, useTimeType); - if (schemasList.contains(nexElement)) { - modelToBuildList.poll(); - } else { - schemasList.add(nexElement); - } - alreadyBuilt.add(modelToBuild); - } - } + final var modelToBuildMap = new HashMap(); + schemasList.add(ModelBuilder.buildSchemaObject(totalSchemas, className, model, new HashSet<>(), modelToBuildMap, parentPackage, specFile, baseDir)); + schemasList.addAll(modelToBuildMap.values()); } return schemasList; } - private static String getParentName(final String[] path) { - final String parenName; - if (path.length > 1) { - parenName = String.join(".", Arrays.copyOf(path, path.length - 1)); - } else { - parenName = ""; - } - return parenName; - } - - private static String getComponent(final String[] path) { - final String componentName; - if (path.length > 1) { - componentName = String.join(".", Arrays.copyOf(path, path.length - 1)) + "/" + path[path.length - 1]; - } else { - componentName = path[0]; - } - return componentName.toUpperCase(); - } - - private static String getSchema(final String[] path) { - final String componentName; - if (path.length > 1) { - componentName = path[path.length - 2] + "/" + path[path.length - 1]; - } else { - componentName = path[0]; - } - return componentName.toUpperCase(); - } - - private static SchemaObject buildSchemaObject( - final Map totalSchemas, final String component, final JsonNode model, - final String prefix, final String suffix, final Collection modelToBuildList, final String parentPackage, - final String modelPackage, final Map formats, final TimeType useTimeType) { - - final var listSchema = getFields(totalSchemas, model, true, prefix, suffix, modelToBuildList, modelPackage, formats, useTimeType); - final var splitPackage = MapperUtil.splitName(component); - final String className = splitPackage[splitPackage.length - 1]; - return SchemaObject.builder() - .schemaName(WordUtils.capitalizeFully(className)) - .className(MapperUtil.getPojoName(className, prefix, suffix)) - .importList(getImportList(listSchema)) - .schemaCombinator(StringUtils.isNotBlank(schemaCombinatorType) ? schemaCombinatorType : "") - .fieldObjectList(listSchema) - .parentPackage(parentPackage.toLowerCase()) - .build(); - } - - private static List getImportList(final List schemaListToImport) { - final var importList = new HashSet(); - - for (final SchemaFieldObject fieldObject : schemaListToImport) { - importList.addAll(getTypeImports(fieldObject)); - } - return new ArrayList<>(importList); - } - - private static List getTypeImports(final SchemaFieldObject fieldObject) { - final List importList = new ArrayList<>(); - if (Objects.nonNull(fieldObject.getDataTypeSimple())) { - if (fieldObject.getDataTypeSimple().equals(ARRAY)) { - importList.addAll(List.of("java.util.List", "java.util.ArrayList")); - if (Objects.nonNull(fieldObject.getDataType())) { - if (Objects.equals(fieldObject.getDataType(), LOCAL_DATE)) { - importList.add("java.time.LocalDate"); - } else if (Objects.equals(fieldObject.getDataType(), LOCAL_DATE_TIME)) { - importList.add("java.time.LocalDateTime"); - } else if (Objects.equals(fieldObject.getDataType(), ZONED_DATE_TIME)) { - importList.add("java.time.ZonedDateTime"); - } - } - } else if (Objects.equals(fieldObject.getDataTypeSimple(), MAP)) { - importList.addAll(List.of("java.util.Map", "java.util.HashMap")); - } else if (fieldObject.getDataTypeSimple().equals(BIG_DECIMAL) - || Objects.nonNull(fieldObject.getDataType()) && fieldObject.getDataType().equals(BIG_DECIMAL)) { - importList.add("java.math.BigDecimal"); - } else if (Objects.equals(fieldObject.getDataTypeSimple(), LOCAL_DATE)) { - importList.add("java.time.LocalDate"); - } else if (Objects.equals(fieldObject.getDataTypeSimple(), LOCAL_DATE_TIME)) { - importList.add("java.time.LocalDateTime"); - } else if (Objects.equals(fieldObject.getDataTypeSimple(), ZONED_DATE_TIME)) { - importList.add("java.time.ZonedDateTime"); - } - } - return importList; - } - - private static List getFields( - final Map totalSchemas, final JsonNode model, final boolean required, final String prefix, - final String suffix, final Collection modelToBuildList, - final String modelPackage, final Map formats, final TimeType useTimeType) { - final var fieldObjectArrayList = new ArrayList(); - schemaCombinatorType = null; - if (ApiTool.hasType(model)) { - if (OBJECT.equalsIgnoreCase(model.get(TYPE).textValue())) { - fieldObjectArrayList.addAll(processFieldObject(totalSchemas, model, prefix, suffix, modelToBuildList, modelPackage, formats, useTimeType)); - } else if (ARRAY.equalsIgnoreCase(model.get(TYPE).textValue())) { - fieldObjectArrayList.add(processFieldObjectList(totalSchemas, "", model, required, prefix, suffix, modelToBuildList, modelPackage, null, formats, useTimeType)); - } else if ("enum".equalsIgnoreCase(model.get(TYPE).textValue())) { - fieldObjectArrayList.add(processFieldObjectList(totalSchemas, "", model, required, prefix, suffix, modelToBuildList, modelPackage, null, formats, useTimeType)); - } - } 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, modelPackage, formats, useTimeType)); - } else if (model.elements().hasNext()) { - fieldObjectArrayList.addAll(processFieldObject(totalSchemas, model, prefix, suffix, modelToBuildList, modelPackage, formats, useTimeType)); - } - return fieldObjectArrayList; - } - - private static List processFieldObject( - final Map totalSchemas, final JsonNode model, final String prefix, final String suffix, final Collection modelToBuildList, - final String modelPackage, final Map formats, final TimeType useTimeType) { - final Set requiredSet = new HashSet<>(); - final var fieldObjectArrayList = new ArrayList(); - if (model.has("required")) { - final JsonNode arrayNode = model.get("required"); - final Iterator fields = arrayNode.iterator(); - fields.forEachRemaining(field -> requiredSet.add(field.textValue())); - } - final var properties = model.get(PROPERTIES); - if (!(properties.has(ANY_OF) || properties.has(ALL_OF) || properties.has(ONE_OF))) { - final var propertiesIt = model.get(PROPERTIES).fieldNames(); - while (propertiesIt.hasNext()) { - final var property = propertiesIt.next(); - fieldObjectArrayList.add(processFieldObjectList(totalSchemas, property, model.get(PROPERTIES).path(property), requiredSet.contains(property), prefix, suffix, - modelToBuildList, modelPackage, null, formats, useTimeType)); - if (model.get(PROPERTIES).path(property).has(REF) && !totalSchemas.containsKey(createKey(modelPackage, property.toUpperCase(), "/"))) { - modelToBuildList.add(MapperUtil.getLongRefClass(model.get(PROPERTIES).path(property))); - } - } - } else if (properties.has(ALL_OF)) { - fieldObjectArrayList.addAll(processAllOfAnyOfOneOf(totalSchemas, properties.get(ALL_OF), true, prefix, suffix, modelToBuildList, formats, useTimeType)); - schemaCombinatorType = ALL_OF; - } else if (properties.has(ANY_OF)) { - fieldObjectArrayList.addAll(processAllOfAnyOfOneOf(totalSchemas, properties.get(ANY_OF), false, prefix, suffix, modelToBuildList, formats, useTimeType)); - schemaCombinatorType = ANY_OF; - } else if (properties.has(ONE_OF)) { - fieldObjectArrayList.addAll(processAllOfAnyOfOneOf(totalSchemas, properties.get(ONE_OF), false, prefix, suffix, modelToBuildList, formats, useTimeType)); - schemaCombinatorType = ONE_OF; - } - return fieldObjectArrayList; - } - - private static List processAllOfAnyOfOneOf( - final Map totalSchemas, final JsonNode schemaList, final boolean required, final String prefix, final String suffix, - final Collection modelToBuildList, final Map formats, final TimeType useTimeType) { - final var fieldObjectArrayList = new ArrayList(); - final var allOfIterator = schemaList.elements(); - - allOfIterator.forEachRemaining(element -> fieldObjectArrayList.add(solveElement(totalSchemas, required, prefix, suffix, element, - modelToBuildList, formats, useTimeType))); - return fieldObjectArrayList; - } - - private static SchemaFieldObject solveElement( - final Map totalSchemas, final boolean required, final String prefix, final String suffix, - final JsonNode element, final Collection modelToBuildList, final Map formats, final TimeType useTimeType) { - final SchemaFieldObject result; - 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, null, formats, useTimeType); - result.setRequired(false); - } else { - result = processFieldObjectList(totalSchemas, "", element, required, prefix, suffix, modelToBuildList, null, null, formats, useTimeType); - } - return result; - } - - 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, - final Map formats, final TimeType useTimeType) { - final SchemaFieldObject fieldObject; - final var name = schema.has("name") ? schema.get("name").textValue() : propertyName; - if (ApiTool.hasType(schema)) { - final var type = ApiTool.getType(schema); - if (OBJECT.equalsIgnoreCase(type)) { - fieldObject = - SchemaFieldObject - .builder() - .baseName(name) - .restrictions(new SchemaFieldObjectProperties()) - .dataType(MapperUtil.getSimpleType(schema, prefix, suffix, useTimeType)) - .build(); - setFieldType(fieldObject, schema, required, prefix, suffix, className, formats, useTimeType); - final var schemaName = StringUtils.defaultString(className, propertyName); - if (StringUtils.isNotEmpty(schemaName) && !totalSchemas.containsKey(createKey(modelPackage, schemaName.toUpperCase(), "/"))) { - totalSchemas.put(createKey(modelPackage, schemaName.toUpperCase(), "/"), schema); - modelToBuildList.add(createKey(modelPackage.toLowerCase(), schemaName, ".")); - } - } else if (ApiTool.hasItems(schema)) { - final var items = ApiTool.getItems(schema); - final var arrayType = MapperUtil.getSimpleType(items, prefix, suffix, useTimeType); - if (items.has(REF)) { - final var longType = MapperUtil.getLongRefClass(items); - modelToBuildList.add(longType); - } - fieldObject = - SchemaFieldObject - .builder() - .baseName(name) - .restrictions(new SchemaFieldObjectProperties()) - .dataType(arrayType) - .dataTypeSimple(type) - .importClass(getImportClass(arrayType)) - .build(); - setFormatProperies(fieldObject, arrayType, formats); - handleItems(schema, modelToBuildList, fieldObject, required, items); - } else if (ApiTool.isEnum(schema)) { - fieldObject = processEnumField(name, required, schema, prefix, suffix, useTimeType); - } else { - final String simpleType = MapperUtil.getSimpleType(schema, prefix, suffix, useTimeType); - fieldObject = SchemaFieldObject - .builder() - .baseName(name) - .restrictions(new SchemaFieldObjectProperties()) - .dataType(simpleType) - .dataTypeSimple(simpleType) - .constValue(MapperUtil.getConstValue(schema)) - .build(); - setFieldProperties(fieldObject, schema); - setFormatProperies(fieldObject, simpleType, formats); - fieldObject.setRequired(required); - } - } else if (ApiTool.hasRef(schema)) { - final var splitName = MapperUtil.splitName(ApiTool.getRefValue(schema)); - final var solvedRef = totalSchemas.get(getSchema(splitName)); - fieldObject = processFieldObjectList(totalSchemas, name, solvedRef, required, prefix, suffix, modelToBuildList, modelPackage, - splitName[splitName.length - 1], formats, useTimeType); - } else { - final String simpleType = MapperUtil.getSimpleType(schema, prefix, suffix, useTimeType); - fieldObject = SchemaFieldObject - .builder() - .baseName(name) - .dataType(simpleType) - .dataTypeSimple(simpleType) - .restrictions(new SchemaFieldObjectProperties()) - .constValue(MapperUtil.getConstValue(schema)) - .build(); - } - return fieldObject; - } - - private static String createKey(final String modelPackage, final String className, final String separator) { - return Objects.nonNull(modelPackage) ? modelPackage.toUpperCase() + separator + className : className; - } - - private static void handleItems( - final JsonNode schema, final Collection modelToBuildList, final SchemaFieldObject fieldObject, final boolean required, - final JsonNode items) { - if (ApiTool.hasRef(items)) { - modelToBuildList.add(MapperUtil.getLongRefClass(items)); - } - final Iterator> iterator = schema.fields(); - Entry current; - while (iterator.hasNext()) { - current = iterator.next(); - switch (current.getKey()) { - case "maxItems": - fieldObject.getRestrictions().setMaxItems(current.getValue().intValue()); - break; - case "minItems": - fieldObject.getRestrictions().setMinItems(current.getValue().intValue()); - break; - case "uniqueItems": - fieldObject.getRestrictions().setUniqueItems(current.getValue().booleanValue()); - break; - default: - break; - } - } - fieldObject.setRequired(required); - } - - @SuppressWarnings("checkstyle:CyclomaticComplexity") - private static void setFieldProperties(final SchemaFieldObject fieldObject, final JsonNode schema) { - final Iterator> iterator = schema.fields(); - Entry current; - final SchemaFieldObjectProperties props = fieldObject.getRestrictions(); - while (iterator.hasNext()) { - current = iterator.next(); - switch (current.getKey()) { - case "minimum": - props.setMinimum(current.getValue().asText()); - break; - case "maximum": - props.setMaximum(current.getValue().asText()); - break; - case "exclusiveMinimum": - props.setExclusiveMinimum(current.getValue().booleanValue()); - break; - case "exclusiveMaximum": - props.setExclusiveMaximum(current.getValue().booleanValue()); - break; - case "maxItems": - props.setMaxItems(current.getValue().intValue()); - break; - case "maxLength": - props.setMaxLength(current.getValue().intValue()); - break; - case "minItems": - props.setMinItems(current.getValue().intValue()); - break; - case "minLength": - props.setMinLength(current.getValue().intValue()); - break; - case "pattern": - props.setPattern(current.getValue().toString().replace("\"", "")); - break; - case "uniqueItems": - props.setUniqueItems(current.getValue().booleanValue()); - break; - case "multipleOf": - props.setMultipleOf(current.getValue().asText()); - break; - default: - break; - } - } - } - - private static void setFormatProperies(final SchemaFieldObject fieldObject, final String dataType, final Map formats) { - if (Objects.equals(dataType, LOCAL_DATE)) { - fieldObject.getRestrictions().setFormat(formats.get("DATE")); - } else if (Objects.equals(dataType, LOCAL_DATE_TIME)) { - fieldObject.getRestrictions().setFormat(formats.get("DATE_TIME")); - } - } - - private static void setFieldType(final SchemaFieldObject field, final JsonNode value, final boolean required, final String prefix, final String suffix, final String className, - final Map formats, final TimeType useTimeType) { - field.setRequired(required); - if (ApiTool.hasType(value)) { - if (ARRAY.equalsIgnoreCase(ApiTool.getType(value))) { - final var typeArray = MapperUtil.getTypeArray(value, prefix, suffix, useTimeType); - field.setDataType(typeArray); - field.setImportClass(getImportClass(typeArray)); - setFormatProperies(field, typeArray, formats); - } else if (ApiTool.getType(value).equalsIgnoreCase(OBJECT)) { - if (value.has("additionalProperties")) { - final var typeMap = MapperUtil.getTypeMap(value, prefix, suffix, useTimeType); - field.setDataTypeSimple(MAP); - field.setDataType(typeMap); - field.setImportClass(getImportClass(typeMap)); - } else { - var typeObject = ""; - if (ApiTool.hasRef(value)) { - typeObject = MapperUtil.getRef(value, prefix, suffix); - } else { - 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); - field.setDataTypeSimple(typeObject); - } - } else { - throw new NonSupportedSchemaException(value.toPrettyString()); - } - } - } - - private static SchemaFieldObject processEnumField(final String name, final boolean required, final JsonNode value, final String prefix, - final String suffix, final TimeType useTimeType) { - final List enumValues = new ArrayList<>(); - value.get("enum").elements().forEachRemaining(enumValue -> enumValues.add(enumValue.textValue())); - - if (enumValues.isEmpty()) { - throw new BadDefinedEnumException(name); - } - - return SchemaFieldObject - .builder() - .baseName(name) - .dataTypeSimple("enum") - .dataType(MapperUtil.getSimpleType(value, prefix, suffix, useTimeType)) - .required(required) - .enumValues(enumValues) - .restrictions(new SchemaFieldObjectProperties()) - .build(); - } - - private static String getImportClass(final String type) { - return StringUtils.isNotBlank(type) && !"String".equals(type) && !"Integer".equals(type) ? type : ""; - } } diff --git a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/asyncapi/util/MapperUtil.java b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/asyncapi/util/MapperUtil.java deleted file mode 100644 index cf536e62..00000000 --- a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/asyncapi/util/MapperUtil.java +++ /dev/null @@ -1,174 +0,0 @@ -/* - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at https://mozilla.org/MPL/2.0/. - */ - -package com.sngular.api.generator.plugin.asyncapi.util; - -import java.util.Objects; - -import com.fasterxml.jackson.databind.JsonNode; -import com.sngular.api.generator.plugin.common.model.TimeType; -import com.sngular.api.generator.plugin.common.tools.ApiTool; -import org.apache.commons.lang3.ArrayUtils; -import org.apache.commons.lang3.StringUtils; - -public class MapperUtil { - - public static final String INTEGER = "integer"; - - public static final String DOUBLE = "double"; - - public static final String FLOAT = "float"; - - public static final String NUMBER = "number"; - - public static final String INT_64 = "int64"; - - public static final String LONG = "long"; - - public static final String DATE = "date"; - - public static final String DATE_TIME = "date-time"; - - public static final String BIG_DECIMAL = "BigDecimal"; - - public static final String LOCAL_DATE = "LocalDate"; - - public static final String LOCAL_DATE_TIME = "LocalDateTime"; - - public static final String ZONED_DATE_TIME = "ZonedDateTime"; - - public static final String REF = "$ref"; - - private static final String DIVISOR = "([./])"; - - private static final String SLASH = "/"; - - private MapperUtil() {} - - public static String getSimpleType(final JsonNode schema, final String prefix, final String suffix, - final TimeType useTimeType) { - String type = schema.textValue(); - if (schema.has("type")) { - type = schema.get("type").textValue(); - String format = null; - if ("string".equalsIgnoreCase(type)) { - type = "String"; - } - if (schema.has("format")) { - format = schema.get("format").textValue(); - } - if ("string".equalsIgnoreCase(type)) { - type = formatTypeOfString(format, useTimeType); - } else if (NUMBER.equalsIgnoreCase(type)) { - if (FLOAT.equalsIgnoreCase(format)) { - type = StringUtils.capitalize(FLOAT); - } else if (DOUBLE.equalsIgnoreCase(format)) { - type = StringUtils.capitalize(DOUBLE); - } else { - type = StringUtils.capitalize(BIG_DECIMAL); - } - } else if (INTEGER.equalsIgnoreCase(type)) { - if (INT_64.equalsIgnoreCase(format)) { - type = StringUtils.capitalize(LONG); - } else { - type = StringUtils.capitalize(INTEGER); - } - } - } else if (schema.has(REF)) { - type = getRef(schema, prefix, suffix); - } - return type; - } - - public static String formatTypeOfString(final String format, final TimeType useTimeType) { - String type = "String"; - if (format != null) { - if (DATE_TIME.equalsIgnoreCase(format)) { - if (Objects.requireNonNull(useTimeType) == TimeType.ZONED) { - type = ZONED_DATE_TIME; - } else { - type = LOCAL_DATE_TIME; - } - - } else if (DATE.equalsIgnoreCase(format)) { - type = LOCAL_DATE; - } - } - return type; - } - - public static String getRef(final JsonNode schema, final String prefix, final String suffix) { - return getPojoName(getRefClass(schema), prefix, suffix); - } - - public static String getLongRefClass(final JsonNode schema) { - final String[] pathObjectRef = getStrings(schema); - return pathObjectRef[pathObjectRef.length - 2] + "/" + pathObjectRef[pathObjectRef.length - 1]; - } - - private static String[] getStrings(final JsonNode schema) { - return splitName(schema.get(REF).textValue()); - } - - public static String getRefClass(final JsonNode schema) { - final String[] pathObjectRef = getStrings(schema); - return pathObjectRef[pathObjectRef.length - 1]; - } - - public static String getTypeMap(final JsonNode mapSchema, final String prefix, final String suffix, final TimeType useTimeType) { - var typeMap = ""; - final var mapNode = mapSchema.get("additionalProperties"); - final var mapValueType = mapNode.findPath("type"); - typeMap = getCollectionType(mapNode, mapValueType, prefix, suffix, useTimeType); - return typeMap; - } - - public static String getTypeArray(final JsonNode array, final String prefix, final String suffix, final TimeType useTimeType) { - var typeArray = ""; - final var arrayNode = array.get("items"); - final JsonNode mapValueType; - if (arrayNode.has("type")) { - mapValueType = arrayNode.get("type"); - } else { - mapValueType = arrayNode.get(REF); - } - typeArray = getCollectionType(arrayNode, mapValueType, prefix, suffix, useTimeType); - return typeArray; - } - - private static String getCollectionType(final JsonNode mapNode, final JsonNode mapValueType, final String prefix, - final String suffix, final TimeType useTimeType) { - var typeMap = mapValueType.textValue(); - if (!typeMap.contains("#")) { - typeMap = getSimpleType(mapNode, prefix, suffix, useTimeType); - } else { - final var valueSchema = mapNode.findPath(REF); - if (Objects.nonNull(valueSchema)) { - getRef(valueSchema, prefix, suffix); - } - } - return typeMap; - } - - public static String getPojoName(final String namePojo, final String prefix, final String suffix) { - return StringUtils.defaultIfBlank(prefix, "") - + StringUtils.capitalize(namePojo) - + StringUtils.defaultIfBlank(suffix, ""); - } - - public static String[] splitName(final String name) { - return ArrayUtils.removeAllOccurrences(name.split(DIVISOR), ""); - } - - public static String buildKey(final String[] pathList) { - final var arrayLength = pathList.length; - return (arrayLength > 2 ? pathList[arrayLength - 2] + SLASH + pathList[arrayLength - 1] : pathList[0]).toUpperCase(); - } - - protected static Object getConstValue(final JsonNode schema) { - return ApiTool.hasNode(schema, "const") ? ApiTool.getNodeAsObject(schema, "const") : null; - } -} diff --git a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/asyncapi/util/ReferenceProcessor.java b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/asyncapi/util/ReferenceProcessor.java index 29d831f0..21d34420 100644 --- a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/asyncapi/util/ReferenceProcessor.java +++ b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/asyncapi/util/ReferenceProcessor.java @@ -11,6 +11,7 @@ import com.sngular.api.generator.plugin.asyncapi.exception.NonSupportedSchemaException; import com.sngular.api.generator.plugin.common.files.FileLocation; import com.sngular.api.generator.plugin.common.tools.ApiTool; +import com.sngular.api.generator.plugin.common.tools.MapperUtil; import lombok.Builder; public final class ReferenceProcessor { diff --git a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/model/CommonSpecFile.java b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/model/CommonSpecFile.java new file mode 100644 index 00000000..a05190ed --- /dev/null +++ b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/model/CommonSpecFile.java @@ -0,0 +1,43 @@ +package com.sngular.api.generator.plugin.common.model; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; +import lombok.experimental.SuperBuilder; + +import java.util.Map; + +@Data +@SuperBuilder(toBuilder = true) +@NoArgsConstructor +@AllArgsConstructor +public class CommonSpecFile { + + private String filePath; + + private String apiPackage; + + private String modelPackage; + + private String modelNamePrefix; + + private String modelNameSuffix; + + private String classNamePostfix; + + private boolean useLombokModelAnnotation; + + @Builder.Default + private String dateTimeFormat = "yyyy-MM-dd'T'HH:mm:ss"; + + @Builder.Default + private String dateFormat = "yyyy-MM-dd"; + + @Builder.Default + private TypeConstants.TimeType useTimeType = TypeConstants.TimeType.LOCAL; + + public Map getFormats() { + return Map.of("DATE_TIME", dateTimeFormat, "DATE", dateFormat); + } +} diff --git a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/model/SchemaFieldObject.java b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/model/SchemaFieldObject.java new file mode 100644 index 00000000..b9688889 --- /dev/null +++ b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/model/SchemaFieldObject.java @@ -0,0 +1,28 @@ +package com.sngular.api.generator.plugin.common.model; + +import lombok.*; + +import java.util.Map; + +@Data +@Builder +@AllArgsConstructor +@EqualsAndHashCode(of = "baseName") +public class SchemaFieldObject { + + private String baseName; + + @Builder.Default + private SchemaFieldObjectType dataType = new SchemaFieldObjectType(TypeConstants.OBJECT); + + @Builder.Default + private SchemaFieldObjectProperties restrictions = new SchemaFieldObjectProperties(); + + private String importClass; + + private boolean required; + + private Map enumValues; + + private Object constValue; +} diff --git a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/asyncapi/model/SchemaFieldObjectProperties.java b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/model/SchemaFieldObjectProperties.java similarity index 97% rename from multiapi-engine/src/main/java/com/sngular/api/generator/plugin/asyncapi/model/SchemaFieldObjectProperties.java rename to multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/model/SchemaFieldObjectProperties.java index 7c01695e..0e961b52 100644 --- a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/asyncapi/model/SchemaFieldObjectProperties.java +++ b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/model/SchemaFieldObjectProperties.java @@ -1,4 +1,4 @@ -package com.sngular.api.generator.plugin.asyncapi.model; +package com.sngular.api.generator.plugin.common.model; import java.util.HashSet; import java.util.Objects; 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/common/model/SchemaFieldObjectType.java similarity index 99% rename from multiapi-engine/src/main/java/com/sngular/api/generator/plugin/openapi/model/SchemaFieldObjectType.java rename to multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/model/SchemaFieldObjectType.java index 5b8de712..fbfb1f4f 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/common/model/SchemaFieldObjectType.java @@ -4,7 +4,7 @@ * * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ -package com.sngular.api.generator.plugin.openapi.model; +package com.sngular.api.generator.plugin.common.model; import java.util.AbstractMap.SimpleImmutableEntry; import java.util.Map; diff --git a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/model/SchemaObject.java b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/model/SchemaObject.java new file mode 100644 index 00000000..51146538 --- /dev/null +++ b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/model/SchemaObject.java @@ -0,0 +1,56 @@ +package com.sngular.api.generator.plugin.common.model; + +import lombok.*; + +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +@Data +@Builder(toBuilder = true) +@NoArgsConstructor +@AllArgsConstructor +@EqualsAndHashCode(of = {"schemaName", "className"}) +public class SchemaObject { + private boolean isEnum; + + private String schemaName; + + private String className; + + private List importList; + + private Set fieldObjectList; + + private String schemaCombinator; + + private String parentPackage; + + public static final class SchemaObjectBuilder { + + private final List importList = new ArrayList<>(); + + private final Set fieldObjectList = new HashSet<>(); + + public SchemaObjectBuilder importList(final List importList) { + this.importList.addAll(importList); + return this; + } + + public SchemaObjectBuilder importItem(final String importItem) { + this.importList.add(importItem); + return this; + } + + public SchemaObjectBuilder fieldObjectList(final Set fieldObjectList) { + this.fieldObjectList.addAll(fieldObjectList); + return this; + } + + public SchemaObjectBuilder fieldObject(final SchemaFieldObject fieldObject) { + this.fieldObjectList.add(fieldObject); + return this; + } + } +} diff --git a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/model/TimeType.java b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/model/TimeType.java deleted file mode 100644 index baada72c..00000000 --- a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/model/TimeType.java +++ /dev/null @@ -1,6 +0,0 @@ -package com.sngular.api.generator.plugin.common.model; - -public enum TimeType { - LOCAL, - ZONED -} diff --git a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/openapi/model/TypeConstants.java b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/model/TypeConstants.java similarity index 98% rename from multiapi-engine/src/main/java/com/sngular/api/generator/plugin/openapi/model/TypeConstants.java rename to multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/model/TypeConstants.java index 24ba8e09..da239494 100644 --- a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/openapi/model/TypeConstants.java +++ b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/model/TypeConstants.java @@ -4,7 +4,7 @@ * * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ -package com.sngular.api.generator.plugin.openapi.model; +package com.sngular.api.generator.plugin.common.model; import java.util.Set; 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 ba333417..f37eb7d3 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 @@ -20,7 +20,7 @@ import com.fasterxml.jackson.dataformat.yaml.YAMLFactory; import com.sngular.api.generator.plugin.asyncapi.util.FactoryTypeEnum; import com.sngular.api.generator.plugin.common.files.FileLocation; -import com.sngular.api.generator.plugin.openapi.model.TypeConstants; +import com.sngular.api.generator.plugin.common.model.TypeConstants; import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.collections4.IteratorUtils; import org.apache.commons.collections4.Transformer; diff --git a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/openapi/utils/MapperUtil.java b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/tools/MapperUtil.java similarity index 62% rename from multiapi-engine/src/main/java/com/sngular/api/generator/plugin/openapi/utils/MapperUtil.java rename to multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/tools/MapperUtil.java index 55ad86bf..988e4dbe 100644 --- a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/openapi/utils/MapperUtil.java +++ b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/tools/MapperUtil.java @@ -4,20 +4,50 @@ * * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ -package com.sngular.api.generator.plugin.openapi.utils; +package com.sngular.api.generator.plugin.common.tools; import com.fasterxml.jackson.databind.JsonNode; -import com.sngular.api.generator.plugin.common.tools.ApiTool; -import com.sngular.api.generator.plugin.openapi.model.TypeConstants; -import com.sngular.api.generator.plugin.openapi.parameter.SpecFile; +import com.sngular.api.generator.plugin.common.model.CommonSpecFile; +import com.sngular.api.generator.plugin.common.model.TypeConstants; +import org.apache.commons.lang3.ArrayUtils; import org.apache.commons.lang3.ObjectUtils; import org.apache.commons.lang3.StringUtils; public class MapperUtil { + private static final String INTEGER = "integer"; + + private static final String DOUBLE = "double"; + + private static final String FLOAT = "float"; + + private static final String NUMBER = "number"; + + private static final String INT_64 = "int64"; + + private static final String LONG = "long"; + + private static final String DATE = "date"; + + private static final String DATE_TIME = "date-time"; + + private static final String BIG_DECIMAL = "BigDecimal"; + + private static final String LOCAL_DATE = "LocalDate"; + + private static final String LOCAL_DATE_TIME = "LocalDateTime"; + + private static final String ZONED_DATE_TIME = "ZonedDateTime"; + + private static final String REF = "$ref"; + + private static final String DIVISOR = "([./])"; + + private static final String SLASH = "/"; + private MapperUtil() {} - public static String getSimpleType(final JsonNode schema, final SpecFile specFile) { + public static String getSimpleType(final JsonNode schema, final CommonSpecFile specFile) { final String type; final var nodeType = ApiTool.getType(schema); if (checkIfNumber(nodeType)) { @@ -32,16 +62,35 @@ public static String getSimpleType(final JsonNode schema, final SpecFile specFil return type; } + public static String[] splitName(final String name) { + return ArrayUtils.removeAllOccurrences(name.split(DIVISOR), ""); + } + + public static String buildKey(final String[] pathList) { + final var arrayLength = pathList.length; + return (arrayLength > 2 ? pathList[arrayLength - 2] + SLASH + pathList[arrayLength - 1] : pathList[0]).toUpperCase(); + } + public static String getRefSchemaName(final JsonNode parameter) { final String[] pathObjectRef = ApiTool.getRefValue(parameter).split("/"); return pathObjectRef[pathObjectRef.length - 1]; } + public static String getRefSchemaKey(final JsonNode parameter) { + final String[] pathObjectRef = ApiTool.getRefValue(parameter).split("/"); + return StringUtils.upperCase(pathObjectRef[pathObjectRef.length - 2] + "/" + pathObjectRef[pathObjectRef.length - 1]); + } + public static String getRefSchemaName(final String parameter) { final String[] pathObjectRef = parameter.split("/"); return pathObjectRef[pathObjectRef.length - 1]; } + public static String getRefSchemaKey(final String parameter) { + final String[] pathObjectRef = parameter.split("/"); + return StringUtils.upperCase(pathObjectRef[pathObjectRef.length - 2] + "/" + pathObjectRef[pathObjectRef.length - 1]); + } + private static boolean checkIfNumber(final String nodeType) { return TypeConstants.NUMBER.equalsIgnoreCase(nodeType) || TypeConstants.INTEGER.equalsIgnoreCase(nodeType) || TypeConstants.INT_32.equalsIgnoreCase(nodeType) || TypeConstants.INT_64.equalsIgnoreCase(nodeType); @@ -70,7 +119,7 @@ private static String processNumber(final JsonNode schema) { return type; } - public static String getTypeArray(final JsonNode array, final SpecFile specFile) { + public static String getTypeArray(final JsonNode array, final CommonSpecFile specFile) { var typeArray = ""; if (ApiTool.isString(ApiTool.getItems(array))) { typeArray = TypeConstants.STRING; @@ -82,19 +131,19 @@ public static String getTypeArray(final JsonNode array, final SpecFile specFile) return typeArray; } - public static String getPojoName(final String namePojo, final SpecFile specFile) { + public static String getPojoName(final String namePojo, final CommonSpecFile specFile) { return (StringUtils.isNotBlank(specFile.getModelNamePrefix()) ? specFile.getModelNamePrefix() : "") + StringUtils.capitalize(namePojo) + (StringUtils.isNotBlank(specFile.getModelNameSuffix()) ? specFile.getModelNameSuffix() : ""); } - public static String getRef(final JsonNode schema, final SpecFile specFile) { + public static String getRef(final JsonNode schema, final CommonSpecFile specFile) { final String typeObject; typeObject = getPojoName(getRefSchemaName(schema), specFile); return typeObject; } - public static String getDateType(final JsonNode schema, final SpecFile specFile) { + public static String getDateType(final JsonNode schema, final CommonSpecFile specFile) { final String dateType; switch (ApiTool.getFormat(schema)) { @@ -127,4 +176,18 @@ public static String getDateType(final JsonNode schema, final SpecFile specFile) } return dateType; } + + public static String getRefClass(final JsonNode schema) { + final String[] pathObjectRef = getStrings(schema); + return pathObjectRef[pathObjectRef.length - 1]; + } + + private static String[] getStrings(final JsonNode schema) { + return splitName(schema.get(REF).textValue()); + } + + public static String getLongRefClass(final JsonNode schema) { + final String[] pathObjectRef = getStrings(schema); + return pathObjectRef[pathObjectRef.length - 2] + "/" + pathObjectRef[pathObjectRef.length - 1]; + } } diff --git a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/tools/ModelBuilder.java b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/tools/ModelBuilder.java new file mode 100644 index 00000000..10fe2220 --- /dev/null +++ b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/tools/ModelBuilder.java @@ -0,0 +1,738 @@ +package com.sngular.api.generator.plugin.common.tools; + +import com.fasterxml.jackson.databind.JsonNode; +import com.sngular.api.generator.plugin.common.model.*; +import com.sngular.api.generator.plugin.openapi.exception.BadDefinedEnumException; +import org.apache.commons.lang3.ObjectUtils; +import org.apache.commons.lang3.StringUtils; +import org.apache.commons.text.WordUtils; + +import java.nio.file.Path; +import java.util.*; +import java.util.function.Consumer; + +public final class ModelBuilder { + + private static final String ADDITIONAL_PROPERTY_NAME = "AdditionalProperty"; + + private static final String ANY_OF_COMBINATOR = "anyOf"; + + private static final String ONE_OF_COMBINATOR = "oneOf"; + + private static final String ALL_OF_COMBINATOR = "allOf"; + + private static final String ADDITIONAL_PROPERTIES = "additionalProperties"; + + + public static SchemaObject buildSchemaObject( + final Map totalSchemas, final String className, final JsonNode model, + final Set antiLoopList, final Map compositedSchemas, final String parentPackage, final CommonSpecFile specFile, + final Path baseDir) { + + antiLoopList.add(WordUtils.capitalizeFully(className)); + + final var listSchema = getFields(null, totalSchemas, model, specFile, compositedSchemas, antiLoopList, WordUtils.capitalizeFully(className), baseDir); + + final var schemaBuilder = SchemaObject.builder() + .schemaName(WordUtils.capitalizeFully(className)) + .className(MapperUtil.getPojoName(className, specFile)) + .importList(getImportList(listSchema, specFile.getModelPackage())); + + if (ApiTool.isAllOf(model)) { + schemaBuilder.schemaCombinator(ALL_OF_COMBINATOR); + } else if (ApiTool.isAnyOf(model)) { + schemaBuilder.schemaCombinator(ANY_OF_COMBINATOR); + } else if (ApiTool.isOneOf(model)) { + schemaBuilder.schemaCombinator(ONE_OF_COMBINATOR); + } else { + schemaBuilder.schemaCombinator(""); + } + + return schemaBuilder + .fieldObjectList(listSchema) + .parentPackage(parentPackage.toLowerCase()) + .build(); + } + + private static List getImportList(final Set fieldObjectList, final String modelPackage) { + final var listHashMap = new HashMap>(); + final var importList = new ArrayList(); + + for (final var fieldObject : fieldObjectList) { + getTypeImports(listHashMap, fieldObject); + if (StringUtils.isNotBlank(fieldObject.getImportClass()) + && !listHashMap.containsKey(fieldObject.getImportClass()) + && !fieldObject.getDataType().containsType("enum")) { + listHashMap.put(StringUtils.capitalize(fieldObject.getImportClass()), + List.of(modelPackage + "." + StringUtils.capitalize(fieldObject.getImportClass()))); + } + } + if (!listHashMap.isEmpty()) { + listHashMap.forEach((key, value) -> importList.addAll(value)); + } + return importList; + } + + private static void getTypeImports( + final HashMap> listHashMap, + final SchemaFieldObject fieldObject) { + final SchemaFieldObjectType type = fieldObject.getDataType(); + if (type.containsType(TypeConstants.ARRAY)) { + listHashMap.computeIfAbsent(TypeConstants.ARRAY, key -> List.of("java.util.List", "java.util.ArrayList")); + } + + if (type.containsType(TypeConstants.MAP)) { + listHashMap.computeIfAbsent(TypeConstants.MAP, key -> List.of("java.util.Map", "java.util.HashMap")); + } + + if (type.containsType(TypeConstants.BIG_DECIMAL)) { + listHashMap.computeIfAbsent(TypeConstants.BIG_DECIMAL, key -> List.of("java.math.BigDecimal")); + } + + if (type.containsType(TypeConstants.LOCALDATE)) { + listHashMap.computeIfAbsent(TypeConstants.LOCALDATE, key -> List.of("java.time.LocalDate")); + } + + if (type.containsType(TypeConstants.LOCALDATETIME)) { + listHashMap.computeIfAbsent(TypeConstants.LOCALDATETIME, key -> List.of("java.time.LocalDateTime")); + } + + if (type.containsType(TypeConstants.ZONEDDATE)) { + listHashMap.computeIfAbsent(TypeConstants.ZONEDDATETIME, key -> List.of("java.time.ZonedDateTime")); + } + + if (type.containsType(TypeConstants.ZONEDDATETIME)) { + listHashMap.computeIfAbsent(TypeConstants.ZONEDDATETIME, key -> List.of("java.time.ZonedDateTime")); + } + + if (type.containsType(TypeConstants.OFFSETDATE)) { + listHashMap.computeIfAbsent(TypeConstants.OFFSETDATETIME, key -> List.of("java.time.OffsetDateTime")); + } + + if (type.containsType(TypeConstants.OFFSETDATETIME)) { + listHashMap.computeIfAbsent(TypeConstants.OFFSETDATETIME, key -> List.of("java.time.OffsetDateTime")); + } + } + + private static Set getFields(final String buildingSchema, + final Map totalSchemas, final JsonNode schema, final CommonSpecFile specFile, + final Map compositedSchemas, final Set antiLoopList, final String nameSchema, + final Path baseDir) { + final Set fieldObjectArrayList = new HashSet<>(); + + if (ApiTool.hasProperties(schema)) { + if (ApiTool.hasAdditionalProperties(schema)) { + ApiTool.getProperties(schema).forEachRemaining(processProperties(buildingSchema, totalSchemas, compositedSchemas, fieldObjectArrayList, specFile, schema, antiLoopList, + baseDir)); + fieldObjectArrayList.addAll(processAdditionalProperties(ADDITIONAL_PROPERTIES, schema, specFile, totalSchemas, compositedSchemas, antiLoopList, nameSchema, baseDir)); + } else { + ApiTool.getProperties(schema).forEachRemaining(processProperties(buildingSchema, totalSchemas, compositedSchemas, fieldObjectArrayList, specFile, schema, antiLoopList, + baseDir)); + } + } else if (TypeConstants.ARRAY.equalsIgnoreCase(ApiTool.getType(schema))) { + final String itemType = ApiTool.hasRef(ApiTool.getItems(schema)) ? MapperUtil.getRef(ApiTool.getItems(schema), specFile) : ApiTool.getType(ApiTool.getItems(schema)); + fieldObjectArrayList.add(SchemaFieldObject.builder() + .baseName("items") + .dataType(SchemaFieldObjectType.fromTypeList(TypeConstants.ARRAY, itemType)) + .build()); + } else if (ApiTool.isAllOf(schema)) { + fieldObjectArrayList.addAll(processAllOf(totalSchemas, ApiTool.getAllOf(schema), specFile, compositedSchemas, antiLoopList, baseDir)); + } else if (ApiTool.isAnyOf(schema)) { + fieldObjectArrayList.addAll(processAnyOfOneOf(buildingSchema, totalSchemas, ApiTool.getAnyOf(schema), specFile, compositedSchemas, antiLoopList, baseDir)); + } else if (ApiTool.isOneOf(schema)) { + fieldObjectArrayList.addAll(processAnyOfOneOf(buildingSchema, totalSchemas, ApiTool.getOneOf(schema), specFile, compositedSchemas, antiLoopList, baseDir)); + } else if (ApiTool.isEnum(schema)) { + fieldObjectArrayList.add(processEnumField(ApiTool.getName(schema), schema, specFile, ApiTool.getEnumValues(schema), schema)); + } else if (ApiTool.hasRef(schema)) { + final var refSchema = totalSchemas.get(MapperUtil.getRefSchemaKey(schema)); + ApiTool.getProperties(refSchema).forEachRemaining(processProperties(buildingSchema, totalSchemas, compositedSchemas, fieldObjectArrayList, specFile, schema, antiLoopList, + baseDir)); + } else { + fieldObjectArrayList.add(SchemaFieldObject.builder() + .baseName(ApiTool.getName(schema)) + .dataType(new SchemaFieldObjectType(MapperUtil.getSimpleType(schema, specFile))) + .build()); + } + + return fieldObjectArrayList; + } + + + @SuppressWarnings("checkstyle:CyclomaticComplexity") + private static List processFieldObjectList(final String buildingSchema, + final String fieldName, final String className, final JsonNode schema, final CommonSpecFile specFile, + final Map totalSchemas, final Map compositedSchemas, + final Set antiLoopList, final Path baseDir) { + final var fieldObjectArrayList = new ArrayList(); + + if (TypeConstants.ARRAY.equalsIgnoreCase(ApiTool.getType(schema))) { + fieldObjectArrayList.addAll(processArray(fieldName, className, schema, specFile, totalSchemas, compositedSchemas, antiLoopList, baseDir)); + } else if (ApiTool.hasAdditionalProperties(schema)) { + fieldObjectArrayList.addAll(processMap(fieldName, schema, specFile, totalSchemas, compositedSchemas, antiLoopList, baseDir)); + } else if (ApiTool.hasRef(schema)) { + fieldObjectArrayList.add( + processRef(fieldName, schema, new SchemaFieldObjectType(MapperUtil.getSimpleType(schema, specFile)), totalSchemas, compositedSchemas, antiLoopList, specFile, baseDir)); + } else if (ApiTool.isObject(schema) && !ApiTool.hasProperties(schema)) { + fieldObjectArrayList.add(SchemaFieldObject + .builder() + .baseName(fieldName) + .dataType(new SchemaFieldObjectType(TypeConstants.OBJECT)) + .build()); + } else if (ApiTool.isEnum(schema)) { + fieldObjectArrayList.add(processEnumField(fieldName, schema, specFile, ApiTool.getEnumValues(schema), schema)); + } else if (!ApiTool.hasProperties(schema) && !ApiTool.isComposed(schema)) { + fieldObjectArrayList.add(SchemaFieldObject + .builder() + .baseName(fieldName) + .dataType(new SchemaFieldObjectType(TypeConstants.OBJECT)) + .build()); + } else if (ApiTool.isObject(schema)) { + fieldObjectArrayList.addAll(processObject(fieldName, className, schema, specFile, totalSchemas, compositedSchemas, antiLoopList, baseDir)); + } else { + final var composedSchemaName = StringUtils.defaultIfBlank(className, fieldName); + var schemaObjectComposed = compositedSchemas.get(composedSchemaName); + if (Objects.isNull(schemaObjectComposed)) { + schemaObjectComposed = createComposedSchema(buildingSchema, StringUtils.defaultIfBlank(className, fieldName), schema, specFile, + totalSchemas, compositedSchemas, antiLoopList, baseDir); + compositedSchemas.put(composedSchemaName, schemaObjectComposed); + } + + fieldObjectArrayList.add(SchemaFieldObject + .builder() + .baseName(fieldName) + .dataType(SchemaFieldObjectType.fromTypeList(schemaObjectComposed.getClassName(), schemaObjectComposed.getClassName())) + .build()); + } + + return fieldObjectArrayList; + } + + private static Consumer> processProperties(final String buildingSchema, + final Map totalSchemas, final Map compositedSchemas, final Set fieldObjectArrayList, final CommonSpecFile specFile, + final JsonNode schema, final Set antiLoopList, final Path baseDir) { + return field -> { + final var nodeName = field.getKey(); + final var nodeValue = field.getValue(); + if (ApiTool.isEnum(field.getValue())) { + fieldObjectArrayList.add(processEnumField(nodeName, nodeValue, specFile, ApiTool.getEnumValues(nodeValue), schema)); + } else { + fieldObjectArrayList.addAll(processObjectProperty(buildingSchema, totalSchemas, nodeName, nodeValue, compositedSchemas, specFile, schema, antiLoopList, baseDir)); + } + }; + } + + @SuppressWarnings({"checkstyle:CyclomaticComplexity", "checkstyle:ParameterNumber"}) + private static List processObjectProperty(final String buildingSchema, + final Map totalSchemas, final String fieldName, final JsonNode fieldBody, final Map compositedSchemas, final CommonSpecFile specFile, + final JsonNode schema, final Set antiLoopList, final Path baseDir) { + final List fieldObjectArrayList = new LinkedList<>(); + final var isRequired = ApiTool.checkIfRequired(fieldBody, fieldName); + final SchemaFieldObject field; + if (ApiTool.hasRef(fieldBody)) { + final var typeName = MapperUtil.getRefSchemaName(fieldBody); + final var refSchema = totalSchemas.get(MapperUtil.getRefSchemaKey(fieldBody)); + if (!antiLoopList.contains(typeName) && Objects.nonNull(refSchema) && ApiTool.hasType(refSchema) + && ApiTool.hasItems(refSchema) || ApiTool.getRefValue(fieldBody).contains(fieldName)) { + antiLoopList.add(typeName); + fieldObjectArrayList.addAll(processFieldObjectList(buildingSchema, fieldName, typeName, refSchema, specFile, totalSchemas, compositedSchemas, + antiLoopList, baseDir)); + } else if (ApiTool.isEnum(refSchema)) { + fieldObjectArrayList.add(processEnumField(fieldName, refSchema, specFile, ApiTool.getEnumValues(refSchema), schema)); + } else { + compositedSchemas.put(typeName, buildSchemaObject(totalSchemas, typeName, refSchema, antiLoopList, compositedSchemas, "", specFile, baseDir )); + fieldObjectArrayList.add(SchemaFieldObject + .builder() + .baseName(fieldName) + .required(ApiTool.checkIfRequired(schema, fieldName)) + .dataType(SchemaFieldObjectType.fromTypeList(MapperUtil.getSimpleType(refSchema, specFile), + MapperUtil.getPojoName(typeName, specFile))) + .build()); + } + } else if (ApiTool.isEnum(fieldBody)) { + fieldObjectArrayList.add(processEnumField(fieldName, fieldBody, specFile, ApiTool.getEnumValues(fieldBody), fieldBody)); + } else if (TypeConstants.STRING.equalsIgnoreCase(ApiTool.getType(fieldBody))) { + field = processStringProperty(fieldName, fieldBody, specFile); + setFieldType(field, fieldBody, schema, specFile, fieldName); + fieldObjectArrayList.add(field); + } else if (isBasicType(fieldBody)) { + field = SchemaFieldObject + .builder() + .baseName(fieldName) + .required(isRequired) + .dataType(new SchemaFieldObjectType(MapperUtil.getSimpleType(fieldBody, specFile))) + .build(); + addPropertiesToFieldObject(field, fieldBody); + setFieldType(field, fieldBody, schema, specFile, fieldName); + fieldObjectArrayList.add(field); + } else { + fieldObjectArrayList.addAll(processFieldObjectList(buildingSchema, fieldName, fieldName, fieldBody, specFile, totalSchemas, compositedSchemas, antiLoopList, baseDir)); + } + return fieldObjectArrayList; + } + + private static SchemaFieldObject processStringProperty(final String propertyName, final JsonNode schema, final CommonSpecFile specFile) { + final String resultingType = ApiTool.isDateTime(schema) ? MapperUtil.getDateType(schema, specFile) : TypeConstants.STRING; + + final SchemaFieldObject field = SchemaFieldObject + .builder() + .baseName(propertyName) + .required(ApiTool.checkIfRequired(schema, propertyName)) + .dataType(new SchemaFieldObjectType(resultingType)) + .build(); + addPropertiesToFieldObject(field, schema); + return field; + } + + @SuppressWarnings("checkstyle:CyclomaticComplexity") + private static void addPropertiesToFieldObject(final SchemaFieldObject fieldObject, final JsonNode value) { + final var restrictionList = ApiTool.getFieldIterator(value); + while (restrictionList.hasNext()) { + final var restriction = restrictionList.next(); + switch (restriction.getKey()) { + case "pattern": + fieldObject.getRestrictions().setPattern(restriction.getValue().asText()); + break; + case "maxItems": + fieldObject.getRestrictions().setMaxItems(restriction.getValue().asInt()); + break; + case "minItems": + fieldObject.getRestrictions().setMinItems(restriction.getValue().asInt()); + break; + case "maxLength": + fieldObject.getRestrictions().setMaxLength(restriction.getValue().asInt()); + break; + case "minLength": + fieldObject.getRestrictions().setMinLength(restriction.getValue().asInt()); + break; + case "uniqueItems": + fieldObject.getRestrictions().setUniqueItems(restriction.getValue().asBoolean()); + break; + case "exclusiveMaximum": + fieldObject.getRestrictions().setExclusiveMaximum(restriction.getValue().asBoolean()); + break; + case "exclusiveMinimum": + fieldObject.getRestrictions().setExclusiveMinimum(restriction.getValue().asBoolean()); + break; + case "multipleOf": + fieldObject.getRestrictions().setMultipleOf(restriction.getValue().asText()); + break; + case "maximum": + fieldObject.getRestrictions().setMaximum(restriction.getValue().asText()); + break; + case "minimum": + fieldObject.getRestrictions().setMinimum(restriction.getValue().asText()); + break; + default: + break; + } + } + } + + @SuppressWarnings("checkstyle:ParameterNumber") + private static List processArray( + final String fieldName, final String className, final JsonNode schema, final CommonSpecFile specFile, final Map totalSchemas, + final Map compositedSchemas, final Set antiLoopList, final Path baseDir) { + final List fieldObjectArrayList = new LinkedList<>(); + + if (!ApiTool.hasItems(schema)) { + fieldObjectArrayList.add(SchemaFieldObject + .builder() + .baseName(fieldName) + .dataType(new SchemaFieldObjectType(TypeConstants.OBJECT)) + .build()); + } else { + final var items = ApiTool.getItems(schema); + if (ApiTool.hasRef(items)) { + fieldObjectArrayList.add( + processRef(fieldName, items, SchemaFieldObjectType.fromTypeList(TypeConstants.ARRAY, MapperUtil.getSimpleType(items, specFile)), totalSchemas, compositedSchemas, + antiLoopList, specFile, baseDir)); + } else if (ApiTool.isComposed(items)) { + final String composedSchemaName = StringUtils.defaultIfBlank(className, fieldName); + SchemaObject schemaObjectComposed = compositedSchemas.get(composedSchemaName); + if (Objects.isNull(schemaObjectComposed)) { + schemaObjectComposed = createComposedSchema("", StringUtils.defaultIfBlank(className, fieldName), items, specFile, + totalSchemas, compositedSchemas, antiLoopList, baseDir); + compositedSchemas.put(composedSchemaName, schemaObjectComposed); + } + + fieldObjectArrayList.add(SchemaFieldObject + .builder() + .baseName(fieldName) + .dataType(SchemaFieldObjectType.fromTypeList(TypeConstants.ARRAY, schemaObjectComposed.getClassName())) + .importClass(schemaObjectComposed.getClassName()) + .build()); + } else if (ApiTool.hasProperties(items)) { + final var itemsObject = buildSchemaObject(totalSchemas, className, items, antiLoopList, compositedSchemas, "", specFile, baseDir); + compositedSchemas.put(className, itemsObject); + fieldObjectArrayList.add(SchemaFieldObject + .builder() + .baseName(fieldName) + .dataType(SchemaFieldObjectType.fromTypeList(TypeConstants.ARRAY, MapperUtil.getPojoName(fieldName, specFile))) + .build()); + } else { + final SchemaFieldObject field = SchemaFieldObject + .builder() + .baseName(fieldName) + .dataType(SchemaFieldObjectType.fromTypeList(TypeConstants.ARRAY, MapperUtil.getSimpleType(items, specFile))) + .build(); + fieldObjectArrayList.add(field); + addPropertiesToFieldObject(field, schema); + } + } + + return fieldObjectArrayList; + } + + @SuppressWarnings("checkstyle:ParameterNumber") + private static Set processObject( + final String fieldName, final String className, final JsonNode schema, final CommonSpecFile specFile, + final Map totalSchemas, final Map compositedSchemas, + final Set antiLoopList, final Path baseDir) { + final Set fieldObjectArrayList = new HashSet<>(); + + if (ObjectUtils.allNull(className, fieldName)) { + ApiTool.getProperties(schema).forEachRemaining( + processProperties("", totalSchemas, compositedSchemas, fieldObjectArrayList, specFile, schema, antiLoopList, baseDir)); + } else if (antiLoopList.contains(className)) { + fieldObjectArrayList + .add(SchemaFieldObject + .builder() + .baseName(className) + .dataType(SchemaFieldObjectType.fromTypeList(TypeConstants.OBJECT, MapperUtil.getPojoName(className, specFile))) + .build()); + } else if (antiLoopList.contains(fieldName)) { + fieldObjectArrayList + .add(SchemaFieldObject + .builder() + .baseName(fieldName) + .dataType(SchemaFieldObjectType.fromTypeList(TypeConstants.OBJECT, MapperUtil.getPojoName(fieldName, specFile))) + .build()); + } else { + final String name = StringUtils.defaultIfBlank(className, fieldName); + final var itemsObject = buildSchemaObject(totalSchemas, className, schema, antiLoopList, compositedSchemas, "", specFile, baseDir); + compositedSchemas.put(className, itemsObject); + fieldObjectArrayList + .add(SchemaFieldObject + .builder() + .baseName(name) + .dataType(SchemaFieldObjectType.fromTypeList(TypeConstants.OBJECT, MapperUtil.getPojoName(name, specFile))) + .build()); + } + + return fieldObjectArrayList; + } + + private static Set processMap( + final String fieldName, final JsonNode schema, final CommonSpecFile specFile, final Map totalSchemas, + final Map compositedSchemas, final Set antiLoopList, final Path baseDir) { + final Set fieldObjectArrayList = new HashSet<>(); + + if (TypeConstants.OBJECT.equalsIgnoreCase(ApiTool.getType(schema)) && ApiTool.hasProperties(schema)) { + ApiTool.getProperties(schema).forEachRemaining( + processProperties("", totalSchemas, compositedSchemas, fieldObjectArrayList, specFile, schema, antiLoopList, baseDir)); + } + + if (ApiTool.hasAdditionalProperties(schema)) { + fieldObjectArrayList.addAll(processAdditionalProperties(fieldName, schema, specFile, totalSchemas, compositedSchemas, + antiLoopList, ADDITIONAL_PROPERTIES, baseDir)); + } + + return fieldObjectArrayList; + } + + private static List processAdditionalProperties( + final String fieldName, final JsonNode schema, final CommonSpecFile specFile, final Map totalSchemas, + final Map compositedSchemas, final Set antiLoopList, final String nameSchema, + final Path baseDir) { + final var fieldObjectArrayList = new ArrayList(); + + final var addPropObj = ApiTool.getAdditionalProperties(schema); + if (TypeConstants.isBoolean(addPropObj.asText())) { + fieldObjectArrayList + .add(SchemaFieldObject + .builder() + .baseName(fieldName) + .dataType(SchemaFieldObjectType.fromTypeList(TypeConstants.MAP, TypeConstants.OBJECT)) + .build()); + } else if (ApiTool.hasRef(addPropObj)) { + final String refSchemaName = MapperUtil.getRef(addPropObj, specFile); + fieldObjectArrayList.add(processRef(fieldName, addPropObj, + SchemaFieldObjectType.fromTypeList(TypeConstants.MAP, refSchemaName), totalSchemas, compositedSchemas, + antiLoopList, specFile, baseDir)); + } else if (ApiTool.hasItems(addPropObj)) { + fieldObjectArrayList + .add(SchemaFieldObject + .builder() + .baseName(fieldName) + .dataType(SchemaFieldObjectType.fromTypeList(TypeConstants.MAP, TypeConstants.ARRAY, + MapperUtil.getSimpleType(ApiTool.getItems(addPropObj), specFile))) + .build()); + } else if (ApiTool.isObject(addPropObj)) { + final String className = nameSchema + "Value"; + final var itemsObject = buildSchemaObject(totalSchemas, className, addPropObj, antiLoopList, compositedSchemas, "", specFile, baseDir); + compositedSchemas.put(className, itemsObject); + fieldObjectArrayList + .add(SchemaFieldObject + .builder() + .baseName(ADDITIONAL_PROPERTIES) + .dataType(SchemaFieldObjectType.fromTypeList(TypeConstants.MAP, MapperUtil.getPojoName(className, specFile))) + .build()); + } else { + final String type = isBasicType(addPropObj) ? MapperUtil.getSimpleType(addPropObj, specFile) + : MapperUtil.getPojoName(ApiTool.getName(schema) + ADDITIONAL_PROPERTY_NAME, specFile); + fieldObjectArrayList + .add(SchemaFieldObject + .builder() + .baseName(fieldName) + .dataType(SchemaFieldObjectType.fromTypeList(TypeConstants.MAP, type)) + .build()); + } + + return fieldObjectArrayList; + } + + private static boolean isBasicType(final JsonNode value) { + return !(ApiTool.isObject(value) || ApiTool.isArray(value) || ApiTool.isComposed(value) + || ApiTool.hasAdditionalProperties(value)); + } + + private static SchemaObject createComposedSchema(final String buildingSchema, + final String fieldName, final JsonNode schema, final CommonSpecFile specFile, final Map totalSchemas, + final Map compositedSchemas, final Set antiLoopList, final Path baseDir) { + final Set fieldObjectArrayList = new HashSet<>(); + String schemaCombinatorType = ""; + if (ApiTool.isAllOf(schema)) { + fieldObjectArrayList.addAll( + processAllOf(totalSchemas, ApiTool.getAllOf(schema), specFile, compositedSchemas, antiLoopList, baseDir)); + schemaCombinatorType = ALL_OF_COMBINATOR; + } else if (ApiTool.isAnyOf(schema)) { + fieldObjectArrayList.addAll( + processAnyOfOneOf(buildingSchema, totalSchemas, ApiTool.getAnyOf(schema), specFile, compositedSchemas, antiLoopList, baseDir)); + schemaCombinatorType = ANY_OF_COMBINATOR; + } else if (ApiTool.isOneOf(schema)) { + fieldObjectArrayList.addAll( + processAnyOfOneOf(buildingSchema, totalSchemas, ApiTool.getOneOf(schema), specFile, compositedSchemas, antiLoopList, baseDir)); + schemaCombinatorType = ONE_OF_COMBINATOR; + } + + return SchemaObject.builder() + .schemaName(fieldName) + .className(MapperUtil.getPojoName(fieldName, specFile)) + .importList(getImportList(fieldObjectArrayList, specFile.getModelPackage())) + .schemaCombinator(schemaCombinatorType) + .fieldObjectList(fieldObjectArrayList) + .build(); + } + + private static void setFieldType( + final SchemaFieldObject field, final JsonNode schemaProperty, final JsonNode schema, + final CommonSpecFile specFile, final String key) { + field.setRequired(ApiTool.hasRequired(schema) && ApiTool.checkIfRequired(schema, key)); + if (ApiTool.isArray(schemaProperty)) { + final String typeArray; + if (ApiTool.hasItems(schemaProperty)) { + typeArray = MapperUtil.getTypeArray(schemaProperty, specFile); + } else { + typeArray = TypeConstants.OBJECT; + } + field.setDataType(SchemaFieldObjectType.fromTypeList(TypeConstants.ARRAY, typeArray)); + field.setImportClass(getImportClass(typeArray)); + } else if (ApiTool.hasAdditionalProperties(schemaProperty)) { + final String typeObject = getMapTypeObject(schemaProperty, specFile); + field.setDataType(SchemaFieldObjectType.fromTypeList(TypeConstants.MAP, typeObject)); + field.setImportClass(getImportClass(typeObject)); + + } else if (ApiTool.isObject(schemaProperty)) { + var typeObject = ApiTool.getType(schemaProperty); + if (ApiTool.hasRef(schemaProperty)) { + typeObject = MapperUtil.getRef(schema, specFile); + } + field.setImportClass(getImportClass(typeObject)); + field.getDataType().setDeepType(typeObject); + } + } + + private static String getMapTypeObject(final JsonNode schema, final CommonSpecFile specFile) { + final String type; + if (ApiTool.isBoolean(ApiTool.getAdditionalProperties(schema))) { + type = TypeConstants.OBJECT; + } else { + final JsonNode additionalProperties = ApiTool.getAdditionalProperties(schema); + if (ApiTool.hasRef(additionalProperties)) { + type = MapperUtil.getRef(additionalProperties, specFile); + } else if (ApiTool.isObject(schema)) { + final var additionalPropertiesField = SchemaFieldObject + .builder() + .baseName(ApiTool.getName(additionalProperties)) + .dataType(new SchemaFieldObjectType(MapperUtil.getSimpleType(additionalProperties, specFile))) + .build(); + setFieldType(additionalPropertiesField, additionalProperties, additionalProperties, specFile, ""); + type = getMapFieldType(additionalPropertiesField); + } else { + type = TypeConstants.OBJECT; + } + } + + return type; + } + + private static String getMapFieldType(final SchemaFieldObject schemaFieldObject) { + final String fieldType = schemaFieldObject.getDataType().toString(); + final String type; + switch (fieldType) { + case TypeConstants.BIG_DECIMAL: + case TypeConstants.INTEGER: + case TypeConstants.DOUBLE: + case TypeConstants.FLOAT: + case TypeConstants.LONG: + case TypeConstants.STRING: + type = fieldType; + break; + default: + type = TypeConstants.OBJECT; + break; + } + + return type; + } + + private static Set processAllOf( + final Map totalSchemas, final JsonNode schemaList, final CommonSpecFile specFile, + final Map compositedSchemas, final Set antiLoopList, final Path baseDir) { + final Set fieldObjectArrayList = new HashSet<>(); + + for (JsonNode ref : schemaList) { + if (ApiTool.hasRef(ref)) { + final String schemaName = MapperUtil.getRefSchemaName(ref); + final var schemaToProcess = totalSchemas.get(MapperUtil.getRefSchemaKey(ref)); + ApiTool.getProperties(schemaToProcess).forEachRemaining(processProperties("", totalSchemas, compositedSchemas, fieldObjectArrayList, specFile, ref, antiLoopList, baseDir)); + for (var fieldObject : fieldObjectArrayList) { + fieldObject.setRequired(true); + } + } + } + return fieldObjectArrayList; + } + + private static Set processAnyOfOneOf(final String buildingSchema, + final Map totalSchemas, final JsonNode schemaList, final CommonSpecFile specFile, + final Map compositedSchemas, final Set antiLoopList, final Path baseDir) { + final Set fieldObjectArrayList = new HashSet<>(); + + for (JsonNode internalSchema : schemaList) { + if (ApiTool.hasRef(internalSchema)) { + final var schemaName = MapperUtil.getRefSchemaName(internalSchema); + if (!antiLoopList.contains(schemaName)) { + if (compositedSchemas.containsKey(schemaName)) { + antiLoopList.add(schemaName); + fieldObjectArrayList.addAll(compositedSchemas.get(schemaName).getFieldObjectList()); + } else { + final var schemaObject = solveRef(internalSchema, totalSchemas, compositedSchemas, antiLoopList, specFile, baseDir); + compositedSchemas.put(schemaName, schemaObject); + antiLoopList.add(schemaName); + fieldObjectArrayList.addAll(schemaObject.getFieldObjectList()); + } + } else if (compositedSchemas.containsKey(schemaName)) { + fieldObjectArrayList.addAll(compositedSchemas.get(schemaName).getFieldObjectList()); + } else if (!schemaName.equalsIgnoreCase(buildingSchema)) { + fieldObjectArrayList.addAll(getFields(schemaName, totalSchemas, internalSchema, specFile, compositedSchemas, antiLoopList, ApiTool.getName(internalSchema), baseDir)); + } + } else { + fieldObjectArrayList.addAll(getFields(buildingSchema, totalSchemas, internalSchema, specFile, compositedSchemas, antiLoopList, ApiTool.getName(internalSchema), baseDir)); + for (var fieldObject : fieldObjectArrayList) { + if (ApiTool.checkIfRequired(internalSchema, fieldObject.getBaseName())) { + fieldObject.setRequired(true); + } + } + } + } + return fieldObjectArrayList; + } + + private static SchemaFieldObject processRef( + final String fieldName, final JsonNode schema, final SchemaFieldObjectType dataType, + final Map totalSchemas, final Map compositedSchemas, + final Set antiLoopList, final CommonSpecFile specFile, final Path baseDir) { + final var field = SchemaFieldObject.builder() + .baseName(fieldName) + .dataType(dataType) + .build(); + if (!antiLoopList.contains(MapperUtil.getRefSchemaName(schema))) { + antiLoopList.add(MapperUtil.getRefSchemaName(schema)); + final String refSchemaName = MapperUtil.getRef(schema, specFile); + setFieldType(field, schema, schema, specFile, refSchemaName); + + solveRef(schema, totalSchemas, compositedSchemas, antiLoopList, specFile, baseDir); + } + return field; + } + + private static SchemaObject solveRef( + final JsonNode schema, final Map totalSchemas, + final Map compositedSchemas, final Set antiLoopList, final CommonSpecFile specFile, + final Path baseDir) { + + final var referredSchema = SchemaUtil.solveRef(ApiTool.getRefValue(schema), totalSchemas, baseDir.resolve(specFile.getFilePath()).getParent()); + + final var schemaObject = buildSchemaObject(totalSchemas, MapperUtil.getRefSchemaName(schema), referredSchema, + antiLoopList, compositedSchemas, MapperUtil.getRefSchemaName(schema), specFile, baseDir); + schemaObject.setEnum(ApiTool.isEnum(referredSchema)); + + compositedSchemas.put(MapperUtil.getRefSchemaName(schema), schemaObject); + return schemaObject; + } + + private static SchemaFieldObject processEnumField( + final String name, final JsonNode value, + final CommonSpecFile specFile, final List enumValues, final JsonNode schema) { + final var field = SchemaFieldObject + .builder() + .baseName(name) + .dataType(new SchemaFieldObjectType(TypeConstants.ENUM)) + .build(); + field.setRequired(ApiTool.checkIfRequired(schema, name)); + final var dataType = MapperUtil.getSimpleType(value, specFile); + field.getDataType().setDeepType(dataType); + + final HashMap enumValuesMap = new HashMap<>(); + + for (final var enumValue : enumValues) { + String valueName = enumValue; + valueName = valueName.replace(".", "_DOT_"); + + switch (dataType) { + case TypeConstants.INTEGER: + enumValuesMap.put("INTEGER_" + valueName, enumValue); + break; + case TypeConstants.LONG: + enumValuesMap.put("LONG_" + valueName, enumValue + "l"); + break; + case TypeConstants.DOUBLE: + enumValuesMap.put("DOUBLE_" + valueName, enumValue); + break; + case TypeConstants.FLOAT: + enumValuesMap.put("FLOAT_" + valueName, enumValue + "f"); + break; + case TypeConstants.BIG_DECIMAL: + enumValuesMap.put("BIG_DECIMAL_" + valueName, "new BigDecimal(\"" + enumValue + "\")"); + break; + case TypeConstants.STRING: + default: + enumValuesMap.put(StringUtils.upperCase(valueName), '"' + enumValue + '"'); + break; + } + } + + if (enumValuesMap.isEmpty()) { + throw new BadDefinedEnumException(name); + } + field.setEnumValues(enumValuesMap); + return field; + } + + private static String getImportClass(final String type) { + return StringUtils.isNotBlank(type) && !TypeConstants.NO_IMPORT_TYPE.contains(type) ? StringUtils.capitalize(type) : ""; + } + + +} 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 index c3e93ad8..02db5c74 100644 --- 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 @@ -4,7 +4,6 @@ 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; @@ -17,13 +16,13 @@ public static JsonNode solveRef(final String refValue, final Map writeModel( + private Map fillTemplateFactory( final SpecFile specFile, final String fileModelToSave, final String schemaName, final JsonNode basicSchema, final Map basicSchemaMap, final Map builtSchemasMap) { final var schemaObjectMap = MapperContentUtil diff --git a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/openapi/model/ContentObject.java b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/openapi/model/ContentObject.java index 5a868493..b813ccc3 100644 --- a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/openapi/model/ContentObject.java +++ b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/openapi/model/ContentObject.java @@ -6,6 +6,8 @@ package com.sngular.api.generator.plugin.openapi.model; +import com.sngular.api.generator.plugin.common.model.SchemaFieldObjectType; +import com.sngular.api.generator.plugin.common.model.SchemaObject; import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; diff --git a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/openapi/model/ParameterObject.java b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/openapi/model/ParameterObject.java index 130bf210..e18b5ea4 100644 --- a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/openapi/model/ParameterObject.java +++ b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/openapi/model/ParameterObject.java @@ -6,6 +6,7 @@ package com.sngular.api.generator.plugin.openapi.model; +import com.sngular.api.generator.plugin.common.model.SchemaFieldObjectType; import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; diff --git a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/openapi/model/SchemaFieldObject.java b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/openapi/model/SchemaFieldObject.java deleted file mode 100644 index 4319287e..00000000 --- a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/openapi/model/SchemaFieldObject.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * This Source Code Form is subject to the terms of the Mozilla Public - * * License, v. 2.0. If a copy of the MPL was not distributed with this - * * file, You can obtain one at https://mozilla.org/MPL/2.0/. - */ - -package com.sngular.api.generator.plugin.openapi.model; - -import java.util.Map; - -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Builder.Default; -import lombok.Data; -import lombok.EqualsAndHashCode; -import lombok.NoArgsConstructor; - -@Data -@Builder -@NoArgsConstructor -@AllArgsConstructor -@EqualsAndHashCode(of = "baseName") -public class SchemaFieldObject { - - private String baseName; - - @Default - private SchemaFieldObjectType dataType = new SchemaFieldObjectType(TypeConstants.OBJECT); - - @Default - private SchemaFieldObjectProperties restrictionProperties = new SchemaFieldObjectProperties(); - - private String importClass; - - private boolean required; - - private Map enumValues; - -} diff --git a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/openapi/model/SchemaFieldObjectProperties.java b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/openapi/model/SchemaFieldObjectProperties.java deleted file mode 100644 index 8168bc57..00000000 --- a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/openapi/model/SchemaFieldObjectProperties.java +++ /dev/null @@ -1,101 +0,0 @@ -package com.sngular.api.generator.plugin.openapi.model; - -import java.util.HashSet; -import java.util.Objects; -import java.util.Set; - -import lombok.Data; - -@Data -public class SchemaFieldObjectProperties { - - private String maximum = null; - - private String minimum = null; - - private Boolean exclusiveMaximum = null; - - private Boolean exclusiveMinimum = null; - - private Boolean uniqueItems = null; - - private Integer minItems = null; - - private Integer maxItems = null; - - private Integer minLength = null; - - private Integer maxLength = null; - - private String pattern = null; - - private String multipleOf = null; - - private Set properties; - - public SchemaFieldObjectProperties() { - properties = new HashSet<>(); - } - - public void setMultipleOf(final String multipleOf) { - this.multipleOf = multipleOf; - this.properties.add("MultipleOf"); - } - - public void setPattern(final String pattern) { - this.pattern = pattern; - if (Objects.nonNull(pattern)) { - properties.add("Pattern"); - } - } - - public void setMaxLength(final Integer maxLength) { - this.maxLength = maxLength; - if (Objects.nonNull(maxLength)) { - properties.add("Size"); - } - } - - public void setMinLength(final Integer minLength) { - this.minLength = minLength; - if (Objects.nonNull(minLength)) { - properties.add("Size"); - } - } - - public void setMaxItems(final Integer maxItems) { - this.maxItems = maxItems; - if (Objects.nonNull(maxItems)) { - properties.add("MaxItems"); - } - } - - public void setMinItems(final Integer minItems) { - this.minItems = minItems; - if (Objects.nonNull(minItems)) { - properties.add("MinItems"); - } - } - - public void setUniqueItems(final Boolean uniqueItems) { - this.uniqueItems = uniqueItems; - if (Objects.nonNull(uniqueItems)) { - properties.add("UniqueItems"); - } - } - - public void setMaximum(final String maximum) { - this.maximum = maximum; - if (Objects.nonNull(maximum)) { - properties.add("Maximum"); - } - } - - public void setMinimum(final String mininum) { - this.minimum = mininum; - if (Objects.nonNull(mininum)) { - properties.add("Minimum"); - } - } - -} diff --git a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/openapi/model/SchemaObject.java b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/openapi/model/SchemaObject.java deleted file mode 100644 index 451c990d..00000000 --- a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/openapi/model/SchemaObject.java +++ /dev/null @@ -1,72 +0,0 @@ -/* - * This Source Code Form is subject to the terms of the Mozilla Public - * * License, v. 2.0. If a copy of the MPL was not distributed with this - * * file, You can obtain one at https://mozilla.org/MPL/2.0/. - */ - -package com.sngular.api.generator.plugin.openapi.model; - -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Data; -import lombok.EqualsAndHashCode; -import lombok.NoArgsConstructor; - -@Data -@Builder(toBuilder = true) -@NoArgsConstructor -@AllArgsConstructor -@EqualsAndHashCode(of = {"schemaName", "className"}) -public class SchemaObject { - - private boolean isEnum; - - private String schemaName; - - private String className; - - private List importList; - - private Set fieldObjectList; - - private String schemaCombinator; - - public static final class SchemaObjectBuilder { - - private boolean isEnum; - - private final List importList = new ArrayList<>(); - - private final Set fieldObjectList = new HashSet<>(); - - public SchemaObjectBuilder importList(final List importList) { - this.importList.addAll(importList); - return this; - } - - public SchemaObjectBuilder importItem(final String importItem) { - this.importList.add(importItem); - return this; - } - - public SchemaObjectBuilder fieldObjectList(final Set fieldObjectList) { - this.fieldObjectList.addAll(fieldObjectList); - return this; - } - - public SchemaObjectBuilder fieldObject(final SchemaFieldObject fieldObject) { - this.fieldObjectList.add(fieldObject); - return this; - } - - public SchemaObjectBuilder isEnum(final boolean isEnum) { - this.isEnum = isEnum; - return this; - } - } -} diff --git a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/openapi/parameter/SpecFile.java b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/openapi/parameter/SpecFile.java index 1db5ea54..21abc6e2 100644 --- a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/openapi/parameter/SpecFile.java +++ b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/openapi/parameter/SpecFile.java @@ -6,28 +6,16 @@ package com.sngular.api.generator.plugin.openapi.parameter; -import com.sngular.api.generator.plugin.openapi.model.TypeConstants.TimeType; -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Builder.Default; -import lombok.Data; -import lombok.NoArgsConstructor; +import com.sngular.api.generator.plugin.common.model.CommonSpecFile; +import lombok.*; +import lombok.experimental.SuperBuilder; @Data -@Builder +@SuperBuilder(toBuilder = true) @NoArgsConstructor @AllArgsConstructor -public class SpecFile { - - private String filePath; - - private String apiPackage; - - private String modelPackage; - - private String modelNamePrefix; - - private String modelNameSuffix; +@EqualsAndHashCode(callSuper = true) +public class SpecFile extends CommonSpecFile { private String clientPackage; @@ -35,10 +23,6 @@ public class SpecFile { private boolean useTagsGroup; - private boolean useLombokModelAnnotation; - private boolean isReactive; - - @Default - private TimeType useTimeType = TimeType.LOCAL; } + 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 c5ce0870..231724a3 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 @@ -17,12 +17,12 @@ import java.util.Objects; import java.util.Set; +import com.sngular.api.generator.plugin.common.model.SchemaFieldObject; +import com.sngular.api.generator.plugin.common.model.SchemaObject; import com.sngular.api.generator.plugin.exception.GeneratorTemplateException; 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; -import com.sngular.api.generator.plugin.openapi.model.SchemaFieldObject; -import com.sngular.api.generator.plugin.openapi.model.SchemaObject; import com.sngular.api.generator.plugin.openapi.parameter.SpecFile; import freemarker.template.Configuration; import freemarker.template.Template; @@ -58,7 +58,7 @@ public final void fillTemplateSchema( final String pathToSaveMainClass = fileToSave.toPath().resolve(schemaObject.getClassName() + JAVA_EXTENSION).toString(); writeTemplateToFile(templateSelector(useLombok, schemaObject), root, pathToSaveMainClass); for (SchemaFieldObject fieldObject : schemaObject.getFieldObjectList()) { - propertiesSet.addAll(fieldObject.getRestrictionProperties().getProperties()); + propertiesSet.addAll(fieldObject.getRestrictions().getProperties()); if (fieldObject.isRequired() && Boolean.FALSE.equals(useLombok)) { propertiesSet.add("NotNull"); } 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 d78dd7e7..1e97483b 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 @@ -6,770 +6,42 @@ package com.sngular.api.generator.plugin.openapi.utils; +import com.fasterxml.jackson.databind.JsonNode; +import com.sngular.api.generator.plugin.common.model.CommonSpecFile; +import com.sngular.api.generator.plugin.common.model.SchemaObject; +import com.sngular.api.generator.plugin.common.tools.ApiTool; +import com.sngular.api.generator.plugin.common.tools.ModelBuilder; +import org.apache.commons.lang3.StringUtils; + import java.nio.file.Path; -import java.util.ArrayList; -import java.util.HashMap; import java.util.HashSet; -import java.util.LinkedList; -import java.util.List; import java.util.Map; -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; -import com.sngular.api.generator.plugin.openapi.model.SchemaObject; -import com.sngular.api.generator.plugin.openapi.model.TypeConstants; -import com.sngular.api.generator.plugin.openapi.parameter.SpecFile; -import org.apache.commons.lang3.ObjectUtils; -import org.apache.commons.lang3.StringUtils; public class MapperContentUtil { - private static final String ADDITIONAL_PROPERTY_NAME = "AdditionalProperty"; - - private static final String ANY_OF_COMBINATOR = "anyOf"; - - private static final String ONE_OF_COMBINATOR = "oneOf"; - - private static final String ALL_OF_COMBINATOR = "allOf"; - - private static final String ADDITIONAL_PROPERTIES = "additionalProperties"; private MapperContentUtil() { } public static Map mapComponentToSchemaObject( - final Map totalSchemas, final Map compositedSchemas, final JsonNode schema, - final String schemaName, final SpecFile specFile, final Path baseDir) { + final Map totalSchemas, final Map compositedSchemas, final JsonNode model, + final String schemaName, final CommonSpecFile specFile, final Path baseDir) { - return mapComponentToSchemaObject(totalSchemas, compositedSchemas, new HashSet<>(), schema, - StringUtils.defaultIfEmpty(ApiTool.getName(schema), schemaName), specFile, baseDir); + return mapComponentToSchemaObject(totalSchemas, compositedSchemas, new HashSet<>(), model, + StringUtils.defaultIfEmpty(ApiTool.getName(model), schemaName), specFile, baseDir); } private static Map mapComponentToSchemaObject( final Map totalSchemas, final Map compositedSchemas, - final Set antiLoopList, final JsonNode schema, final String schemaName, final SpecFile specFile, + final Set antiLoopList, final JsonNode schema, final String schemaName, final CommonSpecFile specFile, final Path baseDir) { final var name = StringUtils.defaultIfBlank(ApiTool.getName(schema), schemaName); if (!compositedSchemas.containsKey(name)) { compositedSchemas - .put(name, toSchemaObject(name, totalSchemas, compositedSchemas, antiLoopList, schema, schemaName, specFile, baseDir)); + .put(name, ModelBuilder.buildSchemaObject(totalSchemas, schemaName, schema, antiLoopList, compositedSchemas,"", specFile, baseDir)); } return compositedSchemas; } - @SuppressWarnings("checkstyle:ParameterNumber") - private static SchemaObject toSchemaObject( - final String name, final Map totalSchemas, final Map compositedSchemas, - final Set antiLoopList, final JsonNode schema, final String schemaName, final SpecFile specFile, - final Path baseDir) { - - antiLoopList.add(schemaName); - - final var listSchema = getFields(null, totalSchemas, schema, specFile, compositedSchemas, antiLoopList, schemaName, baseDir); - - String schemaCombinatorType = ""; - if (ApiTool.isAllOf(schema)) { - schemaCombinatorType = ALL_OF_COMBINATOR; - } - - if (ApiTool.isAnyOf(schema)) { - schemaCombinatorType = ANY_OF_COMBINATOR; - } - - if (ApiTool.isOneOf(schema)) { - schemaCombinatorType = ONE_OF_COMBINATOR; - } - - return SchemaObject.builder() - .schemaName(name) - .className(MapperUtil.getPojoName(schemaName, specFile)) - .importList(getImportList(listSchema, specFile.getModelPackage())) - .schemaCombinator(schemaCombinatorType) - .fieldObjectList(listSchema) - .build(); - } - - private static List getImportList(final Set fieldObjectList, final String modelPackage) { - final var listHashMap = new HashMap>(); - final var importList = new ArrayList(); - - for (final var fieldObject : fieldObjectList) { - getTypeImports(listHashMap, fieldObject); - if (StringUtils.isNotBlank(fieldObject.getImportClass()) - && !listHashMap.containsKey(fieldObject.getImportClass()) - && !fieldObject.getDataType().containsType("enum")) { - listHashMap.put(StringUtils.capitalize(fieldObject.getImportClass()), - List.of(modelPackage + "." + StringUtils.capitalize(fieldObject.getImportClass()))); - } - } - if (!listHashMap.isEmpty()) { - listHashMap.forEach((key, value) -> importList.addAll(value)); - } - return importList; - } - - private static void getTypeImports( - final HashMap> listHashMap, - final SchemaFieldObject fieldObject) { - final SchemaFieldObjectType type = fieldObject.getDataType(); - if (type.containsType(TypeConstants.ARRAY)) { - listHashMap.computeIfAbsent(TypeConstants.ARRAY, key -> List.of("java.util.List", "java.util.ArrayList")); - } - - if (type.containsType(TypeConstants.MAP)) { - listHashMap.computeIfAbsent(TypeConstants.MAP, key -> List.of("java.util.Map", "java.util.HashMap")); - } - - if (type.containsType(TypeConstants.BIG_DECIMAL)) { - listHashMap.computeIfAbsent(TypeConstants.BIG_DECIMAL, key -> List.of("java.math.BigDecimal")); - } - - if (type.containsType(TypeConstants.LOCALDATE)) { - listHashMap.computeIfAbsent(TypeConstants.LOCALDATE, key -> List.of("java.time.LocalDate")); - } - - if (type.containsType(TypeConstants.LOCALDATETIME)) { - listHashMap.computeIfAbsent(TypeConstants.LOCALDATETIME, key -> List.of("java.time.LocalDateTime")); - } - - if (type.containsType(TypeConstants.ZONEDDATE)) { - listHashMap.computeIfAbsent(TypeConstants.ZONEDDATETIME, key -> List.of("java.time.ZonedDateTime")); - } - - if (type.containsType(TypeConstants.ZONEDDATETIME)) { - listHashMap.computeIfAbsent(TypeConstants.ZONEDDATETIME, key -> List.of("java.time.ZonedDateTime")); - } - - if (type.containsType(TypeConstants.OFFSETDATE)) { - listHashMap.computeIfAbsent(TypeConstants.OFFSETDATETIME, key -> List.of("java.time.OffsetDateTime")); - } - - if (type.containsType(TypeConstants.OFFSETDATETIME)) { - listHashMap.computeIfAbsent(TypeConstants.OFFSETDATETIME, key -> List.of("java.time.OffsetDateTime")); - } - } - - private static Set getFields(final String buildingSchema, - final Map totalSchemas, final JsonNode schema, final SpecFile specFile, - final Map compositedSchemas, final Set antiLoopList, final String nameSchema, - final Path baseDir) { - final Set fieldObjectArrayList = new HashSet<>(); - - if (ApiTool.hasProperties(schema)) { - if (ApiTool.hasAdditionalProperties(schema)) { - ApiTool.getProperties(schema).forEachRemaining(processProperties(buildingSchema, totalSchemas, compositedSchemas, fieldObjectArrayList, specFile, schema, antiLoopList, - baseDir)); - fieldObjectArrayList.addAll(processAdditionalProperties(ADDITIONAL_PROPERTIES, schema, specFile, totalSchemas, compositedSchemas, antiLoopList, nameSchema, baseDir)); - } else { - ApiTool.getProperties(schema).forEachRemaining(processProperties(buildingSchema, totalSchemas, compositedSchemas, fieldObjectArrayList, specFile, schema, antiLoopList, - baseDir)); - } - } else if (TypeConstants.ARRAY.equalsIgnoreCase(ApiTool.getType(schema))) { - final String itemType = ApiTool.hasRef(ApiTool.getItems(schema)) ? MapperUtil.getRef(ApiTool.getItems(schema), specFile) : ApiTool.getType(ApiTool.getItems(schema)); - fieldObjectArrayList.add(SchemaFieldObject.builder() - .baseName("items") - .dataType(SchemaFieldObjectType.fromTypeList(TypeConstants.ARRAY, itemType)) - .build()); - } else if (ApiTool.isAllOf(schema)) { - fieldObjectArrayList.addAll(processAllOf(totalSchemas, ApiTool.getAllOf(schema), specFile, compositedSchemas, antiLoopList, baseDir)); - } else if (ApiTool.isAnyOf(schema)) { - fieldObjectArrayList.addAll(processAnyOfOneOf(buildingSchema, totalSchemas, ApiTool.getAnyOf(schema), specFile, compositedSchemas, antiLoopList, baseDir)); - } else if (ApiTool.isOneOf(schema)) { - fieldObjectArrayList.addAll(processAnyOfOneOf(buildingSchema, totalSchemas, ApiTool.getOneOf(schema), specFile, compositedSchemas, antiLoopList, baseDir)); - } else if (ApiTool.isEnum(schema)) { - fieldObjectArrayList.add(processEnumField(ApiTool.getName(schema), schema, specFile, ApiTool.getEnumValues(schema), schema)); - } else if (ApiTool.hasRef(schema)) { - final var refSchema = totalSchemas.get(MapperUtil.getRefSchemaName(schema)); - ApiTool.getProperties(refSchema).forEachRemaining(processProperties(buildingSchema, totalSchemas, compositedSchemas, fieldObjectArrayList, specFile, schema, antiLoopList, - baseDir)); - } else { - fieldObjectArrayList.add(SchemaFieldObject.builder() - .baseName(ApiTool.getName(schema)) - .dataType(new SchemaFieldObjectType(MapperUtil.getSimpleType(schema, specFile))) - .build()); - } - - return fieldObjectArrayList; - } - - private static Set processAllOf( - final Map totalSchemas, final JsonNode schemaList, final SpecFile specFile, - final Map compositedSchemas, final Set antiLoopList, final Path baseDir) { - final Set fieldObjectArrayList = new HashSet<>(); - - for (JsonNode ref : schemaList) { - if (ApiTool.hasRef(ref)) { - final String schemaName = MapperUtil.getRefSchemaName(ref); - final var schemaToProcess = totalSchemas.get(schemaName); - ApiTool.getProperties(schemaToProcess).forEachRemaining(processProperties("", totalSchemas, compositedSchemas, fieldObjectArrayList, specFile, ref, antiLoopList, baseDir)); - for (var fieldObject : fieldObjectArrayList) { - fieldObject.setRequired(true); - } - } - } - return fieldObjectArrayList; - } - - private static Set processAnyOfOneOf(final String buildingSchema, - final Map totalSchemas, final JsonNode schemaList, final SpecFile specFile, - final Map compositedSchemas, final Set antiLoopList, final Path baseDir) { - final Set fieldObjectArrayList = new HashSet<>(); - - for (JsonNode internalSchema : schemaList) { - if (ApiTool.hasRef(internalSchema)) { - final var schemaName = MapperUtil.getRefSchemaName(internalSchema); - if (!antiLoopList.contains(schemaName)) { - if (compositedSchemas.containsKey(schemaName)) { - antiLoopList.add(schemaName); - fieldObjectArrayList.addAll(compositedSchemas.get(schemaName).getFieldObjectList()); - } else { - final var schemaObject = solveRef(internalSchema, totalSchemas, compositedSchemas, antiLoopList, specFile, baseDir); - compositedSchemas.put(schemaName, schemaObject); - antiLoopList.add(schemaName); - fieldObjectArrayList.addAll(schemaObject.getFieldObjectList()); - } - } else if (compositedSchemas.containsKey(schemaName)) { - fieldObjectArrayList.addAll(compositedSchemas.get(schemaName).getFieldObjectList()); - } else if (!schemaName.equalsIgnoreCase(buildingSchema)) { - fieldObjectArrayList.addAll(getFields(schemaName, totalSchemas, internalSchema, specFile, compositedSchemas, antiLoopList, ApiTool.getName(internalSchema), baseDir)); - } - } else { - fieldObjectArrayList.addAll(getFields(buildingSchema, totalSchemas, internalSchema, specFile, compositedSchemas, antiLoopList, ApiTool.getName(internalSchema), baseDir)); - for (var fieldObject : fieldObjectArrayList) { - if (ApiTool.checkIfRequired(internalSchema, fieldObject.getBaseName())) { - fieldObject.setRequired(true); - } - } - } - } - return fieldObjectArrayList; - } - - @SuppressWarnings("checkstyle:CyclomaticComplexity") - private static List processFieldObjectList(final String buildingSchema, - final String fieldName, final String className, final JsonNode schema, final SpecFile specFile, final Map totalSchemas, - final Map compositedSchemas, final Set antiLoopList, final Path baseDir) { - final var fieldObjectArrayList = new ArrayList(); - - if (TypeConstants.ARRAY.equalsIgnoreCase(ApiTool.getType(schema))) { - fieldObjectArrayList.addAll(processArray(fieldName, className, schema, specFile, totalSchemas, compositedSchemas, antiLoopList, baseDir)); - } else if (ApiTool.hasAdditionalProperties(schema)) { - fieldObjectArrayList.addAll(processMap(fieldName, schema, specFile, totalSchemas, compositedSchemas, antiLoopList, baseDir)); - } else if (ApiTool.hasRef(schema)) { - fieldObjectArrayList.add( - processRef(fieldName, schema, new SchemaFieldObjectType(MapperUtil.getSimpleType(schema, specFile)), totalSchemas, compositedSchemas, antiLoopList, specFile, baseDir)); - } else if (ApiTool.isObject(schema) && !ApiTool.hasProperties(schema)) { - fieldObjectArrayList.add(SchemaFieldObject - .builder() - .baseName(fieldName) - .dataType(new SchemaFieldObjectType(TypeConstants.OBJECT)) - .build()); - } else if (ApiTool.isEnum(schema)) { - fieldObjectArrayList.add(processEnumField(fieldName, schema, specFile, ApiTool.getEnumValues(schema), schema)); - } else if (!ApiTool.hasProperties(schema) && !ApiTool.isComposed(schema)) { - fieldObjectArrayList.add(SchemaFieldObject - .builder() - .baseName(fieldName) - .dataType(new SchemaFieldObjectType(TypeConstants.OBJECT)) - .build()); - } else if (ApiTool.isObject(schema)) { - fieldObjectArrayList.addAll(processObject(fieldName, className, schema, specFile, totalSchemas, compositedSchemas, antiLoopList, baseDir)); - } else { - final var composedSchemaName = StringUtils.defaultIfBlank(className, fieldName); - var schemaObjectComposed = compositedSchemas.get(composedSchemaName); - if (Objects.isNull(schemaObjectComposed)) { - schemaObjectComposed = createComposedSchema(buildingSchema, StringUtils.defaultIfBlank(className, fieldName), schema, specFile, - totalSchemas, compositedSchemas, antiLoopList, baseDir); - compositedSchemas.put(composedSchemaName, schemaObjectComposed); - } - - fieldObjectArrayList.add(SchemaFieldObject - .builder() - .baseName(fieldName) - .dataType(SchemaFieldObjectType.fromTypeList(schemaObjectComposed.getClassName(), schemaObjectComposed.getClassName())) - .build()); - } - - return fieldObjectArrayList; - } - - private static SchemaFieldObject processRef( - final String fieldName, final JsonNode schema, final SchemaFieldObjectType dataType, - final Map totalSchemas, final Map compositedSchemas, - final Set antiLoopList, final SpecFile specFile, final Path baseDir) { - final var field = SchemaFieldObject.builder() - .baseName(fieldName) - .dataType(dataType) - .build(); - if (!antiLoopList.contains(MapperUtil.getRefSchemaName(schema))) { - antiLoopList.add(MapperUtil.getRefSchemaName(schema)); - final String refSchemaName = MapperUtil.getRef(schema, specFile); - setFieldType(field, schema, schema, specFile, refSchemaName); - - solveRef(schema, totalSchemas, compositedSchemas, antiLoopList, specFile, baseDir); - } - return field; - } - - private static SchemaObject solveRef( - final JsonNode schema, final Map totalSchemas, - final Map compositedSchemas, final Set antiLoopList, final SpecFile specFile, - final Path baseDir) { - - 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); - schemaObject.setEnum(ApiTool.isEnum(referredSchema)); - - compositedSchemas.put(MapperUtil.getRefSchemaName(schema), schemaObject); - return schemaObject; - } - - private static Consumer> processProperties(final String buildingSchema, - final Map totalSchemas, final Map compositedSchemas, final Set fieldObjectArrayList, final SpecFile specFile, - final JsonNode schema, final Set antiLoopList, final Path baseDir) { - return field -> { - final var nodeName = field.getKey(); - final var nodeValue = field.getValue(); - if (ApiTool.isEnum(field.getValue())) { - fieldObjectArrayList.add(processEnumField(nodeName, nodeValue, specFile, ApiTool.getEnumValues(nodeValue), schema)); - } else { - fieldObjectArrayList.addAll(processObjectProperty(buildingSchema, totalSchemas, nodeName, nodeValue, compositedSchemas, specFile, schema, antiLoopList, baseDir)); - } - }; - } - - @SuppressWarnings({"checkstyle:CyclomaticComplexity", "checkstyle:ParameterNumber"}) - private static List processObjectProperty(final String buildingSchema, - final Map totalSchemas, final String fieldName, final JsonNode fieldBody, final Map compositedSchemas, final SpecFile specFile, - final JsonNode schema, final Set antiLoopList, final Path baseDir) { - final List fieldObjectArrayList = new LinkedList<>(); - final var isRequired = ApiTool.checkIfRequired(fieldBody, fieldName); - final SchemaFieldObject field; - if (ApiTool.hasRef(fieldBody)) { - final var typeName = MapperUtil.getRefSchemaName(fieldBody); - final var refSchema = totalSchemas.get(typeName); - if (!antiLoopList.contains(typeName) && totalSchemas.containsKey(typeName) && ApiTool.hasType(refSchema) - && ApiTool.hasItems(refSchema) || ApiTool.getRefValue(fieldBody).contains(fieldName)) { - antiLoopList.add(typeName); - fieldObjectArrayList.addAll(processFieldObjectList(buildingSchema, fieldName, typeName, totalSchemas.get(typeName), specFile, totalSchemas, compositedSchemas, - antiLoopList, baseDir)); - } else if (ApiTool.isEnum(refSchema)) { - fieldObjectArrayList.add(processEnumField(fieldName, refSchema, specFile, ApiTool.getEnumValues(refSchema), schema)); - } else { - fieldObjectArrayList.add(SchemaFieldObject - .builder() - .baseName(fieldName) - .required(ApiTool.checkIfRequired(schema, fieldName)) - .dataType(SchemaFieldObjectType.fromTypeList(MapperUtil.getSimpleType(refSchema, specFile), - MapperUtil.getPojoName(typeName, specFile))) - .build()); - } - } else if (ApiTool.isEnum(fieldBody)) { - fieldObjectArrayList.add(processEnumField(fieldName, fieldBody, specFile, ApiTool.getEnumValues(fieldBody), fieldBody)); - } else if (TypeConstants.STRING.equalsIgnoreCase(ApiTool.getType(fieldBody))) { - field = processStringProperty(fieldName, fieldBody, specFile); - setFieldType(field, fieldBody, schema, specFile, fieldName); - fieldObjectArrayList.add(field); - } else if (isBasicType(fieldBody)) { - field = SchemaFieldObject - .builder() - .baseName(fieldName) - .required(isRequired) - .dataType(new SchemaFieldObjectType(MapperUtil.getSimpleType(fieldBody, specFile))) - .build(); - addPropertiesToFieldObject(field, fieldBody); - setFieldType(field, fieldBody, schema, specFile, fieldName); - fieldObjectArrayList.add(field); - } else { - fieldObjectArrayList.addAll(processFieldObjectList(buildingSchema, fieldName, fieldName, fieldBody, specFile, totalSchemas, compositedSchemas, antiLoopList, baseDir)); - } - return fieldObjectArrayList; - } - - private static SchemaFieldObject processStringProperty(final String propertyName, final JsonNode schema, final SpecFile specFile) { - final String resultingType = ApiTool.isDateTime(schema) ? MapperUtil.getDateType(schema, specFile) : TypeConstants.STRING; - - final SchemaFieldObject field = SchemaFieldObject - .builder() - .baseName(propertyName) - .required(ApiTool.checkIfRequired(schema, propertyName)) - .dataType(new SchemaFieldObjectType(resultingType)) - .build(); - addPropertiesToFieldObject(field, schema); - return field; - } - - @SuppressWarnings("checkstyle:CyclomaticComplexity") - private static void addPropertiesToFieldObject(final SchemaFieldObject fieldObject, final JsonNode value) { - final var restrictionList = ApiTool.getFieldIterator(value); - while (restrictionList.hasNext()) { - final var restriction = restrictionList.next(); - switch (restriction.getKey()) { - case "pattern": - fieldObject.getRestrictionProperties().setPattern(restriction.getValue().asText()); - break; - case "maxItems": - fieldObject.getRestrictionProperties().setMaxItems(restriction.getValue().asInt()); - break; - case "minItems": - fieldObject.getRestrictionProperties().setMinItems(restriction.getValue().asInt()); - break; - case "maxLength": - fieldObject.getRestrictionProperties().setMaxLength(restriction.getValue().asInt()); - break; - case "minLength": - fieldObject.getRestrictionProperties().setMinLength(restriction.getValue().asInt()); - break; - case "uniqueItems": - fieldObject.getRestrictionProperties().setUniqueItems(restriction.getValue().asBoolean()); - break; - case "exclusiveMaximum": - fieldObject.getRestrictionProperties().setExclusiveMaximum(restriction.getValue().asBoolean()); - break; - case "exclusiveMinimum": - fieldObject.getRestrictionProperties().setExclusiveMinimum(restriction.getValue().asBoolean()); - break; - case "multipleOf": - fieldObject.getRestrictionProperties().setMultipleOf(restriction.getValue().asText()); - break; - case "maximum": - fieldObject.getRestrictionProperties().setMaximum(restriction.getValue().asText()); - break; - case "minimum": - fieldObject.getRestrictionProperties().setMinimum(restriction.getValue().asText()); - break; - default: - break; - } - } - } - - @SuppressWarnings("checkstyle:ParameterNumber") - private static List processArray( - final String fieldName, final String className, final JsonNode schema, final SpecFile specFile, final Map totalSchemas, - final Map compositedSchemas, final Set antiLoopList, final Path baseDir) { - final List fieldObjectArrayList = new LinkedList<>(); - - if (!ApiTool.hasItems(schema)) { - fieldObjectArrayList.add(SchemaFieldObject - .builder() - .baseName(fieldName) - .dataType(new SchemaFieldObjectType(TypeConstants.OBJECT)) - .build()); - } else { - final var items = ApiTool.getItems(schema); - if (ApiTool.hasRef(items)) { - fieldObjectArrayList.add( - processRef(fieldName, items, SchemaFieldObjectType.fromTypeList(TypeConstants.ARRAY, MapperUtil.getSimpleType(items, specFile)), totalSchemas, compositedSchemas, - antiLoopList, specFile, baseDir)); - } else if (ApiTool.isComposed(items)) { - final String composedSchemaName = StringUtils.defaultIfBlank(className, fieldName); - SchemaObject schemaObjectComposed = compositedSchemas.get(composedSchemaName); - if (Objects.isNull(schemaObjectComposed)) { - schemaObjectComposed = createComposedSchema("", StringUtils.defaultIfBlank(className, fieldName), items, specFile, - totalSchemas, compositedSchemas, antiLoopList, baseDir); - compositedSchemas.put(composedSchemaName, schemaObjectComposed); - } - - fieldObjectArrayList.add(SchemaFieldObject - .builder() - .baseName(fieldName) - .dataType(SchemaFieldObjectType.fromTypeList(TypeConstants.ARRAY, schemaObjectComposed.getClassName())) - .importClass(schemaObjectComposed.getClassName()) - .build()); - } else if (ApiTool.hasProperties(items)) { - compositedSchemas.putAll(mapComponentToSchemaObject(totalSchemas, compositedSchemas, items, fieldName, specFile, baseDir)); - fieldObjectArrayList.add(SchemaFieldObject - .builder() - .baseName(fieldName) - .dataType(SchemaFieldObjectType.fromTypeList(TypeConstants.ARRAY, MapperUtil.getPojoName(fieldName, specFile))) - .build()); - } else { - final SchemaFieldObject field = SchemaFieldObject - .builder() - .baseName(fieldName) - .dataType(SchemaFieldObjectType.fromTypeList(TypeConstants.ARRAY, MapperUtil.getSimpleType(items, specFile))) - .build(); - fieldObjectArrayList.add(field); - addPropertiesToFieldObject(field, schema); - } - } - - return fieldObjectArrayList; - } - - @SuppressWarnings("checkstyle:ParameterNumber") - private static Set processObject( - final String fieldName, final String className, final JsonNode schema, final SpecFile specFile, - final Map totalSchemas, final Map compositedSchemas, - final Set antiLoopList, final Path baseDir) { - final Set fieldObjectArrayList = new HashSet<>(); - - if (ObjectUtils.allNull(className, fieldName)) { - ApiTool.getProperties(schema).forEachRemaining( - processProperties("", totalSchemas, compositedSchemas, fieldObjectArrayList, specFile, schema, antiLoopList, baseDir)); - } else if (antiLoopList.contains(className)) { - fieldObjectArrayList - .add(SchemaFieldObject - .builder() - .baseName(className) - .dataType(SchemaFieldObjectType.fromTypeList(TypeConstants.OBJECT, MapperUtil.getPojoName(className, specFile))) - .build()); - } else if (antiLoopList.contains(fieldName)) { - fieldObjectArrayList - .add(SchemaFieldObject - .builder() - .baseName(fieldName) - .dataType(SchemaFieldObjectType.fromTypeList(TypeConstants.OBJECT, MapperUtil.getPojoName(fieldName, specFile))) - .build()); - } else { - final String name = StringUtils.defaultIfBlank(className, fieldName); - compositedSchemas.putAll( - mapComponentToSchemaObject(totalSchemas, compositedSchemas, antiLoopList, schema, name, specFile, - baseDir)); - fieldObjectArrayList - .add(SchemaFieldObject - .builder() - .baseName(name) - .dataType(SchemaFieldObjectType.fromTypeList(TypeConstants.OBJECT, MapperUtil.getPojoName(name, specFile))) - .build()); - } - - return fieldObjectArrayList; - } - - private static Set processMap( - final String fieldName, final JsonNode schema, final SpecFile specFile, final Map totalSchemas, - final Map compositedSchemas, final Set antiLoopList, final Path baseDir) { - final Set fieldObjectArrayList = new HashSet<>(); - - if (TypeConstants.OBJECT.equalsIgnoreCase(ApiTool.getType(schema)) && ApiTool.hasProperties(schema)) { - ApiTool.getProperties(schema).forEachRemaining( - processProperties("", totalSchemas, compositedSchemas, fieldObjectArrayList, specFile, schema, antiLoopList, baseDir)); - } - - if (ApiTool.hasAdditionalProperties(schema)) { - fieldObjectArrayList.addAll(processAdditionalProperties(fieldName, schema, specFile, totalSchemas, compositedSchemas, - antiLoopList, ADDITIONAL_PROPERTIES, baseDir)); - } - - return fieldObjectArrayList; - } - - private static List processAdditionalProperties( - final String fieldName, final JsonNode schema, final SpecFile specFile, final Map totalSchemas, - final Map compositedSchemas, final Set antiLoopList, final String nameSchema, - final Path baseDir) { - final var fieldObjectArrayList = new ArrayList(); - - final var addPropObj = ApiTool.getAdditionalProperties(schema); - if (TypeConstants.isBoolean(addPropObj.asText())) { - fieldObjectArrayList - .add(SchemaFieldObject - .builder() - .baseName(fieldName) - .dataType(SchemaFieldObjectType.fromTypeList(TypeConstants.MAP, TypeConstants.OBJECT)) - .build()); - } else if (ApiTool.hasRef(addPropObj)) { - final String refSchemaName = MapperUtil.getRef(addPropObj, specFile); - fieldObjectArrayList.add(processRef(fieldName, addPropObj, - SchemaFieldObjectType.fromTypeList(TypeConstants.MAP, refSchemaName), totalSchemas, compositedSchemas, - antiLoopList, specFile, baseDir)); - } else if (ApiTool.hasItems(addPropObj)) { - fieldObjectArrayList - .add(SchemaFieldObject - .builder() - .baseName(fieldName) - .dataType(SchemaFieldObjectType.fromTypeList(TypeConstants.MAP, TypeConstants.ARRAY, - MapperUtil.getSimpleType(ApiTool.getItems(addPropObj), specFile))) - .build()); - } else if (ApiTool.isObject(addPropObj)) { - compositedSchemas.putAll( - mapComponentToSchemaObject(totalSchemas, compositedSchemas, antiLoopList, addPropObj, nameSchema + "Value", specFile, - baseDir)); - fieldObjectArrayList - .add(SchemaFieldObject - .builder() - .baseName(ADDITIONAL_PROPERTIES) - .dataType(SchemaFieldObjectType.fromTypeList(TypeConstants.MAP, MapperUtil.getPojoName(nameSchema + "Value", specFile))) - .build()); - } else { - final String type = isBasicType(addPropObj) ? MapperUtil.getSimpleType(addPropObj, specFile) - : MapperUtil.getPojoName(ApiTool.getName(schema) + ADDITIONAL_PROPERTY_NAME, specFile); - fieldObjectArrayList - .add(SchemaFieldObject - .builder() - .baseName(fieldName) - .dataType(SchemaFieldObjectType.fromTypeList(TypeConstants.MAP, type)) - .build()); - } - - return fieldObjectArrayList; - } - - private static boolean isBasicType(final JsonNode value) { - return !(ApiTool.isObject(value) || ApiTool.isArray(value) || ApiTool.isComposed(value) - || ApiTool.hasAdditionalProperties(value)); - } - - private static SchemaObject createComposedSchema(final String buildingSchema, - final String fieldName, final JsonNode schema, final SpecFile specFile, final Map totalSchemas, - final Map compositedSchemas, final Set antiLoopList, final Path baseDir) { - final Set fieldObjectArrayList = new HashSet<>(); - String schemaCombinatorType = ""; - if (ApiTool.isAllOf(schema)) { - fieldObjectArrayList.addAll( - processAllOf(totalSchemas, ApiTool.getAllOf(schema), specFile, compositedSchemas, antiLoopList, baseDir)); - schemaCombinatorType = ALL_OF_COMBINATOR; - } else if (ApiTool.isAnyOf(schema)) { - fieldObjectArrayList.addAll( - processAnyOfOneOf(buildingSchema, totalSchemas, ApiTool.getAnyOf(schema), specFile, compositedSchemas, antiLoopList, baseDir)); - schemaCombinatorType = ANY_OF_COMBINATOR; - } else if (ApiTool.isOneOf(schema)) { - fieldObjectArrayList.addAll( - processAnyOfOneOf(buildingSchema, totalSchemas, ApiTool.getOneOf(schema), specFile, compositedSchemas, antiLoopList, baseDir)); - schemaCombinatorType = ONE_OF_COMBINATOR; - } - - return SchemaObject.builder() - .schemaName(fieldName) - .className(MapperUtil.getPojoName(fieldName, specFile)) - .importList(getImportList(fieldObjectArrayList, specFile.getModelPackage())) - .schemaCombinator(schemaCombinatorType) - .fieldObjectList(fieldObjectArrayList) - .build(); - } - - private static void setFieldType( - final SchemaFieldObject field, final JsonNode schemaProperty, final JsonNode schema, - final SpecFile specFile, final String key) { - field.setRequired(ApiTool.hasRequired(schema) && ApiTool.checkIfRequired(schema, key)); - if (ApiTool.isArray(schemaProperty)) { - final String typeArray; - if (ApiTool.hasItems(schemaProperty)) { - typeArray = MapperUtil.getTypeArray(schemaProperty, specFile); - } else { - typeArray = TypeConstants.OBJECT; - } - field.setDataType(SchemaFieldObjectType.fromTypeList(TypeConstants.ARRAY, typeArray)); - field.setImportClass(getImportClass(typeArray)); - } else if (ApiTool.hasAdditionalProperties(schemaProperty)) { - final String typeObject = getMapTypeObject(schemaProperty, specFile); - field.setDataType(SchemaFieldObjectType.fromTypeList(TypeConstants.MAP, typeObject)); - field.setImportClass(getImportClass(typeObject)); - - } else if (ApiTool.isObject(schemaProperty)) { - var typeObject = ApiTool.getType(schemaProperty); - if (ApiTool.hasRef(schemaProperty)) { - typeObject = MapperUtil.getRef(schema, specFile); - } - field.setImportClass(getImportClass(typeObject)); - field.getDataType().setDeepType(typeObject); - } - } - - private static String getMapTypeObject(final JsonNode schema, final SpecFile specFile) { - final String type; - if (ApiTool.isBoolean(ApiTool.getAdditionalProperties(schema))) { - type = TypeConstants.OBJECT; - } else { - final JsonNode additionalProperties = ApiTool.getAdditionalProperties(schema); - if (ApiTool.hasRef(additionalProperties)) { - type = MapperUtil.getRef(additionalProperties, specFile); - } else if (ApiTool.isObject(schema)) { - final var additionalPropertiesField = SchemaFieldObject - .builder() - .baseName(ApiTool.getName(additionalProperties)) - .dataType(new SchemaFieldObjectType(MapperUtil.getSimpleType(additionalProperties, specFile))) - .build(); - setFieldType(additionalPropertiesField, additionalProperties, additionalProperties, specFile, ""); - type = getMapFieldType(additionalPropertiesField); - } else { - type = TypeConstants.OBJECT; - } - } - - return type; - } - - private static String getMapFieldType(final SchemaFieldObject schemaFieldObject) { - final String fieldType = schemaFieldObject.getDataType().toString(); - final String type; - switch (fieldType) { - case TypeConstants.BIG_DECIMAL: - case TypeConstants.INTEGER: - case TypeConstants.DOUBLE: - case TypeConstants.FLOAT: - case TypeConstants.LONG: - case TypeConstants.STRING: - type = fieldType; - break; - default: - type = TypeConstants.OBJECT; - break; - } - - return type; - } - - private static SchemaFieldObject processEnumField( - final String key, final JsonNode value, final SpecFile specFile, final List enumValues, final JsonNode schema) { - final var field = SchemaFieldObject - .builder() - .baseName(key) - .dataType(new SchemaFieldObjectType(TypeConstants.ENUM)) - .build(); - field.setRequired(ApiTool.checkIfRequired(schema, key)); - final var dataType = MapperUtil.getSimpleType(value, specFile); - field.getDataType().setDeepType(dataType); - - final HashMap enumValuesMap = new HashMap<>(); - - for (final var enumValue : enumValues) { - String valueName = enumValue; - valueName = valueName.replace(".", "_DOT_"); - - switch (dataType) { - case TypeConstants.INTEGER: - enumValuesMap.put("INTEGER_" + valueName, enumValue); - break; - case TypeConstants.LONG: - enumValuesMap.put("LONG_" + valueName, enumValue + "l"); - break; - case TypeConstants.DOUBLE: - enumValuesMap.put("DOUBLE_" + valueName, enumValue); - break; - case TypeConstants.FLOAT: - enumValuesMap.put("FLOAT_" + valueName, enumValue + "f"); - break; - case TypeConstants.BIG_DECIMAL: - enumValuesMap.put("BIG_DECIMAL_" + valueName, "new BigDecimal(\"" + enumValue + "\")"); - break; - case TypeConstants.STRING: - default: - enumValuesMap.put(StringUtils.upperCase(valueName), '"' + enumValue + '"'); - break; - } - } - - if (enumValuesMap.isEmpty()) { - throw new BadDefinedEnumException(key); - } - field.setEnumValues(enumValuesMap); - return field; - } - - private static String getImportClass(final String type) { - return StringUtils.isNotBlank(type) && !TypeConstants.NO_IMPORT_TYPE.contains(type) ? StringUtils.capitalize(type) : ""; - } - } 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 6a32c51f..8b4ed802 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 @@ -7,7 +7,11 @@ package com.sngular.api.generator.plugin.openapi.utils; import com.fasterxml.jackson.databind.JsonNode; +import com.sngular.api.generator.plugin.common.model.SchemaFieldObjectType; +import com.sngular.api.generator.plugin.common.model.SchemaObject; +import com.sngular.api.generator.plugin.common.model.TypeConstants; import com.sngular.api.generator.plugin.common.tools.ApiTool; +import com.sngular.api.generator.plugin.common.tools.MapperUtil; 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; 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 0d8f040a..beb62bdb 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 @@ -130,7 +130,7 @@ private static String readFile(final Path rootFilePath, final String filePath) t return sb.toString(); } - public static Map processBasicJsonNodes(final JsonNode openApi, final Map schemaMap) { + public static Map processPaths(final JsonNode openApi, final Map schemaMap) { final var basicJsonNodeMap = new HashMap<>(schemaMap); for (final var pathElement = openApi.findValue(PATHS).elements(); pathElement.hasNext();) { @@ -138,7 +138,7 @@ public static Map processBasicJsonNodes(final JsonNode openApi for (Iterator it = pathDefinition.fieldNames(); it.hasNext();) { final var pathDefElement = it.next(); if (REST_VERB_SET.contains(pathDefElement)) { - processContentForBasicJsonNodes(basicJsonNodeMap, ApiTool.getNode(pathDefinition, pathDefElement)); + processPathContent(basicJsonNodeMap, ApiTool.getNode(pathDefinition, pathDefElement)); } } } @@ -146,7 +146,7 @@ public static Map processBasicJsonNodes(final JsonNode openApi return basicJsonNodeMap; } - private static void processContentForBasicJsonNodes(final HashMap basicJsonNodeMap, final JsonNode operation) { + private static void processPathContent(final HashMap basicJsonNodeMap, final JsonNode operation) { processParameters(basicJsonNodeMap, operation); processRequestBody(basicJsonNodeMap, operation); diff --git a/multiapi-engine/src/main/resources/templates/asyncapi/templateSchema.ftlh b/multiapi-engine/src/main/resources/templates/asyncapi/templateSchema.ftlh index 452b059a..3b10fa2e 100644 --- a/multiapi-engine/src/main/resources/templates/asyncapi/templateSchema.ftlh +++ b/multiapi-engine/src/main/resources/templates/asyncapi/templateSchema.ftlh @@ -1,3 +1,4 @@ +<#ftl output_format="plainText"> <#assign words = ["abstract", "assert", "boolean", "break", "byte", "case", "catch", "char", "class", "const", "continue", "default", "double", "do", "else", "enum", "extends", "false", "final", "finally", "float", "for", "goto", "if", "implements", "import", "instanceof", "int", "interface", "long", "native", "new", "null", "package", "private", "protected", "public", "return", "short", "static", "strictfp", "super", "switch", "synchronized", "this", "throw", "throws", "transient", "true", "try", "void", "volatile", "while"]> <#function calculateSafeName propertyName ender> <#if words?seq_contains(propertyName?uncap_first) || propertyName?matches("[0-9].*")> @@ -42,7 +43,7 @@ <#elseif value?is_number> <#return value> <#elseif value?is_string> - <#return '\"${value}\"'?no_esc> + <#return '\"${value}\"'> package ${packageModel}; @@ -53,7 +54,7 @@ import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder; import com.fasterxml.jackson.annotation.JsonProperty; <#list schema.fieldObjectList as field> - <#if field.dataType?has_content && field.dataTypeSimple == "enum"> + <#if field.enumValues?has_content> import com.fasterxml.jackson.annotation.JsonValue; <#break> @@ -99,27 +100,27 @@ import com.fasterxml.jackson.annotation.JsonFormat; <#list schema.fieldObjectList as field> - <#if field.required || schema.schemaCombinator == "anyOf" || schema.schemaCombinator == "oneOf"> + <#if field.required || schema.schemaCombinator?has_content && (schema.schemaCombinator == "anyOf" || schema.schemaCombinator == "oneOf")> import ${exceptionPackage}.exception.ModelClassException; <#break> <#list schema.fieldObjectList as field> - <#if field.restrictions.pattern?has_content> + <#if field.restrictions.pattern?has_content> import ${packageModel}.customvalidator.Pattern; - <#break> - + <#break> + <#list schema.fieldObjectList as field> - <#if field.restrictions.multipleOf?has_content> + <#if field.restrictions.multipleOf?has_content> import ${packageModel}.customvalidator.MultipleOf; - <#break> - + <#break> + <#list schema.fieldObjectList as field> <#if field.required?has_content && field.required == true> import ${packageModel}.customvalidator.NotNull; - <#break> + <#break> <#list schema.fieldObjectList as field> @@ -133,70 +134,82 @@ import ${packageModel}.customvalidator.UniqueItems; public class ${schema.className} { <#list schema.fieldObjectList as field> - @JsonProperty(value ="${field.baseName?uncap_first}") -<#if field.restrictions.minimum?has_content && (!field.restrictions.exclusiveMinimum?has_content || field.restrictions.exclusiveMinimum == false)> + @JsonProperty(value ="${calculateSafeName (field.baseName, "")}") + <#if field.restrictions.minimum?has_content && (!field.restrictions.exclusiveMinimum?has_content || field.restrictions.exclusiveMinimum == false)> @Min(minimum = "${field.restrictions.minimum}", exclusive = false) - -<#if field.restrictions.minimum?has_content && field.restrictions.exclusiveMinimum?has_content && field.restrictions.exclusiveMinimum == true> + + <#if field.restrictions.minimum?has_content && field.restrictions.exclusiveMinimum?has_content && field.restrictions.exclusiveMinimum == true> @Min(minimum = "${field.restrictions.minimum}", exclusive = ${field.restrictions.exclusiveMinimum?string}) - -<#if field.restrictions.maximum?has_content && (!field.restrictions.exclusiveMaximum?has_content || field.restrictions.exclusiveMaximum == false)> + + <#if field.restrictions.maximum?has_content && (!field.restrictions.exclusiveMaximum?has_content || field.restrictions.exclusiveMaximum == false)> @Max(maximum = "${field.restrictions.maximum}", exclusive = false) - -<#if field.restrictions.maximum?has_content && field.restrictions.exclusiveMaximum?has_content && field.restrictions.exclusiveMaximum == true> + + <#if field.restrictions.maximum?has_content && field.restrictions.exclusiveMaximum?has_content && field.restrictions.exclusiveMaximum == true> @Max(maximum = "${field.restrictions.maximum}", exclusive = ${field.restrictions.exclusiveMaximum?string}) - -<#if field.restrictions.maxItems?has_content> + + <#if field.restrictions.maxItems?has_content> @MaxItems(maximum = ${field.restrictions.maxItems}) - -<#if field.restrictions.minItems?has_content> + + <#if field.restrictions.minItems?has_content> @MinItems(minimum = ${field.restrictions.minItems}) - -<#if field.restrictions.format?has_content> - @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "${field.restrictions.format?no_esc}") - -<#if field.restrictions.uniqueItems?has_content && field.restrictions.uniqueItems == true> + + <#if field.restrictions.format?has_content> + @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "${field.restrictions.format}") + + <#if field.restrictions.uniqueItems?has_content && field.restrictions.uniqueItems == true> @UniqueItems - -<#if field.restrictions.maxLength?has_content && field.restrictions.minLength?has_content> + + <#if field.restrictions.maxLength?has_content && field.restrictions.minLength?has_content> @Size(min =${field.restrictions.minLength}, max =${field.restrictions.maxLength}) -<#elseif field.restrictions.maxLength?has_content && !field.restrictions.minLength?has_content> - @Size(max =${field.restrictions.maxLength}) -<#elseif !field.restrictions.maxLength?has_content && field.restrictions.minLength?has_content> - @Size(min =${field.restrictions.minLength}) - -<#if field.restrictions.pattern?has_content> + <#elseif field.restrictions.maxLength?has_content && !field.restrictions.minLength?has_content> + @Size(max =${field.restrictions.maxLength}, min =0) + <#elseif !field.restrictions.maxLength?has_content && field.restrictions.minLength?has_content> + @Size(max =0, min =${field.restrictions.minLength}) + + <#if field.restrictions.pattern?has_content> @Pattern(regex = "${field.restrictions.pattern}") - -<#if field.restrictions.multipleOf?has_content> + + <#if field.restrictions.multipleOf?has_content> @MultipleOf(multiple = "${field.restrictions.multipleOf}") - -<#if field.required?has_content && field.required == true> + + <#if field.required?has_content && field.required == true> @NotNull - - <#if field.dataType?has_content && (field.dataTypeSimple == "array" || field.dataTypeSimple == "Array")> - private ${requireFinal (field)}List<<#if field.parentPackage??>${packageModel}.${field.parentPackage}.${field.dataType}> ${calculateSafeName (field.baseName, "")} = new ArrayList<<#if field.parentPackage??>${packageModel}.${field.parentPackage}.${field.dataType}>(); - <#elseif field.dataType?has_content && field.dataTypeSimple == "map"> - private ${requireFinal (field)}Map ${calculateSafeName (field.baseName,"")} = new HashMap${packageModel}.${field.parentPackage}.${field.dataType}>(); - <#elseif field.dataType?has_content && field.dataTypeSimple == "enum"> - private ${requireFinal (field)}${field.baseName?cap_first} ${calculateSafeName (field.baseName, hasConstValue(field.constValue))} + + <#if field.dataType.baseType == "array"> + <#if field.required> + private final ${field.dataType} ${calculateSafeName (field.baseName, ";")} + <#else> + private ${field.dataType} ${calculateSafeName (field.baseName, "")} = new ${field.dataType?api.getImplementationTypeString()}(); + + <#elseif field.dataType.baseType == "map"> + <#if field.required> + private final ${field.dataType} ${calculateSafeName (field.baseName, ";")} + <#else> + private ${field.dataType} ${calculateSafeName (field.baseName, "")} = new ${field.dataType?api.getImplementationTypeString()}(); + + <#elseif field.dataType.baseType == "enum"> + <#if field.required> + private final ${field.baseName?cap_first} ${calculateSafeName (field.baseName, ";")} + <#else> + private ${field.baseName?cap_first} ${calculateSafeName (field.baseName, ";")} + public enum ${field.baseName?cap_first} { -<#list field.enumValues as value> - <#if value?matches("[0-9].*")> - ${"_"+value?upper_case?replace('[\\W]','_','r')}("${value?no_esc}")<#sep>, +<#list field.enumValues as key, value> + <#if key?matches("[0-9].*")> + ${"_"+key}(${value})<#sep>, <#else> - ${value?upper_case?replace('[\\W]','_','r')}("${value?no_esc}")<#sep>, + ${key}(${value})<#sep>, ; - private ${field.dataType?cap_first} value; + private ${field.dataType.innerType?cap_first} value; - ${field.baseName?cap_first}(${field.dataType?cap_first} value) { + ${field.baseName?cap_first}(${field.dataType.innerType?cap_first} value) { this.value = value; } @JsonValue - public ${field.dataType?cap_first} getValue() { + public ${field.dataType.innerType?cap_first} getValue() { return value; } @@ -205,25 +218,25 @@ public class ${schema.className} { return String.valueOf(value); } } - <#elseif field.dataTypeSimple?has_content> - <#if field.parentPackage??> - private ${requireFinal (field)}${packageModel}.${field.parentPackage}.${field.dataTypeSimple} ${calculateSafeName (field.baseName, ";")} - <#else> - private ${requireFinal (field)}${field.dataTypeSimple?cap_first} ${calculateSafeName (field.baseName, ";")} + <#elseif field.dataType.innerType?has_content && field.dataType.baseType == "object"> + <#if field.required> + private final ${field.dataType.innerType?cap_first} ${calculateSafeName (field.baseName, ";")} + <#else> + private ${field.dataType.innerType?cap_first} ${calculateSafeName (field.baseName, ";")} + + <#else> + <#if field.required> + private final ${field.dataType} ${calculateSafeName (field.baseName, ";")} + <#else> + private ${field.dataType} ${calculateSafeName (field.baseName, ";")} private ${schema.className}(${schema.className}Builder builder) { -<#list schema.fieldObjectList as field> - <#if field.dataType?has_content && (field.dataTypeSimple == "array" || field.dataTypeSimple == "Array")> - this.${calculateSafeName (field.baseName, "")}.addAll(builder.${calculateSafeName (field.baseName, "")}); - <#elseif field.dataType?has_content && field.dataTypeSimple == "map"> - this.${calculateSafeName (field.baseName, "")}.putAll(builder.${calculateSafeName (field.baseName, "")}); - <#else > + <#list schema.fieldObjectList as field> this.${calculateSafeName (field.baseName, "")} = builder.${calculateSafeName (field.baseName, ";")} - - + <#list schema.fieldObjectList as field> <#if field.required> @@ -244,21 +257,22 @@ public class ${schema.className} { public static class ${schema.className}Builder { <#list schema.fieldObjectList as field> - <#if field.dataType?has_content && field.dataTypeSimple == "array"> - private List<<#if field.parentPackage??>${packageModel}.${field.parentPackage}.${field.dataType}> ${calculateSafeName (field.baseName, "")} = new ArrayList<<#if field.parentPackage??>${packageModel}.${field.parentPackage}.${field.dataType}>(); - <#elseif field.dataType?has_content && field.dataTypeSimple == "map"> - private Map${packageModel}.${field.parentPackage}.${field.dataType}> ${calculateSafeName (field.baseName, "")} = new HashMap${packageModel}.${field.parentPackage}.${field.dataType}>(); - <#elseif field.dataType?has_content && field.dataTypeSimple == "enum"> + <#if field.dataType.baseType == "array"> + private ${field.dataType} ${calculateSafeName (field.baseName, "")} = new ${field.dataType?api.getImplementationTypeString()}(); + <#elseif field.dataType.baseType == "map"> + private ${field.dataType} ${calculateSafeName (field.baseName, "")} = new ${field.dataType?api.getImplementationTypeString()}(); + <#elseif field.dataType.baseType == "enum"> private ${field.baseName?cap_first} ${calculateSafeName (field.baseName, ";")} + <#elseif field.dataType.innerType?has_content && field.dataType.baseType == "object"> + private ${field.dataType.innerType?cap_first} ${calculateSafeName (field.baseName, ";")} <#else> - private <#if field.parentPackage??>${packageModel}.${field.parentPackage}.${field.dataTypeSimple?cap_first}<#else>${field.dataTypeSimple?cap_first} ${calculateSafeName (field.baseName, hasConstValue(field.constValue))} + private ${field.dataType} ${calculateSafeName (field.baseName, ";")} - <#list schema.fieldObjectList as field> - <#if field.dataType?has_content && field.dataTypeSimple == "array"> + <#if field.dataType.baseType == "array"> <#assign propName>${calculateSafeName (field.baseName, "")} - public ${schema.className}.${schema.className}Builder ${propName}(List<<#if field.parentPackage??>${packageModel}.${field.parentPackage}.${field.dataType}> ${propName}) { + public ${schema.className}.${schema.className}Builder ${propName}(${field.dataType} ${propName}) { if (!${propName}.isEmpty()) { this.${propName}.addAll(${propName}); } @@ -266,43 +280,42 @@ public class ${schema.className} { } <#assign singName>${singularizeName (calculateSafeName (field.baseName, ""))} - public ${schema.className}.${schema.className}Builder ${singName}(<#if field.parentPackage??>${packageModel}.${field.parentPackage}.${field.dataType} ${singName}) { + public ${schema.className}.${schema.className}Builder ${singName}(${field.dataType.innerType} ${singName}) { if (${singName} != null) { this.${propName}.add(${singName}); } return this; } - - <#elseif field.dataType?has_content && field.dataTypeSimple == "map"> + <#elseif field.dataType.baseType == "map"> <#assign propName>${calculateSafeName (field.baseName, "")} - public ${schema.className}.${schema.className}Builder ${propName}(Map ${propName}) { - this.${propName} = ${propName}; + public ${schema.className}.${schema.className}Builder ${propName}(${field.dataType} ${propName}) { + this.${propName} = ${propName}; return this; } - public ${schema.className}.${schema.className}Builder ${propName}Value(String key, ${field.dataType} value) { + public ${schema.className}.${schema.className}Builder ${propName}Value(String key, ${field.dataType.innerType} value) { this.${propName}.put(key, value); return this; } - - <#elseif field.dataType?has_content && field.dataTypeSimple == "enum"> - public ${schema.className}.${schema.className}Builder ${calculateSafeName (field.baseName, "")}(${field.baseName?cap_first} ${calculateSafeName (field.baseName, "")}) { + <#elseif field.dataType.baseType == "enum"> + public ${schema.className}.${schema.className}Builder ${calculateSafeName (field.baseName, "")}(${field.baseName?cap_first} ${field.baseName}) { this.${calculateSafeName (field.baseName, "")} = ${calculateSafeName (field.baseName, ";")} return this; } - - <#elseif !(field.constValue??)> - <#if field.parentPackage??> - public ${schema.className}.${schema.className}Builder ${calculateSafeName (field.baseName, "")}(${packageModel}.${field.parentPackage}.${field.dataTypeSimple?cap_first} ${calculateSafeName (field.baseName, "")}) { - <#else> - public ${schema.className}.${schema.className}Builder ${calculateSafeName (field.baseName, "")}(${field.dataTypeSimple?cap_first} ${calculateSafeName (field.baseName, "")}) { - - this.${calculateSafeName (field.baseName, "")} = ${calculateSafeName (field.baseName, "")}; + <#elseif field.dataType.innerType?has_content && field.dataType.baseType == "object"> + public ${schema.className}.${schema.className}Builder ${calculateSafeName (field.baseName, "")}(${field.dataType.innerType?cap_first} ${calculateSafeName (field.baseName, "")}) { + this.${calculateSafeName (field.baseName, "")} = ${calculateSafeName (field.baseName, ";")} return this; } + <#else> + public ${schema.className}.${schema.className}Builder ${calculateSafeName (field.baseName, "")}(${field.dataType} ${calculateSafeName (field.baseName, "")}) { + this.${calculateSafeName (field.baseName, "")} = ${calculateSafeName (field.baseName, ";")} + return this; + } + public ${schema.className} build() { ${schema.className} ${schema.className?uncap_first} = new ${schema.className}(this); return ${schema.className?uncap_first}; @@ -310,30 +323,26 @@ public class ${schema.className} { } <#list schema.fieldObjectList as field> - /** - * Get ${field.baseName?uncap_first} - * @return ${field.baseName?uncap_first} - */ @Schema(name = "${field.baseName?uncap_first}", required = <#if field.required?has_content && field.required == true>true<#else>false) - <#if field.dataType?has_content && field.dataTypeSimple == "array"> - public List<<#if field.parentPackage??>${packageModel}.${field.parentPackage}.${field.dataType}> get${field.baseName?cap_first}() { + <#if field.dataType.baseType == "array"> + public ${field.dataType} get${field.baseName?cap_first}() { return ${calculateSafeName (field.baseName, ";")} } <#if checkIfShouldSet (field)> - public void set${field.baseName?cap_first}(List<<#if field.parentPackage??>${packageModel}.${field.parentPackage}.${field.dataType}> ${calculateSafeName (field.baseName, "")}) { + public void set${field.baseName?cap_first}(${field.dataType} ${calculateSafeName (field.baseName, "")}) { this.${calculateSafeName (field.baseName, "")} = ${calculateSafeName (field.baseName, ";")} } - <#elseif field.dataType?has_content && field.dataTypeSimple == "map"> - public Map get${field.baseName?cap_first}() { + <#elseif field.dataType.baseType == "map"> + public ${field.dataType} get${field.baseName?cap_first}() { return ${calculateSafeName (field.baseName, ";")} } <#if checkIfShouldSet (field)> - public void set${field.baseName?cap_first}(Map ${calculateSafeName (field.baseName, "")}) { + public void set${field.baseName?cap_first}(${field.dataType} ${calculateSafeName (field.baseName, "")}) { this.${calculateSafeName (field.baseName, "")} = ${calculateSafeName (field.baseName, ";")} } - <#elseif field.dataType?has_content && field.dataTypeSimple == "enum"> + <#elseif field.dataType.baseType == "enum"> public ${field.baseName?cap_first} get${field.baseName?cap_first}() { return ${calculateSafeName (field.baseName, ";")} } @@ -342,21 +351,22 @@ public class ${schema.className} { this.${calculateSafeName (field.baseName, "")} = ${calculateSafeName (field.baseName, ";")} } - <#elseif field.dataTypeSimple?has_content> - <#if field.parentPackage??> - public ${packageModel}.${field.parentPackage}.${field.dataTypeSimple?cap_first} get${field.baseName?cap_first}() { - <#else> - public ${field.dataTypeSimple?cap_first} get${field.baseName?cap_first}() { - + <#elseif field.dataType.innerType?has_content && field.dataType.baseType == "object"> + public ${field.dataType.innerType?cap_first} get${field.baseName?cap_first}() { return ${calculateSafeName (field.baseName, ";")} } <#if checkIfShouldSet (field)> - <#if field.parentPackage??> - public void set${field.baseName?cap_first}(${packageModel}.${field.parentPackage}.${field.dataTypeSimple?cap_first} ${field.baseName?uncap_first}) { - <#else> - public void set${field.baseName?cap_first}(${field.dataTypeSimple?cap_first} ${calculateSafeName (field.baseName, "")}) { - - this.${calculateSafeName (field.baseName, "")} = ${calculateSafeName (field.baseName, "")}; + public void set${field.baseName?cap_first}(${field.dataType.innerType?cap_first} ${calculateSafeName (field.baseName, "")}) { + this.${calculateSafeName (field.baseName, "")} = ${calculateSafeName (field.baseName, ";")} + } + + <#else> + public ${field.dataType} get${field.baseName?cap_first}() { + return ${calculateSafeName (field.baseName, ";")} + } + <#if field.required == false> + public void set${field.baseName?cap_first}(${field.dataType} ${calculateSafeName (field.baseName, "")}) { + this.${calculateSafeName (field.baseName, "")} = ${calculateSafeName (field.baseName, ";")} } @@ -402,8 +412,7 @@ public class ${schema.className} { <#if field == schema.fieldObjectList?first> if (Objects.nonNull(this.${calculateSafeName (field.baseName, "")})) { <#else> else if (Objects.nonNull(this.${calculateSafeName (field.baseName, "")})) { - - satisfiedCondition = true; + satisfiedCondition = true; } if (!satisfiedCondition) { @@ -411,7 +420,6 @@ public class ${schema.className} { } } - <#list schema.fieldObjectList as field> <#if field.required> private void validateRequiredAttributes() { @@ -430,7 +438,8 @@ public class ${schema.className} { throw new ModelClassException("${schema.className}"); } } -<#break> - - + <#break> + + + } diff --git a/multiapi-engine/src/main/resources/templates/asyncapi/templateSchemaWithLombok.ftlh b/multiapi-engine/src/main/resources/templates/asyncapi/templateSchemaWithLombok.ftlh index ed5f0dca..75fdfb52 100644 --- a/multiapi-engine/src/main/resources/templates/asyncapi/templateSchemaWithLombok.ftlh +++ b/multiapi-engine/src/main/resources/templates/asyncapi/templateSchemaWithLombok.ftlh @@ -1,209 +1,187 @@ -<#assign words = ["abstract", "assert", "boolean", "break", "byte", "case", "catch", "char", "class", "const", "continue", "default", "double", "do", "else", "enum", "extends", "false", "final", "finally", "float", "for", "goto", "if", "implements", "import", "instanceof", "int", "interface", "long", "native", "new", "null", "package", "private", "protected", "public", "return", "short", "static", "strictfp", "super", "switch", "synchronized", "this", "throw", "throws", "transient", "true", "try", "void", "volatile", "while"]> -<#function calculateSafeName propertyName ender> - <#if words?seq_contains(propertyName?uncap_first) || propertyName?matches("[0-9].*")> - <#return "_"+propertyName+ender/> - <#else > - <#return propertyName+ender/> - - -<#function requireFinal property> - <#if property.required || property.const?has_content> - <#return "final "/> - <#else > - <#return ""/> - - -<#function hasConstValue value> - <#if value?has_content> - <#return "= " + value +";"/> - <#else > - <#return ";"/> - - +<#ftl output_format="plainText"> package ${packageModel}; -import java.util.Objects; - +<#if schema.schemaCombinator == "anyOf" || schema.schemaCombinator == "oneOf"> + import java.util.Objects; + import com.fasterxml.jackson.annotation.JsonProperty; <#list schema.fieldObjectList as field> - <#if field.dataType?has_content && field.dataTypeSimple == "enum"> -import com.fasterxml.jackson.annotation.JsonValue; - <#break> - + <#if field.dataType.baseType == "enum"> + import com.fasterxml.jackson.annotation.JsonValue; + <#break> + <#list schema.importList as import> -import ${import}; + import ${import}; <#list schema.fieldObjectList as field> - <#if field.restrictions.maxLength?has_content || field.restrictions.minLength?has_content> -import ${packageModel}.customvalidator.Size; + <#if field.restrictionProperties.maxLength?has_content || field.restrictionProperties.minLength?has_content> + import ${packageModel}.customvalidator.Size; <#break> <#list schema.fieldObjectList as field> - <#if field.restrictions.maximum?has_content> -import ${packageModel}.customvalidator.Max; + <#if field.restrictionProperties.maximum?has_content> + import ${packageModel}.customvalidator.Max; <#break> <#list schema.fieldObjectList as field> - <#if field.restrictions.minimum?has_content> -import ${packageModel}.customvalidator.Min; + <#if field.restrictionProperties.minimum?has_content> + import ${packageModel}.customvalidator.Min; <#break> <#list schema.fieldObjectList as field> - <#if field.restrictions.pattern?has_content> -import ${packageModel}.customvalidator.Pattern; + <#if field.restrictionProperties.pattern?has_content> + import ${packageModel}.customvalidator.Pattern; <#list schema.fieldObjectList as field> - <#if field.restrictions.multipleOf?has_content> -import ${packageModel}.customvalidator.MultipleOf; + <#if field.restrictionProperties.multipleOf?has_content> + import ${packageModel}.customvalidator.MultipleOf; <#break> <#list schema.fieldObjectList as field> - <#if field.restrictions.maxItems?has_content> -import ${packageModel}.customvalidator.MaxItems; + <#if field.restrictionProperties.maxItems?has_content> + import ${packageModel}.customvalidator.MaxItems; <#break> <#list schema.fieldObjectList as field> - <#if field.restrictions.minItems?has_content> -import ${packageModel}.customvalidator.MinItems; + <#if field.restrictionProperties.minItems?has_content> + import ${packageModel}.customvalidator.MinItems; <#break> <#list schema.fieldObjectList as field> - <#if field.restrictions.uniqueItems?has_content && field.restrictions.uniqueItems == true> -import ${packageModel}.customvalidator.UniqueItems; + <#if field.restrictionProperties.uniqueItems?has_content && field.restrictionProperties.uniqueItems == true> + import ${packageModel}.customvalidator.UniqueItems; <#break> import lombok.Builder; import lombok.Data; <#list schema.fieldObjectList as field> - <#if field.required> -import lombok.NonNull; - <#break> - + <#if field.required> + import lombok.NonNull; + <#break> + +import lombok.extern.jackson.Jacksonized; <#if schema.schemaCombinator == "anyOf" || schema.schemaCombinator == "oneOf"> -import ${exceptionPackage}.exception.ModelClassException; + import ${packageModel}.exception.ModelClassException; @Data public class ${schema.className} { <#list schema.fieldObjectList as field> - @JsonProperty(value ="${field.baseName?uncap_first}") - <#if field.restrictions.minimum?has_content && (!field.restrictions.exclusiveMinimum?has_content || field.restrictions.exclusiveMinimum == false)> - @Min(minimum = "${field.restrictions.minimum}", exclusive = false) - - <#if field.restrictions.minimum?has_content && field.restrictions.exclusiveMinimum?has_content && field.restrictions.exclusiveMinimum == true> - @Min(minimum = "${field.restrictions.minimum}", exclusive = ${field.restrictions.exclusiveMinimum?string}) - - <#if field.restrictions.maximum?has_content && (!field.restrictions.exclusiveMaximum?has_content || field.restrictions.exclusiveMaximum == false)> - @Max(maximum = "${field.restrictions.maximum}", exclusive = false) - - <#if field.restrictions.maximum?has_content && field.restrictions.exclusiveMaximum?has_content && field.restrictions.exclusiveMaximum == true> - @Max(maximum = "${field.restrictions.maximum}", exclusive = ${field.restrictions.exclusiveMaximum?string}) - - <#if field.restrictions.maxItems?has_content> - @MaxItems(maximum = ${field.restrictions.maxItems}) - - <#if field.restrictions.minItems?has_content> - @MinItems(minimum = ${field.restrictions.minItems}) - - <#if field.restrictions.uniqueItems?has_content && field.restrictions.uniqueItems == true> - @UniqueItems - - <#if field.restrictions.maxLength?has_content && field.restrictions.minLength?has_content> - @Size(min =${field.restrictions.minLength}, max =${field.restrictions.maxLength}) - <#elseif field.restrictions.maxLength?has_content && !field.restrictions.minLength?has_content> - @Size(max =${field.restrictions.maxLength}) - <#elseif !field.restrictions.maxLength?has_content && field.restrictions.minLength?has_content> - @Size(min =${field.restrictions.minLength}) - - <#if field.restrictions.pattern?has_content> - @Pattern(regex = "${field.restrictions.pattern}") - - <#if field.restrictions.multipleOf?has_content> - @MultipleOf(multiple = "${field.restrictions.multipleOf}") - - <#if field.required?has_content && field.required == true> - @NonNull - - <#if field.dataType?has_content && field.dataTypeSimple == "array"> - @Builder.Default - private List<${field.dataType}> ${calculateSafeName (field.baseName, "")} = new ArrayList<${field.dataType}>(); - <#elseif field.dataType?has_content && field.dataTypeSimple == "map"> - @Builder.Default - private Map ${calculateSafeName (field.baseName, "")} = new HashMap(); - <#elseif field.dataType?has_content && field.dataTypeSimple == "enum"> - private ${requireFinal (field)}${field.baseName?cap_first} ${calculateSafeName (field.baseName, hasConstValue(field.constValue))} + @JsonProperty(value ="${field.baseName?uncap_first}") + <#if field.restrictionProperties.minimum?has_content && (!field.restrictionProperties.exclusiveMinimum?has_content || field.restrictionProperties.exclusiveMinimum == false)> + @Min(minimum = "${field.restrictionProperties.minimum}", exclusive = false) + + <#if field.restrictionProperties.minimum?has_content && field.restrictionProperties.exclusiveMinimum?has_content && field.restrictionProperties.exclusiveMinimum == true> + @Min(minimum = "${field.restrictionProperties.minimum}", exclusive = ${field.restrictionProperties.exclusiveMinimum?string}) + + <#if field.restrictionProperties.maximum?has_content && (!field.restrictionProperties.exclusiveMaximum?has_content || field.restrictionProperties.exclusiveMaximum == false)> + @Max(maximum = "${field.restrictionProperties.maximum}", exclusive = false) + + <#if field.restrictionProperties.maximum?has_content && field.restrictionProperties.exclusiveMaximum?has_content && field.restrictionProperties.exclusiveMaximum == true> + @Max(maximum = "${field.restrictionProperties.maximum}", exclusive = ${field.restrictionProperties.exclusiveMaximum?string}) + + <#if field.restrictionProperties.maxItems?has_content> + @MaxItems(maximum = ${field.restrictionProperties.maxItems}) + + <#if field.restrictionProperties.minItems?has_content> + @MinItems(minimum = ${field.restrictionProperties.minItems}) + + <#if field.restrictionProperties.uniqueItems?has_content && field.restrictionProperties.uniqueItems == true> + @UniqueItems + + <#if field.restrictionProperties.maxLength?has_content && field.restrictionProperties.minLength?has_content> + @Size(min =${field.restrictionProperties.minLength}, max =${field.restrictionProperties.maxLength}) + <#elseif field.restrictionProperties.maxLength?has_content && !field.restrictionProperties.minLength?has_content> + @Size(min =0, max =${field.restrictionProperties.maxLength}) + <#elseif !field.restrictionProperties.maxLength?has_content && field.restrictionProperties.minLength?has_content> + @Size(min =${field.restrictionProperties.minLength}, max =0) + + <#if field.restrictionProperties.pattern?has_content> + @Pattern(regex = "${field.restrictionProperties.pattern}") + + <#if field.restrictionProperties.multipleOf?has_content> + @MultipleOf(multiple = "${field.restrictionProperties.multipleOf}") + + <#if field.required?has_content && field.required == true> + @NonNull + + <#if field.dataType.baseType == "array"> + private ${field.dataType} ${field.baseName?uncap_first} = new ${field.dataType?api.getImplementationTypeString()}(); + <#elseif field.dataType.baseType == "map"> + private ${field.dataType} ${field.baseName?uncap_first} = new ${field.dataType?api.getImplementationTypeString()}(); + <#elseif field.dataType.baseType == "enum"> + private ${field.baseName?cap_first} ${field.baseName?uncap_first}; - public enum ${field.baseName?cap_first} { -<#list field.enumValues as key, value> - <#if key?matches("[0-9].*")> - ${"_"+key}(${value?no_esc})<#sep>, - <#else> - ${key}(${value?no_esc})<#sep>, - -; + public enum ${field.baseName?cap_first} { + <#list field.enumValues as key, value> + <#if key?matches("[0-9].*")> + ${"_"+key}(${value})<#sep>, + <#else> + ${key}(${value})<#sep>, + + ; - private ${field.dataType?cap_first} value; + private ${field.dataType.innerType?cap_first} value; - ${field.baseName?cap_first}(${field.dataType?cap_first} value) { - this.value = value; - } + ${field.baseName?cap_first}(${field.dataType.innerType?cap_first} value) { + this.value = value; + } - @JsonValue - public ${field.dataType?cap_first} getValue() { - return value; - } + @JsonValue + public ${field.dataType.innerType?cap_first} getValue() { + return value; + } - @Override - public String toString() { - return String.valueOf(value); - } - } - <#elseif field.dataTypeSimple?has_content> - private ${requireFinal (field)}${field.baseName?cap_first} ${calculateSafeName (field.baseName, hasConstValue(field.constValue))} - + @Override + public String toString() { + return String.valueOf(value); + } + } + <#elseif field.dataType.innerType?has_content && field.dataType.baseType == "object"> + private ${field.dataType.innerType?cap_first} ${field.baseName?uncap_first}; + <#else> + private ${field.dataType} ${field.baseName?uncap_first}; + - @Builder - private ${schema.className}(<@compress single_line=true><#list schema.fieldObjectList as field> - <#if field.required>@NonNull <#if field.dataType?has_content && field.dataTypeSimple == "enum">${field.baseName?cap_first} ${calculateSafeName (field.baseName, ";")}<#elseif field.dataType?has_content && field.dataTypeSimple == "array">List<${field.dataType}> ${calculateSafeName (field.baseName, ";")}<#elseif field.dataType?has_content && field.dataTypeSimple == "map">Map ${calculateSafeName (field.baseName, ";")}<#else>${field.dataTypeSimple?cap_first} ${calculateSafeName (field.baseName, ";")}<#sep>, ) { - <#list schema.fieldObjectList as field> - this.${calculateSafeName (field.baseName, ";")} = ${calculateSafeName (field.baseName, ";")}; - +@Builder +@Jacksonized +private ${schema.className}(<@compress single_line=true><#list schema.fieldObjectList as field> + <#if field.required>@NonNull <#if field.dataType.baseType == "enum">${field.baseName?cap_first} ${field.baseName?uncap_first}<#elseif field.dataType.baseType == "array">${field.dataType} ${field.baseName?uncap_first}<#elseif field.dataType.baseType == "map">${field.dataType} ${field.baseName?uncap_first}<#elseif field.dataType.innerType?has_content && field.dataType.baseType == "object">${field.dataType.innerType?cap_first} ${field.baseName?uncap_first}<#else>${field.dataType} ${field.baseName?uncap_first}<#sep>, ) { +<#list schema.fieldObjectList as field> + this.${field.baseName?uncap_first} = ${field.baseName?uncap_first}; + - <#if schema.schemaCombinator == "anyOf" || schema.schemaCombinator == "oneOf"> +<#if schema.schemaCombinator == "anyOf" || schema.schemaCombinator == "oneOf"> validatePartialCombinations(); - - } + +} - <#if schema.schemaCombinator == "anyOf" || schema.schemaCombinator == "oneOf"> +<#if schema.schemaCombinator == "anyOf" || schema.schemaCombinator == "oneOf"> private void validatePartialCombinations() { boolean satisfiedCondition = false; - <#list schema.fieldObjectList as field> - <#if field == schema.fieldObjectList?first> - if (Objects.nonNull(this.${calculateSafeName (field.baseName, ";")})) { - <#else> - else if (Objects.nonNull(this.${calculateSafeName (field.baseName, ";")})) { - - satisfiedCondition = true; - } - + <#list schema.fieldObjectList as field> + <#if field == schema.fieldObjectList?first> + if (Objects.nonNull(this.${field.baseName?uncap_first})) {<#else> else if (Objects.nonNull(this.${field.baseName?uncap_first})) { + satisfiedCondition = true; + } if (!satisfiedCondition) { - throw new ModelClassException("${schema.className}"); + throw new ModelClassException("${schema.className}"); } } - + } diff --git a/multiapi-engine/src/main/resources/templates/openapi/templateSchema.ftlh b/multiapi-engine/src/main/resources/templates/openapi/templateSchema.ftlh index fc4c282e..bf2cb362 100644 --- a/multiapi-engine/src/main/resources/templates/openapi/templateSchema.ftlh +++ b/multiapi-engine/src/main/resources/templates/openapi/templateSchema.ftlh @@ -16,6 +16,36 @@ <#return propertyName/> +<#function requireFinal field> + <#if field.required == true || field.constValue??> + <#return "final "/> + <#else > + <#return ""/> + + +<#function checkIfShouldSet field> + <#if field.required == true || field.constValue??> + <#return false/> + <#else > + <#return true/> + + +<#function hasConstValue value=""> + <#if value?has_content> + <#return " = " + renderValue (value) + ";"/> + <#else > + <#return ";"/> + + +<#function renderValue value=""> + <#if value?is_boolean> + <#return value == true> + <#elseif value?is_number> + <#return value> + <#elseif value?is_string> + <#return '\"${value}\"'?no_esc> + + package ${packageModel}; import java.util.Objects; @@ -34,31 +64,31 @@ import io.swagger.v3.oas.annotations.media.Schema; import ${import}; <#list schema.fieldObjectList as field> - <#if field.restrictionProperties.maxLength?has_content || field.restrictionProperties.minLength?has_content> + <#if field.restrictions.maxLength?has_content || field.restrictions.minLength?has_content> import ${packageModel}.customvalidator.Size; <#break> <#list schema.fieldObjectList as field> - <#if field.restrictionProperties.maximum?has_content> + <#if field.restrictions.maximum?has_content> import ${packageModel}.customvalidator.Max; <#break> <#list schema.fieldObjectList as field> - <#if field.restrictionProperties.minimum?has_content> + <#if field.restrictions.minimum?has_content> import ${packageModel}.customvalidator.Min; <#break> <#list schema.fieldObjectList as field> - <#if field.restrictionProperties.maxItems?has_content> + <#if field.restrictions.maxItems?has_content> import ${packageModel}.customvalidator.MaxItems; <#break> <#list schema.fieldObjectList as field> - <#if field.restrictionProperties.minItems?has_content> + <#if field.restrictions.minItems?has_content> import ${packageModel}.customvalidator.MinItems; <#break> @@ -70,13 +100,13 @@ import ${packageModel}.exception.ModelClassException; <#list schema.fieldObjectList as field> - <#if field.restrictionProperties.pattern?has_content> + <#if field.restrictions.pattern?has_content> import ${packageModel}.customvalidator.Pattern; <#break> <#list schema.fieldObjectList as field> - <#if field.restrictionProperties.multipleOf?has_content> + <#if field.restrictions.multipleOf?has_content> import ${packageModel}.customvalidator.MultipleOf; <#break> @@ -88,7 +118,7 @@ import ${packageModel}.customvalidator.NotNull; <#list schema.fieldObjectList as field> - <#if field.restrictionProperties.uniqueItems?has_content && field.restrictionProperties.uniqueItems == true> + <#if field.restrictions.uniqueItems?has_content && field.restrictions.uniqueItems == true> import ${packageModel}.customvalidator.UniqueItems; <#break> @@ -99,39 +129,39 @@ public class ${schema.className} { <#list schema.fieldObjectList as field> @JsonProperty(value ="${calculateSafeName (field.baseName, "")}") - <#if field.restrictionProperties.minimum?has_content && (!field.restrictionProperties.exclusiveMinimum?has_content || field.restrictionProperties.exclusiveMinimum == false)> - @Min(minimum = "${field.restrictionProperties.minimum}", exclusive = false) + <#if field.restrictions.minimum?has_content && (!field.restrictions.exclusiveMinimum?has_content || field.restrictions.exclusiveMinimum == false)> + @Min(minimum = "${field.restrictions.minimum}", exclusive = false) - <#if field.restrictionProperties.minimum?has_content && field.restrictionProperties.exclusiveMinimum?has_content && field.restrictionProperties.exclusiveMinimum == true> - @Min(minimum = "${field.restrictionProperties.minimum}", exclusive = ${field.restrictionProperties.exclusiveMinimum?string}) + <#if field.restrictions.minimum?has_content && field.restrictions.exclusiveMinimum?has_content && field.restrictions.exclusiveMinimum == true> + @Min(minimum = "${field.restrictions.minimum}", exclusive = ${field.restrictions.exclusiveMinimum?string}) - <#if field.restrictionProperties.maximum?has_content && (!field.restrictionProperties.exclusiveMaximum?has_content || field.restrictionProperties.exclusiveMaximum == false)> - @Max(maximum = "${field.restrictionProperties.maximum}", exclusive = false) + <#if field.restrictions.maximum?has_content && (!field.restrictions.exclusiveMaximum?has_content || field.restrictions.exclusiveMaximum == false)> + @Max(maximum = "${field.restrictions.maximum}", exclusive = false) - <#if field.restrictionProperties.maximum?has_content && field.restrictionProperties.exclusiveMaximum?has_content && field.restrictionProperties.exclusiveMaximum == true> - @Max(maximum = "${field.restrictionProperties.maximum}", exclusive = ${field.restrictionProperties.exclusiveMaximum?string}) + <#if field.restrictions.maximum?has_content && field.restrictions.exclusiveMaximum?has_content && field.restrictions.exclusiveMaximum == true> + @Max(maximum = "${field.restrictions.maximum}", exclusive = ${field.restrictions.exclusiveMaximum?string}) - <#if field.restrictionProperties.maxItems?has_content> - @MaxItems(maximum = ${field.restrictionProperties.maxItems}) + <#if field.restrictions.maxItems?has_content> + @MaxItems(maximum = ${field.restrictions.maxItems}) - <#if field.restrictionProperties.minItems?has_content> - @MinItems(minimum = ${field.restrictionProperties.minItems}) + <#if field.restrictions.minItems?has_content> + @MinItems(minimum = ${field.restrictions.minItems}) - <#if field.restrictionProperties.uniqueItems?has_content && field.restrictionProperties.uniqueItems == true> + <#if field.restrictions.uniqueItems?has_content && field.restrictions.uniqueItems == true> @UniqueItems - <#if field.restrictionProperties.maxLength?has_content && field.restrictionProperties.minLength?has_content> - @Size(min =${field.restrictionProperties.minLength}, max =${field.restrictionProperties.maxLength}) - <#elseif field.restrictionProperties.maxLength?has_content && !field.restrictionProperties.minLength?has_content> - @Size(max =${field.restrictionProperties.maxLength}, min =0) - <#elseif !field.restrictionProperties.maxLength?has_content && field.restrictionProperties.minLength?has_content> - @Size(max =0, min =${field.restrictionProperties.minLength}) + <#if field.restrictions.maxLength?has_content && field.restrictions.minLength?has_content> + @Size(min =${field.restrictions.minLength}, max =${field.restrictions.maxLength}) + <#elseif field.restrictions.maxLength?has_content && !field.restrictions.minLength?has_content> + @Size(max =${field.restrictions.maxLength}, min =0) + <#elseif !field.restrictions.maxLength?has_content && field.restrictions.minLength?has_content> + @Size(max =0, min =${field.restrictions.minLength}) - <#if field.restrictionProperties.pattern?has_content> - @Pattern(regex = "${field.restrictionProperties.pattern}") + <#if field.restrictions.pattern?has_content> + @Pattern(regex = "${field.restrictions.pattern}") - <#if field.restrictionProperties.multipleOf?has_content> - @MultipleOf(multiple = "${field.restrictionProperties.multipleOf}") + <#if field.restrictions.multipleOf?has_content> + @MultipleOf(multiple = "${field.restrictions.multipleOf}") <#if field.required?has_content && field.required == true> @NotNull @@ -306,7 +336,7 @@ public class ${schema.className} { public ${field.dataType} get${field.baseName?cap_first}() { return ${calculateSafeName (field.baseName, ";")} } - <#if field.required == false> + <#if checkIfShouldSet (field)> public void set${field.baseName?cap_first}(${field.dataType} ${calculateSafeName (field.baseName, "")}) { this.${calculateSafeName (field.baseName, "")} = ${calculateSafeName (field.baseName, ";")} } @@ -315,7 +345,7 @@ public class ${schema.className} { public ${field.dataType} get${field.baseName?cap_first}() { return ${calculateSafeName (field.baseName, ";")} } - <#if field.required == false> + <#if checkIfShouldSet (field)> public void set${field.baseName?cap_first}(${field.dataType} ${calculateSafeName (field.baseName, "")}) { this.${calculateSafeName (field.baseName, "")} = ${calculateSafeName (field.baseName, ";")} } @@ -324,7 +354,7 @@ public class ${schema.className} { public ${field.baseName?cap_first} get${field.baseName?cap_first}() { return ${calculateSafeName (field.baseName, ";")} } - <#if field.required == false> + <#if checkIfShouldSet (field)> public void set${field.baseName?cap_first}(${field.baseName?cap_first} ${calculateSafeName (field.baseName, "")}) { this.${calculateSafeName (field.baseName, "")} = ${calculateSafeName (field.baseName, ";")} } @@ -333,7 +363,7 @@ public class ${schema.className} { public ${field.dataType.innerType?cap_first} get${field.baseName?cap_first}() { return ${calculateSafeName (field.baseName, ";")} } - <#if field.required == false> + <#if checkIfShouldSet (field)> public void set${field.baseName?cap_first}(${field.dataType.innerType?cap_first} ${calculateSafeName (field.baseName, "")}) { this.${calculateSafeName (field.baseName, "")} = ${calculateSafeName (field.baseName, ";")} } @@ -407,7 +437,7 @@ public class ${schema.className} { <#if field?index == 0> if (!Objects.nonNull(this.${calculateSafeName (field.baseName, "")})) { <#else> - else if (!Objects.nonNull(this.${calculateSafeName (field.baseName, "")})) { + else if (!Objects.nonNull(this.${calculateSafeName (field.baseName, "")})) { satisfiedCondition = false; } diff --git a/multiapi-engine/src/test/java/com/sngular/api/generator/plugin/openapi/OpenApiGeneratorFixtures.java b/multiapi-engine/src/test/java/com/sngular/api/generator/plugin/openapi/OpenApiGeneratorFixtures.java index 564c9836..7d4280d9 100644 --- a/multiapi-engine/src/test/java/com/sngular/api/generator/plugin/openapi/OpenApiGeneratorFixtures.java +++ b/multiapi-engine/src/test/java/com/sngular/api/generator/plugin/openapi/OpenApiGeneratorFixtures.java @@ -15,7 +15,7 @@ import java.util.List; import java.util.function.Function; -import com.sngular.api.generator.plugin.openapi.model.TypeConstants.TimeType; +import com.sngular.api.generator.plugin.common.model.TypeConstants.TimeType; import com.sngular.api.generator.plugin.openapi.parameter.SpecFile; import com.sngular.api.generator.test.utils.TestUtils; import lombok.extern.slf4j.Slf4j; diff --git a/multiapi-engine/src/test/resources/asyncapigenerator/testConstantGeneration/assets/payload/SomeOtherObject.java b/multiapi-engine/src/test/resources/asyncapigenerator/testConstantGeneration/assets/payload/SomeOtherObject.java index 12cccd46..b086d071 100644 --- a/multiapi-engine/src/test/resources/asyncapigenerator/testConstantGeneration/assets/payload/SomeOtherObject.java +++ b/multiapi-engine/src/test/resources/asyncapigenerator/testConstantGeneration/assets/payload/SomeOtherObject.java @@ -10,14 +10,14 @@ @JsonDeserialize(builder = SomeOtherObject.SomeOtherObjectBuilder.class) public class SomeOtherObject { - @JsonProperty(value ="property1") - private final Integer property1; @JsonProperty(value ="property2") - private final Integer property2; + private Integer property2; + @JsonProperty(value ="property1") + private Integer property1; private SomeOtherObject(SomeOtherObjectBuilder builder) { - this.property1 = builder.property1; this.property2 = builder.property2; + this.property1 = builder.property1; } @@ -28,9 +28,18 @@ public static SomeOtherObject.SomeOtherObjectBuilder builder() { @JsonPOJOBuilder(buildMethodName = "build", withPrefix = "") public static class SomeOtherObjectBuilder { + private Integer property2 = 6; private Integer property1 = 3; - private Integer property2 = 6; + public SomeOtherObject.SomeOtherObjectBuilder property2(Integer property2) { + this.property2 = property2; + return this; + } + + public SomeOtherObject.SomeOtherObjectBuilder property1(Integer property1) { + this.property1 = property1; + return this; + } public SomeOtherObject build() { SomeOtherObject someOtherObject = new SomeOtherObject(this); @@ -38,22 +47,20 @@ public SomeOtherObject build() { } } - /** - * Get property1 - * @return property1 - */ + @Schema(name = "property2", required = false) + public Integer getProperty2() { + return property2; + } + public void setProperty2(Integer property2) { + this.property2 = property2; + } + @Schema(name = "property1", required = false) public Integer getProperty1() { return property1; } - - /** - * Get property2 - * @return property2 - */ - @Schema(name = "property2", required = false) - public Integer getProperty2() { - return property2; + public void setProperty1(Integer property1) { + this.property1 = property1; } @Override @@ -65,23 +72,23 @@ public boolean equals(Object o) { return false; } SomeOtherObject someOtherObject = (SomeOtherObject) o; - return Objects.equals(this.property1, someOtherObject.property1) && Objects.equals(this.property2, someOtherObject.property2); + return Objects.equals(this.property2, someOtherObject.property2) && Objects.equals(this.property1, someOtherObject.property1); } @Override public int hashCode() { - return Objects.hash(property1, property2); + return Objects.hash(property2, property1); } @Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append("SomeOtherObject{"); - sb.append(" property1:").append(property1).append(","); - sb.append(" property2:").append(property2); + sb.append(" property2:").append(property2).append(","); + sb.append(" property1:").append(property1); sb.append("}"); return sb.toString(); } -} \ No newline at end of file +} diff --git a/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/assets/DataDTO.java b/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/assets/DataDTO.java index 11efb65f..13bca324 100644 --- a/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/assets/DataDTO.java +++ b/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/assets/DataDTO.java @@ -13,43 +13,36 @@ import com.sngular.scsplugin.customvalidator.model.event.customvalidator.Min; import com.sngular.scsplugin.customvalidator.model.event.customvalidator.MaxItems; import com.sngular.scsplugin.customvalidator.model.event.customvalidator.MinItems; -import com.sngular.scsplugin.customvalidator.model.event.exception.ModelClassException; import com.sngular.scsplugin.customvalidator.model.event.customvalidator.Pattern; import com.sngular.scsplugin.customvalidator.model.event.customvalidator.MultipleOf; -import com.sngular.scsplugin.customvalidator.model.event.customvalidator.NotNull; import com.sngular.scsplugin.customvalidator.model.event.customvalidator.UniqueItems; @JsonDeserialize(builder = DataDTO.DataDTOBuilder.class) public class DataDTO { - @JsonProperty(value ="clientId") - @Min(minimum = "10", exclusive = false) - @Max(maximum = "200", exclusive = true) - @MultipleOf(multiple = "10") - @NotNull - private final Integer clientId; @JsonProperty(value ="clientName") @Size(min =50, max =200) @Pattern(regex = "^[a-zA-Z0-9_.-]*$") - @NotNull - private final String clientName; + private String clientName; @JsonProperty(value ="flightNumber") - @NotNull - private final String flightNumber; + private String flightNumber; + @JsonProperty(value ="clientId") + @Min(minimum = "10", exclusive = false) + @Max(maximum = "200", exclusive = true) + @MultipleOf(multiple = "10") + private Integer clientId; @JsonProperty(value ="test") @MaxItems(maximum = 10) @MinItems(minimum = 5) @UniqueItems - @NotNull - private final List test = new ArrayList(); + private List test = new ArrayList(); private DataDTO(DataDTOBuilder builder) { - this.clientId = builder.clientId; this.clientName = builder.clientName; this.flightNumber = builder.flightNumber; - this.test.addAll(builder.test); + this.clientId = builder.clientId; + this.test = builder.test; - validateRequiredAttributes(); } public static DataDTO.DataDTOBuilder builder() { @@ -59,19 +52,11 @@ public static DataDTO.DataDTOBuilder builder() { @JsonPOJOBuilder(buildMethodName = "build", withPrefix = "") public static class DataDTOBuilder { - private Integer clientId; - private String clientName; - private String flightNumber; - + private Integer clientId; private List test = new ArrayList(); - public DataDTO.DataDTOBuilder clientId(Integer clientId) { - this.clientId = clientId; - return this; - } - public DataDTO.DataDTOBuilder clientName(String clientName) { this.clientName = clientName; return this; @@ -82,6 +67,10 @@ public DataDTO.DataDTOBuilder flightNumber(String flightNumber) { return this; } + public DataDTO.DataDTOBuilder clientId(Integer clientId) { + this.clientId = clientId; + return this; + } public DataDTO.DataDTOBuilder test(List test) { if (!test.isEmpty()) { this.test.addAll(test); @@ -102,41 +91,37 @@ public DataDTO build() { } } - /** - * Get clientId - * @return clientId - */ - @Schema(name = "clientId", required = true) - public Integer getClientId() { - return clientId; - } - - /** - * Get clientName - * @return clientName - */ - @Schema(name = "clientName", required = true) + @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 = true) + @Schema(name = "flightNumber", required = false) public String getFlightNumber() { return flightNumber; } + public void setFlightNumber(String flightNumber) { + this.flightNumber = flightNumber; + } - /** - * Get test - * @return test - */ - @Schema(name = "test", required = true) + @Schema(name = "clientId", required = false) + public Integer getClientId() { + return clientId; + } + public void setClientId(Integer clientId) { + this.clientId = clientId; + } + + @Schema(name = "test", required = false) public List getTest() { return test; } + public void setTest(List test) { + this.test = test; + } @Override public boolean equals(Object o) { @@ -147,42 +132,25 @@ public boolean equals(Object o) { 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) && Objects.equals(this.test, dataDTO.test); + return Objects.equals(this.clientName, dataDTO.clientName) && Objects.equals(this.flightNumber, dataDTO.flightNumber) && Objects.equals(this.clientId, dataDTO.clientId) && Objects.equals(this.test, dataDTO.test); } @Override public int hashCode() { - return Objects.hash(clientId, clientName, flightNumber, test); + return Objects.hash(clientName, flightNumber, clientId, test); } @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).append(","); + sb.append(" clientId:").append(clientId).append(","); sb.append(" test:").append(test); sb.append("}"); return sb.toString(); } - private void validateRequiredAttributes() { - boolean satisfiedCondition = true; - - if (!Objects.nonNull(this.clientId)) { - satisfiedCondition = false; - } else if (!Objects.nonNull(this.clientName)) { - satisfiedCondition = false; - } else if (!Objects.nonNull(this.flightNumber)) { - satisfiedCondition = false; - } else if (!Objects.nonNull(this.test)) { - satisfiedCondition = false; - } - - if (!satisfiedCondition) { - throw new ModelClassException("DataDTO"); - } - } } diff --git a/multiapi-engine/src/test/resources/asyncapigenerator/testFileGeneration/assets/CreateOrderMapper.java b/multiapi-engine/src/test/resources/asyncapigenerator/testFileGeneration/assets/CreateOrderMapper.java index 6a674731..d931af72 100644 --- a/multiapi-engine/src/test/resources/asyncapigenerator/testFileGeneration/assets/CreateOrderMapper.java +++ b/multiapi-engine/src/test/resources/asyncapigenerator/testFileGeneration/assets/CreateOrderMapper.java @@ -10,14 +10,14 @@ @JsonDeserialize(builder = CreateOrderMapper.CreateOrderMapperBuilder.class) public class CreateOrderMapper { - @JsonProperty(value ="order") - private OrderMapper order; @JsonProperty(value ="waiter") private WaiterMapper waiter; + @JsonProperty(value ="order") + private OrderMapper order; private CreateOrderMapper(CreateOrderMapperBuilder builder) { - this.order = builder.order; this.waiter = builder.waiter; + this.order = builder.order; } @@ -28,19 +28,16 @@ public static CreateOrderMapper.CreateOrderMapperBuilder builder() { @JsonPOJOBuilder(buildMethodName = "build", withPrefix = "") public static class CreateOrderMapperBuilder { - private OrderMapper order; - private WaiterMapper waiter; - - public CreateOrderMapper.CreateOrderMapperBuilder order(OrderMapper order) { - this.order = order; - return this; - } - + private OrderMapper order; public CreateOrderMapper.CreateOrderMapperBuilder waiter(WaiterMapper waiter) { this.waiter = waiter; return this; } + public CreateOrderMapper.CreateOrderMapperBuilder order(OrderMapper order) { + this.order = order; + return this; + } public CreateOrderMapper build() { CreateOrderMapper createOrderMapper = new CreateOrderMapper(this); @@ -48,22 +45,6 @@ public CreateOrderMapper build() { } } - /** - * Get order - * @return order - */ - @Schema(name = "order", required = false) - public OrderMapper getOrder() { - return order; - } - public void setOrder(OrderMapper order) { - this.order = order; - } - - /** - * Get waiter - * @return waiter - */ @Schema(name = "waiter", required = false) public WaiterMapper getWaiter() { return waiter; @@ -72,6 +53,14 @@ public void setWaiter(WaiterMapper waiter) { this.waiter = waiter; } + @Schema(name = "order", required = false) + public OrderMapper getOrder() { + return order; + } + public void setOrder(OrderMapper order) { + this.order = order; + } + @Override public boolean equals(Object o) { if (this == o) { @@ -81,20 +70,20 @@ public boolean equals(Object o) { return false; } CreateOrderMapper createOrderMapper = (CreateOrderMapper) o; - return Objects.equals(this.order, createOrderMapper.order) && Objects.equals(this.waiter, createOrderMapper.waiter); + return Objects.equals(this.waiter, createOrderMapper.waiter) && Objects.equals(this.order, createOrderMapper.order); } @Override public int hashCode() { - return Objects.hash(order, waiter); + return Objects.hash(waiter, order); } @Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append("CreateOrderMapper{"); - sb.append(" order:").append(order).append(","); - sb.append(" waiter:").append(waiter); + sb.append(" waiter:").append(waiter).append(","); + sb.append(" order:").append(order); sb.append("}"); return sb.toString(); } diff --git a/multiapi-engine/src/test/resources/asyncapigenerator/testFileGeneration/assets/OrderDTO.java b/multiapi-engine/src/test/resources/asyncapigenerator/testFileGeneration/assets/OrderDTO.java index 196ae0ed..c1102627 100644 --- a/multiapi-engine/src/test/resources/asyncapigenerator/testFileGeneration/assets/OrderDTO.java +++ b/multiapi-engine/src/test/resources/asyncapigenerator/testFileGeneration/assets/OrderDTO.java @@ -6,27 +6,27 @@ import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder; import com.fasterxml.jackson.annotation.JsonProperty; import io.swagger.v3.oas.annotations.media.Schema; -import java.math.BigDecimal; import java.util.List; import java.util.ArrayList; +import java.math.BigDecimal; @JsonDeserialize(builder = OrderDTO.OrderDTOBuilder.class) public class OrderDTO { - @JsonProperty(value ="ref") - private String ref; @JsonProperty(value ="clientRef") private String clientRef; @JsonProperty(value ="amount") private BigDecimal amount; @JsonProperty(value ="lines") private List lines = new ArrayList(); + @JsonProperty(value ="ref") + private String ref; private OrderDTO(OrderDTOBuilder builder) { - this.ref = builder.ref; this.clientRef = builder.clientRef; this.amount = builder.amount; - this.lines.addAll(builder.lines); + this.lines = builder.lines; + this.ref = builder.ref; } @@ -37,18 +37,10 @@ public static OrderDTO.OrderDTOBuilder builder() { @JsonPOJOBuilder(buildMethodName = "build", withPrefix = "") public static class OrderDTOBuilder { - private String ref; - private String clientRef; - private BigDecimal amount; - private List lines = new ArrayList(); - - public OrderDTO.OrderDTOBuilder ref(String ref) { - this.ref = ref; - return this; - } + private String ref; public OrderDTO.OrderDTOBuilder clientRef(String clientRef) { this.clientRef = clientRef; @@ -59,7 +51,6 @@ public OrderDTO.OrderDTOBuilder amount(BigDecimal amount) { this.amount = amount; return this; } - public OrderDTO.OrderDTOBuilder lines(List lines) { if (!lines.isEmpty()) { this.lines.addAll(lines); @@ -74,28 +65,17 @@ public OrderDTO.OrderDTOBuilder line(OrderLineDTO line) { return this; } + public OrderDTO.OrderDTOBuilder ref(String ref) { + this.ref = ref; + return this; + } + public OrderDTO build() { OrderDTO orderDTO = new OrderDTO(this); return orderDTO; } } - /** - * Get ref - * @return ref - */ - @Schema(name = "ref", required = false) - public String getRef() { - return ref; - } - public void setRef(String ref) { - this.ref = ref; - } - - /** - * Get clientRef - * @return clientRef - */ @Schema(name = "clientRef", required = false) public String getClientRef() { return clientRef; @@ -104,10 +84,6 @@ public void setClientRef(String clientRef) { this.clientRef = clientRef; } - /** - * Get amount - * @return amount - */ @Schema(name = "amount", required = false) public BigDecimal getAmount() { return amount; @@ -116,10 +92,6 @@ public void setAmount(BigDecimal amount) { this.amount = amount; } - /** - * Get lines - * @return lines - */ @Schema(name = "lines", required = false) public List getLines() { return lines; @@ -128,6 +100,14 @@ public void setLines(List lines) { this.lines = lines; } + @Schema(name = "ref", required = false) + public String getRef() { + return ref; + } + public void setRef(String ref) { + this.ref = ref; + } + @Override public boolean equals(Object o) { if (this == o) { @@ -137,22 +117,22 @@ public boolean equals(Object o) { return false; } OrderDTO orderDTO = (OrderDTO) o; - return Objects.equals(this.ref, orderDTO.ref) && Objects.equals(this.clientRef, orderDTO.clientRef) && Objects.equals(this.amount, orderDTO.amount) && Objects.equals(this.lines, orderDTO.lines); + return Objects.equals(this.clientRef, orderDTO.clientRef) && Objects.equals(this.amount, orderDTO.amount) && Objects.equals(this.lines, orderDTO.lines) && Objects.equals(this.ref, orderDTO.ref); } @Override public int hashCode() { - return Objects.hash(ref, clientRef, amount, lines); + return Objects.hash(clientRef, amount, lines, ref); } @Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append("OrderDTO{"); - sb.append(" ref:").append(ref).append(","); sb.append(" clientRef:").append(clientRef).append(","); sb.append(" amount:").append(amount).append(","); - sb.append(" lines:").append(lines); + sb.append(" lines:").append(lines).append(","); + sb.append(" ref:").append(ref); sb.append("}"); return sb.toString(); } diff --git a/multiapi-engine/src/test/resources/asyncapigenerator/testFileGeneration/assets/OrderLineDTO.java b/multiapi-engine/src/test/resources/asyncapigenerator/testFileGeneration/assets/OrderLineDTO.java index a44f1ac2..fb8f2b64 100644 --- a/multiapi-engine/src/test/resources/asyncapigenerator/testFileGeneration/assets/OrderLineDTO.java +++ b/multiapi-engine/src/test/resources/asyncapigenerator/testFileGeneration/assets/OrderLineDTO.java @@ -14,16 +14,15 @@ @JsonDeserialize(builder = OrderLineDTO.OrderLineDTOBuilder.class) public class OrderLineDTO { + @JsonProperty(value ="products") + private List products = new ArrayList(); @JsonProperty(value ="ref") @NotNull private final String ref; - @JsonProperty(value ="products") - @NotNull - private final List products = new ArrayList(); private OrderLineDTO(OrderLineDTOBuilder builder) { + this.products = builder.products; this.ref = builder.ref; - this.products.addAll(builder.products); validateRequiredAttributes(); } @@ -35,15 +34,8 @@ public static OrderLineDTO.OrderLineDTOBuilder builder() { @JsonPOJOBuilder(buildMethodName = "build", withPrefix = "") public static class OrderLineDTOBuilder { - private String ref; - private List products = new ArrayList(); - - public OrderLineDTO.OrderLineDTOBuilder ref(String ref) { - this.ref = ref; - return this; - } - + private String ref; public OrderLineDTO.OrderLineDTOBuilder products(List products) { if (!products.isEmpty()) { this.products.addAll(products); @@ -58,30 +50,30 @@ public OrderLineDTO.OrderLineDTOBuilder product(OrderProductDTO product) { return this; } + public OrderLineDTO.OrderLineDTOBuilder ref(String ref) { + this.ref = ref; + return this; + } + public OrderLineDTO build() { OrderLineDTO orderLineDTO = new OrderLineDTO(this); return orderLineDTO; } } - /** - * Get ref - * @return ref - */ + @Schema(name = "products", required = false) + public List getProducts() { + return products; + } + public void setProducts(List products) { + this.products = products; + } + @Schema(name = "ref", required = true) public String getRef() { return ref; } - /** - * Get products - * @return products - */ - @Schema(name = "products", required = true) - public List getProducts() { - return products; - } - @Override public boolean equals(Object o) { if (this == o) { @@ -91,36 +83,34 @@ public boolean equals(Object o) { return false; } OrderLineDTO orderLineDTO = (OrderLineDTO) o; - return Objects.equals(this.ref, orderLineDTO.ref) && Objects.equals(this.products, orderLineDTO.products); + return Objects.equals(this.products, orderLineDTO.products) && Objects.equals(this.ref, orderLineDTO.ref); } @Override public int hashCode() { - return Objects.hash(ref, products); + return Objects.hash(products, ref); } @Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append("OrderLineDTO{"); - sb.append(" ref:").append(ref).append(","); - sb.append(" products:").append(products); + sb.append(" products:").append(products).append(","); + sb.append(" ref:").append(ref); sb.append("}"); return sb.toString(); } - private void validateRequiredAttributes() { boolean satisfiedCondition = true; if (!Objects.nonNull(this.ref)) { satisfiedCondition = false; - } else if (!Objects.nonNull(this.products)) { - satisfiedCondition = false; } if (!satisfiedCondition) { throw new ModelClassException("OrderLineDTO"); } } + } diff --git a/multiapi-engine/src/test/resources/asyncapigenerator/testFileGeneration/assets/OrderLineMapper.java b/multiapi-engine/src/test/resources/asyncapigenerator/testFileGeneration/assets/OrderLineMapper.java index 3cb2242e..aefdd51c 100644 --- a/multiapi-engine/src/test/resources/asyncapigenerator/testFileGeneration/assets/OrderLineMapper.java +++ b/multiapi-engine/src/test/resources/asyncapigenerator/testFileGeneration/assets/OrderLineMapper.java @@ -14,16 +14,15 @@ @JsonDeserialize(builder = OrderLineMapper.OrderLineMapperBuilder.class) public class OrderLineMapper { + @JsonProperty(value ="products") + private List products = new ArrayList(); @JsonProperty(value ="ref") @NotNull private final String ref; - @JsonProperty(value ="products") - @NotNull - private final List products = new ArrayList(); private OrderLineMapper(OrderLineMapperBuilder builder) { + this.products = builder.products; this.ref = builder.ref; - this.products.addAll(builder.products); validateRequiredAttributes(); } @@ -35,15 +34,8 @@ public static OrderLineMapper.OrderLineMapperBuilder builder() { @JsonPOJOBuilder(buildMethodName = "build", withPrefix = "") public static class OrderLineMapperBuilder { - private String ref; - private List products = new ArrayList(); - - public OrderLineMapper.OrderLineMapperBuilder ref(String ref) { - this.ref = ref; - return this; - } - + private String ref; public OrderLineMapper.OrderLineMapperBuilder products(List products) { if (!products.isEmpty()) { this.products.addAll(products); @@ -58,30 +50,30 @@ public OrderLineMapper.OrderLineMapperBuilder product(OrderProductMapper product return this; } + public OrderLineMapper.OrderLineMapperBuilder ref(String ref) { + this.ref = ref; + return this; + } + public OrderLineMapper build() { OrderLineMapper orderLineMapper = new OrderLineMapper(this); return orderLineMapper; } } - /** - * Get ref - * @return ref - */ + @Schema(name = "products", required = false) + public List getProducts() { + return products; + } + public void setProducts(List products) { + this.products = products; + } + @Schema(name = "ref", required = true) public String getRef() { return ref; } - /** - * Get products - * @return products - */ - @Schema(name = "products", required = true) - public List getProducts() { - return products; - } - @Override public boolean equals(Object o) { if (this == o) { @@ -91,36 +83,34 @@ public boolean equals(Object o) { return false; } OrderLineMapper orderLineMapper = (OrderLineMapper) o; - return Objects.equals(this.ref, orderLineMapper.ref) && Objects.equals(this.products, orderLineMapper.products); + return Objects.equals(this.products, orderLineMapper.products) && Objects.equals(this.ref, orderLineMapper.ref); } @Override public int hashCode() { - return Objects.hash(ref, products); + return Objects.hash(products, ref); } @Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append("OrderLineMapper{"); - sb.append(" ref:").append(ref).append(","); - sb.append(" products:").append(products); + sb.append(" products:").append(products).append(","); + sb.append(" ref:").append(ref); sb.append("}"); return sb.toString(); } - private void validateRequiredAttributes() { boolean satisfiedCondition = true; if (!Objects.nonNull(this.ref)) { satisfiedCondition = false; - } else if (!Objects.nonNull(this.products)) { - satisfiedCondition = false; } if (!satisfiedCondition) { throw new ModelClassException("OrderLineMapper"); } } + } diff --git a/multiapi-engine/src/test/resources/asyncapigenerator/testFileGeneration/assets/OrderMapper.java b/multiapi-engine/src/test/resources/asyncapigenerator/testFileGeneration/assets/OrderMapper.java index 2bf7f29b..8599cd45 100644 --- a/multiapi-engine/src/test/resources/asyncapigenerator/testFileGeneration/assets/OrderMapper.java +++ b/multiapi-engine/src/test/resources/asyncapigenerator/testFileGeneration/assets/OrderMapper.java @@ -6,27 +6,27 @@ import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder; import com.fasterxml.jackson.annotation.JsonProperty; import io.swagger.v3.oas.annotations.media.Schema; -import java.math.BigDecimal; import java.util.List; import java.util.ArrayList; +import java.math.BigDecimal; @JsonDeserialize(builder = OrderMapper.OrderMapperBuilder.class) public class OrderMapper { - @JsonProperty(value ="ref") - private String ref; @JsonProperty(value ="clientRef") private String clientRef; @JsonProperty(value ="amount") private BigDecimal amount; @JsonProperty(value ="lines") private List lines = new ArrayList(); + @JsonProperty(value ="ref") + private String ref; private OrderMapper(OrderMapperBuilder builder) { - this.ref = builder.ref; this.clientRef = builder.clientRef; this.amount = builder.amount; - this.lines.addAll(builder.lines); + this.lines = builder.lines; + this.ref = builder.ref; } @@ -37,18 +37,10 @@ public static OrderMapper.OrderMapperBuilder builder() { @JsonPOJOBuilder(buildMethodName = "build", withPrefix = "") public static class OrderMapperBuilder { - private String ref; - private String clientRef; - private BigDecimal amount; - private List lines = new ArrayList(); - - public OrderMapper.OrderMapperBuilder ref(String ref) { - this.ref = ref; - return this; - } + private String ref; public OrderMapper.OrderMapperBuilder clientRef(String clientRef) { this.clientRef = clientRef; @@ -59,7 +51,6 @@ public OrderMapper.OrderMapperBuilder amount(BigDecimal amount) { this.amount = amount; return this; } - public OrderMapper.OrderMapperBuilder lines(List lines) { if (!lines.isEmpty()) { this.lines.addAll(lines); @@ -74,28 +65,17 @@ public OrderMapper.OrderMapperBuilder line(OrderLineMapper line) { return this; } + public OrderMapper.OrderMapperBuilder ref(String ref) { + this.ref = ref; + return this; + } + public OrderMapper build() { OrderMapper orderMapper = new OrderMapper(this); return orderMapper; } } - /** - * Get ref - * @return ref - */ - @Schema(name = "ref", required = false) - public String getRef() { - return ref; - } - public void setRef(String ref) { - this.ref = ref; - } - - /** - * Get clientRef - * @return clientRef - */ @Schema(name = "clientRef", required = false) public String getClientRef() { return clientRef; @@ -104,10 +84,6 @@ public void setClientRef(String clientRef) { this.clientRef = clientRef; } - /** - * Get amount - * @return amount - */ @Schema(name = "amount", required = false) public BigDecimal getAmount() { return amount; @@ -116,10 +92,6 @@ public void setAmount(BigDecimal amount) { this.amount = amount; } - /** - * Get lines - * @return lines - */ @Schema(name = "lines", required = false) public List getLines() { return lines; @@ -128,6 +100,14 @@ public void setLines(List lines) { this.lines = lines; } + @Schema(name = "ref", required = false) + public String getRef() { + return ref; + } + public void setRef(String ref) { + this.ref = ref; + } + @Override public boolean equals(Object o) { if (this == o) { @@ -137,22 +117,22 @@ public boolean equals(Object o) { return false; } OrderMapper orderMapper = (OrderMapper) o; - return Objects.equals(this.ref, orderMapper.ref) && Objects.equals(this.clientRef, orderMapper.clientRef) && Objects.equals(this.amount, orderMapper.amount) && Objects.equals(this.lines, orderMapper.lines); + return Objects.equals(this.clientRef, orderMapper.clientRef) && Objects.equals(this.amount, orderMapper.amount) && Objects.equals(this.lines, orderMapper.lines) && Objects.equals(this.ref, orderMapper.ref); } @Override public int hashCode() { - return Objects.hash(ref, clientRef, amount, lines); + return Objects.hash(clientRef, amount, lines, ref); } @Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append("OrderMapper{"); - sb.append(" ref:").append(ref).append(","); sb.append(" clientRef:").append(clientRef).append(","); sb.append(" amount:").append(amount).append(","); - sb.append(" lines:").append(lines); + sb.append(" lines:").append(lines).append(","); + sb.append(" ref:").append(ref); sb.append("}"); return sb.toString(); } diff --git a/multiapi-engine/src/test/resources/asyncapigenerator/testFileGeneration/assets/OrderProductDTO.java b/multiapi-engine/src/test/resources/asyncapigenerator/testFileGeneration/assets/OrderProductDTO.java index 8669e8dc..e9930c03 100644 --- a/multiapi-engine/src/test/resources/asyncapigenerator/testFileGeneration/assets/OrderProductDTO.java +++ b/multiapi-engine/src/test/resources/asyncapigenerator/testFileGeneration/assets/OrderProductDTO.java @@ -12,9 +12,6 @@ @JsonDeserialize(builder = OrderProductDTO.OrderProductDTOBuilder.class) public class OrderProductDTO { - @JsonProperty(value ="ref") - @NotNull - private final String ref; @JsonProperty(value ="productRef") @NotNull private final String productRef; @@ -24,12 +21,15 @@ public class OrderProductDTO { @JsonProperty(value ="quantity") @NotNull private final String quantity; + @JsonProperty(value ="ref") + @NotNull + private final String ref; private OrderProductDTO(OrderProductDTOBuilder builder) { - this.ref = builder.ref; this.productRef = builder.productRef; this.price = builder.price; this.quantity = builder.quantity; + this.ref = builder.ref; validateRequiredAttributes(); } @@ -41,18 +41,10 @@ public static OrderProductDTO.OrderProductDTOBuilder builder() { @JsonPOJOBuilder(buildMethodName = "build", withPrefix = "") public static class OrderProductDTOBuilder { - private String ref; - private String productRef; - private String price; - private String quantity; - - public OrderProductDTO.OrderProductDTOBuilder ref(String ref) { - this.ref = ref; - return this; - } + private String ref; public OrderProductDTO.OrderProductDTOBuilder productRef(String productRef) { this.productRef = productRef; @@ -69,48 +61,37 @@ public OrderProductDTO.OrderProductDTOBuilder quantity(String quantity) { return this; } + public OrderProductDTO.OrderProductDTOBuilder ref(String ref) { + this.ref = ref; + return this; + } + public OrderProductDTO build() { OrderProductDTO orderProductDTO = new OrderProductDTO(this); return orderProductDTO; } } - /** - * Get ref - * @return ref - */ - @Schema(name = "ref", required = true) - public String getRef() { - return ref; - } - - /** - * Get productRef - * @return productRef - */ @Schema(name = "productRef", required = true) public String getProductRef() { return productRef; } - /** - * Get price - * @return price - */ @Schema(name = "price", required = true) public String getPrice() { return price; } - /** - * Get quantity - * @return quantity - */ @Schema(name = "quantity", required = true) public String getQuantity() { return quantity; } + @Schema(name = "ref", required = true) + public String getRef() { + return ref; + } + @Override public boolean equals(Object o) { if (this == o) { @@ -120,42 +101,42 @@ public boolean equals(Object o) { return false; } OrderProductDTO orderProductDTO = (OrderProductDTO) o; - return Objects.equals(this.ref, orderProductDTO.ref) && Objects.equals(this.productRef, orderProductDTO.productRef) && Objects.equals(this.price, orderProductDTO.price) && Objects.equals(this.quantity, orderProductDTO.quantity); + return Objects.equals(this.productRef, orderProductDTO.productRef) && Objects.equals(this.price, orderProductDTO.price) && Objects.equals(this.quantity, orderProductDTO.quantity) && Objects.equals(this.ref, orderProductDTO.ref); } @Override public int hashCode() { - return Objects.hash(ref, productRef, price, quantity); + return Objects.hash(productRef, price, quantity, ref); } @Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append("OrderProductDTO{"); - sb.append(" ref:").append(ref).append(","); sb.append(" productRef:").append(productRef).append(","); sb.append(" price:").append(price).append(","); - sb.append(" quantity:").append(quantity); + sb.append(" quantity:").append(quantity).append(","); + sb.append(" ref:").append(ref); sb.append("}"); return sb.toString(); } - private void validateRequiredAttributes() { boolean satisfiedCondition = true; - if (!Objects.nonNull(this.ref)) { - satisfiedCondition = false; - } else if (!Objects.nonNull(this.productRef)) { + if (!Objects.nonNull(this.productRef)) { satisfiedCondition = false; } else if (!Objects.nonNull(this.price)) { satisfiedCondition = false; } else if (!Objects.nonNull(this.quantity)) { satisfiedCondition = false; + } else if (!Objects.nonNull(this.ref)) { + satisfiedCondition = false; } if (!satisfiedCondition) { throw new ModelClassException("OrderProductDTO"); } } + } diff --git a/multiapi-engine/src/test/resources/asyncapigenerator/testFileGeneration/assets/OrderProductMapper.java b/multiapi-engine/src/test/resources/asyncapigenerator/testFileGeneration/assets/OrderProductMapper.java index 6b094183..90153fe6 100644 --- a/multiapi-engine/src/test/resources/asyncapigenerator/testFileGeneration/assets/OrderProductMapper.java +++ b/multiapi-engine/src/test/resources/asyncapigenerator/testFileGeneration/assets/OrderProductMapper.java @@ -12,9 +12,6 @@ @JsonDeserialize(builder = OrderProductMapper.OrderProductMapperBuilder.class) public class OrderProductMapper { - @JsonProperty(value ="ref") - @NotNull - private final String ref; @JsonProperty(value ="productRef") @NotNull private final String productRef; @@ -24,12 +21,15 @@ public class OrderProductMapper { @JsonProperty(value ="quantity") @NotNull private final String quantity; + @JsonProperty(value ="ref") + @NotNull + private final String ref; private OrderProductMapper(OrderProductMapperBuilder builder) { - this.ref = builder.ref; this.productRef = builder.productRef; this.price = builder.price; this.quantity = builder.quantity; + this.ref = builder.ref; validateRequiredAttributes(); } @@ -41,18 +41,10 @@ public static OrderProductMapper.OrderProductMapperBuilder builder() { @JsonPOJOBuilder(buildMethodName = "build", withPrefix = "") public static class OrderProductMapperBuilder { - private String ref; - private String productRef; - private String price; - private String quantity; - - public OrderProductMapper.OrderProductMapperBuilder ref(String ref) { - this.ref = ref; - return this; - } + private String ref; public OrderProductMapper.OrderProductMapperBuilder productRef(String productRef) { this.productRef = productRef; @@ -69,48 +61,37 @@ public OrderProductMapper.OrderProductMapperBuilder quantity(String quantity) { return this; } + public OrderProductMapper.OrderProductMapperBuilder ref(String ref) { + this.ref = ref; + return this; + } + public OrderProductMapper build() { OrderProductMapper orderProductMapper = new OrderProductMapper(this); return orderProductMapper; } } - /** - * Get ref - * @return ref - */ - @Schema(name = "ref", required = true) - public String getRef() { - return ref; - } - - /** - * Get productRef - * @return productRef - */ @Schema(name = "productRef", required = true) public String getProductRef() { return productRef; } - /** - * Get price - * @return price - */ @Schema(name = "price", required = true) public String getPrice() { return price; } - /** - * Get quantity - * @return quantity - */ @Schema(name = "quantity", required = true) public String getQuantity() { return quantity; } + @Schema(name = "ref", required = true) + public String getRef() { + return ref; + } + @Override public boolean equals(Object o) { if (this == o) { @@ -120,42 +101,42 @@ public boolean equals(Object o) { return false; } OrderProductMapper orderProductMapper = (OrderProductMapper) o; - return Objects.equals(this.ref, orderProductMapper.ref) && Objects.equals(this.productRef, orderProductMapper.productRef) && Objects.equals(this.price, orderProductMapper.price) && Objects.equals(this.quantity, orderProductMapper.quantity); + return Objects.equals(this.productRef, orderProductMapper.productRef) && Objects.equals(this.price, orderProductMapper.price) && Objects.equals(this.quantity, orderProductMapper.quantity) && Objects.equals(this.ref, orderProductMapper.ref); } @Override public int hashCode() { - return Objects.hash(ref, productRef, price, quantity); + return Objects.hash(productRef, price, quantity, ref); } @Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append("OrderProductMapper{"); - sb.append(" ref:").append(ref).append(","); sb.append(" productRef:").append(productRef).append(","); sb.append(" price:").append(price).append(","); - sb.append(" quantity:").append(quantity); + sb.append(" quantity:").append(quantity).append(","); + sb.append(" ref:").append(ref); sb.append("}"); return sb.toString(); } - private void validateRequiredAttributes() { boolean satisfiedCondition = true; - if (!Objects.nonNull(this.ref)) { - satisfiedCondition = false; - } else if (!Objects.nonNull(this.productRef)) { + if (!Objects.nonNull(this.productRef)) { satisfiedCondition = false; } else if (!Objects.nonNull(this.price)) { satisfiedCondition = false; } else if (!Objects.nonNull(this.quantity)) { satisfiedCondition = false; + } else if (!Objects.nonNull(this.ref)) { + satisfiedCondition = false; } if (!satisfiedCondition) { throw new ModelClassException("OrderProductMapper"); } } + } diff --git a/multiapi-engine/src/test/resources/asyncapigenerator/testFileGeneration/assets/WaiterMapper.java b/multiapi-engine/src/test/resources/asyncapigenerator/testFileGeneration/assets/WaiterMapper.java index 8fa6fc10..d67d7f7c 100644 --- a/multiapi-engine/src/test/resources/asyncapigenerator/testFileGeneration/assets/WaiterMapper.java +++ b/multiapi-engine/src/test/resources/asyncapigenerator/testFileGeneration/assets/WaiterMapper.java @@ -10,17 +10,17 @@ @JsonDeserialize(builder = WaiterMapper.WaiterMapperBuilder.class) public class WaiterMapper { - @JsonProperty(value ="ref") - private String ref; @JsonProperty(value ="timestamp") private String timestamp; @JsonProperty(value ="table") private String table; + @JsonProperty(value ="ref") + private String ref; private WaiterMapper(WaiterMapperBuilder builder) { - this.ref = builder.ref; this.timestamp = builder.timestamp; this.table = builder.table; + this.ref = builder.ref; } @@ -31,16 +31,9 @@ public static WaiterMapper.WaiterMapperBuilder builder() { @JsonPOJOBuilder(buildMethodName = "build", withPrefix = "") public static class WaiterMapperBuilder { - private String ref; - private String timestamp; - private String table; - - public WaiterMapper.WaiterMapperBuilder ref(String ref) { - this.ref = ref; - return this; - } + private String ref; public WaiterMapper.WaiterMapperBuilder timestamp(String timestamp) { this.timestamp = timestamp; @@ -52,28 +45,17 @@ public WaiterMapper.WaiterMapperBuilder table(String table) { return this; } + public WaiterMapper.WaiterMapperBuilder ref(String ref) { + this.ref = ref; + return this; + } + public WaiterMapper build() { WaiterMapper waiterMapper = new WaiterMapper(this); return waiterMapper; } } - /** - * Get ref - * @return ref - */ - @Schema(name = "ref", required = false) - public String getRef() { - return ref; - } - public void setRef(String ref) { - this.ref = ref; - } - - /** - * Get timestamp - * @return timestamp - */ @Schema(name = "timestamp", required = false) public String getTimestamp() { return timestamp; @@ -82,10 +64,6 @@ public void setTimestamp(String timestamp) { this.timestamp = timestamp; } - /** - * Get table - * @return table - */ @Schema(name = "table", required = false) public String getTable() { return table; @@ -94,6 +72,14 @@ public void setTable(String table) { this.table = table; } + @Schema(name = "ref", required = false) + public String getRef() { + return ref; + } + public void setRef(String ref) { + this.ref = ref; + } + @Override public boolean equals(Object o) { if (this == o) { @@ -103,21 +89,21 @@ public boolean equals(Object o) { return false; } WaiterMapper waiterMapper = (WaiterMapper) o; - return Objects.equals(this.ref, waiterMapper.ref) && Objects.equals(this.timestamp, waiterMapper.timestamp) && Objects.equals(this.table, waiterMapper.table); + return Objects.equals(this.timestamp, waiterMapper.timestamp) && Objects.equals(this.table, waiterMapper.table) && Objects.equals(this.ref, waiterMapper.ref); } @Override public int hashCode() { - return Objects.hash(ref, timestamp, table); + return Objects.hash(timestamp, table, ref); } @Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append("WaiterMapper{"); - sb.append(" ref:").append(ref).append(","); sb.append(" timestamp:").append(timestamp).append(","); - sb.append(" table:").append(table); + sb.append(" table:").append(table).append(","); + sb.append(" ref:").append(ref); sb.append("}"); return sb.toString(); } diff --git a/multiapi-engine/src/test/resources/asyncapigenerator/testFileGenerationArrayString/assets/ObjectArrayDTO.java b/multiapi-engine/src/test/resources/asyncapigenerator/testFileGenerationArrayString/assets/ObjectArrayDTO.java index c1ef5395..5e7ce75a 100644 --- a/multiapi-engine/src/test/resources/asyncapigenerator/testFileGenerationArrayString/assets/ObjectArrayDTO.java +++ b/multiapi-engine/src/test/resources/asyncapigenerator/testFileGenerationArrayString/assets/ObjectArrayDTO.java @@ -14,15 +14,15 @@ public class ObjectArrayDTO { @JsonProperty(value ="idObject") private Integer idObject; - @JsonProperty(value ="players") - private List players = new ArrayList(); @JsonProperty(value ="info") private String info; + @JsonProperty(value ="players") + private List players = new ArrayList(); private ObjectArrayDTO(ObjectArrayDTOBuilder builder) { this.idObject = builder.idObject; - this.players.addAll(builder.players); this.info = builder.info; + this.players = builder.players; } @@ -34,16 +34,18 @@ public static ObjectArrayDTO.ObjectArrayDTOBuilder builder() { public static class ObjectArrayDTOBuilder { private Integer idObject; - - private List players = new ArrayList(); - private String info; + private List players = new ArrayList(); public ObjectArrayDTO.ObjectArrayDTOBuilder idObject(Integer idObject) { this.idObject = idObject; return this; } + public ObjectArrayDTO.ObjectArrayDTOBuilder info(String info) { + this.info = info; + return this; + } public ObjectArrayDTO.ObjectArrayDTOBuilder players(List players) { if (!players.isEmpty()) { this.players.addAll(players); @@ -58,21 +60,12 @@ public ObjectArrayDTO.ObjectArrayDTOBuilder player(String player) { return this; } - public ObjectArrayDTO.ObjectArrayDTOBuilder info(String info) { - this.info = info; - return this; - } - public ObjectArrayDTO build() { ObjectArrayDTO objectArrayDTO = new ObjectArrayDTO(this); return objectArrayDTO; } } - /** - * Get idObject - * @return idObject - */ @Schema(name = "idObject", required = false) public Integer getIdObject() { return idObject; @@ -81,22 +74,6 @@ public void setIdObject(Integer idObject) { this.idObject = idObject; } - /** - * Get players - * @return players - */ - @Schema(name = "players", required = false) - public List getPlayers() { - return players; - } - public void setPlayers(List players) { - this.players = players; - } - - /** - * Get info - * @return info - */ @Schema(name = "info", required = false) public String getInfo() { return info; @@ -105,6 +82,14 @@ public void setInfo(String info) { this.info = info; } + @Schema(name = "players", required = false) + public List getPlayers() { + return players; + } + public void setPlayers(List players) { + this.players = players; + } + @Override public boolean equals(Object o) { if (this == o) { @@ -114,12 +99,12 @@ public boolean equals(Object o) { return false; } ObjectArrayDTO objectArrayDTO = (ObjectArrayDTO) o; - return Objects.equals(this.idObject, objectArrayDTO.idObject) && Objects.equals(this.players, objectArrayDTO.players) && Objects.equals(this.info, objectArrayDTO.info); + return Objects.equals(this.idObject, objectArrayDTO.idObject) && Objects.equals(this.info, objectArrayDTO.info) && Objects.equals(this.players, objectArrayDTO.players); } @Override public int hashCode() { - return Objects.hash(idObject, players, info); + return Objects.hash(idObject, info, players); } @Override @@ -127,8 +112,8 @@ public String toString() { StringBuilder sb = new StringBuilder(); sb.append("ObjectArrayDTO{"); sb.append(" idObject:").append(idObject).append(","); - sb.append(" players:").append(players).append(","); - sb.append(" info:").append(info); + sb.append(" info:").append(info).append(","); + sb.append(" players:").append(players); sb.append("}"); return sb.toString(); } diff --git a/multiapi-engine/src/test/resources/asyncapigenerator/testFileGenerationIssue/assets/CustomerDTO.java b/multiapi-engine/src/test/resources/asyncapigenerator/testFileGenerationIssue/assets/CustomerDTO.java index 0c31c4fa..4d7222e2 100644 --- a/multiapi-engine/src/test/resources/asyncapigenerator/testFileGenerationIssue/assets/CustomerDTO.java +++ b/multiapi-engine/src/test/resources/asyncapigenerator/testFileGenerationIssue/assets/CustomerDTO.java @@ -13,8 +13,16 @@ @JsonDeserialize(builder = CustomerDTO.CustomerDTOBuilder.class) public class CustomerDTO { + @JsonProperty(value ="email") + @Size(min =3, max =250) + @NotNull + private final String email; @JsonProperty(value ="id") private String id; + @JsonProperty(value ="username") + @Size(min =3, max =250) + @NotNull + private final String username; @JsonProperty(value ="firstName") @Size(min =3, max =250) @NotNull @@ -27,22 +35,14 @@ public class CustomerDTO { @Size(min =3, max =250) @NotNull private final String password; - @JsonProperty(value ="email") - @Size(min =3, max =250) - @NotNull - private final String email; - @JsonProperty(value ="username") - @Size(min =3, max =250) - @NotNull - private final String username; private CustomerDTO(CustomerDTOBuilder builder) { + this.email = builder.email; this.id = builder.id; + this.username = builder.username; this.firstName = builder.firstName; this.lastName = builder.lastName; this.password = builder.password; - this.email = builder.email; - this.username = builder.username; validateRequiredAttributes(); } @@ -54,23 +54,28 @@ public static CustomerDTO.CustomerDTOBuilder builder() { @JsonPOJOBuilder(buildMethodName = "build", withPrefix = "") public static class CustomerDTOBuilder { + private String email; private String id; - + private String username; private String firstName; - private String lastName; - private String password; - private String email; - - private String username; + public CustomerDTO.CustomerDTOBuilder email(String email) { + this.email = email; + return this; + } public CustomerDTO.CustomerDTOBuilder id(String id) { this.id = id; return this; } + public CustomerDTO.CustomerDTOBuilder username(String username) { + this.username = username; + return this; + } + public CustomerDTO.CustomerDTOBuilder firstName(String firstName) { this.firstName = firstName; return this; @@ -86,26 +91,17 @@ public CustomerDTO.CustomerDTOBuilder password(String password) { return this; } - public CustomerDTO.CustomerDTOBuilder email(String email) { - this.email = email; - return this; - } - - public CustomerDTO.CustomerDTOBuilder username(String username) { - this.username = username; - return this; - } - public CustomerDTO build() { CustomerDTO customerDTO = new CustomerDTO(this); return customerDTO; } } - /** - * Get id - * @return id - */ + @Schema(name = "email", required = true) + public String getEmail() { + return email; + } + @Schema(name = "id", required = false) public String getId() { return id; @@ -114,51 +110,26 @@ public void setId(String id) { this.id = id; } - /** - * Get firstName - * @return firstName - */ + @Schema(name = "username", required = true) + public String getUsername() { + return username; + } + @Schema(name = "firstName", required = true) public String getFirstName() { return firstName; } - /** - * Get lastName - * @return lastName - */ @Schema(name = "lastName", required = true) public String getLastName() { return lastName; } - /** - * Get password - * @return password - */ @Schema(name = "password", required = true) public String getPassword() { return password; } - /** - * Get email - * @return email - */ - @Schema(name = "email", required = true) - public String getEmail() { - return email; - } - - /** - * Get username - * @return username - */ - @Schema(name = "username", required = true) - public String getUsername() { - return username; - } - @Override public boolean equals(Object o) { if (this == o) { @@ -168,41 +139,40 @@ public boolean equals(Object o) { return false; } CustomerDTO customerDTO = (CustomerDTO) o; - return Objects.equals(this.id, customerDTO.id) && Objects.equals(this.firstName, customerDTO.firstName) && Objects.equals(this.lastName, customerDTO.lastName) && Objects.equals(this.password, customerDTO.password) && Objects.equals(this.email, customerDTO.email) && Objects.equals(this.username, customerDTO.username); + return Objects.equals(this.email, customerDTO.email) && Objects.equals(this.id, customerDTO.id) && Objects.equals(this.username, customerDTO.username) && Objects.equals(this.firstName, customerDTO.firstName) && Objects.equals(this.lastName, customerDTO.lastName) && Objects.equals(this.password, customerDTO.password); } @Override public int hashCode() { - return Objects.hash(id, firstName, lastName, password, email, username); + return Objects.hash(email, id, username, firstName, lastName, password); } @Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append("CustomerDTO{"); + sb.append(" email:").append(email).append(","); sb.append(" id:").append(id).append(","); + sb.append(" username:").append(username).append(","); sb.append(" firstName:").append(firstName).append(","); sb.append(" lastName:").append(lastName).append(","); - sb.append(" password:").append(password).append(","); - sb.append(" email:").append(email).append(","); - sb.append(" username:").append(username); + sb.append(" password:").append(password); sb.append("}"); return sb.toString(); } - private void validateRequiredAttributes() { boolean satisfiedCondition = true; - if (!Objects.nonNull(this.firstName)) { + if (!Objects.nonNull(this.email)) { satisfiedCondition = false; - } else if (!Objects.nonNull(this.lastName)) { + } else if (!Objects.nonNull(this.username)) { satisfiedCondition = false; - } else if (!Objects.nonNull(this.password)) { + } else if (!Objects.nonNull(this.firstName)) { satisfiedCondition = false; - } else if (!Objects.nonNull(this.email)) { + } else if (!Objects.nonNull(this.lastName)) { satisfiedCondition = false; - } else if (!Objects.nonNull(this.username)) { + } else if (!Objects.nonNull(this.password)) { satisfiedCondition = false; } @@ -210,4 +180,5 @@ private void validateRequiredAttributes() { throw new ModelClassException("CustomerDTO"); } } + } diff --git a/multiapi-engine/src/test/resources/asyncapigenerator/testFileGenerationIssue/assets/CustomerEventPayloadDTO.java b/multiapi-engine/src/test/resources/asyncapigenerator/testFileGenerationIssue/assets/CustomerEventPayloadDTO.java index 7ec68781..66bb9e86 100644 --- a/multiapi-engine/src/test/resources/asyncapigenerator/testFileGenerationIssue/assets/CustomerEventPayloadDTO.java +++ b/multiapi-engine/src/test/resources/asyncapigenerator/testFileGenerationIssue/assets/CustomerEventPayloadDTO.java @@ -11,8 +11,6 @@ @JsonDeserialize(builder = CustomerEventPayloadDTO.CustomerEventPayloadDTOBuilder.class) public class CustomerEventPayloadDTO { - @JsonProperty(value ="customerId") - private String customerId; @JsonProperty(value ="eventType") private EventType eventType; public enum EventType { @@ -36,12 +34,14 @@ public String toString() { return String.valueOf(value); } } + @JsonProperty(value ="customerId") + private String customerId; @JsonProperty(value ="customer") private CustomerDTO customer; private CustomerEventPayloadDTO(CustomerEventPayloadDTOBuilder builder) { - this.customerId = builder.customerId; this.eventType = builder.eventType; + this.customerId = builder.customerId; this.customer = builder.customer; } @@ -53,22 +53,18 @@ public static CustomerEventPayloadDTO.CustomerEventPayloadDTOBuilder builder() { @JsonPOJOBuilder(buildMethodName = "build", withPrefix = "") public static class CustomerEventPayloadDTOBuilder { - private String customerId; - private EventType eventType; - + private String customerId; private CustomerDTO customer; - - public CustomerEventPayloadDTO.CustomerEventPayloadDTOBuilder customerId(String customerId) { - this.customerId = customerId; - return this; - } - public CustomerEventPayloadDTO.CustomerEventPayloadDTOBuilder eventType(EventType eventType) { this.eventType = eventType; return this; } + public CustomerEventPayloadDTO.CustomerEventPayloadDTOBuilder customerId(String customerId) { + this.customerId = customerId; + return this; + } public CustomerEventPayloadDTO.CustomerEventPayloadDTOBuilder customer(CustomerDTO customer) { this.customer = customer; return this; @@ -80,22 +76,6 @@ public CustomerEventPayloadDTO build() { } } - /** - * Get customerId - * @return customerId - */ - @Schema(name = "customerId", required = false) - public String getCustomerId() { - return customerId; - } - public void setCustomerId(String customerId) { - this.customerId = customerId; - } - - /** - * Get eventType - * @return eventType - */ @Schema(name = "eventType", required = false) public EventType getEventType() { return eventType; @@ -104,10 +84,14 @@ public void setEventType(EventType eventType) { this.eventType = eventType; } - /** - * Get customer - * @return customer - */ + @Schema(name = "customerId", required = false) + public String getCustomerId() { + return customerId; + } + public void setCustomerId(String customerId) { + this.customerId = customerId; + } + @Schema(name = "customer", required = false) public CustomerDTO getCustomer() { return customer; @@ -125,20 +109,20 @@ public boolean equals(Object o) { return false; } CustomerEventPayloadDTO customerEventPayloadDTO = (CustomerEventPayloadDTO) o; - return Objects.equals(this.customerId, customerEventPayloadDTO.customerId) && Objects.equals(this.eventType, customerEventPayloadDTO.eventType) && Objects.equals(this.customer, customerEventPayloadDTO.customer); + return Objects.equals(this.eventType, customerEventPayloadDTO.eventType) && Objects.equals(this.customerId, customerEventPayloadDTO.customerId) && Objects.equals(this.customer, customerEventPayloadDTO.customer); } @Override public int hashCode() { - return Objects.hash(customerId, eventType, customer); + return Objects.hash(eventType, customerId, customer); } @Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append("CustomerEventPayloadDTO{"); - sb.append(" customerId:").append(customerId).append(","); sb.append(" eventType:").append(eventType).append(","); + sb.append(" customerId:").append(customerId).append(","); sb.append(" customer:").append(customer); sb.append("}"); return sb.toString(); 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 3a445ed2..0c78ef63 100644 --- a/multiapi-engine/src/test/resources/asyncapigenerator/testFileGenerationIssue/assets/CustomerOrderDTO.java +++ b/multiapi-engine/src/test/resources/asyncapigenerator/testFileGenerationIssue/assets/CustomerOrderDTO.java @@ -8,24 +8,12 @@ import com.fasterxml.jackson.annotation.JsonValue; import io.swagger.v3.oas.annotations.media.Schema; import java.util.List; -import java.time.LocalDateTime; import java.util.ArrayList; -import com.fasterxml.jackson.annotation.JsonFormat; +import java.time.LocalDateTime; @JsonDeserialize(builder = CustomerOrderDTO.CustomerOrderDTOBuilder.class) public class CustomerOrderDTO { - @JsonProperty(value ="id") - private String id; - @JsonProperty(value ="date") - @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss") - private LocalDateTime date; - @JsonProperty(value ="shippingDetails") - private ShippingDetailsDTO shippingDetails; - @JsonProperty(value ="orderedItems") - private List orderedItems = new ArrayList(); - @JsonProperty(value ="paymentDetails") - private List paymentDetails = new ArrayList(); @JsonProperty(value ="status") private Status status; public enum Status { @@ -49,17 +37,27 @@ public String toString() { return String.valueOf(value); } } + @JsonProperty(value ="id") + private String id; + @JsonProperty(value ="date") + private LocalDateTime date; + @JsonProperty(value ="orderedItems") + private List orderedItems = new ArrayList(); + @JsonProperty(value ="paymentDetails") + private List paymentDetails = new ArrayList(); @JsonProperty(value ="customer") private CustomerDTO customer; + @JsonProperty(value ="shippingDetails") + private ShippingDetailsDTO shippingDetails; private CustomerOrderDTO(CustomerOrderDTOBuilder builder) { + this.status = builder.status; this.id = builder.id; this.date = builder.date; - this.shippingDetails = builder.shippingDetails; - this.orderedItems.addAll(builder.orderedItems); - this.paymentDetails.addAll(builder.paymentDetails); - this.status = builder.status; + this.orderedItems = builder.orderedItems; + this.paymentDetails = builder.paymentDetails; this.customer = builder.customer; + this.shippingDetails = builder.shippingDetails; } @@ -70,19 +68,17 @@ public static CustomerOrderDTO.CustomerOrderDTOBuilder builder() { @JsonPOJOBuilder(buildMethodName = "build", withPrefix = "") public static class CustomerOrderDTOBuilder { + private Status status; private String id; - private LocalDateTime date; - - private ShippingDetailsDTO shippingDetails; - private List orderedItems = new ArrayList(); - private List paymentDetails = new ArrayList(); - - private Status status; - private CustomerDTO customer; + private ShippingDetailsDTO shippingDetails; + public CustomerOrderDTO.CustomerOrderDTOBuilder status(Status status) { + this.status = status; + return this; + } public CustomerOrderDTO.CustomerOrderDTOBuilder id(String id) { this.id = id; @@ -93,12 +89,6 @@ public CustomerOrderDTO.CustomerOrderDTOBuilder date(LocalDateTime date) { this.date = date; return this; } - - public CustomerOrderDTO.CustomerOrderDTOBuilder shippingDetails(ShippingDetailsDTO shippingDetails) { - this.shippingDetails = shippingDetails; - return this; - } - public CustomerOrderDTO.CustomerOrderDTOBuilder orderedItems(List orderedItems) { if (!orderedItems.isEmpty()) { this.orderedItems.addAll(orderedItems); @@ -112,7 +102,6 @@ public CustomerOrderDTO.CustomerOrderDTOBuilder orderedItem(OrderedItemDTO order } return this; } - public CustomerOrderDTO.CustomerOrderDTOBuilder paymentDetails(List paymentDetails) { if (!paymentDetails.isEmpty()) { this.paymentDetails.addAll(paymentDetails); @@ -126,16 +115,14 @@ public CustomerOrderDTO.CustomerOrderDTOBuilder paymentDetail(PaymentDetailsDTO } return this; } - - public CustomerOrderDTO.CustomerOrderDTOBuilder status(Status status) { - this.status = status; - return this; - } - public CustomerOrderDTO.CustomerOrderDTOBuilder customer(CustomerDTO customer) { this.customer = customer; return this; } + public CustomerOrderDTO.CustomerOrderDTOBuilder shippingDetails(ShippingDetailsDTO shippingDetails) { + this.shippingDetails = shippingDetails; + return this; + } public CustomerOrderDTO build() { CustomerOrderDTO customerOrderDTO = new CustomerOrderDTO(this); @@ -143,10 +130,14 @@ public CustomerOrderDTO build() { } } - /** - * Get id - * @return id - */ + @Schema(name = "status", required = false) + public Status getStatus() { + return status; + } + public void setStatus(Status status) { + this.status = status; + } + @Schema(name = "id", required = false) public String getId() { return id; @@ -155,10 +146,6 @@ public void setId(String id) { this.id = id; } - /** - * Get date - * @return date - */ @Schema(name = "date", required = false) public LocalDateTime getDate() { return date; @@ -167,22 +154,6 @@ public void setDate(LocalDateTime date) { this.date = date; } - /** - * Get shippingDetails - * @return shippingDetails - */ - @Schema(name = "shippingDetails", required = false) - public ShippingDetailsDTO getShippingDetails() { - return shippingDetails; - } - public void setShippingDetails(ShippingDetailsDTO shippingDetails) { - this.shippingDetails = shippingDetails; - } - - /** - * Get orderedItems - * @return orderedItems - */ @Schema(name = "orderedItems", required = false) public List getOrderedItems() { return orderedItems; @@ -191,10 +162,6 @@ public void setOrderedItems(List orderedItems) { this.orderedItems = orderedItems; } - /** - * Get paymentDetails - * @return paymentDetails - */ @Schema(name = "paymentDetails", required = false) public List getPaymentDetails() { return paymentDetails; @@ -203,22 +170,6 @@ public void setPaymentDetails(List paymentDetails) { this.paymentDetails = paymentDetails; } - /** - * Get status - * @return status - */ - @Schema(name = "status", required = false) - public Status getStatus() { - return status; - } - public void setStatus(Status status) { - this.status = status; - } - - /** - * Get customer - * @return customer - */ @Schema(name = "customer", required = false) public CustomerDTO getCustomer() { return customer; @@ -227,6 +178,14 @@ public void setCustomer(CustomerDTO customer) { this.customer = customer; } + @Schema(name = "shippingDetails", required = false) + public ShippingDetailsDTO getShippingDetails() { + return shippingDetails; + } + public void setShippingDetails(ShippingDetailsDTO shippingDetails) { + this.shippingDetails = shippingDetails; + } + @Override public boolean equals(Object o) { if (this == o) { @@ -236,25 +195,25 @@ public boolean equals(Object o) { return false; } CustomerOrderDTO customerOrderDTO = (CustomerOrderDTO) o; - return Objects.equals(this.id, customerOrderDTO.id) && Objects.equals(this.date, customerOrderDTO.date) && Objects.equals(this.shippingDetails, customerOrderDTO.shippingDetails) && Objects.equals(this.orderedItems, customerOrderDTO.orderedItems) && Objects.equals(this.paymentDetails, customerOrderDTO.paymentDetails) && Objects.equals(this.status, customerOrderDTO.status) && Objects.equals(this.customer, customerOrderDTO.customer); + return Objects.equals(this.status, customerOrderDTO.status) && Objects.equals(this.id, customerOrderDTO.id) && Objects.equals(this.date, customerOrderDTO.date) && Objects.equals(this.orderedItems, customerOrderDTO.orderedItems) && Objects.equals(this.paymentDetails, customerOrderDTO.paymentDetails) && Objects.equals(this.customer, customerOrderDTO.customer) && Objects.equals(this.shippingDetails, customerOrderDTO.shippingDetails); } @Override public int hashCode() { - return Objects.hash(id, date, shippingDetails, orderedItems, paymentDetails, status, customer); + return Objects.hash(status, id, date, orderedItems, paymentDetails, customer, shippingDetails); } @Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append("CustomerOrderDTO{"); + sb.append(" status:").append(status).append(","); sb.append(" id:").append(id).append(","); sb.append(" date:").append(date).append(","); - sb.append(" shippingDetails:").append(shippingDetails).append(","); sb.append(" orderedItems:").append(orderedItems).append(","); sb.append(" paymentDetails:").append(paymentDetails).append(","); - sb.append(" status:").append(status).append(","); - sb.append(" customer:").append(customer); + sb.append(" customer:").append(customer).append(","); + sb.append(" shippingDetails:").append(shippingDetails); sb.append("}"); return sb.toString(); } diff --git a/multiapi-engine/src/test/resources/asyncapigenerator/testFileGenerationIssue/assets/CustomerOrderEventPayloadDTO.java b/multiapi-engine/src/test/resources/asyncapigenerator/testFileGenerationIssue/assets/CustomerOrderEventPayloadDTO.java index 120ca9ed..7a9041c9 100644 --- a/multiapi-engine/src/test/resources/asyncapigenerator/testFileGenerationIssue/assets/CustomerOrderEventPayloadDTO.java +++ b/multiapi-engine/src/test/resources/asyncapigenerator/testFileGenerationIssue/assets/CustomerOrderEventPayloadDTO.java @@ -11,8 +11,6 @@ @JsonDeserialize(builder = CustomerOrderEventPayloadDTO.CustomerOrderEventPayloadDTOBuilder.class) public class CustomerOrderEventPayloadDTO { - @JsonProperty(value ="customerOrderId") - private String customerOrderId; @JsonProperty(value ="eventType") private EventType eventType; public enum EventType { @@ -38,11 +36,13 @@ public String toString() { } @JsonProperty(value ="customerOrder") private CustomerOrderDTO customerOrder; + @JsonProperty(value ="customerOrderId") + private String customerOrderId; private CustomerOrderEventPayloadDTO(CustomerOrderEventPayloadDTOBuilder builder) { - this.customerOrderId = builder.customerOrderId; this.eventType = builder.eventType; this.customerOrder = builder.customerOrder; + this.customerOrderId = builder.customerOrderId; } @@ -53,49 +53,29 @@ public static CustomerOrderEventPayloadDTO.CustomerOrderEventPayloadDTOBuilder b @JsonPOJOBuilder(buildMethodName = "build", withPrefix = "") public static class CustomerOrderEventPayloadDTOBuilder { - private String customerOrderId; - private EventType eventType; - private CustomerOrderDTO customerOrder; - - public CustomerOrderEventPayloadDTO.CustomerOrderEventPayloadDTOBuilder customerOrderId(String customerOrderId) { - this.customerOrderId = customerOrderId; - return this; - } - + private String customerOrderId; public CustomerOrderEventPayloadDTO.CustomerOrderEventPayloadDTOBuilder eventType(EventType eventType) { this.eventType = eventType; return this; } - public CustomerOrderEventPayloadDTO.CustomerOrderEventPayloadDTOBuilder customerOrder(CustomerOrderDTO customerOrder) { this.customerOrder = customerOrder; return this; } + public CustomerOrderEventPayloadDTO.CustomerOrderEventPayloadDTOBuilder customerOrderId(String customerOrderId) { + this.customerOrderId = customerOrderId; + return this; + } + public CustomerOrderEventPayloadDTO build() { CustomerOrderEventPayloadDTO customerOrderEventPayloadDTO = new CustomerOrderEventPayloadDTO(this); return customerOrderEventPayloadDTO; } } - /** - * Get customerOrderId - * @return customerOrderId - */ - @Schema(name = "customerOrderId", required = false) - public String getCustomerOrderId() { - return customerOrderId; - } - public void setCustomerOrderId(String customerOrderId) { - this.customerOrderId = customerOrderId; - } - - /** - * Get eventType - * @return eventType - */ @Schema(name = "eventType", required = false) public EventType getEventType() { return eventType; @@ -104,10 +84,6 @@ public void setEventType(EventType eventType) { this.eventType = eventType; } - /** - * Get customerOrder - * @return customerOrder - */ @Schema(name = "customerOrder", required = false) public CustomerOrderDTO getCustomerOrder() { return customerOrder; @@ -116,6 +92,14 @@ public void setCustomerOrder(CustomerOrderDTO customerOrder) { this.customerOrder = customerOrder; } + @Schema(name = "customerOrderId", required = false) + public String getCustomerOrderId() { + return customerOrderId; + } + public void setCustomerOrderId(String customerOrderId) { + this.customerOrderId = customerOrderId; + } + @Override public boolean equals(Object o) { if (this == o) { @@ -125,21 +109,21 @@ public boolean equals(Object o) { return false; } CustomerOrderEventPayloadDTO customerOrderEventPayloadDTO = (CustomerOrderEventPayloadDTO) o; - return Objects.equals(this.customerOrderId, customerOrderEventPayloadDTO.customerOrderId) && Objects.equals(this.eventType, customerOrderEventPayloadDTO.eventType) && Objects.equals(this.customerOrder, customerOrderEventPayloadDTO.customerOrder); + return Objects.equals(this.eventType, customerOrderEventPayloadDTO.eventType) && Objects.equals(this.customerOrder, customerOrderEventPayloadDTO.customerOrder) && Objects.equals(this.customerOrderId, customerOrderEventPayloadDTO.customerOrderId); } @Override public int hashCode() { - return Objects.hash(customerOrderId, eventType, customerOrder); + return Objects.hash(eventType, customerOrder, customerOrderId); } @Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append("CustomerOrderEventPayloadDTO{"); - sb.append(" customerOrderId:").append(customerOrderId).append(","); sb.append(" eventType:").append(eventType).append(","); - sb.append(" customerOrder:").append(customerOrder); + sb.append(" customerOrder:").append(customerOrder).append(","); + sb.append(" customerOrderId:").append(customerOrderId); sb.append("}"); return sb.toString(); } diff --git a/multiapi-engine/src/test/resources/asyncapigenerator/testFileGenerationIssue/assets/OrderedItemDTO.java b/multiapi-engine/src/test/resources/asyncapigenerator/testFileGenerationIssue/assets/OrderedItemDTO.java index 906fa069..41dbd6d8 100644 --- a/multiapi-engine/src/test/resources/asyncapigenerator/testFileGenerationIssue/assets/OrderedItemDTO.java +++ b/multiapi-engine/src/test/resources/asyncapigenerator/testFileGenerationIssue/assets/OrderedItemDTO.java @@ -19,17 +19,17 @@ public class OrderedItemDTO { @Size(min =3, max =250) @NotNull private final String name; - @JsonProperty(value ="quantity") - private Integer quantity; @JsonProperty(value ="price") @NotNull private final Double price; + @JsonProperty(value ="quantity") + private Integer quantity; private OrderedItemDTO(OrderedItemDTOBuilder builder) { this.catalogItemId = builder.catalogItemId; this.name = builder.name; - this.quantity = builder.quantity; this.price = builder.price; + this.quantity = builder.quantity; validateRequiredAttributes(); } @@ -42,12 +42,9 @@ public static OrderedItemDTO.OrderedItemDTOBuilder builder() { public static class OrderedItemDTOBuilder { private Long catalogItemId; - private String name; - - private Integer quantity; - private Double price; + private Integer quantity; public OrderedItemDTO.OrderedItemDTOBuilder catalogItemId(Long catalogItemId) { this.catalogItemId = catalogItemId; @@ -59,13 +56,13 @@ public OrderedItemDTO.OrderedItemDTOBuilder name(String name) { return this; } - public OrderedItemDTO.OrderedItemDTOBuilder quantity(Integer quantity) { - this.quantity = quantity; + public OrderedItemDTO.OrderedItemDTOBuilder price(Double price) { + this.price = price; return this; } - public OrderedItemDTO.OrderedItemDTOBuilder price(Double price) { - this.price = price; + public OrderedItemDTO.OrderedItemDTOBuilder quantity(Integer quantity) { + this.quantity = quantity; return this; } @@ -75,10 +72,6 @@ public OrderedItemDTO build() { } } - /** - * Get catalogItemId - * @return catalogItemId - */ @Schema(name = "catalogItemId", required = false) public Long getCatalogItemId() { return catalogItemId; @@ -87,19 +80,16 @@ public void setCatalogItemId(Long catalogItemId) { this.catalogItemId = catalogItemId; } - /** - * Get name - * @return name - */ @Schema(name = "name", required = true) public String getName() { return name; } - /** - * Get quantity - * @return quantity - */ + @Schema(name = "price", required = true) + public Double getPrice() { + return price; + } + @Schema(name = "quantity", required = false) public Integer getQuantity() { return quantity; @@ -108,15 +98,6 @@ public void setQuantity(Integer quantity) { this.quantity = quantity; } - /** - * Get price - * @return price - */ - @Schema(name = "price", required = true) - public Double getPrice() { - return price; - } - @Override public boolean equals(Object o) { if (this == o) { @@ -126,12 +107,12 @@ public boolean equals(Object o) { return false; } OrderedItemDTO orderedItemDTO = (OrderedItemDTO) o; - return Objects.equals(this.catalogItemId, orderedItemDTO.catalogItemId) && Objects.equals(this.name, orderedItemDTO.name) && Objects.equals(this.quantity, orderedItemDTO.quantity) && Objects.equals(this.price, orderedItemDTO.price); + return Objects.equals(this.catalogItemId, orderedItemDTO.catalogItemId) && Objects.equals(this.name, orderedItemDTO.name) && Objects.equals(this.price, orderedItemDTO.price) && Objects.equals(this.quantity, orderedItemDTO.quantity); } @Override public int hashCode() { - return Objects.hash(catalogItemId, name, quantity, price); + return Objects.hash(catalogItemId, name, price, quantity); } @Override @@ -140,13 +121,12 @@ public String toString() { sb.append("OrderedItemDTO{"); sb.append(" catalogItemId:").append(catalogItemId).append(","); sb.append(" name:").append(name).append(","); - sb.append(" quantity:").append(quantity).append(","); - sb.append(" price:").append(price); + sb.append(" price:").append(price).append(","); + sb.append(" quantity:").append(quantity); sb.append("}"); return sb.toString(); } - private void validateRequiredAttributes() { boolean satisfiedCondition = true; @@ -160,4 +140,5 @@ private void validateRequiredAttributes() { throw new ModelClassException("OrderedItemDTO"); } } + } diff --git a/multiapi-engine/src/test/resources/asyncapigenerator/testFileGenerationIssue/assets/PaymentDetailsDTO.java b/multiapi-engine/src/test/resources/asyncapigenerator/testFileGenerationIssue/assets/PaymentDetailsDTO.java index 3a93a761..1cde28e4 100644 --- a/multiapi-engine/src/test/resources/asyncapigenerator/testFileGenerationIssue/assets/PaymentDetailsDTO.java +++ b/multiapi-engine/src/test/resources/asyncapigenerator/testFileGenerationIssue/assets/PaymentDetailsDTO.java @@ -38,10 +38,6 @@ public PaymentDetailsDTO build() { } } - /** - * Get creditCardNumber - * @return creditCardNumber - */ @Schema(name = "creditCardNumber", required = false) public String getCreditCardNumber() { return creditCardNumber; diff --git a/multiapi-engine/src/test/resources/asyncapigenerator/testFileGenerationIssue/assets/ShippingDetailsDTO.java b/multiapi-engine/src/test/resources/asyncapigenerator/testFileGenerationIssue/assets/ShippingDetailsDTO.java index ee404fe3..648a0329 100644 --- a/multiapi-engine/src/test/resources/asyncapigenerator/testFileGenerationIssue/assets/ShippingDetailsDTO.java +++ b/multiapi-engine/src/test/resources/asyncapigenerator/testFileGenerationIssue/assets/ShippingDetailsDTO.java @@ -38,10 +38,6 @@ public ShippingDetailsDTO build() { } } - /** - * Get address - * @return address - */ @Schema(name = "address", required = false) public String getAddress() { return address; diff --git a/multiapi-engine/src/test/resources/asyncapigenerator/testIssueGeneration/assets/DataDTO.java b/multiapi-engine/src/test/resources/asyncapigenerator/testIssueGeneration/assets/DataDTO.java index cbbdd804..93069cfe 100644 --- a/multiapi-engine/src/test/resources/asyncapigenerator/testIssueGeneration/assets/DataDTO.java +++ b/multiapi-engine/src/test/resources/asyncapigenerator/testIssueGeneration/assets/DataDTO.java @@ -10,17 +10,17 @@ @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; + @JsonProperty(value ="clientId") + private Integer clientId; private DataDTO(DataDTOBuilder builder) { - this.clientId = builder.clientId; this.clientName = builder.clientName; this.flightNumber = builder.flightNumber; + this.clientId = builder.clientId; } @@ -31,16 +31,9 @@ public static DataDTO.DataDTOBuilder builder() { @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; - } + private Integer clientId; public DataDTO.DataDTOBuilder clientName(String clientName) { this.clientName = clientName; @@ -52,28 +45,17 @@ public DataDTO.DataDTOBuilder flightNumber(String flightNumber) { return this; } + public DataDTO.DataDTOBuilder clientId(Integer clientId) { + this.clientId = clientId; + 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; @@ -82,10 +64,6 @@ public void setClientName(String clientName) { this.clientName = clientName; } - /** - * Get flightNumber - * @return flightNumber - */ @Schema(name = "flightNumber", required = false) public String getFlightNumber() { return flightNumber; @@ -94,6 +72,14 @@ public void setFlightNumber(String flightNumber) { this.flightNumber = flightNumber; } + @Schema(name = "clientId", required = false) + public Integer getClientId() { + return clientId; + } + public void setClientId(Integer clientId) { + this.clientId = clientId; + } + @Override public boolean equals(Object o) { if (this == o) { @@ -103,21 +89,21 @@ public boolean equals(Object o) { 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); + return Objects.equals(this.clientName, dataDTO.clientName) && Objects.equals(this.flightNumber, dataDTO.flightNumber) && Objects.equals(this.clientId, dataDTO.clientId); } @Override public int hashCode() { - return Objects.hash(clientId, clientName, flightNumber); + return Objects.hash(clientName, flightNumber, clientId); } @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(" flightNumber:").append(flightNumber).append(","); + sb.append(" clientId:").append(clientId); sb.append("}"); return sb.toString(); } diff --git a/multiapi-engine/src/test/resources/asyncapigenerator/testIssueGeneration/assets/StatusMsgDTO.java b/multiapi-engine/src/test/resources/asyncapigenerator/testIssueGeneration/assets/StatusMsgDTO.java index f98d9450..849c3884 100644 --- a/multiapi-engine/src/test/resources/asyncapigenerator/testIssueGeneration/assets/StatusMsgDTO.java +++ b/multiapi-engine/src/test/resources/asyncapigenerator/testIssueGeneration/assets/StatusMsgDTO.java @@ -11,13 +11,11 @@ @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"); + KO("KO"), + OK("OK"); private String value; @@ -35,10 +33,12 @@ public String toString() { return String.valueOf(value); } } + @JsonProperty(value ="clientId") + private Integer clientId; private StatusMsgDTO(StatusMsgDTOBuilder builder) { - this.clientId = builder.clientId; this.status = builder.status; + this.clientId = builder.clientId; } @@ -49,17 +49,15 @@ public static StatusMsgDTO.StatusMsgDTOBuilder builder() { @JsonPOJOBuilder(buildMethodName = "build", withPrefix = "") public static class StatusMsgDTOBuilder { - private Integer clientId; - private Status status; - - public StatusMsgDTO.StatusMsgDTOBuilder clientId(Integer clientId) { - this.clientId = clientId; + private Integer clientId; + public StatusMsgDTO.StatusMsgDTOBuilder status(Status status) { + this.status = status; return this; } - public StatusMsgDTO.StatusMsgDTOBuilder status(Status status) { - this.status = status; + public StatusMsgDTO.StatusMsgDTOBuilder clientId(Integer clientId) { + this.clientId = clientId; return this; } @@ -69,22 +67,6 @@ public StatusMsgDTO build() { } } - /** - * 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; @@ -93,6 +75,14 @@ public void setStatus(Status status) { this.status = status; } + @Schema(name = "clientId", required = false) + public Integer getClientId() { + return clientId; + } + public void setClientId(Integer clientId) { + this.clientId = clientId; + } + @Override public boolean equals(Object o) { if (this == o) { @@ -102,20 +92,20 @@ public boolean equals(Object o) { return false; } StatusMsgDTO statusMsgDTO = (StatusMsgDTO) o; - return Objects.equals(this.clientId, statusMsgDTO.clientId) && Objects.equals(this.status, statusMsgDTO.status); + return Objects.equals(this.status, statusMsgDTO.status) && Objects.equals(this.clientId, statusMsgDTO.clientId); } @Override public int hashCode() { - return Objects.hash(clientId, status); + return Objects.hash(status, clientId); } @Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append("StatusMsgDTO{"); - sb.append(" clientId:").append(clientId).append(","); - sb.append(" status:").append(status); + sb.append(" status:").append(status).append(","); + sb.append(" clientId:").append(clientId); sb.append("}"); return sb.toString(); } diff --git a/multiapi-engine/src/test/resources/asyncapigenerator/testIssueInfiniteLoop/assets/MailRequestInfiniteDTO.java b/multiapi-engine/src/test/resources/asyncapigenerator/testIssueInfiniteLoop/assets/MailRequestInfiniteDTO.java index bc092a8c..8e0f6b7b 100644 --- a/multiapi-engine/src/test/resources/asyncapigenerator/testIssueInfiniteLoop/assets/MailRequestInfiniteDTO.java +++ b/multiapi-engine/src/test/resources/asyncapigenerator/testIssueInfiniteLoop/assets/MailRequestInfiniteDTO.java @@ -14,15 +14,15 @@ public class MailRequestInfiniteDTO { @JsonProperty(value ="sender") private String sender; - @JsonProperty(value ="recipients") - private List recipients = new ArrayList(); @JsonProperty(value ="config") private ConfigDTO config; + @JsonProperty(value ="recipients") + private List recipients = new ArrayList(); private MailRequestInfiniteDTO(MailRequestInfiniteDTOBuilder builder) { this.sender = builder.sender; - this.recipients.addAll(builder.recipients); this.config = builder.config; + this.recipients = builder.recipients; } @@ -34,16 +34,17 @@ public static MailRequestInfiniteDTO.MailRequestInfiniteDTOBuilder builder() { public static class MailRequestInfiniteDTOBuilder { private String sender; - - private List recipients = new ArrayList(); - private ConfigDTO config; + private List recipients = new ArrayList(); public MailRequestInfiniteDTO.MailRequestInfiniteDTOBuilder sender(String sender) { this.sender = sender; return this; } - + public MailRequestInfiniteDTO.MailRequestInfiniteDTOBuilder config(ConfigDTO config) { + this.config = config; + return this; + } public MailRequestInfiniteDTO.MailRequestInfiniteDTOBuilder recipients(List recipients) { if (!recipients.isEmpty()) { this.recipients.addAll(recipients); @@ -58,21 +59,12 @@ public MailRequestInfiniteDTO.MailRequestInfiniteDTOBuilder recipient(String rec return this; } - public MailRequestInfiniteDTO.MailRequestInfiniteDTOBuilder config(ConfigDTO config) { - this.config = config; - return this; - } - public MailRequestInfiniteDTO build() { MailRequestInfiniteDTO mailRequestInfiniteDTO = new MailRequestInfiniteDTO(this); return mailRequestInfiniteDTO; } } - /** - * Get sender - * @return sender - */ @Schema(name = "sender", required = false) public String getSender() { return sender; @@ -81,22 +73,6 @@ public void setSender(String sender) { this.sender = sender; } - /** - * Get recipients - * @return recipients - */ - @Schema(name = "recipients", required = false) - public List getRecipients() { - return recipients; - } - public void setRecipients(List recipients) { - this.recipients = recipients; - } - - /** - * Get config - * @return config - */ @Schema(name = "config", required = false) public ConfigDTO getConfig() { return config; @@ -105,6 +81,14 @@ public void setConfig(ConfigDTO config) { this.config = config; } + @Schema(name = "recipients", required = false) + public List getRecipients() { + return recipients; + } + public void setRecipients(List recipients) { + this.recipients = recipients; + } + @Override public boolean equals(Object o) { if (this == o) { @@ -114,12 +98,12 @@ public boolean equals(Object o) { return false; } MailRequestInfiniteDTO mailRequestInfiniteDTO = (MailRequestInfiniteDTO) o; - return Objects.equals(this.sender, mailRequestInfiniteDTO.sender) && Objects.equals(this.recipients, mailRequestInfiniteDTO.recipients) && Objects.equals(this.config, mailRequestInfiniteDTO.config); + return Objects.equals(this.sender, mailRequestInfiniteDTO.sender) && Objects.equals(this.config, mailRequestInfiniteDTO.config) && Objects.equals(this.recipients, mailRequestInfiniteDTO.recipients); } @Override public int hashCode() { - return Objects.hash(sender, recipients, config); + return Objects.hash(sender, config, recipients); } @Override @@ -127,8 +111,8 @@ public String toString() { StringBuilder sb = new StringBuilder(); sb.append("MailRequestInfiniteDTO{"); sb.append(" sender:").append(sender).append(","); - sb.append(" recipients:").append(recipients).append(","); - sb.append(" config:").append(config); + sb.append(" config:").append(config).append(","); + sb.append(" recipients:").append(recipients); sb.append("}"); return sb.toString(); } 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 fbd2a08b..1f42795e 100644 --- a/multiapi-engine/src/test/resources/asyncapigenerator/testIssueSimpleTypeGeneration/assets/DataDTO.java +++ b/multiapi-engine/src/test/resources/asyncapigenerator/testIssueSimpleTypeGeneration/assets/DataDTO.java @@ -10,17 +10,17 @@ @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; + @JsonProperty(value ="clientId") + private Object clientId; private DataDTO(DataDTOBuilder builder) { - this.clientId = builder.clientId; this.clientName = builder.clientName; this.flightNumber = builder.flightNumber; + this.clientId = builder.clientId; } @@ -31,16 +31,9 @@ public static DataDTO.DataDTOBuilder builder() { @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; - } + private Object clientId; public DataDTO.DataDTOBuilder clientName(String clientName) { this.clientName = clientName; @@ -52,28 +45,17 @@ public DataDTO.DataDTOBuilder flightNumber(String flightNumber) { return this; } + public DataDTO.DataDTOBuilder clientId(Object clientId) { + this.clientId = clientId; + 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; @@ -82,10 +64,6 @@ public void setClientName(String clientName) { this.clientName = clientName; } - /** - * Get flightNumber - * @return flightNumber - */ @Schema(name = "flightNumber", required = false) public String getFlightNumber() { return flightNumber; @@ -94,6 +72,14 @@ public void setFlightNumber(String flightNumber) { this.flightNumber = flightNumber; } + @Schema(name = "clientId", required = false) + public Object getClientId() { + return clientId; + } + public void setClientId(Object clientId) { + this.clientId = clientId; + } + @Override public boolean equals(Object o) { if (this == o) { @@ -103,21 +89,21 @@ public boolean equals(Object o) { 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); + return Objects.equals(this.clientName, dataDTO.clientName) && Objects.equals(this.flightNumber, dataDTO.flightNumber) && Objects.equals(this.clientId, dataDTO.clientId); } @Override public int hashCode() { - return Objects.hash(clientId, clientName, flightNumber); + return Objects.hash(clientName, flightNumber, clientId); } @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(" flightNumber:").append(flightNumber).append(","); + sb.append(" clientId:").append(clientId); sb.append("}"); return sb.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 012c7d0d..f666c9a6 100644 --- a/multiapi-engine/src/test/resources/asyncapigenerator/testIssueSimpleTypeGeneration/assets/StatusMsgDTO.java +++ b/multiapi-engine/src/test/resources/asyncapigenerator/testIssueSimpleTypeGeneration/assets/StatusMsgDTO.java @@ -11,13 +11,11 @@ @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"); + KO("KO"), + OK("OK"); private String value; @@ -35,10 +33,12 @@ public String toString() { return String.valueOf(value); } } + @JsonProperty(value ="clientId") + private Object clientId; private StatusMsgDTO(StatusMsgDTOBuilder builder) { - this.clientId = builder.clientId; this.status = builder.status; + this.clientId = builder.clientId; } @@ -49,17 +49,15 @@ public static StatusMsgDTO.StatusMsgDTOBuilder builder() { @JsonPOJOBuilder(buildMethodName = "build", withPrefix = "") public static class StatusMsgDTOBuilder { - private Integer clientId; - private Status status; - - public StatusMsgDTO.StatusMsgDTOBuilder clientId(Integer clientId) { - this.clientId = clientId; + private Object clientId; + public StatusMsgDTO.StatusMsgDTOBuilder status(Status status) { + this.status = status; return this; } - public StatusMsgDTO.StatusMsgDTOBuilder status(Status status) { - this.status = status; + public StatusMsgDTO.StatusMsgDTOBuilder clientId(Object clientId) { + this.clientId = clientId; return this; } @@ -69,22 +67,6 @@ public StatusMsgDTO build() { } } - /** - * 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; @@ -93,6 +75,14 @@ public void setStatus(Status status) { this.status = status; } + @Schema(name = "clientId", required = false) + public Object getClientId() { + return clientId; + } + public void setClientId(Object clientId) { + this.clientId = clientId; + } + @Override public boolean equals(Object o) { if (this == o) { @@ -102,20 +92,20 @@ public boolean equals(Object o) { return false; } StatusMsgDTO statusMsgDTO = (StatusMsgDTO) o; - return Objects.equals(this.clientId, statusMsgDTO.clientId) && Objects.equals(this.status, statusMsgDTO.status); + return Objects.equals(this.status, statusMsgDTO.status) && Objects.equals(this.clientId, statusMsgDTO.clientId); } @Override public int hashCode() { - return Objects.hash(clientId, status); + return Objects.hash(status, clientId); } @Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append("StatusMsgDTO{"); - sb.append(" clientId:").append(clientId).append(","); - sb.append(" status:").append(status); + sb.append(" status:").append(status).append(","); + sb.append(" clientId:").append(clientId); sb.append("}"); return sb.toString(); } diff --git a/multiapi-engine/src/test/resources/asyncapigenerator/testModelClassExceptionGeneration/assets/CreateOrderEventDTO.java b/multiapi-engine/src/test/resources/asyncapigenerator/testModelClassExceptionGeneration/assets/CreateOrderEventDTO.java index 026ca857..b4ac4df5 100644 --- a/multiapi-engine/src/test/resources/asyncapigenerator/testModelClassExceptionGeneration/assets/CreateOrderEventDTO.java +++ b/multiapi-engine/src/test/resources/asyncapigenerator/testModelClassExceptionGeneration/assets/CreateOrderEventDTO.java @@ -10,14 +10,14 @@ @JsonDeserialize(builder = CreateOrderEventDTO.CreateOrderEventDTOBuilder.class) public class CreateOrderEventDTO { - @JsonProperty(value ="order") - private OrderDTO order; @JsonProperty(value ="waiter") private WaiterDTO waiter; + @JsonProperty(value ="order") + private OrderDTO order; private CreateOrderEventDTO(CreateOrderEventDTOBuilder builder) { - this.order = builder.order; this.waiter = builder.waiter; + this.order = builder.order; } @@ -28,19 +28,16 @@ public static CreateOrderEventDTO.CreateOrderEventDTOBuilder builder() { @JsonPOJOBuilder(buildMethodName = "build", withPrefix = "") public static class CreateOrderEventDTOBuilder { - private OrderDTO order; - private WaiterDTO waiter; - - public CreateOrderEventDTO.CreateOrderEventDTOBuilder order(OrderDTO order) { - this.order = order; - return this; - } - + private OrderDTO order; public CreateOrderEventDTO.CreateOrderEventDTOBuilder waiter(WaiterDTO waiter) { this.waiter = waiter; return this; } + public CreateOrderEventDTO.CreateOrderEventDTOBuilder order(OrderDTO order) { + this.order = order; + return this; + } public CreateOrderEventDTO build() { CreateOrderEventDTO createOrderEventDTO = new CreateOrderEventDTO(this); @@ -48,22 +45,6 @@ public CreateOrderEventDTO build() { } } - /** - * Get order - * @return order - */ - @Schema(name = "order", required = false) - public OrderDTO getOrder() { - return order; - } - public void setOrder(OrderDTO order) { - this.order = order; - } - - /** - * Get waiter - * @return waiter - */ @Schema(name = "waiter", required = false) public WaiterDTO getWaiter() { return waiter; @@ -72,6 +53,14 @@ public void setWaiter(WaiterDTO waiter) { this.waiter = waiter; } + @Schema(name = "order", required = false) + public OrderDTO getOrder() { + return order; + } + public void setOrder(OrderDTO order) { + this.order = order; + } + @Override public boolean equals(Object o) { if (this == o) { @@ -81,20 +70,20 @@ public boolean equals(Object o) { return false; } CreateOrderEventDTO createOrderEventDTO = (CreateOrderEventDTO) o; - return Objects.equals(this.order, createOrderEventDTO.order) && Objects.equals(this.waiter, createOrderEventDTO.waiter); + return Objects.equals(this.waiter, createOrderEventDTO.waiter) && Objects.equals(this.order, createOrderEventDTO.order); } @Override public int hashCode() { - return Objects.hash(order, waiter); + return Objects.hash(waiter, order); } @Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append("CreateOrderEventDTO{"); - sb.append(" order:").append(order).append(","); - sb.append(" waiter:").append(waiter); + sb.append(" waiter:").append(waiter).append(","); + sb.append(" order:").append(order); sb.append("}"); return sb.toString(); } diff --git a/multiapi-engine/src/test/resources/asyncapigenerator/testModelClassExceptionGeneration/assets/OrderDTO.java b/multiapi-engine/src/test/resources/asyncapigenerator/testModelClassExceptionGeneration/assets/OrderDTO.java index cbb1c170..0fda2f26 100644 --- a/multiapi-engine/src/test/resources/asyncapigenerator/testModelClassExceptionGeneration/assets/OrderDTO.java +++ b/multiapi-engine/src/test/resources/asyncapigenerator/testModelClassExceptionGeneration/assets/OrderDTO.java @@ -12,20 +12,20 @@ @JsonDeserialize(builder = OrderDTO.OrderDTOBuilder.class) public class OrderDTO { - @JsonProperty(value ="ref") - private String ref; @JsonProperty(value ="clientRef") private String clientRef; @JsonProperty(value ="amount") private String amount; @JsonProperty(value ="lines") private List lines = new ArrayList(); + @JsonProperty(value ="ref") + private String ref; private OrderDTO(OrderDTOBuilder builder) { - this.ref = builder.ref; this.clientRef = builder.clientRef; this.amount = builder.amount; - this.lines.addAll(builder.lines); + this.lines = builder.lines; + this.ref = builder.ref; } @@ -36,18 +36,10 @@ public static OrderDTO.OrderDTOBuilder builder() { @JsonPOJOBuilder(buildMethodName = "build", withPrefix = "") public static class OrderDTOBuilder { - private String ref; - private String clientRef; - private String amount; - private List lines = new ArrayList(); - - public OrderDTO.OrderDTOBuilder ref(String ref) { - this.ref = ref; - return this; - } + private String ref; public OrderDTO.OrderDTOBuilder clientRef(String clientRef) { this.clientRef = clientRef; @@ -58,7 +50,6 @@ public OrderDTO.OrderDTOBuilder amount(String amount) { this.amount = amount; return this; } - public OrderDTO.OrderDTOBuilder lines(List lines) { if (!lines.isEmpty()) { this.lines.addAll(lines); @@ -73,28 +64,17 @@ public OrderDTO.OrderDTOBuilder line(OrderLineDTO line) { return this; } + public OrderDTO.OrderDTOBuilder ref(String ref) { + this.ref = ref; + return this; + } + public OrderDTO build() { OrderDTO orderDTO = new OrderDTO(this); return orderDTO; } } - /** - * Get ref - * @return ref - */ - @Schema(name = "ref", required = false) - public String getRef() { - return ref; - } - public void setRef(String ref) { - this.ref = ref; - } - - /** - * Get clientRef - * @return clientRef - */ @Schema(name = "clientRef", required = false) public String getClientRef() { return clientRef; @@ -103,10 +83,6 @@ public void setClientRef(String clientRef) { this.clientRef = clientRef; } - /** - * Get amount - * @return amount - */ @Schema(name = "amount", required = false) public String getAmount() { return amount; @@ -115,10 +91,6 @@ public void setAmount(String amount) { this.amount = amount; } - /** - * Get lines - * @return lines - */ @Schema(name = "lines", required = false) public List getLines() { return lines; @@ -127,6 +99,14 @@ public void setLines(List lines) { this.lines = lines; } + @Schema(name = "ref", required = false) + public String getRef() { + return ref; + } + public void setRef(String ref) { + this.ref = ref; + } + @Override public boolean equals(Object o) { if (this == o) { @@ -136,22 +116,22 @@ public boolean equals(Object o) { return false; } OrderDTO orderDTO = (OrderDTO) o; - return Objects.equals(this.ref, orderDTO.ref) && Objects.equals(this.clientRef, orderDTO.clientRef) && Objects.equals(this.amount, orderDTO.amount) && Objects.equals(this.lines, orderDTO.lines); + return Objects.equals(this.clientRef, orderDTO.clientRef) && Objects.equals(this.amount, orderDTO.amount) && Objects.equals(this.lines, orderDTO.lines) && Objects.equals(this.ref, orderDTO.ref); } @Override public int hashCode() { - return Objects.hash(ref, clientRef, amount, lines); + return Objects.hash(clientRef, amount, lines, ref); } @Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append("OrderDTO{"); - sb.append(" ref:").append(ref).append(","); sb.append(" clientRef:").append(clientRef).append(","); sb.append(" amount:").append(amount).append(","); - sb.append(" lines:").append(lines); + sb.append(" lines:").append(lines).append(","); + sb.append(" ref:").append(ref); sb.append("}"); return sb.toString(); } diff --git a/multiapi-engine/src/test/resources/asyncapigenerator/testModelClassExceptionGeneration/assets/OrderLineDTO.java b/multiapi-engine/src/test/resources/asyncapigenerator/testModelClassExceptionGeneration/assets/OrderLineDTO.java index a97d2d35..6fff7b3a 100644 --- a/multiapi-engine/src/test/resources/asyncapigenerator/testModelClassExceptionGeneration/assets/OrderLineDTO.java +++ b/multiapi-engine/src/test/resources/asyncapigenerator/testModelClassExceptionGeneration/assets/OrderLineDTO.java @@ -14,16 +14,15 @@ @JsonDeserialize(builder = OrderLineDTO.OrderLineDTOBuilder.class) public class OrderLineDTO { + @JsonProperty(value ="products") + private List products = new ArrayList(); @JsonProperty(value ="ref") @NotNull private final String ref; - @JsonProperty(value ="products") - @NotNull - private final List products = new ArrayList(); private OrderLineDTO(OrderLineDTOBuilder builder) { + this.products = builder.products; this.ref = builder.ref; - this.products.addAll(builder.products); validateRequiredAttributes(); } @@ -35,15 +34,8 @@ public static OrderLineDTO.OrderLineDTOBuilder builder() { @JsonPOJOBuilder(buildMethodName = "build", withPrefix = "") public static class OrderLineDTOBuilder { - private String ref; - private List products = new ArrayList(); - - public OrderLineDTO.OrderLineDTOBuilder ref(String ref) { - this.ref = ref; - return this; - } - + private String ref; public OrderLineDTO.OrderLineDTOBuilder products(List products) { if (!products.isEmpty()) { this.products.addAll(products); @@ -58,30 +50,30 @@ public OrderLineDTO.OrderLineDTOBuilder product(OrderProductDTO product) { return this; } + public OrderLineDTO.OrderLineDTOBuilder ref(String ref) { + this.ref = ref; + return this; + } + public OrderLineDTO build() { OrderLineDTO orderLineDTO = new OrderLineDTO(this); return orderLineDTO; } } - /** - * Get ref - * @return ref - */ + @Schema(name = "products", required = false) + public List getProducts() { + return products; + } + public void setProducts(List products) { + this.products = products; + } + @Schema(name = "ref", required = true) public String getRef() { return ref; } - /** - * Get products - * @return products - */ - @Schema(name = "products", required = true) - public List getProducts() { - return products; - } - @Override public boolean equals(Object o) { if (this == o) { @@ -91,36 +83,34 @@ public boolean equals(Object o) { return false; } OrderLineDTO orderLineDTO = (OrderLineDTO) o; - return Objects.equals(this.ref, orderLineDTO.ref) && Objects.equals(this.products, orderLineDTO.products); + return Objects.equals(this.products, orderLineDTO.products) && Objects.equals(this.ref, orderLineDTO.ref); } @Override public int hashCode() { - return Objects.hash(ref, products); + return Objects.hash(products, ref); } @Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append("OrderLineDTO{"); - sb.append(" ref:").append(ref).append(","); - sb.append(" products:").append(products); + sb.append(" products:").append(products).append(","); + sb.append(" ref:").append(ref); sb.append("}"); return sb.toString(); } - private void validateRequiredAttributes() { boolean satisfiedCondition = true; if (!Objects.nonNull(this.ref)) { satisfiedCondition = false; - } else if (!Objects.nonNull(this.products)) { - satisfiedCondition = false; } if (!satisfiedCondition) { throw new ModelClassException("OrderLineDTO"); } } + } diff --git a/multiapi-engine/src/test/resources/asyncapigenerator/testModelClassExceptionGeneration/assets/OrderProductDTO.java b/multiapi-engine/src/test/resources/asyncapigenerator/testModelClassExceptionGeneration/assets/OrderProductDTO.java index ccfe46e6..04d3071d 100644 --- a/multiapi-engine/src/test/resources/asyncapigenerator/testModelClassExceptionGeneration/assets/OrderProductDTO.java +++ b/multiapi-engine/src/test/resources/asyncapigenerator/testModelClassExceptionGeneration/assets/OrderProductDTO.java @@ -12,9 +12,6 @@ @JsonDeserialize(builder = OrderProductDTO.OrderProductDTOBuilder.class) public class OrderProductDTO { - @JsonProperty(value ="ref") - @NotNull - private final String ref; @JsonProperty(value ="productRef") @NotNull private final String productRef; @@ -24,12 +21,15 @@ public class OrderProductDTO { @JsonProperty(value ="quantity") @NotNull private final String quantity; + @JsonProperty(value ="ref") + @NotNull + private final String ref; private OrderProductDTO(OrderProductDTOBuilder builder) { - this.ref = builder.ref; this.productRef = builder.productRef; this.price = builder.price; this.quantity = builder.quantity; + this.ref = builder.ref; validateRequiredAttributes(); } @@ -41,18 +41,10 @@ public static OrderProductDTO.OrderProductDTOBuilder builder() { @JsonPOJOBuilder(buildMethodName = "build", withPrefix = "") public static class OrderProductDTOBuilder { - private String ref; - private String productRef; - private String price; - private String quantity; - - public OrderProductDTO.OrderProductDTOBuilder ref(String ref) { - this.ref = ref; - return this; - } + private String ref; public OrderProductDTO.OrderProductDTOBuilder productRef(String productRef) { this.productRef = productRef; @@ -69,48 +61,37 @@ public OrderProductDTO.OrderProductDTOBuilder quantity(String quantity) { return this; } + public OrderProductDTO.OrderProductDTOBuilder ref(String ref) { + this.ref = ref; + return this; + } + public OrderProductDTO build() { OrderProductDTO orderProductDTO = new OrderProductDTO(this); return orderProductDTO; } } - /** - * Get ref - * @return ref - */ - @Schema(name = "ref", required = true) - public String getRef() { - return ref; - } - - /** - * Get productRef - * @return productRef - */ @Schema(name = "productRef", required = true) public String getProductRef() { return productRef; } - /** - * Get price - * @return price - */ @Schema(name = "price", required = true) public String getPrice() { return price; } - /** - * Get quantity - * @return quantity - */ @Schema(name = "quantity", required = true) public String getQuantity() { return quantity; } + @Schema(name = "ref", required = true) + public String getRef() { + return ref; + } + @Override public boolean equals(Object o) { if (this == o) { @@ -120,42 +101,42 @@ public boolean equals(Object o) { return false; } OrderProductDTO orderProductDTO = (OrderProductDTO) o; - return Objects.equals(this.ref, orderProductDTO.ref) && Objects.equals(this.productRef, orderProductDTO.productRef) && Objects.equals(this.price, orderProductDTO.price) && Objects.equals(this.quantity, orderProductDTO.quantity); + return Objects.equals(this.productRef, orderProductDTO.productRef) && Objects.equals(this.price, orderProductDTO.price) && Objects.equals(this.quantity, orderProductDTO.quantity) && Objects.equals(this.ref, orderProductDTO.ref); } @Override public int hashCode() { - return Objects.hash(ref, productRef, price, quantity); + return Objects.hash(productRef, price, quantity, ref); } @Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append("OrderProductDTO{"); - sb.append(" ref:").append(ref).append(","); sb.append(" productRef:").append(productRef).append(","); sb.append(" price:").append(price).append(","); - sb.append(" quantity:").append(quantity); + sb.append(" quantity:").append(quantity).append(","); + sb.append(" ref:").append(ref); sb.append("}"); return sb.toString(); } - private void validateRequiredAttributes() { boolean satisfiedCondition = true; - if (!Objects.nonNull(this.ref)) { - satisfiedCondition = false; - } else if (!Objects.nonNull(this.productRef)) { + if (!Objects.nonNull(this.productRef)) { satisfiedCondition = false; } else if (!Objects.nonNull(this.price)) { satisfiedCondition = false; } else if (!Objects.nonNull(this.quantity)) { satisfiedCondition = false; + } else if (!Objects.nonNull(this.ref)) { + satisfiedCondition = false; } if (!satisfiedCondition) { throw new ModelClassException("OrderProductDTO"); } } + } diff --git a/multiapi-engine/src/test/resources/asyncapigenerator/testModelClassExceptionGeneration/assets/WaiterDTO.java b/multiapi-engine/src/test/resources/asyncapigenerator/testModelClassExceptionGeneration/assets/WaiterDTO.java index 5bc0f211..32a8762f 100644 --- a/multiapi-engine/src/test/resources/asyncapigenerator/testModelClassExceptionGeneration/assets/WaiterDTO.java +++ b/multiapi-engine/src/test/resources/asyncapigenerator/testModelClassExceptionGeneration/assets/WaiterDTO.java @@ -10,17 +10,17 @@ @JsonDeserialize(builder = WaiterDTO.WaiterDTOBuilder.class) public class WaiterDTO { - @JsonProperty(value ="ref") - private String ref; @JsonProperty(value ="timestamp") private String timestamp; @JsonProperty(value ="table") private String table; + @JsonProperty(value ="ref") + private String ref; private WaiterDTO(WaiterDTOBuilder builder) { - this.ref = builder.ref; this.timestamp = builder.timestamp; this.table = builder.table; + this.ref = builder.ref; } @@ -31,16 +31,9 @@ public static WaiterDTO.WaiterDTOBuilder builder() { @JsonPOJOBuilder(buildMethodName = "build", withPrefix = "") public static class WaiterDTOBuilder { - private String ref; - private String timestamp; - private String table; - - public WaiterDTO.WaiterDTOBuilder ref(String ref) { - this.ref = ref; - return this; - } + private String ref; public WaiterDTO.WaiterDTOBuilder timestamp(String timestamp) { this.timestamp = timestamp; @@ -52,28 +45,17 @@ public WaiterDTO.WaiterDTOBuilder table(String table) { return this; } + public WaiterDTO.WaiterDTOBuilder ref(String ref) { + this.ref = ref; + return this; + } + public WaiterDTO build() { WaiterDTO waiterDTO = new WaiterDTO(this); return waiterDTO; } } - /** - * Get ref - * @return ref - */ - @Schema(name = "ref", required = false) - public String getRef() { - return ref; - } - public void setRef(String ref) { - this.ref = ref; - } - - /** - * Get timestamp - * @return timestamp - */ @Schema(name = "timestamp", required = false) public String getTimestamp() { return timestamp; @@ -82,10 +64,6 @@ public void setTimestamp(String timestamp) { this.timestamp = timestamp; } - /** - * Get table - * @return table - */ @Schema(name = "table", required = false) public String getTable() { return table; @@ -94,6 +72,14 @@ public void setTable(String table) { this.table = table; } + @Schema(name = "ref", required = false) + public String getRef() { + return ref; + } + public void setRef(String ref) { + this.ref = ref; + } + @Override public boolean equals(Object o) { if (this == o) { @@ -103,21 +89,21 @@ public boolean equals(Object o) { return false; } WaiterDTO waiterDTO = (WaiterDTO) o; - return Objects.equals(this.ref, waiterDTO.ref) && Objects.equals(this.timestamp, waiterDTO.timestamp) && Objects.equals(this.table, waiterDTO.table); + return Objects.equals(this.timestamp, waiterDTO.timestamp) && Objects.equals(this.table, waiterDTO.table) && Objects.equals(this.ref, waiterDTO.ref); } @Override public int hashCode() { - return Objects.hash(ref, timestamp, table); + return Objects.hash(timestamp, table, ref); } @Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append("WaiterDTO{"); - sb.append(" ref:").append(ref).append(","); sb.append(" timestamp:").append(timestamp).append(","); - sb.append(" table:").append(table); + sb.append(" table:").append(table).append(","); + sb.append(" ref:").append(ref); sb.append("}"); return sb.toString(); } diff --git a/multiapi-engine/src/test/resources/asyncapigenerator/testNestedObjectIssue/assets/payload/SomeOtherObject.java b/multiapi-engine/src/test/resources/asyncapigenerator/testNestedObjectIssue/assets/payload/SomeOtherObject.java index cc39475f..37b7cb70 100644 --- a/multiapi-engine/src/test/resources/asyncapigenerator/testNestedObjectIssue/assets/payload/SomeOtherObject.java +++ b/multiapi-engine/src/test/resources/asyncapigenerator/testNestedObjectIssue/assets/payload/SomeOtherObject.java @@ -10,14 +10,14 @@ @JsonDeserialize(builder = SomeOtherObject.SomeOtherObjectBuilder.class) public class SomeOtherObject { - @JsonProperty(value ="property1") - private String property1; @JsonProperty(value ="property2") private Integer property2; + @JsonProperty(value ="property1") + private String property1; private SomeOtherObject(SomeOtherObjectBuilder builder) { - this.property1 = builder.property1; this.property2 = builder.property2; + this.property1 = builder.property1; } @@ -28,17 +28,16 @@ public static SomeOtherObject.SomeOtherObjectBuilder builder() { @JsonPOJOBuilder(buildMethodName = "build", withPrefix = "") public static class SomeOtherObjectBuilder { - private String property1; - private Integer property2; + private String property1; - public SomeOtherObject.SomeOtherObjectBuilder property1(String property1) { - this.property1 = property1; + public SomeOtherObject.SomeOtherObjectBuilder property2(Integer property2) { + this.property2 = property2; return this; } - public SomeOtherObject.SomeOtherObjectBuilder property2(Integer property2) { - this.property2 = property2; + public SomeOtherObject.SomeOtherObjectBuilder property1(String property1) { + this.property1 = property1; return this; } @@ -48,22 +47,6 @@ public SomeOtherObject build() { } } - /** - * Get property1 - * @return property1 - */ - @Schema(name = "property1", required = false) - public String getProperty1() { - return property1; - } - public void setProperty1(String property1) { - this.property1 = property1; - } - - /** - * Get property2 - * @return property2 - */ @Schema(name = "property2", required = false) public Integer getProperty2() { return property2; @@ -72,6 +55,14 @@ public void setProperty2(Integer property2) { this.property2 = property2; } + @Schema(name = "property1", required = false) + public String getProperty1() { + return property1; + } + public void setProperty1(String property1) { + this.property1 = property1; + } + @Override public boolean equals(Object o) { if (this == o) { @@ -81,23 +72,23 @@ public boolean equals(Object o) { return false; } SomeOtherObject someOtherObject = (SomeOtherObject) o; - return Objects.equals(this.property1, someOtherObject.property1) && Objects.equals(this.property2, someOtherObject.property2); + return Objects.equals(this.property2, someOtherObject.property2) && Objects.equals(this.property1, someOtherObject.property1); } @Override public int hashCode() { - return Objects.hash(property1, property2); + return Objects.hash(property2, property1); } @Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append("SomeOtherObject{"); - sb.append(" property1:").append(property1).append(","); - sb.append(" property2:").append(property2); + sb.append(" property2:").append(property2).append(","); + sb.append(" property1:").append(property1); sb.append("}"); return sb.toString(); } -} \ No newline at end of file +} diff --git a/multiapi-engine/src/test/resources/asyncapigenerator/testNestedObjectIssue/assets/payload/UserSignedUpPayload.java b/multiapi-engine/src/test/resources/asyncapigenerator/testNestedObjectIssue/assets/payload/UserSignedUpPayload.java index f8f4d7fc..6097e3b4 100644 --- a/multiapi-engine/src/test/resources/asyncapigenerator/testNestedObjectIssue/assets/payload/UserSignedUpPayload.java +++ b/multiapi-engine/src/test/resources/asyncapigenerator/testNestedObjectIssue/assets/payload/UserSignedUpPayload.java @@ -7,29 +7,27 @@ import com.fasterxml.jackson.annotation.JsonProperty; import io.swagger.v3.oas.annotations.media.Schema; import java.time.LocalDateTime; -import com.fasterxml.jackson.annotation.JsonFormat; @JsonDeserialize(builder = UserSignedUpPayload.UserSignedUpPayloadBuilder.class) public class UserSignedUpPayload { + @JsonProperty(value ="someOtherObject") + private SomeOtherObject someOtherObject; + @JsonProperty(value ="email") + private String email; @JsonProperty(value ="firstName") private String firstName; @JsonProperty(value ="lastName") private String lastName; - @JsonProperty(value ="email") - private String email; @JsonProperty(value ="createdAt") - @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss") private LocalDateTime createdAt; - @JsonProperty(value ="someOtherObject") - private SomeOtherObject someOtherObject; private UserSignedUpPayload(UserSignedUpPayloadBuilder builder) { + this.someOtherObject = builder.someOtherObject; + this.email = builder.email; this.firstName = builder.firstName; this.lastName = builder.lastName; - this.email = builder.email; this.createdAt = builder.createdAt; - this.someOtherObject = builder.someOtherObject; } @@ -40,15 +38,20 @@ public static UserSignedUpPayload.UserSignedUpPayloadBuilder builder() { @JsonPOJOBuilder(buildMethodName = "build", withPrefix = "") public static class UserSignedUpPayloadBuilder { + private SomeOtherObject someOtherObject; + private String email; private String firstName; - private String lastName; - - private String email; - private LocalDateTime createdAt; + public UserSignedUpPayload.UserSignedUpPayloadBuilder someOtherObject(SomeOtherObject someOtherObject) { + this.someOtherObject = someOtherObject; + return this; + } - private SomeOtherObject someOtherObject; + public UserSignedUpPayload.UserSignedUpPayloadBuilder email(String email) { + this.email = email; + return this; + } public UserSignedUpPayload.UserSignedUpPayloadBuilder firstName(String firstName) { this.firstName = firstName; @@ -60,31 +63,33 @@ public UserSignedUpPayload.UserSignedUpPayloadBuilder lastName(String lastName) return this; } - public UserSignedUpPayload.UserSignedUpPayloadBuilder email(String email) { - this.email = email; - return this; - } - public UserSignedUpPayload.UserSignedUpPayloadBuilder createdAt(LocalDateTime createdAt) { this.createdAt = createdAt; return this; } - public UserSignedUpPayload.UserSignedUpPayloadBuilder someOtherObject(SomeOtherObject someOtherObject) { - this.someOtherObject = someOtherObject; - return this; - } - public UserSignedUpPayload build() { UserSignedUpPayload userSignedUpPayload = new UserSignedUpPayload(this); return userSignedUpPayload; } } - /** - * Get firstName - * @return firstName - */ + @Schema(name = "someOtherObject", required = false) + public SomeOtherObject getSomeOtherObject() { + return someOtherObject; + } + public void setSomeOtherObject(SomeOtherObject someOtherObject) { + this.someOtherObject = someOtherObject; + } + + @Schema(name = "email", required = false) + public String getEmail() { + return email; + } + public void setEmail(String email) { + this.email = email; + } + @Schema(name = "firstName", required = false) public String getFirstName() { return firstName; @@ -93,10 +98,6 @@ public void setFirstName(String firstName) { this.firstName = firstName; } - /** - * Get lastName - * @return lastName - */ @Schema(name = "lastName", required = false) public String getLastName() { return lastName; @@ -105,22 +106,6 @@ public void setLastName(String lastName) { this.lastName = lastName; } - /** - * Get email - * @return email - */ - @Schema(name = "email", required = false) - public String getEmail() { - return email; - } - public void setEmail(String email) { - this.email = email; - } - - /** - * Get createdAt - * @return createdAt - */ @Schema(name = "createdAt", required = false) public LocalDateTime getCreatedAt() { return createdAt; @@ -129,18 +114,6 @@ public void setCreatedAt(LocalDateTime createdAt) { this.createdAt = createdAt; } - /** - * Get someOtherObject - * @return someOtherObject - */ - @Schema(name = "someOtherObject", required = false) - public SomeOtherObject getSomeOtherObject() { - return someOtherObject; - } - public void setSomeOtherObject(SomeOtherObject someOtherObject) { - this.someOtherObject = someOtherObject; - } - @Override public boolean equals(Object o) { if (this == o) { @@ -150,23 +123,23 @@ public boolean equals(Object o) { return false; } UserSignedUpPayload userSignedUpPayload = (UserSignedUpPayload) o; - return Objects.equals(this.firstName, userSignedUpPayload.firstName) && Objects.equals(this.lastName, userSignedUpPayload.lastName) && Objects.equals(this.email, userSignedUpPayload.email) && Objects.equals(this.createdAt, userSignedUpPayload.createdAt) && Objects.equals(this.someOtherObject, userSignedUpPayload.someOtherObject); + return Objects.equals(this.someOtherObject, userSignedUpPayload.someOtherObject) && Objects.equals(this.email, userSignedUpPayload.email) && Objects.equals(this.firstName, userSignedUpPayload.firstName) && Objects.equals(this.lastName, userSignedUpPayload.lastName) && Objects.equals(this.createdAt, userSignedUpPayload.createdAt); } @Override public int hashCode() { - return Objects.hash(firstName, lastName, email, createdAt, someOtherObject); + return Objects.hash(someOtherObject, email, firstName, lastName, createdAt); } @Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append("UserSignedUpPayload{"); + sb.append(" someOtherObject:").append(someOtherObject).append(","); + sb.append(" email:").append(email).append(","); sb.append(" firstName:").append(firstName).append(","); sb.append(" lastName:").append(lastName).append(","); - sb.append(" email:").append(email).append(","); - sb.append(" createdAt:").append(createdAt).append(","); - sb.append(" someOtherObject:").append(someOtherObject); + sb.append(" createdAt:").append(createdAt); sb.append("}"); return sb.toString(); } diff --git a/multiapi-engine/src/test/resources/asyncapigenerator/testNoSchemas/assets/TestMsg.java b/multiapi-engine/src/test/resources/asyncapigenerator/testNoSchemas/assets/TestMsg.java index e2974173..06ea868b 100644 --- a/multiapi-engine/src/test/resources/asyncapigenerator/testNoSchemas/assets/TestMsg.java +++ b/multiapi-engine/src/test/resources/asyncapigenerator/testNoSchemas/assets/TestMsg.java @@ -38,10 +38,6 @@ public TestMsg build() { } } - /** - * Get id - * @return id - */ @Schema(name = "id", required = false) public Integer getId() { return id; diff --git a/multiapi-engine/src/test/resources/asyncapigenerator/testNoSchemas/assets/Thing.java b/multiapi-engine/src/test/resources/asyncapigenerator/testNoSchemas/assets/Thing.java index 13ef908b..f109da1a 100644 --- a/multiapi-engine/src/test/resources/asyncapigenerator/testNoSchemas/assets/Thing.java +++ b/multiapi-engine/src/test/resources/asyncapigenerator/testNoSchemas/assets/Thing.java @@ -38,10 +38,6 @@ public Thing build() { } } - /** - * Get id - * @return id - */ @Schema(name = "id", required = false) public Integer getId() { return id; 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 4b971652..f9611c24 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 @@ -10,17 +10,17 @@ @JsonDeserialize(builder = UserDetails.UserDetailsBuilder.class) public class UserDetails { + @JsonProperty(value ="email") + private String email; @JsonProperty(value ="firstName") private String firstName; @JsonProperty(value ="lastName") private String lastName; - @JsonProperty(value ="email") - private String email; private UserDetails(UserDetailsBuilder builder) { + this.email = builder.email; this.firstName = builder.firstName; this.lastName = builder.lastName; - this.email = builder.email; } @@ -31,11 +31,14 @@ public static UserDetails.UserDetailsBuilder builder() { @JsonPOJOBuilder(buildMethodName = "build", withPrefix = "") public static class UserDetailsBuilder { + private String email; private String firstName; - private String lastName; - private String email; + public UserDetails.UserDetailsBuilder email(String email) { + this.email = email; + return this; + } public UserDetails.UserDetailsBuilder firstName(String firstName) { this.firstName = firstName; @@ -47,21 +50,20 @@ public UserDetails.UserDetailsBuilder lastName(String lastName) { return this; } - public UserDetails.UserDetailsBuilder email(String email) { - this.email = email; - return this; - } - public UserDetails build() { UserDetails userDetails = new UserDetails(this); return userDetails; } } - /** - * Get firstName - * @return firstName - */ + @Schema(name = "email", required = false) + public String getEmail() { + return email; + } + public void setEmail(String email) { + this.email = email; + } + @Schema(name = "firstName", required = false) public String getFirstName() { return firstName; @@ -70,10 +72,6 @@ public void setFirstName(String firstName) { this.firstName = firstName; } - /** - * Get lastName - * @return lastName - */ @Schema(name = "lastName", required = false) public String getLastName() { return lastName; @@ -82,18 +80,6 @@ public void setLastName(String lastName) { this.lastName = lastName; } - /** - * Get email - * @return email - */ - @Schema(name = "email", required = false) - public String getEmail() { - return email; - } - public void setEmail(String email) { - this.email = email; - } - @Override public boolean equals(Object o) { if (this == o) { @@ -103,21 +89,21 @@ public boolean equals(Object o) { 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); + return Objects.equals(this.email, userDetails.email) && Objects.equals(this.firstName, userDetails.firstName) && Objects.equals(this.lastName, userDetails.lastName); } @Override public int hashCode() { - return Objects.hash(firstName, lastName, email); + return Objects.hash(email, firstName, lastName); } @Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append("UserDetails{"); + sb.append(" email:").append(email).append(","); sb.append(" firstName:").append(firstName).append(","); - sb.append(" lastName:").append(lastName).append(","); - sb.append(" email:").append(email); + sb.append(" lastName:").append(lastName); sb.append("}"); return sb.toString(); } 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 23e71dae..06a34063 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 @@ -10,14 +10,14 @@ @JsonDeserialize(builder = UserSignedUp.UserSignedUpBuilder.class) public class UserSignedUp { - @JsonProperty(value ="id") - private String id; @JsonProperty(value ="details") private UserDetails details; + @JsonProperty(value ="id") + private String id; private UserSignedUp(UserSignedUpBuilder builder) { - this.id = builder.id; this.details = builder.details; + this.id = builder.id; } @@ -28,17 +28,15 @@ public static UserSignedUp.UserSignedUpBuilder builder() { @JsonPOJOBuilder(buildMethodName = "build", withPrefix = "") public static class UserSignedUpBuilder { - private String id; - private UserDetails details; - - public UserSignedUp.UserSignedUpBuilder id(String id) { - this.id = id; + private String id; + public UserSignedUp.UserSignedUpBuilder details(UserDetails details) { + this.details = details; return this; } - public UserSignedUp.UserSignedUpBuilder details(UserDetails details) { - this.details = details; + public UserSignedUp.UserSignedUpBuilder id(String id) { + this.id = id; return this; } @@ -48,22 +46,6 @@ public UserSignedUp build() { } } - /** - * Get id - * @return id - */ - @Schema(name = "id", required = false) - public String getId() { - return id; - } - public void setId(String id) { - this.id = id; - } - - /** - * Get details - * @return details - */ @Schema(name = "details", required = false) public UserDetails getDetails() { return details; @@ -72,6 +54,14 @@ public void setDetails(UserDetails details) { this.details = details; } + @Schema(name = "id", required = false) + public String getId() { + return id; + } + public void setId(String id) { + this.id = id; + } + @Override public boolean equals(Object o) { if (this == o) { @@ -81,20 +71,20 @@ public boolean equals(Object o) { return false; } UserSignedUp userSignedUp = (UserSignedUp) o; - return Objects.equals(this.id, userSignedUp.id) && Objects.equals(this.details, userSignedUp.details); + return Objects.equals(this.details, userSignedUp.details) && Objects.equals(this.id, userSignedUp.id); } @Override public int hashCode() { - return Objects.hash(id, details); + return Objects.hash(details, id); } @Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append("UserSignedUp{"); - sb.append(" id:").append(id).append(","); - sb.append(" details:").append(details); + sb.append(" details:").append(details).append(","); + sb.append(" id:").append(id); sb.append("}"); return sb.toString(); } diff --git a/multiapi-engine/src/test/resources/asyncapigenerator/testRareCharsGeneration/assets/CreateOrderDTO.java b/multiapi-engine/src/test/resources/asyncapigenerator/testRareCharsGeneration/assets/CreateOrderDTO.java index 8469d036..8f6c91d9 100644 --- a/multiapi-engine/src/test/resources/asyncapigenerator/testRareCharsGeneration/assets/CreateOrderDTO.java +++ b/multiapi-engine/src/test/resources/asyncapigenerator/testRareCharsGeneration/assets/CreateOrderDTO.java @@ -10,14 +10,14 @@ @JsonDeserialize(builder = CreateOrderDTO.CreateOrderDTOBuilder.class) public class CreateOrderDTO { - @JsonProperty(value ="order") - private OrderDTO order; @JsonProperty(value ="waiter") private WaiterDTO waiter; + @JsonProperty(value ="order") + private OrderDTO order; private CreateOrderDTO(CreateOrderDTOBuilder builder) { - this.order = builder.order; this.waiter = builder.waiter; + this.order = builder.order; } @@ -28,19 +28,16 @@ public static CreateOrderDTO.CreateOrderDTOBuilder builder() { @JsonPOJOBuilder(buildMethodName = "build", withPrefix = "") public static class CreateOrderDTOBuilder { - private OrderDTO order; - private WaiterDTO waiter; - - public CreateOrderDTO.CreateOrderDTOBuilder order(OrderDTO order) { - this.order = order; - return this; - } - + private OrderDTO order; public CreateOrderDTO.CreateOrderDTOBuilder waiter(WaiterDTO waiter) { this.waiter = waiter; return this; } + public CreateOrderDTO.CreateOrderDTOBuilder order(OrderDTO order) { + this.order = order; + return this; + } public CreateOrderDTO build() { CreateOrderDTO createOrderDTO = new CreateOrderDTO(this); @@ -48,22 +45,6 @@ public CreateOrderDTO build() { } } - /** - * Get order - * @return order - */ - @Schema(name = "order", required = false) - public OrderDTO getOrder() { - return order; - } - public void setOrder(OrderDTO order) { - this.order = order; - } - - /** - * Get waiter - * @return waiter - */ @Schema(name = "waiter", required = false) public WaiterDTO getWaiter() { return waiter; @@ -72,6 +53,14 @@ public void setWaiter(WaiterDTO waiter) { this.waiter = waiter; } + @Schema(name = "order", required = false) + public OrderDTO getOrder() { + return order; + } + public void setOrder(OrderDTO order) { + this.order = order; + } + @Override public boolean equals(Object o) { if (this == o) { @@ -81,20 +70,20 @@ public boolean equals(Object o) { return false; } CreateOrderDTO createOrderDTO = (CreateOrderDTO) o; - return Objects.equals(this.order, createOrderDTO.order) && Objects.equals(this.waiter, createOrderDTO.waiter); + return Objects.equals(this.waiter, createOrderDTO.waiter) && Objects.equals(this.order, createOrderDTO.order); } @Override public int hashCode() { - return Objects.hash(order, waiter); + return Objects.hash(waiter, order); } @Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append("CreateOrderDTO{"); - sb.append(" order:").append(order).append(","); - sb.append(" waiter:").append(waiter); + sb.append(" waiter:").append(waiter).append(","); + sb.append(" order:").append(order); sb.append("}"); return sb.toString(); } diff --git a/multiapi-engine/src/test/resources/asyncapigenerator/testRareCharsGeneration/assets/OrderDTO.java b/multiapi-engine/src/test/resources/asyncapigenerator/testRareCharsGeneration/assets/OrderDTO.java index 91c2792e..270a63c8 100644 --- a/multiapi-engine/src/test/resources/asyncapigenerator/testRareCharsGeneration/assets/OrderDTO.java +++ b/multiapi-engine/src/test/resources/asyncapigenerator/testRareCharsGeneration/assets/OrderDTO.java @@ -12,18 +12,16 @@ @JsonDeserialize(builder = OrderDTO.OrderDTOBuilder.class) public class OrderDTO { - @JsonProperty(value ="ref") - private String ref; @JsonProperty(value ="clientRef") private String clientRef; @JsonProperty(value ="amount") private BigDecimal amount; - @JsonProperty(value ="new") + @JsonProperty(value ="_new") private New _new; public enum New { - ONE_PIECE_WORKS("one:piece:works"), - TWO_PIECE_WORKS("two:piece:works"), - THREE_PIECE_WORKS("three:piece:works"); + TWO:PIECE:WORKS("two:piece:works"), + THREE:PIECE:WORKS("three:piece:works"), + ONE:PIECE:WORKS("one:piece:works"); private String value; @@ -41,12 +39,14 @@ public String toString() { return String.valueOf(value); } } + @JsonProperty(value ="ref") + private String ref; private OrderDTO(OrderDTOBuilder builder) { - this.ref = builder.ref; this.clientRef = builder.clientRef; this.amount = builder.amount; this._new = builder._new; + this.ref = builder.ref; } @@ -57,18 +57,10 @@ public static OrderDTO.OrderDTOBuilder builder() { @JsonPOJOBuilder(buildMethodName = "build", withPrefix = "") public static class OrderDTOBuilder { - private String ref; - private String clientRef; - private BigDecimal amount; - private New _new; - - public OrderDTO.OrderDTOBuilder ref(String ref) { - this.ref = ref; - return this; - } + private String ref; public OrderDTO.OrderDTOBuilder clientRef(String clientRef) { this.clientRef = clientRef; @@ -79,34 +71,22 @@ public OrderDTO.OrderDTOBuilder amount(BigDecimal amount) { this.amount = amount; return this; } - - public OrderDTO.OrderDTOBuilder _new(New _new) { + public OrderDTO.OrderDTOBuilder _new(New new) { this._new = _new; return this; } + public OrderDTO.OrderDTOBuilder ref(String ref) { + this.ref = ref; + return this; + } + public OrderDTO build() { OrderDTO orderDTO = new OrderDTO(this); return orderDTO; } } - /** - * Get ref - * @return ref - */ - @Schema(name = "ref", required = false) - public String getRef() { - return ref; - } - public void setRef(String ref) { - this.ref = ref; - } - - /** - * Get clientRef - * @return clientRef - */ @Schema(name = "clientRef", required = false) public String getClientRef() { return clientRef; @@ -115,10 +95,6 @@ public void setClientRef(String clientRef) { this.clientRef = clientRef; } - /** - * Get amount - * @return amount - */ @Schema(name = "amount", required = false) public BigDecimal getAmount() { return amount; @@ -127,10 +103,6 @@ public void setAmount(BigDecimal amount) { this.amount = amount; } - /** - * Get new - * @return new - */ @Schema(name = "new", required = false) public New getNew() { return _new; @@ -139,6 +111,14 @@ public void setNew(New _new) { this._new = _new; } + @Schema(name = "ref", required = false) + public String getRef() { + return ref; + } + public void setRef(String ref) { + this.ref = ref; + } + @Override public boolean equals(Object o) { if (this == o) { @@ -148,22 +128,22 @@ public boolean equals(Object o) { return false; } OrderDTO orderDTO = (OrderDTO) o; - return Objects.equals(this.ref, orderDTO.ref) && Objects.equals(this.clientRef, orderDTO.clientRef) && Objects.equals(this.amount, orderDTO.amount) && Objects.equals(this._new, orderDTO._new); + return Objects.equals(this.clientRef, orderDTO.clientRef) && Objects.equals(this.amount, orderDTO.amount) && Objects.equals(this._new, orderDTO._new) && Objects.equals(this.ref, orderDTO.ref); } @Override public int hashCode() { - return Objects.hash(ref, clientRef, amount, _new); + return Objects.hash(clientRef, amount, _new, ref); } @Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append("OrderDTO{"); - sb.append(" ref:").append(ref).append(","); sb.append(" clientRef:").append(clientRef).append(","); sb.append(" amount:").append(amount).append(","); - sb.append(" new:").append(_new); + sb.append(" new:").append(_new).append(","); + sb.append(" ref:").append(ref); sb.append("}"); return sb.toString(); } diff --git a/multiapi-engine/src/test/resources/asyncapigenerator/testRareCharsGeneration/assets/WaiterDTO.java b/multiapi-engine/src/test/resources/asyncapigenerator/testRareCharsGeneration/assets/WaiterDTO.java index ecf296df..2649626e 100644 --- a/multiapi-engine/src/test/resources/asyncapigenerator/testRareCharsGeneration/assets/WaiterDTO.java +++ b/multiapi-engine/src/test/resources/asyncapigenerator/testRareCharsGeneration/assets/WaiterDTO.java @@ -10,17 +10,17 @@ @JsonDeserialize(builder = WaiterDTO.WaiterDTOBuilder.class) public class WaiterDTO { - @JsonProperty(value ="new") + @JsonProperty(value ="_abstract") + private String _abstract; + @JsonProperty(value ="_new") private Boolean _new; - @JsonProperty(value ="private") + @JsonProperty(value ="_private") private String _private; - @JsonProperty(value ="abstract") - private String _abstract; private WaiterDTO(WaiterDTOBuilder builder) { + this._abstract = builder._abstract; this._new = builder._new; this._private = builder._private; - this._abstract = builder._abstract; } @@ -31,11 +31,14 @@ public static WaiterDTO.WaiterDTOBuilder builder() { @JsonPOJOBuilder(buildMethodName = "build", withPrefix = "") public static class WaiterDTOBuilder { + private String _abstract; private Boolean _new; - private String _private; - private String _abstract; + public WaiterDTO.WaiterDTOBuilder _abstract(String _abstract) { + this._abstract = _abstract; + return this; + } public WaiterDTO.WaiterDTOBuilder _new(Boolean _new) { this._new = _new; @@ -47,21 +50,20 @@ public WaiterDTO.WaiterDTOBuilder _private(String _private) { return this; } - public WaiterDTO.WaiterDTOBuilder _abstract(String _abstract) { - this._abstract = _abstract; - return this; - } - public WaiterDTO build() { WaiterDTO waiterDTO = new WaiterDTO(this); return waiterDTO; } } - /** - * Get new - * @return new - */ + @Schema(name = "abstract", required = false) + public String getAbstract() { + return _abstract; + } + public void setAbstract(String _abstract) { + this._abstract = _abstract; + } + @Schema(name = "new", required = false) public Boolean getNew() { return _new; @@ -70,10 +72,6 @@ public void setNew(Boolean _new) { this._new = _new; } - /** - * Get private - * @return private - */ @Schema(name = "private", required = false) public String getPrivate() { return _private; @@ -82,18 +80,6 @@ public void setPrivate(String _private) { this._private = _private; } - /** - * Get abstract - * @return abstract - */ - @Schema(name = "abstract", required = false) - public String getAbstract() { - return _abstract; - } - public void setAbstract(String _abstract) { - this._abstract = _abstract; - } - @Override public boolean equals(Object o) { if (this == o) { @@ -103,21 +89,21 @@ public boolean equals(Object o) { return false; } WaiterDTO waiterDTO = (WaiterDTO) o; - return Objects.equals(this._new, waiterDTO._new) && Objects.equals(this._private, waiterDTO._private) && Objects.equals(this._abstract, waiterDTO._abstract); + return Objects.equals(this._abstract, waiterDTO._abstract) && Objects.equals(this._new, waiterDTO._new) && Objects.equals(this._private, waiterDTO._private); } @Override public int hashCode() { - return Objects.hash(_new, _private, _abstract); + return Objects.hash(_abstract, _new, _private); } @Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append("WaiterDTO{"); + sb.append(" abstract:").append(_abstract).append(","); sb.append(" new:").append(_new).append(","); - sb.append(" private:").append(_private).append(","); - sb.append(" abstract:").append(_abstract); + sb.append(" private:").append(_private); sb.append("}"); return sb.toString(); } diff --git a/multiapi-engine/src/test/resources/asyncapigenerator/testReservedWordsGeneration/assets/CreateOrderDTO.java b/multiapi-engine/src/test/resources/asyncapigenerator/testReservedWordsGeneration/assets/CreateOrderDTO.java index 437c2f4b..822a7584 100644 --- a/multiapi-engine/src/test/resources/asyncapigenerator/testReservedWordsGeneration/assets/CreateOrderDTO.java +++ b/multiapi-engine/src/test/resources/asyncapigenerator/testReservedWordsGeneration/assets/CreateOrderDTO.java @@ -10,14 +10,14 @@ @JsonDeserialize(builder = CreateOrderDTO.CreateOrderDTOBuilder.class) public class CreateOrderDTO { - @JsonProperty(value ="order") - private OrderDTO order; @JsonProperty(value ="waiter") private WaiterDTO waiter; + @JsonProperty(value ="order") + private OrderDTO order; private CreateOrderDTO(CreateOrderDTOBuilder builder) { - this.order = builder.order; this.waiter = builder.waiter; + this.order = builder.order; } @@ -28,19 +28,16 @@ public static CreateOrderDTO.CreateOrderDTOBuilder builder() { @JsonPOJOBuilder(buildMethodName = "build", withPrefix = "") public static class CreateOrderDTOBuilder { - private OrderDTO order; - private WaiterDTO waiter; - - public CreateOrderDTO.CreateOrderDTOBuilder order(OrderDTO order) { - this.order = order; - return this; - } - + private OrderDTO order; public CreateOrderDTO.CreateOrderDTOBuilder waiter(WaiterDTO waiter) { this.waiter = waiter; return this; } + public CreateOrderDTO.CreateOrderDTOBuilder order(OrderDTO order) { + this.order = order; + return this; + } public CreateOrderDTO build() { CreateOrderDTO createOrderDTO = new CreateOrderDTO(this); @@ -48,22 +45,6 @@ public CreateOrderDTO build() { } } - /** - * Get order - * @return order - */ - @Schema(name = "order", required = false) - public OrderDTO getOrder() { - return order; - } - public void setOrder(OrderDTO order) { - this.order = order; - } - - /** - * Get waiter - * @return waiter - */ @Schema(name = "waiter", required = false) public WaiterDTO getWaiter() { return waiter; @@ -72,6 +53,14 @@ public void setWaiter(WaiterDTO waiter) { this.waiter = waiter; } + @Schema(name = "order", required = false) + public OrderDTO getOrder() { + return order; + } + public void setOrder(OrderDTO order) { + this.order = order; + } + @Override public boolean equals(Object o) { if (this == o) { @@ -81,20 +70,20 @@ public boolean equals(Object o) { return false; } CreateOrderDTO createOrderDTO = (CreateOrderDTO) o; - return Objects.equals(this.order, createOrderDTO.order) && Objects.equals(this.waiter, createOrderDTO.waiter); + return Objects.equals(this.waiter, createOrderDTO.waiter) && Objects.equals(this.order, createOrderDTO.order); } @Override public int hashCode() { - return Objects.hash(order, waiter); + return Objects.hash(waiter, order); } @Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append("CreateOrderDTO{"); - sb.append(" order:").append(order).append(","); - sb.append(" waiter:").append(waiter); + sb.append(" waiter:").append(waiter).append(","); + sb.append(" order:").append(order); sb.append("}"); return sb.toString(); } diff --git a/multiapi-engine/src/test/resources/asyncapigenerator/testReservedWordsGeneration/assets/OrderDTO.java b/multiapi-engine/src/test/resources/asyncapigenerator/testReservedWordsGeneration/assets/OrderDTO.java index e462f48d..a28deef0 100644 --- a/multiapi-engine/src/test/resources/asyncapigenerator/testReservedWordsGeneration/assets/OrderDTO.java +++ b/multiapi-engine/src/test/resources/asyncapigenerator/testReservedWordsGeneration/assets/OrderDTO.java @@ -6,27 +6,27 @@ import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder; import com.fasterxml.jackson.annotation.JsonProperty; import io.swagger.v3.oas.annotations.media.Schema; -import java.math.BigDecimal; import java.util.List; import java.util.ArrayList; +import java.math.BigDecimal; @JsonDeserialize(builder = OrderDTO.OrderDTOBuilder.class) public class OrderDTO { - @JsonProperty(value ="ref") - private String ref; @JsonProperty(value ="clientRef") private String clientRef; @JsonProperty(value ="amount") private BigDecimal amount; - @JsonProperty(value ="new") + @JsonProperty(value ="_new") private List _new = new ArrayList(); + @JsonProperty(value ="ref") + private String ref; private OrderDTO(OrderDTOBuilder builder) { - this.ref = builder.ref; this.clientRef = builder.clientRef; this.amount = builder.amount; - this._new.addAll(builder._new); + this._new = builder._new; + this.ref = builder.ref; } @@ -37,18 +37,10 @@ public static OrderDTO.OrderDTOBuilder builder() { @JsonPOJOBuilder(buildMethodName = "build", withPrefix = "") public static class OrderDTOBuilder { - private String ref; - private String clientRef; - private BigDecimal amount; - private List _new = new ArrayList(); - - public OrderDTO.OrderDTOBuilder ref(String ref) { - this.ref = ref; - return this; - } + private String ref; public OrderDTO.OrderDTOBuilder clientRef(String clientRef) { this.clientRef = clientRef; @@ -59,7 +51,6 @@ public OrderDTO.OrderDTOBuilder amount(BigDecimal amount) { this.amount = amount; return this; } - public OrderDTO.OrderDTOBuilder _new(List _new) { if (!_new.isEmpty()) { this._new.addAll(_new); @@ -74,28 +65,17 @@ public OrderDTO.OrderDTOBuilder _new(OrderLineDTO _new) { return this; } + public OrderDTO.OrderDTOBuilder ref(String ref) { + this.ref = ref; + return this; + } + public OrderDTO build() { OrderDTO orderDTO = new OrderDTO(this); return orderDTO; } } - /** - * Get ref - * @return ref - */ - @Schema(name = "ref", required = false) - public String getRef() { - return ref; - } - public void setRef(String ref) { - this.ref = ref; - } - - /** - * Get clientRef - * @return clientRef - */ @Schema(name = "clientRef", required = false) public String getClientRef() { return clientRef; @@ -104,10 +84,6 @@ public void setClientRef(String clientRef) { this.clientRef = clientRef; } - /** - * Get amount - * @return amount - */ @Schema(name = "amount", required = false) public BigDecimal getAmount() { return amount; @@ -116,10 +92,6 @@ public void setAmount(BigDecimal amount) { this.amount = amount; } - /** - * Get new - * @return new - */ @Schema(name = "new", required = false) public List getNew() { return _new; @@ -128,6 +100,14 @@ public void setNew(List _new) { this._new = _new; } + @Schema(name = "ref", required = false) + public String getRef() { + return ref; + } + public void setRef(String ref) { + this.ref = ref; + } + @Override public boolean equals(Object o) { if (this == o) { @@ -137,22 +117,22 @@ public boolean equals(Object o) { return false; } OrderDTO orderDTO = (OrderDTO) o; - return Objects.equals(this.ref, orderDTO.ref) && Objects.equals(this.clientRef, orderDTO.clientRef) && Objects.equals(this.amount, orderDTO.amount) && Objects.equals(this._new, orderDTO._new); + return Objects.equals(this.clientRef, orderDTO.clientRef) && Objects.equals(this.amount, orderDTO.amount) && Objects.equals(this._new, orderDTO._new) && Objects.equals(this.ref, orderDTO.ref); } @Override public int hashCode() { - return Objects.hash(ref, clientRef, amount, _new); + return Objects.hash(clientRef, amount, _new, ref); } @Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append("OrderDTO{"); - sb.append(" ref:").append(ref).append(","); sb.append(" clientRef:").append(clientRef).append(","); sb.append(" amount:").append(amount).append(","); - sb.append(" new:").append(_new); + sb.append(" new:").append(_new).append(","); + sb.append(" ref:").append(ref); sb.append("}"); return sb.toString(); } diff --git a/multiapi-engine/src/test/resources/asyncapigenerator/testReservedWordsGeneration/assets/OrderLineDTO.java b/multiapi-engine/src/test/resources/asyncapigenerator/testReservedWordsGeneration/assets/OrderLineDTO.java index e1dbbd1d..dc0972f5 100644 --- a/multiapi-engine/src/test/resources/asyncapigenerator/testReservedWordsGeneration/assets/OrderLineDTO.java +++ b/multiapi-engine/src/test/resources/asyncapigenerator/testReservedWordsGeneration/assets/OrderLineDTO.java @@ -6,24 +6,24 @@ import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder; import com.fasterxml.jackson.annotation.JsonProperty; import io.swagger.v3.oas.annotations.media.Schema; -import java.math.BigDecimal; import java.util.List; import java.util.ArrayList; +import java.math.BigDecimal; import com.sngular.scsplugin.reservedwordsgeneration.model.event.exception.ModelClassException; import com.sngular.scsplugin.reservedwordsgeneration.model.event.customvalidator.NotNull; @JsonDeserialize(builder = OrderLineDTO.OrderLineDTOBuilder.class) public class OrderLineDTO { - @JsonProperty(value ="byte") + @JsonProperty(value ="_continue") + private List _continue = new ArrayList(); + @JsonProperty(value ="_byte") @NotNull private final BigDecimal _byte; - @JsonProperty(value ="continue") - private List _continue = new ArrayList(); private OrderLineDTO(OrderLineDTOBuilder builder) { + this._continue = builder._continue; this._byte = builder._byte; - this._continue.addAll(builder._continue); validateRequiredAttributes(); } @@ -35,15 +35,8 @@ public static OrderLineDTO.OrderLineDTOBuilder builder() { @JsonPOJOBuilder(buildMethodName = "build", withPrefix = "") public static class OrderLineDTOBuilder { - private BigDecimal _byte; - private List _continue = new ArrayList(); - - public OrderLineDTO.OrderLineDTOBuilder _byte(BigDecimal _byte) { - this._byte = _byte; - return this; - } - + private BigDecimal _byte; public OrderLineDTO.OrderLineDTOBuilder _continue(List _continue) { if (!_continue.isEmpty()) { this._continue.addAll(_continue); @@ -58,25 +51,17 @@ public OrderLineDTO.OrderLineDTOBuilder _continue(String _continue) { return this; } + public OrderLineDTO.OrderLineDTOBuilder _byte(BigDecimal _byte) { + this._byte = _byte; + return this; + } + public OrderLineDTO build() { OrderLineDTO orderLineDTO = new OrderLineDTO(this); return orderLineDTO; } } - /** - * Get byte - * @return byte - */ - @Schema(name = "byte", required = true) - public BigDecimal getByte() { - return _byte; - } - - /** - * Get continue - * @return continue - */ @Schema(name = "continue", required = false) public List getContinue() { return _continue; @@ -85,6 +70,11 @@ public void setContinue(List _continue) { this._continue = _continue; } + @Schema(name = "byte", required = true) + public BigDecimal getByte() { + return _byte; + } + @Override public boolean equals(Object o) { if (this == o) { @@ -94,25 +84,24 @@ public boolean equals(Object o) { return false; } OrderLineDTO orderLineDTO = (OrderLineDTO) o; - return Objects.equals(this._byte, orderLineDTO._byte) && Objects.equals(this._continue, orderLineDTO._continue); + return Objects.equals(this._continue, orderLineDTO._continue) && Objects.equals(this._byte, orderLineDTO._byte); } @Override public int hashCode() { - return Objects.hash(_byte, _continue); + return Objects.hash(_continue, _byte); } @Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append("OrderLineDTO{"); - sb.append(" byte:").append(_byte).append(","); - sb.append(" continue:").append(_continue); + sb.append(" continue:").append(_continue).append(","); + sb.append(" byte:").append(_byte); sb.append("}"); return sb.toString(); } - private void validateRequiredAttributes() { boolean satisfiedCondition = true; @@ -124,4 +113,5 @@ private void validateRequiredAttributes() { throw new ModelClassException("OrderLineDTO"); } } + } diff --git a/multiapi-engine/src/test/resources/asyncapigenerator/testReservedWordsGeneration/assets/WaiterDTO.java b/multiapi-engine/src/test/resources/asyncapigenerator/testReservedWordsGeneration/assets/WaiterDTO.java index 00896be9..c0d3dcc2 100644 --- a/multiapi-engine/src/test/resources/asyncapigenerator/testReservedWordsGeneration/assets/WaiterDTO.java +++ b/multiapi-engine/src/test/resources/asyncapigenerator/testReservedWordsGeneration/assets/WaiterDTO.java @@ -10,17 +10,17 @@ @JsonDeserialize(builder = WaiterDTO.WaiterDTOBuilder.class) public class WaiterDTO { - @JsonProperty(value ="new") + @JsonProperty(value ="_abstract") + private String _abstract; + @JsonProperty(value ="_new") private Boolean _new; - @JsonProperty(value ="private") + @JsonProperty(value ="_private") private String _private; - @JsonProperty(value ="abstract") - private String _abstract; private WaiterDTO(WaiterDTOBuilder builder) { + this._abstract = builder._abstract; this._new = builder._new; this._private = builder._private; - this._abstract = builder._abstract; } @@ -31,11 +31,14 @@ public static WaiterDTO.WaiterDTOBuilder builder() { @JsonPOJOBuilder(buildMethodName = "build", withPrefix = "") public static class WaiterDTOBuilder { + private String _abstract; private Boolean _new; - private String _private; - private String _abstract; + public WaiterDTO.WaiterDTOBuilder _abstract(String _abstract) { + this._abstract = _abstract; + return this; + } public WaiterDTO.WaiterDTOBuilder _new(Boolean _new) { this._new = _new; @@ -47,21 +50,20 @@ public WaiterDTO.WaiterDTOBuilder _private(String _private) { return this; } - public WaiterDTO.WaiterDTOBuilder _abstract(String _abstract) { - this._abstract = _abstract; - return this; - } - public WaiterDTO build() { WaiterDTO waiterDTO = new WaiterDTO(this); return waiterDTO; } } - /** - * Get new - * @return new - */ + @Schema(name = "abstract", required = false) + public String getAbstract() { + return _abstract; + } + public void setAbstract(String _abstract) { + this._abstract = _abstract; + } + @Schema(name = "new", required = false) public Boolean getNew() { return _new; @@ -70,10 +72,6 @@ public void setNew(Boolean _new) { this._new = _new; } - /** - * Get private - * @return private - */ @Schema(name = "private", required = false) public String getPrivate() { return _private; @@ -82,18 +80,6 @@ public void setPrivate(String _private) { this._private = _private; } - /** - * Get abstract - * @return abstract - */ - @Schema(name = "abstract", required = false) - public String getAbstract() { - return _abstract; - } - public void setAbstract(String _abstract) { - this._abstract = _abstract; - } - @Override public boolean equals(Object o) { if (this == o) { @@ -103,21 +89,21 @@ public boolean equals(Object o) { return false; } WaiterDTO waiterDTO = (WaiterDTO) o; - return Objects.equals(this._new, waiterDTO._new) && Objects.equals(this._private, waiterDTO._private) && Objects.equals(this._abstract, waiterDTO._abstract); + return Objects.equals(this._abstract, waiterDTO._abstract) && Objects.equals(this._new, waiterDTO._new) && Objects.equals(this._private, waiterDTO._private); } @Override public int hashCode() { - return Objects.hash(_new, _private, _abstract); + return Objects.hash(_abstract, _new, _private); } @Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append("WaiterDTO{"); + sb.append(" abstract:").append(_abstract).append(","); sb.append(" new:").append(_new).append(","); - sb.append(" private:").append(_private).append(","); - sb.append(" abstract:").append(_abstract); + sb.append(" private:").append(_private); sb.append("}"); return sb.toString(); } diff --git a/multiapi-engine/src/test/resources/asyncapigenerator/testSubObjectSameName/assets/input/model/Data.java b/multiapi-engine/src/test/resources/asyncapigenerator/testSubObjectSameName/assets/input/model/Data.java index b5b17bec..b1ff789a 100644 --- a/multiapi-engine/src/test/resources/asyncapigenerator/testSubObjectSameName/assets/input/model/Data.java +++ b/multiapi-engine/src/test/resources/asyncapigenerator/testSubObjectSameName/assets/input/model/Data.java @@ -38,10 +38,6 @@ public Data build() { } } - /** - * Get commitId - * @return commitId - */ @Schema(name = "commitId", required = false) public String getCommitId() { return commitId; diff --git a/multiapi-engine/src/test/resources/asyncapigenerator/testSubObjectSameName/assets/input/model/Input.java b/multiapi-engine/src/test/resources/asyncapigenerator/testSubObjectSameName/assets/input/model/Input.java index 10781348..5a2498a2 100644 --- a/multiapi-engine/src/test/resources/asyncapigenerator/testSubObjectSameName/assets/input/model/Input.java +++ b/multiapi-engine/src/test/resources/asyncapigenerator/testSubObjectSameName/assets/input/model/Input.java @@ -49,14 +49,11 @@ public static Input.InputBuilder builder() { public static class InputBuilder { private Source source; - private Data data; - public Input.InputBuilder source(Source source) { this.source = source; return this; } - public Input.InputBuilder data(Data data) { this.data = data; return this; @@ -68,10 +65,6 @@ public Input build() { } } - /** - * Get source - * @return source - */ @Schema(name = "source", required = false) public Source getSource() { return source; @@ -80,10 +73,6 @@ public void setSource(Source source) { this.source = source; } - /** - * Get data - * @return data - */ @Schema(name = "data", required = false) public Data getData() { return data; diff --git a/multiapi-engine/src/test/resources/asyncapigenerator/testSubObjectSameName/assets/output/model/Data.java b/multiapi-engine/src/test/resources/asyncapigenerator/testSubObjectSameName/assets/output/model/Data.java index 74c81981..4a0c24dd 100644 --- a/multiapi-engine/src/test/resources/asyncapigenerator/testSubObjectSameName/assets/output/model/Data.java +++ b/multiapi-engine/src/test/resources/asyncapigenerator/testSubObjectSameName/assets/output/model/Data.java @@ -10,14 +10,14 @@ @JsonDeserialize(builder = Data.DataBuilder.class) public class Data { - @JsonProperty(value ="tenantId") - private String tenantId; @JsonProperty(value ="name") private String name; + @JsonProperty(value ="tenantId") + private String tenantId; private Data(DataBuilder builder) { - this.tenantId = builder.tenantId; this.name = builder.name; + this.tenantId = builder.tenantId; } @@ -28,17 +28,16 @@ public static Data.DataBuilder builder() { @JsonPOJOBuilder(buildMethodName = "build", withPrefix = "") public static class DataBuilder { - private String tenantId; - private String name; + private String tenantId; - public Data.DataBuilder tenantId(String tenantId) { - this.tenantId = tenantId; + public Data.DataBuilder name(String name) { + this.name = name; return this; } - public Data.DataBuilder name(String name) { - this.name = name; + public Data.DataBuilder tenantId(String tenantId) { + this.tenantId = tenantId; return this; } @@ -48,22 +47,6 @@ public Data build() { } } - /** - * Get tenantId - * @return tenantId - */ - @Schema(name = "tenantId", required = false) - public String getTenantId() { - return tenantId; - } - public void setTenantId(String tenantId) { - this.tenantId = tenantId; - } - - /** - * Get name - * @return name - */ @Schema(name = "name", required = false) public String getName() { return name; @@ -72,6 +55,14 @@ public void setName(String name) { this.name = name; } + @Schema(name = "tenantId", required = false) + public String getTenantId() { + return tenantId; + } + public void setTenantId(String tenantId) { + this.tenantId = tenantId; + } + @Override public boolean equals(Object o) { if (this == o) { @@ -81,20 +72,20 @@ public boolean equals(Object o) { return false; } Data data = (Data) o; - return Objects.equals(this.tenantId, data.tenantId) && Objects.equals(this.name, data.name); + return Objects.equals(this.name, data.name) && Objects.equals(this.tenantId, data.tenantId); } @Override public int hashCode() { - return Objects.hash(tenantId, name); + return Objects.hash(name, tenantId); } @Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append("Data{"); - sb.append(" tenantId:").append(tenantId).append(","); - sb.append(" name:").append(name); + sb.append(" name:").append(name).append(","); + sb.append(" tenantId:").append(tenantId); sb.append("}"); return sb.toString(); } diff --git a/multiapi-engine/src/test/resources/asyncapigenerator/testSubObjectSameName/assets/output/model/Output.java b/multiapi-engine/src/test/resources/asyncapigenerator/testSubObjectSameName/assets/output/model/Output.java index cbbdbc88..efa5c77f 100644 --- a/multiapi-engine/src/test/resources/asyncapigenerator/testSubObjectSameName/assets/output/model/Output.java +++ b/multiapi-engine/src/test/resources/asyncapigenerator/testSubObjectSameName/assets/output/model/Output.java @@ -11,14 +11,15 @@ @JsonDeserialize(builder = Output.OutputBuilder.class) public class Output { - @JsonProperty(value ="source") - private Source source; - public enum Source { - TENANT("tenant"); + @JsonProperty(value ="type") + private Type type; + public enum Type { + DELETE("delete"), + UPDATE("update"); private String value; - Source(String value) { + Type(String value) { this.value = value; } @@ -32,15 +33,14 @@ public String toString() { return String.valueOf(value); } } - @JsonProperty(value ="type") - private Type type; - public enum Type { - UPDATE("update"), - DELETE("delete"); + @JsonProperty(value ="source") + private Source source; + public enum Source { + TENANT("tenant"); private String value; - Type(String value) { + Source(String value) { this.value = value; } @@ -58,8 +58,8 @@ public String toString() { private Data data; private Output(OutputBuilder builder) { - this.source = builder.source; this.type = builder.type; + this.source = builder.source; this.data = builder.data; } @@ -71,22 +71,17 @@ public static Output.OutputBuilder builder() { @JsonPOJOBuilder(buildMethodName = "build", withPrefix = "") public static class OutputBuilder { - private Source source; - private Type type; - + private Source source; private Data data; - - public Output.OutputBuilder source(Source source) { - this.source = source; - return this; - } - public Output.OutputBuilder type(Type type) { this.type = type; return this; } - + public Output.OutputBuilder source(Source source) { + this.source = source; + return this; + } public Output.OutputBuilder data(Data data) { this.data = data; return this; @@ -98,22 +93,6 @@ public Output build() { } } - /** - * Get source - * @return source - */ - @Schema(name = "source", required = false) - public Source getSource() { - return source; - } - public void setSource(Source source) { - this.source = source; - } - - /** - * Get type - * @return type - */ @Schema(name = "type", required = false) public Type getType() { return type; @@ -122,10 +101,14 @@ public void setType(Type type) { this.type = type; } - /** - * Get data - * @return data - */ + @Schema(name = "source", required = false) + public Source getSource() { + return source; + } + public void setSource(Source source) { + this.source = source; + } + @Schema(name = "data", required = false) public Data getData() { return data; @@ -143,20 +126,20 @@ public boolean equals(Object o) { return false; } Output output = (Output) o; - return Objects.equals(this.source, output.source) && Objects.equals(this.type, output.type) && Objects.equals(this.data, output.data); + return Objects.equals(this.type, output.type) && Objects.equals(this.source, output.source) && Objects.equals(this.data, output.data); } @Override public int hashCode() { - return Objects.hash(source, type, data); + return Objects.hash(type, source, data); } @Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append("Output{"); - sb.append(" source:").append(source).append(","); sb.append(" type:").append(type).append(","); + sb.append(" source:").append(source).append(","); sb.append(" data:").append(data); sb.append("}"); return sb.toString(); From 9fd58defb4d64890cfd1688961ab287476a8ecdf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Enrique=20Garc=C3=ADa=20Maci=C3=B1eiras?= Date: Mon, 12 Aug 2024 19:07:31 +0200 Subject: [PATCH 02/26] Refactor --- .../plugin/common/tools/ApiTool.java | 55 +- .../plugin/common/tools/ModelBuilder.java | 1330 +++++++++-------- .../templates/asyncapi/templateSchema.ftlh | 40 +- .../asyncapi/templateSchemaWithLombok.ftlh | 24 +- .../assets/payload/SomeOtherObject.java | 24 +- 5 files changed, 761 insertions(+), 712 deletions(-) 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 f37eb7d3..8178c85c 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 @@ -1,20 +1,5 @@ package com.sngular.api.generator.plugin.common.tools; -import java.io.FileInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.math.BigDecimal; -import java.math.BigInteger; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -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; @@ -26,6 +11,14 @@ import org.apache.commons.collections4.Transformer; import org.apache.commons.lang3.StringUtils; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.math.BigDecimal; +import java.math.BigInteger; +import java.util.*; +import java.util.Map.Entry; + public final class ApiTool { public static final String FORMAT = "format"; @@ -349,4 +342,36 @@ private static Object getNodeAsType(final JsonNode node) { } return result; } + + public static boolean hasConst(final JsonNode fieldBody) { + return hasNode(fieldBody, "const"); + } + + public static Object getConst(final JsonNode fieldBody) { + return getValue(getNode(fieldBody, "const")); + } + + private static Object getValue(final JsonNode aConst) { + Object value = null; + if (aConst.isTextual()) { + value = aConst.textValue(); + } else if (aConst.isNumber()) { + value = aConst.numberValue(); + } else if (aConst.isBoolean()) { + value = aConst.booleanValue(); + } else if (aConst.isFloat()) { + value = aConst.floatValue(); + } else if (aConst.isDouble()) { + value = aConst.doubleValue(); + } else if (aConst.isInt()) { + value = aConst.intValue(); + } else if (aConst.isLong()) { + value = aConst.longValue(); + } else if (aConst.isBigDecimal()) { + value = aConst.decimalValue(); + } + return value; + } + + } diff --git a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/tools/ModelBuilder.java b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/tools/ModelBuilder.java index 10fe2220..70a4bd1e 100644 --- a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/tools/ModelBuilder.java +++ b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/tools/ModelBuilder.java @@ -13,726 +13,736 @@ public final class ModelBuilder { - private static final String ADDITIONAL_PROPERTY_NAME = "AdditionalProperty"; + private static final String ADDITIONAL_PROPERTY_NAME = "AdditionalProperty"; - private static final String ANY_OF_COMBINATOR = "anyOf"; + private static final String ANY_OF_COMBINATOR = "anyOf"; - private static final String ONE_OF_COMBINATOR = "oneOf"; + private static final String ONE_OF_COMBINATOR = "oneOf"; - private static final String ALL_OF_COMBINATOR = "allOf"; + private static final String ALL_OF_COMBINATOR = "allOf"; - private static final String ADDITIONAL_PROPERTIES = "additionalProperties"; + private static final String ADDITIONAL_PROPERTIES = "additionalProperties"; - public static SchemaObject buildSchemaObject( - final Map totalSchemas, final String className, final JsonNode model, - final Set antiLoopList, final Map compositedSchemas, final String parentPackage, final CommonSpecFile specFile, - final Path baseDir) { + public static SchemaObject buildSchemaObject( + final Map totalSchemas, final String className, final JsonNode model, + final Set antiLoopList, final Map compositedSchemas, final String parentPackage, final CommonSpecFile specFile, + final Path baseDir) { - antiLoopList.add(WordUtils.capitalizeFully(className)); + antiLoopList.add(WordUtils.capitalizeFully(className)); - final var listSchema = getFields(null, totalSchemas, model, specFile, compositedSchemas, antiLoopList, WordUtils.capitalizeFully(className), baseDir); + final var listSchema = getFields(null, totalSchemas, model, specFile, compositedSchemas, antiLoopList, WordUtils.capitalizeFully(className), baseDir); - final var schemaBuilder = SchemaObject.builder() - .schemaName(WordUtils.capitalizeFully(className)) - .className(MapperUtil.getPojoName(className, specFile)) - .importList(getImportList(listSchema, specFile.getModelPackage())); + final var schemaBuilder = SchemaObject.builder() + .schemaName(WordUtils.capitalizeFully(className)) + .className(MapperUtil.getPojoName(className, specFile)) + .importList(getImportList(listSchema, specFile.getModelPackage())); - if (ApiTool.isAllOf(model)) { - schemaBuilder.schemaCombinator(ALL_OF_COMBINATOR); - } else if (ApiTool.isAnyOf(model)) { - schemaBuilder.schemaCombinator(ANY_OF_COMBINATOR); - } else if (ApiTool.isOneOf(model)) { - schemaBuilder.schemaCombinator(ONE_OF_COMBINATOR); - } else { - schemaBuilder.schemaCombinator(""); - } - - return schemaBuilder - .fieldObjectList(listSchema) - .parentPackage(parentPackage.toLowerCase()) - .build(); + if (ApiTool.isAllOf(model)) { + schemaBuilder.schemaCombinator(ALL_OF_COMBINATOR); + } else if (ApiTool.isAnyOf(model)) { + schemaBuilder.schemaCombinator(ANY_OF_COMBINATOR); + } else if (ApiTool.isOneOf(model)) { + schemaBuilder.schemaCombinator(ONE_OF_COMBINATOR); + } else { + schemaBuilder.schemaCombinator(""); } - private static List getImportList(final Set fieldObjectList, final String modelPackage) { - final var listHashMap = new HashMap>(); - final var importList = new ArrayList(); - - for (final var fieldObject : fieldObjectList) { - getTypeImports(listHashMap, fieldObject); - if (StringUtils.isNotBlank(fieldObject.getImportClass()) - && !listHashMap.containsKey(fieldObject.getImportClass()) - && !fieldObject.getDataType().containsType("enum")) { - listHashMap.put(StringUtils.capitalize(fieldObject.getImportClass()), - List.of(modelPackage + "." + StringUtils.capitalize(fieldObject.getImportClass()))); - } - } - if (!listHashMap.isEmpty()) { - listHashMap.forEach((key, value) -> importList.addAll(value)); - } - return importList; + return schemaBuilder + .fieldObjectList(listSchema) + .parentPackage(parentPackage.toLowerCase()) + .build(); + } + + private static List getImportList(final Set fieldObjectList, final String modelPackage) { + final var listHashMap = new HashMap>(); + final var importList = new ArrayList(); + + for (final var fieldObject : fieldObjectList) { + getTypeImports(listHashMap, fieldObject); + if (StringUtils.isNotBlank(fieldObject.getImportClass()) + && !listHashMap.containsKey(fieldObject.getImportClass()) + && !fieldObject.getDataType().containsType("enum")) { + listHashMap.put(StringUtils.capitalize(fieldObject.getImportClass()), + List.of(modelPackage + "." + StringUtils.capitalize(fieldObject.getImportClass()))); + } } - - private static void getTypeImports( - final HashMap> listHashMap, - final SchemaFieldObject fieldObject) { - final SchemaFieldObjectType type = fieldObject.getDataType(); - if (type.containsType(TypeConstants.ARRAY)) { - listHashMap.computeIfAbsent(TypeConstants.ARRAY, key -> List.of("java.util.List", "java.util.ArrayList")); - } - - if (type.containsType(TypeConstants.MAP)) { - listHashMap.computeIfAbsent(TypeConstants.MAP, key -> List.of("java.util.Map", "java.util.HashMap")); - } - - if (type.containsType(TypeConstants.BIG_DECIMAL)) { - listHashMap.computeIfAbsent(TypeConstants.BIG_DECIMAL, key -> List.of("java.math.BigDecimal")); - } - - if (type.containsType(TypeConstants.LOCALDATE)) { - listHashMap.computeIfAbsent(TypeConstants.LOCALDATE, key -> List.of("java.time.LocalDate")); - } - - if (type.containsType(TypeConstants.LOCALDATETIME)) { - listHashMap.computeIfAbsent(TypeConstants.LOCALDATETIME, key -> List.of("java.time.LocalDateTime")); - } - - if (type.containsType(TypeConstants.ZONEDDATE)) { - listHashMap.computeIfAbsent(TypeConstants.ZONEDDATETIME, key -> List.of("java.time.ZonedDateTime")); - } - - if (type.containsType(TypeConstants.ZONEDDATETIME)) { - listHashMap.computeIfAbsent(TypeConstants.ZONEDDATETIME, key -> List.of("java.time.ZonedDateTime")); - } - - if (type.containsType(TypeConstants.OFFSETDATE)) { - listHashMap.computeIfAbsent(TypeConstants.OFFSETDATETIME, key -> List.of("java.time.OffsetDateTime")); - } - - if (type.containsType(TypeConstants.OFFSETDATETIME)) { - listHashMap.computeIfAbsent(TypeConstants.OFFSETDATETIME, key -> List.of("java.time.OffsetDateTime")); - } + if (!listHashMap.isEmpty()) { + listHashMap.forEach((key, value) -> importList.addAll(value)); } - - private static Set getFields(final String buildingSchema, - final Map totalSchemas, final JsonNode schema, final CommonSpecFile specFile, - final Map compositedSchemas, final Set antiLoopList, final String nameSchema, - final Path baseDir) { - final Set fieldObjectArrayList = new HashSet<>(); - - if (ApiTool.hasProperties(schema)) { - if (ApiTool.hasAdditionalProperties(schema)) { - ApiTool.getProperties(schema).forEachRemaining(processProperties(buildingSchema, totalSchemas, compositedSchemas, fieldObjectArrayList, specFile, schema, antiLoopList, - baseDir)); - fieldObjectArrayList.addAll(processAdditionalProperties(ADDITIONAL_PROPERTIES, schema, specFile, totalSchemas, compositedSchemas, antiLoopList, nameSchema, baseDir)); - } else { - ApiTool.getProperties(schema).forEachRemaining(processProperties(buildingSchema, totalSchemas, compositedSchemas, fieldObjectArrayList, specFile, schema, antiLoopList, - baseDir)); - } - } else if (TypeConstants.ARRAY.equalsIgnoreCase(ApiTool.getType(schema))) { - final String itemType = ApiTool.hasRef(ApiTool.getItems(schema)) ? MapperUtil.getRef(ApiTool.getItems(schema), specFile) : ApiTool.getType(ApiTool.getItems(schema)); - fieldObjectArrayList.add(SchemaFieldObject.builder() - .baseName("items") - .dataType(SchemaFieldObjectType.fromTypeList(TypeConstants.ARRAY, itemType)) - .build()); - } else if (ApiTool.isAllOf(schema)) { - fieldObjectArrayList.addAll(processAllOf(totalSchemas, ApiTool.getAllOf(schema), specFile, compositedSchemas, antiLoopList, baseDir)); - } else if (ApiTool.isAnyOf(schema)) { - fieldObjectArrayList.addAll(processAnyOfOneOf(buildingSchema, totalSchemas, ApiTool.getAnyOf(schema), specFile, compositedSchemas, antiLoopList, baseDir)); - } else if (ApiTool.isOneOf(schema)) { - fieldObjectArrayList.addAll(processAnyOfOneOf(buildingSchema, totalSchemas, ApiTool.getOneOf(schema), specFile, compositedSchemas, antiLoopList, baseDir)); - } else if (ApiTool.isEnum(schema)) { - fieldObjectArrayList.add(processEnumField(ApiTool.getName(schema), schema, specFile, ApiTool.getEnumValues(schema), schema)); - } else if (ApiTool.hasRef(schema)) { - final var refSchema = totalSchemas.get(MapperUtil.getRefSchemaKey(schema)); - ApiTool.getProperties(refSchema).forEachRemaining(processProperties(buildingSchema, totalSchemas, compositedSchemas, fieldObjectArrayList, specFile, schema, antiLoopList, - baseDir)); - } else { - fieldObjectArrayList.add(SchemaFieldObject.builder() - .baseName(ApiTool.getName(schema)) - .dataType(new SchemaFieldObjectType(MapperUtil.getSimpleType(schema, specFile))) - .build()); - } - - return fieldObjectArrayList; + return importList; + } + + private static void getTypeImports( + final HashMap> listHashMap, + final SchemaFieldObject fieldObject) { + final SchemaFieldObjectType type = fieldObject.getDataType(); + if (type.containsType(TypeConstants.ARRAY)) { + listHashMap.computeIfAbsent(TypeConstants.ARRAY, key -> List.of("java.util.List", "java.util.ArrayList")); } - - @SuppressWarnings("checkstyle:CyclomaticComplexity") - private static List processFieldObjectList(final String buildingSchema, - final String fieldName, final String className, final JsonNode schema, final CommonSpecFile specFile, - final Map totalSchemas, final Map compositedSchemas, - final Set antiLoopList, final Path baseDir) { - final var fieldObjectArrayList = new ArrayList(); - - if (TypeConstants.ARRAY.equalsIgnoreCase(ApiTool.getType(schema))) { - fieldObjectArrayList.addAll(processArray(fieldName, className, schema, specFile, totalSchemas, compositedSchemas, antiLoopList, baseDir)); - } else if (ApiTool.hasAdditionalProperties(schema)) { - fieldObjectArrayList.addAll(processMap(fieldName, schema, specFile, totalSchemas, compositedSchemas, antiLoopList, baseDir)); - } else if (ApiTool.hasRef(schema)) { - fieldObjectArrayList.add( - processRef(fieldName, schema, new SchemaFieldObjectType(MapperUtil.getSimpleType(schema, specFile)), totalSchemas, compositedSchemas, antiLoopList, specFile, baseDir)); - } else if (ApiTool.isObject(schema) && !ApiTool.hasProperties(schema)) { - fieldObjectArrayList.add(SchemaFieldObject - .builder() - .baseName(fieldName) - .dataType(new SchemaFieldObjectType(TypeConstants.OBJECT)) - .build()); - } else if (ApiTool.isEnum(schema)) { - fieldObjectArrayList.add(processEnumField(fieldName, schema, specFile, ApiTool.getEnumValues(schema), schema)); - } else if (!ApiTool.hasProperties(schema) && !ApiTool.isComposed(schema)) { - fieldObjectArrayList.add(SchemaFieldObject - .builder() - .baseName(fieldName) - .dataType(new SchemaFieldObjectType(TypeConstants.OBJECT)) - .build()); - } else if (ApiTool.isObject(schema)) { - fieldObjectArrayList.addAll(processObject(fieldName, className, schema, specFile, totalSchemas, compositedSchemas, antiLoopList, baseDir)); - } else { - final var composedSchemaName = StringUtils.defaultIfBlank(className, fieldName); - var schemaObjectComposed = compositedSchemas.get(composedSchemaName); - if (Objects.isNull(schemaObjectComposed)) { - schemaObjectComposed = createComposedSchema(buildingSchema, StringUtils.defaultIfBlank(className, fieldName), schema, specFile, - totalSchemas, compositedSchemas, antiLoopList, baseDir); - compositedSchemas.put(composedSchemaName, schemaObjectComposed); - } - - fieldObjectArrayList.add(SchemaFieldObject - .builder() - .baseName(fieldName) - .dataType(SchemaFieldObjectType.fromTypeList(schemaObjectComposed.getClassName(), schemaObjectComposed.getClassName())) - .build()); - } - - return fieldObjectArrayList; + if (type.containsType(TypeConstants.MAP)) { + listHashMap.computeIfAbsent(TypeConstants.MAP, key -> List.of("java.util.Map", "java.util.HashMap")); } - private static Consumer> processProperties(final String buildingSchema, - final Map totalSchemas, final Map compositedSchemas, final Set fieldObjectArrayList, final CommonSpecFile specFile, - final JsonNode schema, final Set antiLoopList, final Path baseDir) { - return field -> { - final var nodeName = field.getKey(); - final var nodeValue = field.getValue(); - if (ApiTool.isEnum(field.getValue())) { - fieldObjectArrayList.add(processEnumField(nodeName, nodeValue, specFile, ApiTool.getEnumValues(nodeValue), schema)); - } else { - fieldObjectArrayList.addAll(processObjectProperty(buildingSchema, totalSchemas, nodeName, nodeValue, compositedSchemas, specFile, schema, antiLoopList, baseDir)); - } - }; + if (type.containsType(TypeConstants.BIG_DECIMAL)) { + listHashMap.computeIfAbsent(TypeConstants.BIG_DECIMAL, key -> List.of("java.math.BigDecimal")); } - @SuppressWarnings({"checkstyle:CyclomaticComplexity", "checkstyle:ParameterNumber"}) - private static List processObjectProperty(final String buildingSchema, - final Map totalSchemas, final String fieldName, final JsonNode fieldBody, final Map compositedSchemas, final CommonSpecFile specFile, - final JsonNode schema, final Set antiLoopList, final Path baseDir) { - final List fieldObjectArrayList = new LinkedList<>(); - final var isRequired = ApiTool.checkIfRequired(fieldBody, fieldName); - final SchemaFieldObject field; - if (ApiTool.hasRef(fieldBody)) { - final var typeName = MapperUtil.getRefSchemaName(fieldBody); - final var refSchema = totalSchemas.get(MapperUtil.getRefSchemaKey(fieldBody)); - if (!antiLoopList.contains(typeName) && Objects.nonNull(refSchema) && ApiTool.hasType(refSchema) - && ApiTool.hasItems(refSchema) || ApiTool.getRefValue(fieldBody).contains(fieldName)) { - antiLoopList.add(typeName); - fieldObjectArrayList.addAll(processFieldObjectList(buildingSchema, fieldName, typeName, refSchema, specFile, totalSchemas, compositedSchemas, - antiLoopList, baseDir)); - } else if (ApiTool.isEnum(refSchema)) { - fieldObjectArrayList.add(processEnumField(fieldName, refSchema, specFile, ApiTool.getEnumValues(refSchema), schema)); - } else { - compositedSchemas.put(typeName, buildSchemaObject(totalSchemas, typeName, refSchema, antiLoopList, compositedSchemas, "", specFile, baseDir )); - fieldObjectArrayList.add(SchemaFieldObject - .builder() - .baseName(fieldName) - .required(ApiTool.checkIfRequired(schema, fieldName)) - .dataType(SchemaFieldObjectType.fromTypeList(MapperUtil.getSimpleType(refSchema, specFile), - MapperUtil.getPojoName(typeName, specFile))) - .build()); - } - } else if (ApiTool.isEnum(fieldBody)) { - fieldObjectArrayList.add(processEnumField(fieldName, fieldBody, specFile, ApiTool.getEnumValues(fieldBody), fieldBody)); - } else if (TypeConstants.STRING.equalsIgnoreCase(ApiTool.getType(fieldBody))) { - field = processStringProperty(fieldName, fieldBody, specFile); - setFieldType(field, fieldBody, schema, specFile, fieldName); - fieldObjectArrayList.add(field); - } else if (isBasicType(fieldBody)) { - field = SchemaFieldObject - .builder() - .baseName(fieldName) - .required(isRequired) - .dataType(new SchemaFieldObjectType(MapperUtil.getSimpleType(fieldBody, specFile))) - .build(); - addPropertiesToFieldObject(field, fieldBody); - setFieldType(field, fieldBody, schema, specFile, fieldName); - fieldObjectArrayList.add(field); - } else { - fieldObjectArrayList.addAll(processFieldObjectList(buildingSchema, fieldName, fieldName, fieldBody, specFile, totalSchemas, compositedSchemas, antiLoopList, baseDir)); - } - return fieldObjectArrayList; + if (type.containsType(TypeConstants.LOCALDATE)) { + listHashMap.computeIfAbsent(TypeConstants.LOCALDATE, key -> List.of("java.time.LocalDate")); } - private static SchemaFieldObject processStringProperty(final String propertyName, final JsonNode schema, final CommonSpecFile specFile) { - final String resultingType = ApiTool.isDateTime(schema) ? MapperUtil.getDateType(schema, specFile) : TypeConstants.STRING; - - final SchemaFieldObject field = SchemaFieldObject - .builder() - .baseName(propertyName) - .required(ApiTool.checkIfRequired(schema, propertyName)) - .dataType(new SchemaFieldObjectType(resultingType)) - .build(); - addPropertiesToFieldObject(field, schema); - return field; + if (type.containsType(TypeConstants.LOCALDATETIME)) { + listHashMap.computeIfAbsent(TypeConstants.LOCALDATETIME, key -> List.of("java.time.LocalDateTime")); } - @SuppressWarnings("checkstyle:CyclomaticComplexity") - private static void addPropertiesToFieldObject(final SchemaFieldObject fieldObject, final JsonNode value) { - final var restrictionList = ApiTool.getFieldIterator(value); - while (restrictionList.hasNext()) { - final var restriction = restrictionList.next(); - switch (restriction.getKey()) { - case "pattern": - fieldObject.getRestrictions().setPattern(restriction.getValue().asText()); - break; - case "maxItems": - fieldObject.getRestrictions().setMaxItems(restriction.getValue().asInt()); - break; - case "minItems": - fieldObject.getRestrictions().setMinItems(restriction.getValue().asInt()); - break; - case "maxLength": - fieldObject.getRestrictions().setMaxLength(restriction.getValue().asInt()); - break; - case "minLength": - fieldObject.getRestrictions().setMinLength(restriction.getValue().asInt()); - break; - case "uniqueItems": - fieldObject.getRestrictions().setUniqueItems(restriction.getValue().asBoolean()); - break; - case "exclusiveMaximum": - fieldObject.getRestrictions().setExclusiveMaximum(restriction.getValue().asBoolean()); - break; - case "exclusiveMinimum": - fieldObject.getRestrictions().setExclusiveMinimum(restriction.getValue().asBoolean()); - break; - case "multipleOf": - fieldObject.getRestrictions().setMultipleOf(restriction.getValue().asText()); - break; - case "maximum": - fieldObject.getRestrictions().setMaximum(restriction.getValue().asText()); - break; - case "minimum": - fieldObject.getRestrictions().setMinimum(restriction.getValue().asText()); - break; - default: - break; - } - } + if (type.containsType(TypeConstants.ZONEDDATE)) { + listHashMap.computeIfAbsent(TypeConstants.ZONEDDATETIME, key -> List.of("java.time.ZonedDateTime")); } - @SuppressWarnings("checkstyle:ParameterNumber") - private static List processArray( - final String fieldName, final String className, final JsonNode schema, final CommonSpecFile specFile, final Map totalSchemas, - final Map compositedSchemas, final Set antiLoopList, final Path baseDir) { - final List fieldObjectArrayList = new LinkedList<>(); - - if (!ApiTool.hasItems(schema)) { - fieldObjectArrayList.add(SchemaFieldObject - .builder() - .baseName(fieldName) - .dataType(new SchemaFieldObjectType(TypeConstants.OBJECT)) - .build()); - } else { - final var items = ApiTool.getItems(schema); - if (ApiTool.hasRef(items)) { - fieldObjectArrayList.add( - processRef(fieldName, items, SchemaFieldObjectType.fromTypeList(TypeConstants.ARRAY, MapperUtil.getSimpleType(items, specFile)), totalSchemas, compositedSchemas, - antiLoopList, specFile, baseDir)); - } else if (ApiTool.isComposed(items)) { - final String composedSchemaName = StringUtils.defaultIfBlank(className, fieldName); - SchemaObject schemaObjectComposed = compositedSchemas.get(composedSchemaName); - if (Objects.isNull(schemaObjectComposed)) { - schemaObjectComposed = createComposedSchema("", StringUtils.defaultIfBlank(className, fieldName), items, specFile, - totalSchemas, compositedSchemas, antiLoopList, baseDir); - compositedSchemas.put(composedSchemaName, schemaObjectComposed); - } - - fieldObjectArrayList.add(SchemaFieldObject - .builder() - .baseName(fieldName) - .dataType(SchemaFieldObjectType.fromTypeList(TypeConstants.ARRAY, schemaObjectComposed.getClassName())) - .importClass(schemaObjectComposed.getClassName()) - .build()); - } else if (ApiTool.hasProperties(items)) { - final var itemsObject = buildSchemaObject(totalSchemas, className, items, antiLoopList, compositedSchemas, "", specFile, baseDir); - compositedSchemas.put(className, itemsObject); - fieldObjectArrayList.add(SchemaFieldObject - .builder() - .baseName(fieldName) - .dataType(SchemaFieldObjectType.fromTypeList(TypeConstants.ARRAY, MapperUtil.getPojoName(fieldName, specFile))) - .build()); - } else { - final SchemaFieldObject field = SchemaFieldObject - .builder() - .baseName(fieldName) - .dataType(SchemaFieldObjectType.fromTypeList(TypeConstants.ARRAY, MapperUtil.getSimpleType(items, specFile))) - .build(); - fieldObjectArrayList.add(field); - addPropertiesToFieldObject(field, schema); - } - } - - return fieldObjectArrayList; + if (type.containsType(TypeConstants.ZONEDDATETIME)) { + listHashMap.computeIfAbsent(TypeConstants.ZONEDDATETIME, key -> List.of("java.time.ZonedDateTime")); } - @SuppressWarnings("checkstyle:ParameterNumber") - private static Set processObject( - final String fieldName, final String className, final JsonNode schema, final CommonSpecFile specFile, - final Map totalSchemas, final Map compositedSchemas, - final Set antiLoopList, final Path baseDir) { - final Set fieldObjectArrayList = new HashSet<>(); - - if (ObjectUtils.allNull(className, fieldName)) { - ApiTool.getProperties(schema).forEachRemaining( - processProperties("", totalSchemas, compositedSchemas, fieldObjectArrayList, specFile, schema, antiLoopList, baseDir)); - } else if (antiLoopList.contains(className)) { - fieldObjectArrayList - .add(SchemaFieldObject - .builder() - .baseName(className) - .dataType(SchemaFieldObjectType.fromTypeList(TypeConstants.OBJECT, MapperUtil.getPojoName(className, specFile))) - .build()); - } else if (antiLoopList.contains(fieldName)) { - fieldObjectArrayList - .add(SchemaFieldObject - .builder() - .baseName(fieldName) - .dataType(SchemaFieldObjectType.fromTypeList(TypeConstants.OBJECT, MapperUtil.getPojoName(fieldName, specFile))) - .build()); - } else { - final String name = StringUtils.defaultIfBlank(className, fieldName); - final var itemsObject = buildSchemaObject(totalSchemas, className, schema, antiLoopList, compositedSchemas, "", specFile, baseDir); - compositedSchemas.put(className, itemsObject); - fieldObjectArrayList - .add(SchemaFieldObject - .builder() - .baseName(name) - .dataType(SchemaFieldObjectType.fromTypeList(TypeConstants.OBJECT, MapperUtil.getPojoName(name, specFile))) - .build()); - } - - return fieldObjectArrayList; + if (type.containsType(TypeConstants.OFFSETDATE)) { + listHashMap.computeIfAbsent(TypeConstants.OFFSETDATETIME, key -> List.of("java.time.OffsetDateTime")); } - private static Set processMap( - final String fieldName, final JsonNode schema, final CommonSpecFile specFile, final Map totalSchemas, - final Map compositedSchemas, final Set antiLoopList, final Path baseDir) { - final Set fieldObjectArrayList = new HashSet<>(); - - if (TypeConstants.OBJECT.equalsIgnoreCase(ApiTool.getType(schema)) && ApiTool.hasProperties(schema)) { - ApiTool.getProperties(schema).forEachRemaining( - processProperties("", totalSchemas, compositedSchemas, fieldObjectArrayList, specFile, schema, antiLoopList, baseDir)); - } - - if (ApiTool.hasAdditionalProperties(schema)) { - fieldObjectArrayList.addAll(processAdditionalProperties(fieldName, schema, specFile, totalSchemas, compositedSchemas, - antiLoopList, ADDITIONAL_PROPERTIES, baseDir)); - } + if (type.containsType(TypeConstants.OFFSETDATETIME)) { + listHashMap.computeIfAbsent(TypeConstants.OFFSETDATETIME, key -> List.of("java.time.OffsetDateTime")); + } + } + + private static Set getFields(final String buildingSchema, + final Map totalSchemas, final JsonNode schema, final CommonSpecFile specFile, + final Map compositedSchemas, final Set antiLoopList, final String nameSchema, + final Path baseDir) { + final Set fieldObjectArrayList = new HashSet<>(); + + if (ApiTool.hasProperties(schema)) { + if (ApiTool.hasAdditionalProperties(schema)) { + ApiTool.getProperties(schema).forEachRemaining(processProperties(buildingSchema, totalSchemas, compositedSchemas, fieldObjectArrayList, specFile, schema, antiLoopList, + baseDir)); + fieldObjectArrayList.addAll(processAdditionalProperties(ADDITIONAL_PROPERTIES, schema, specFile, totalSchemas, compositedSchemas, antiLoopList, nameSchema, baseDir)); + } else { + ApiTool.getProperties(schema).forEachRemaining(processProperties(buildingSchema, totalSchemas, compositedSchemas, fieldObjectArrayList, specFile, schema, antiLoopList, + baseDir)); + } + } else if (TypeConstants.ARRAY.equalsIgnoreCase(ApiTool.getType(schema))) { + final String itemType = ApiTool.hasRef(ApiTool.getItems(schema)) ? MapperUtil.getRef(ApiTool.getItems(schema), specFile) : ApiTool.getType(ApiTool.getItems(schema)); + fieldObjectArrayList.add(SchemaFieldObject.builder() + .baseName("items") + .dataType(SchemaFieldObjectType.fromTypeList(TypeConstants.ARRAY, itemType)) + .build()); + } else if (ApiTool.isAllOf(schema)) { + fieldObjectArrayList.addAll(processAllOf(totalSchemas, ApiTool.getAllOf(schema), specFile, compositedSchemas, antiLoopList, baseDir)); + } else if (ApiTool.isAnyOf(schema)) { + fieldObjectArrayList.addAll(processAnyOfOneOf(buildingSchema, totalSchemas, ApiTool.getAnyOf(schema), specFile, compositedSchemas, antiLoopList, baseDir)); + } else if (ApiTool.isOneOf(schema)) { + fieldObjectArrayList.addAll(processAnyOfOneOf(buildingSchema, totalSchemas, ApiTool.getOneOf(schema), specFile, compositedSchemas, antiLoopList, baseDir)); + } else if (ApiTool.isEnum(schema)) { + fieldObjectArrayList.add(processEnumField(ApiTool.getName(schema), schema, specFile, ApiTool.getEnumValues(schema), schema)); + } else if (ApiTool.hasRef(schema)) { + final var refSchema = totalSchemas.get(MapperUtil.getRefSchemaKey(schema)); + ApiTool.getProperties(refSchema).forEachRemaining(processProperties(buildingSchema, totalSchemas, compositedSchemas, fieldObjectArrayList, specFile, schema, antiLoopList, + baseDir)); + } else { + fieldObjectArrayList.add(SchemaFieldObject.builder() + .baseName(ApiTool.getName(schema)) + .dataType(new SchemaFieldObjectType(MapperUtil.getSimpleType(schema, specFile))) + .build()); + } - return fieldObjectArrayList; + return fieldObjectArrayList; + } + + + @SuppressWarnings("checkstyle:CyclomaticComplexity") + private static List processFieldObjectList(final String buildingSchema, + final String fieldName, final String className, final JsonNode schema, final CommonSpecFile specFile, + final Map totalSchemas, final Map compositedSchemas, + final Set antiLoopList, final Path baseDir) { + final var fieldObjectArrayList = new ArrayList(); + + if (TypeConstants.ARRAY.equalsIgnoreCase(ApiTool.getType(schema))) { + fieldObjectArrayList.addAll(processArray(fieldName, className, schema, specFile, totalSchemas, compositedSchemas, antiLoopList, baseDir)); + } else if (ApiTool.hasAdditionalProperties(schema)) { + fieldObjectArrayList.addAll(processMap(fieldName, schema, specFile, totalSchemas, compositedSchemas, antiLoopList, baseDir)); + } else if (ApiTool.hasRef(schema)) { + fieldObjectArrayList.add( + processRef(fieldName, schema, new SchemaFieldObjectType(MapperUtil.getSimpleType(schema, specFile)), totalSchemas, compositedSchemas, antiLoopList, specFile, baseDir)); + } else if (ApiTool.isObject(schema) && !ApiTool.hasProperties(schema)) { + fieldObjectArrayList.add(SchemaFieldObject + .builder() + .baseName(fieldName) + .dataType(new SchemaFieldObjectType(TypeConstants.OBJECT)) + .build()); + } else if (ApiTool.isEnum(schema)) { + fieldObjectArrayList.add(processEnumField(fieldName, schema, specFile, ApiTool.getEnumValues(schema), schema)); + } else if (!ApiTool.hasProperties(schema) && !ApiTool.isComposed(schema)) { + fieldObjectArrayList.add(SchemaFieldObject + .builder() + .baseName(fieldName) + .dataType(new SchemaFieldObjectType(TypeConstants.OBJECT)) + .build()); + } else if (ApiTool.isObject(schema)) { + fieldObjectArrayList.addAll(processObject(fieldName, className, schema, specFile, totalSchemas, compositedSchemas, antiLoopList, baseDir)); + } else { + final var composedSchemaName = StringUtils.defaultIfBlank(className, fieldName); + var schemaObjectComposed = compositedSchemas.get(composedSchemaName); + if (Objects.isNull(schemaObjectComposed)) { + schemaObjectComposed = createComposedSchema(buildingSchema, StringUtils.defaultIfBlank(className, fieldName), schema, specFile, + totalSchemas, compositedSchemas, antiLoopList, baseDir); + compositedSchemas.put(composedSchemaName, schemaObjectComposed); + } + + fieldObjectArrayList.add(SchemaFieldObject + .builder() + .baseName(fieldName) + .dataType(SchemaFieldObjectType.fromTypeList(schemaObjectComposed.getClassName(), schemaObjectComposed.getClassName())) + .build()); } - private static List processAdditionalProperties( - final String fieldName, final JsonNode schema, final CommonSpecFile specFile, final Map totalSchemas, - final Map compositedSchemas, final Set antiLoopList, final String nameSchema, - final Path baseDir) { - final var fieldObjectArrayList = new ArrayList(); - - final var addPropObj = ApiTool.getAdditionalProperties(schema); - if (TypeConstants.isBoolean(addPropObj.asText())) { - fieldObjectArrayList - .add(SchemaFieldObject - .builder() - .baseName(fieldName) - .dataType(SchemaFieldObjectType.fromTypeList(TypeConstants.MAP, TypeConstants.OBJECT)) - .build()); - } else if (ApiTool.hasRef(addPropObj)) { - final String refSchemaName = MapperUtil.getRef(addPropObj, specFile); - fieldObjectArrayList.add(processRef(fieldName, addPropObj, - SchemaFieldObjectType.fromTypeList(TypeConstants.MAP, refSchemaName), totalSchemas, compositedSchemas, + return fieldObjectArrayList; + } + + private static Consumer> processProperties(final String buildingSchema, + final Map totalSchemas, final Map compositedSchemas, final Set fieldObjectArrayList, final CommonSpecFile specFile, + final JsonNode schema, final Set antiLoopList, final Path baseDir) { + return field -> { + final var nodeName = field.getKey(); + final var nodeValue = field.getValue(); + if (ApiTool.isEnum(field.getValue())) { + fieldObjectArrayList.add(processEnumField(nodeName, nodeValue, specFile, ApiTool.getEnumValues(nodeValue), schema)); + } else { + fieldObjectArrayList.addAll(processObjectProperty(buildingSchema, totalSchemas, nodeName, nodeValue, compositedSchemas, specFile, schema, antiLoopList, baseDir)); + } + }; + } + + @SuppressWarnings({"checkstyle:CyclomaticComplexity", "checkstyle:ParameterNumber"}) + private static List processObjectProperty(final String buildingSchema, + final Map totalSchemas, final String fieldName, final JsonNode fieldBody, final Map compositedSchemas, final CommonSpecFile specFile, + final JsonNode schema, final Set antiLoopList, final Path baseDir) { + final List fieldObjectArrayList = new LinkedList<>(); + final var isRequired = ApiTool.checkIfRequired(fieldBody, fieldName); + final SchemaFieldObject field; + if (ApiTool.hasRef(fieldBody)) { + final var typeName = MapperUtil.getRefSchemaName(fieldBody); + final var refSchema = totalSchemas.get(MapperUtil.getRefSchemaKey(fieldBody)); + if (!antiLoopList.contains(typeName) && Objects.nonNull(refSchema) && ApiTool.hasType(refSchema) + && ApiTool.hasItems(refSchema) || ApiTool.getRefValue(fieldBody).contains(fieldName)) { + antiLoopList.add(typeName); + fieldObjectArrayList.addAll(processFieldObjectList(buildingSchema, fieldName, typeName, refSchema, specFile, totalSchemas, compositedSchemas, + antiLoopList, baseDir)); + } else if (ApiTool.isEnum(refSchema)) { + fieldObjectArrayList.add(processEnumField(fieldName, refSchema, specFile, ApiTool.getEnumValues(refSchema), schema)); + } else { + compositedSchemas.put(typeName, buildSchemaObject(totalSchemas, typeName, refSchema, antiLoopList, compositedSchemas, "", specFile, baseDir )); + fieldObjectArrayList.add(SchemaFieldObject + .builder() + .baseName(fieldName) + .required(ApiTool.checkIfRequired(schema, fieldName)) + .dataType(SchemaFieldObjectType.fromTypeList(MapperUtil.getSimpleType(refSchema, specFile), + MapperUtil.getPojoName(typeName, specFile))) + .build()); + } + } else if (ApiTool.isEnum(fieldBody)) { + fieldObjectArrayList.add(processEnumField(fieldName, fieldBody, specFile, ApiTool.getEnumValues(fieldBody), fieldBody)); + } else if (TypeConstants.STRING.equalsIgnoreCase(ApiTool.getType(fieldBody))) { + field = processStringProperty(fieldName, fieldBody, specFile); + setFieldType(field, fieldBody, schema, specFile, fieldName); + fieldObjectArrayList.add(field); + } else if (isBasicType(fieldBody)) { + field = SchemaFieldObject + .builder() + .baseName(fieldName) + .required(isRequired || ApiTool.hasConst(fieldBody)) + .dataType(new SchemaFieldObjectType(MapperUtil.getSimpleType(fieldBody, specFile))) + .constValue(getConst(fieldBody)) + .build(); + addPropertiesToFieldObject(field, fieldBody); + setFieldType(field, fieldBody, schema, specFile, fieldName); + fieldObjectArrayList.add(field); + } else { + fieldObjectArrayList.addAll(processFieldObjectList(buildingSchema, fieldName, fieldName, fieldBody, specFile, totalSchemas, compositedSchemas, antiLoopList, baseDir)); + } + return fieldObjectArrayList; + } + + private static Object getConst(final JsonNode fieldBody) { + return ApiTool.hasConst(fieldBody) ? ApiTool.getConst(fieldBody) : null; + } + + private static SchemaFieldObject processStringProperty(final String propertyName, final JsonNode schema, final CommonSpecFile specFile) { + final String resultingType = ApiTool.isDateTime(schema) ? MapperUtil.getDateType(schema, specFile) : TypeConstants.STRING; + + final SchemaFieldObject field = SchemaFieldObject + .builder() + .baseName(propertyName) + .required(ApiTool.checkIfRequired(schema, propertyName)) + .dataType(new SchemaFieldObjectType(resultingType)) + .constValue(ApiTool.getConst(schema)) + .required(ApiTool.hasConst(schema)) + .build(); + addPropertiesToFieldObject(field, schema); + return field; + } + + @SuppressWarnings("checkstyle:CyclomaticComplexity") + private static void addPropertiesToFieldObject(final SchemaFieldObject fieldObject, final JsonNode value) { + final var restrictionList = ApiTool.getFieldIterator(value); + while (restrictionList.hasNext()) { + final var restriction = restrictionList.next(); + switch (restriction.getKey()) { + case "pattern": + case "format": + fieldObject.getRestrictions().setPattern(restriction.getValue().asText()); + break; + case "maxItems": + fieldObject.getRestrictions().setMaxItems(restriction.getValue().asInt()); + break; + case "minItems": + fieldObject.getRestrictions().setMinItems(restriction.getValue().asInt()); + break; + case "maxLength": + fieldObject.getRestrictions().setMaxLength(restriction.getValue().asInt()); + break; + case "minLength": + fieldObject.getRestrictions().setMinLength(restriction.getValue().asInt()); + break; + case "uniqueItems": + fieldObject.getRestrictions().setUniqueItems(restriction.getValue().asBoolean()); + break; + case "exclusiveMaximum": + fieldObject.getRestrictions().setExclusiveMaximum(restriction.getValue().asBoolean()); + break; + case "exclusiveMinimum": + fieldObject.getRestrictions().setExclusiveMinimum(restriction.getValue().asBoolean()); + break; + case "multipleOf": + fieldObject.getRestrictions().setMultipleOf(restriction.getValue().asText()); + break; + case "maximum": + fieldObject.getRestrictions().setMaximum(restriction.getValue().asText()); + break; + case "minimum": + fieldObject.getRestrictions().setMinimum(restriction.getValue().asText()); + break; + default: + break; + } + } + } + + @SuppressWarnings("checkstyle:ParameterNumber") + private static List processArray( + final String fieldName, final String className, final JsonNode schema, final CommonSpecFile specFile, final Map totalSchemas, + final Map compositedSchemas, final Set antiLoopList, final Path baseDir) { + final List fieldObjectArrayList = new LinkedList<>(); + + if (!ApiTool.hasItems(schema)) { + fieldObjectArrayList.add(SchemaFieldObject + .builder() + .baseName(fieldName) + .dataType(new SchemaFieldObjectType(TypeConstants.OBJECT)) + .build()); + } else { + final var items = ApiTool.getItems(schema); + if (ApiTool.hasRef(items)) { + fieldObjectArrayList.add( + processRef(fieldName, items, SchemaFieldObjectType.fromTypeList(TypeConstants.ARRAY, MapperUtil.getSimpleType(items, specFile)), totalSchemas, compositedSchemas, antiLoopList, specFile, baseDir)); - } else if (ApiTool.hasItems(addPropObj)) { - fieldObjectArrayList - .add(SchemaFieldObject - .builder() - .baseName(fieldName) - .dataType(SchemaFieldObjectType.fromTypeList(TypeConstants.MAP, TypeConstants.ARRAY, - MapperUtil.getSimpleType(ApiTool.getItems(addPropObj), specFile))) - .build()); - } else if (ApiTool.isObject(addPropObj)) { - final String className = nameSchema + "Value"; - final var itemsObject = buildSchemaObject(totalSchemas, className, addPropObj, antiLoopList, compositedSchemas, "", specFile, baseDir); - compositedSchemas.put(className, itemsObject); - fieldObjectArrayList - .add(SchemaFieldObject - .builder() - .baseName(ADDITIONAL_PROPERTIES) - .dataType(SchemaFieldObjectType.fromTypeList(TypeConstants.MAP, MapperUtil.getPojoName(className, specFile))) - .build()); - } else { - final String type = isBasicType(addPropObj) ? MapperUtil.getSimpleType(addPropObj, specFile) - : MapperUtil.getPojoName(ApiTool.getName(schema) + ADDITIONAL_PROPERTY_NAME, specFile); - fieldObjectArrayList - .add(SchemaFieldObject - .builder() - .baseName(fieldName) - .dataType(SchemaFieldObjectType.fromTypeList(TypeConstants.MAP, type)) - .build()); + } else if (ApiTool.isComposed(items)) { + final String composedSchemaName = StringUtils.defaultIfBlank(className, fieldName); + SchemaObject schemaObjectComposed = compositedSchemas.get(composedSchemaName); + if (Objects.isNull(schemaObjectComposed)) { + schemaObjectComposed = createComposedSchema("", StringUtils.defaultIfBlank(className, fieldName), items, specFile, + totalSchemas, compositedSchemas, antiLoopList, baseDir); + compositedSchemas.put(composedSchemaName, schemaObjectComposed); } - return fieldObjectArrayList; + fieldObjectArrayList.add(SchemaFieldObject + .builder() + .baseName(fieldName) + .dataType(SchemaFieldObjectType.fromTypeList(TypeConstants.ARRAY, schemaObjectComposed.getClassName())) + .importClass(schemaObjectComposed.getClassName()) + .build()); + } else if (ApiTool.hasProperties(items)) { + final var itemsObject = buildSchemaObject(totalSchemas, className, items, antiLoopList, compositedSchemas, "", specFile, baseDir); + compositedSchemas.put(className, itemsObject); + fieldObjectArrayList.add(SchemaFieldObject + .builder() + .baseName(fieldName) + .dataType(SchemaFieldObjectType.fromTypeList(TypeConstants.ARRAY, MapperUtil.getPojoName(fieldName, specFile))) + .build()); + } else { + final SchemaFieldObject field = SchemaFieldObject + .builder() + .baseName(fieldName) + .dataType(SchemaFieldObjectType.fromTypeList(TypeConstants.ARRAY, MapperUtil.getSimpleType(items, specFile))) + .build(); + fieldObjectArrayList.add(field); + addPropertiesToFieldObject(field, schema); + } } - private static boolean isBasicType(final JsonNode value) { - return !(ApiTool.isObject(value) || ApiTool.isArray(value) || ApiTool.isComposed(value) - || ApiTool.hasAdditionalProperties(value)); + return fieldObjectArrayList; + } + + @SuppressWarnings("checkstyle:ParameterNumber") + private static Set processObject( + final String fieldName, final String className, final JsonNode schema, final CommonSpecFile specFile, + final Map totalSchemas, final Map compositedSchemas, + final Set antiLoopList, final Path baseDir) { + final Set fieldObjectArrayList = new HashSet<>(); + + if (ObjectUtils.allNull(className, fieldName)) { + ApiTool.getProperties(schema).forEachRemaining( + processProperties("", totalSchemas, compositedSchemas, fieldObjectArrayList, specFile, schema, antiLoopList, baseDir)); + } else if (antiLoopList.contains(className)) { + fieldObjectArrayList + .add(SchemaFieldObject + .builder() + .baseName(className) + .dataType(SchemaFieldObjectType.fromTypeList(TypeConstants.OBJECT, MapperUtil.getPojoName(className, specFile))) + .build()); + } else if (antiLoopList.contains(fieldName)) { + fieldObjectArrayList + .add(SchemaFieldObject + .builder() + .baseName(fieldName) + .dataType(SchemaFieldObjectType.fromTypeList(TypeConstants.OBJECT, MapperUtil.getPojoName(fieldName, specFile))) + .build()); + } else { + final String name = StringUtils.defaultIfBlank(className, fieldName); + final var itemsObject = buildSchemaObject(totalSchemas, className, schema, antiLoopList, compositedSchemas, "", specFile, baseDir); + compositedSchemas.put(className, itemsObject); + fieldObjectArrayList + .add(SchemaFieldObject + .builder() + .baseName(name) + .dataType(SchemaFieldObjectType.fromTypeList(TypeConstants.OBJECT, MapperUtil.getPojoName(name, specFile))) + .build()); } - private static SchemaObject createComposedSchema(final String buildingSchema, - final String fieldName, final JsonNode schema, final CommonSpecFile specFile, final Map totalSchemas, - final Map compositedSchemas, final Set antiLoopList, final Path baseDir) { - final Set fieldObjectArrayList = new HashSet<>(); - String schemaCombinatorType = ""; - if (ApiTool.isAllOf(schema)) { - fieldObjectArrayList.addAll( - processAllOf(totalSchemas, ApiTool.getAllOf(schema), specFile, compositedSchemas, antiLoopList, baseDir)); - schemaCombinatorType = ALL_OF_COMBINATOR; - } else if (ApiTool.isAnyOf(schema)) { - fieldObjectArrayList.addAll( - processAnyOfOneOf(buildingSchema, totalSchemas, ApiTool.getAnyOf(schema), specFile, compositedSchemas, antiLoopList, baseDir)); - schemaCombinatorType = ANY_OF_COMBINATOR; - } else if (ApiTool.isOneOf(schema)) { - fieldObjectArrayList.addAll( - processAnyOfOneOf(buildingSchema, totalSchemas, ApiTool.getOneOf(schema), specFile, compositedSchemas, antiLoopList, baseDir)); - schemaCombinatorType = ONE_OF_COMBINATOR; - } + return fieldObjectArrayList; + } - return SchemaObject.builder() - .schemaName(fieldName) - .className(MapperUtil.getPojoName(fieldName, specFile)) - .importList(getImportList(fieldObjectArrayList, specFile.getModelPackage())) - .schemaCombinator(schemaCombinatorType) - .fieldObjectList(fieldObjectArrayList) - .build(); - } + private static Set processMap( + final String fieldName, final JsonNode schema, final CommonSpecFile specFile, final Map totalSchemas, + final Map compositedSchemas, final Set antiLoopList, final Path baseDir) { + final Set fieldObjectArrayList = new HashSet<>(); - private static void setFieldType( - final SchemaFieldObject field, final JsonNode schemaProperty, final JsonNode schema, - final CommonSpecFile specFile, final String key) { - field.setRequired(ApiTool.hasRequired(schema) && ApiTool.checkIfRequired(schema, key)); - if (ApiTool.isArray(schemaProperty)) { - final String typeArray; - if (ApiTool.hasItems(schemaProperty)) { - typeArray = MapperUtil.getTypeArray(schemaProperty, specFile); - } else { - typeArray = TypeConstants.OBJECT; - } - field.setDataType(SchemaFieldObjectType.fromTypeList(TypeConstants.ARRAY, typeArray)); - field.setImportClass(getImportClass(typeArray)); - } else if (ApiTool.hasAdditionalProperties(schemaProperty)) { - final String typeObject = getMapTypeObject(schemaProperty, specFile); - field.setDataType(SchemaFieldObjectType.fromTypeList(TypeConstants.MAP, typeObject)); - field.setImportClass(getImportClass(typeObject)); - - } else if (ApiTool.isObject(schemaProperty)) { - var typeObject = ApiTool.getType(schemaProperty); - if (ApiTool.hasRef(schemaProperty)) { - typeObject = MapperUtil.getRef(schema, specFile); - } - field.setImportClass(getImportClass(typeObject)); - field.getDataType().setDeepType(typeObject); - } + if (TypeConstants.OBJECT.equalsIgnoreCase(ApiTool.getType(schema)) && ApiTool.hasProperties(schema)) { + ApiTool.getProperties(schema).forEachRemaining( + processProperties("", totalSchemas, compositedSchemas, fieldObjectArrayList, specFile, schema, antiLoopList, baseDir)); } - private static String getMapTypeObject(final JsonNode schema, final CommonSpecFile specFile) { - final String type; - if (ApiTool.isBoolean(ApiTool.getAdditionalProperties(schema))) { - type = TypeConstants.OBJECT; - } else { - final JsonNode additionalProperties = ApiTool.getAdditionalProperties(schema); - if (ApiTool.hasRef(additionalProperties)) { - type = MapperUtil.getRef(additionalProperties, specFile); - } else if (ApiTool.isObject(schema)) { - final var additionalPropertiesField = SchemaFieldObject - .builder() - .baseName(ApiTool.getName(additionalProperties)) - .dataType(new SchemaFieldObjectType(MapperUtil.getSimpleType(additionalProperties, specFile))) - .build(); - setFieldType(additionalPropertiesField, additionalProperties, additionalProperties, specFile, ""); - type = getMapFieldType(additionalPropertiesField); - } else { - type = TypeConstants.OBJECT; - } - } - - return type; + if (ApiTool.hasAdditionalProperties(schema)) { + fieldObjectArrayList.addAll(processAdditionalProperties(fieldName, schema, specFile, totalSchemas, compositedSchemas, + antiLoopList, ADDITIONAL_PROPERTIES, baseDir)); } - private static String getMapFieldType(final SchemaFieldObject schemaFieldObject) { - final String fieldType = schemaFieldObject.getDataType().toString(); - final String type; - switch (fieldType) { - case TypeConstants.BIG_DECIMAL: - case TypeConstants.INTEGER: - case TypeConstants.DOUBLE: - case TypeConstants.FLOAT: - case TypeConstants.LONG: - case TypeConstants.STRING: - type = fieldType; - break; - default: - type = TypeConstants.OBJECT; - break; - } - - return type; + return fieldObjectArrayList; + } + + private static List processAdditionalProperties( + final String fieldName, final JsonNode schema, final CommonSpecFile specFile, final Map totalSchemas, + final Map compositedSchemas, final Set antiLoopList, final String nameSchema, + final Path baseDir) { + final var fieldObjectArrayList = new ArrayList(); + + final var addPropObj = ApiTool.getAdditionalProperties(schema); + if (TypeConstants.isBoolean(addPropObj.asText())) { + fieldObjectArrayList + .add(SchemaFieldObject + .builder() + .baseName(fieldName) + .dataType(SchemaFieldObjectType.fromTypeList(TypeConstants.MAP, TypeConstants.OBJECT)) + .build()); + } else if (ApiTool.hasRef(addPropObj)) { + final String refSchemaName = MapperUtil.getRef(addPropObj, specFile); + fieldObjectArrayList.add(processRef(fieldName, addPropObj, + SchemaFieldObjectType.fromTypeList(TypeConstants.MAP, refSchemaName), totalSchemas, compositedSchemas, + antiLoopList, specFile, baseDir)); + } else if (ApiTool.hasItems(addPropObj)) { + fieldObjectArrayList + .add(SchemaFieldObject + .builder() + .baseName(fieldName) + .dataType(SchemaFieldObjectType.fromTypeList(TypeConstants.MAP, TypeConstants.ARRAY, + MapperUtil.getSimpleType(ApiTool.getItems(addPropObj), specFile))) + .build()); + } else if (ApiTool.isObject(addPropObj)) { + final String className = nameSchema + "Value"; + final var itemsObject = buildSchemaObject(totalSchemas, className, addPropObj, antiLoopList, compositedSchemas, "", specFile, baseDir); + compositedSchemas.put(className, itemsObject); + fieldObjectArrayList + .add(SchemaFieldObject + .builder() + .baseName(ADDITIONAL_PROPERTIES) + .dataType(SchemaFieldObjectType.fromTypeList(TypeConstants.MAP, MapperUtil.getPojoName(className, specFile))) + .build()); + } else { + final String type = isBasicType(addPropObj) ? MapperUtil.getSimpleType(addPropObj, specFile) + : MapperUtil.getPojoName(ApiTool.getName(schema) + ADDITIONAL_PROPERTY_NAME, specFile); + fieldObjectArrayList + .add(SchemaFieldObject + .builder() + .baseName(fieldName) + .dataType(SchemaFieldObjectType.fromTypeList(TypeConstants.MAP, type)) + .constValue(getConst(addPropObj)) + .required(ApiTool.hasConst(addPropObj)) + .build()); } - private static Set processAllOf( - final Map totalSchemas, final JsonNode schemaList, final CommonSpecFile specFile, - final Map compositedSchemas, final Set antiLoopList, final Path baseDir) { - final Set fieldObjectArrayList = new HashSet<>(); - - for (JsonNode ref : schemaList) { - if (ApiTool.hasRef(ref)) { - final String schemaName = MapperUtil.getRefSchemaName(ref); - final var schemaToProcess = totalSchemas.get(MapperUtil.getRefSchemaKey(ref)); - ApiTool.getProperties(schemaToProcess).forEachRemaining(processProperties("", totalSchemas, compositedSchemas, fieldObjectArrayList, specFile, ref, antiLoopList, baseDir)); - for (var fieldObject : fieldObjectArrayList) { - fieldObject.setRequired(true); - } - } - } - return fieldObjectArrayList; + return fieldObjectArrayList; + } + + private static boolean isBasicType(final JsonNode value) { + return !(ApiTool.isObject(value) || ApiTool.isArray(value) || ApiTool.isComposed(value) + || ApiTool.hasAdditionalProperties(value)); + } + + private static SchemaObject createComposedSchema(final String buildingSchema, + final String fieldName, final JsonNode schema, final CommonSpecFile specFile, final Map totalSchemas, + final Map compositedSchemas, final Set antiLoopList, final Path baseDir) { + final Set fieldObjectArrayList = new HashSet<>(); + String schemaCombinatorType = ""; + if (ApiTool.isAllOf(schema)) { + fieldObjectArrayList.addAll( + processAllOf(totalSchemas, ApiTool.getAllOf(schema), specFile, compositedSchemas, antiLoopList, baseDir)); + schemaCombinatorType = ALL_OF_COMBINATOR; + } else if (ApiTool.isAnyOf(schema)) { + fieldObjectArrayList.addAll( + processAnyOfOneOf(buildingSchema, totalSchemas, ApiTool.getAnyOf(schema), specFile, compositedSchemas, antiLoopList, baseDir)); + schemaCombinatorType = ANY_OF_COMBINATOR; + } else if (ApiTool.isOneOf(schema)) { + fieldObjectArrayList.addAll( + processAnyOfOneOf(buildingSchema, totalSchemas, ApiTool.getOneOf(schema), specFile, compositedSchemas, antiLoopList, baseDir)); + schemaCombinatorType = ONE_OF_COMBINATOR; } - private static Set processAnyOfOneOf(final String buildingSchema, - final Map totalSchemas, final JsonNode schemaList, final CommonSpecFile specFile, - final Map compositedSchemas, final Set antiLoopList, final Path baseDir) { - final Set fieldObjectArrayList = new HashSet<>(); - - for (JsonNode internalSchema : schemaList) { - if (ApiTool.hasRef(internalSchema)) { - final var schemaName = MapperUtil.getRefSchemaName(internalSchema); - if (!antiLoopList.contains(schemaName)) { - if (compositedSchemas.containsKey(schemaName)) { - antiLoopList.add(schemaName); - fieldObjectArrayList.addAll(compositedSchemas.get(schemaName).getFieldObjectList()); - } else { - final var schemaObject = solveRef(internalSchema, totalSchemas, compositedSchemas, antiLoopList, specFile, baseDir); - compositedSchemas.put(schemaName, schemaObject); - antiLoopList.add(schemaName); - fieldObjectArrayList.addAll(schemaObject.getFieldObjectList()); - } - } else if (compositedSchemas.containsKey(schemaName)) { - fieldObjectArrayList.addAll(compositedSchemas.get(schemaName).getFieldObjectList()); - } else if (!schemaName.equalsIgnoreCase(buildingSchema)) { - fieldObjectArrayList.addAll(getFields(schemaName, totalSchemas, internalSchema, specFile, compositedSchemas, antiLoopList, ApiTool.getName(internalSchema), baseDir)); - } - } else { - fieldObjectArrayList.addAll(getFields(buildingSchema, totalSchemas, internalSchema, specFile, compositedSchemas, antiLoopList, ApiTool.getName(internalSchema), baseDir)); - for (var fieldObject : fieldObjectArrayList) { - if (ApiTool.checkIfRequired(internalSchema, fieldObject.getBaseName())) { - fieldObject.setRequired(true); - } - } - } - } - return fieldObjectArrayList; + return SchemaObject.builder() + .schemaName(fieldName) + .className(MapperUtil.getPojoName(fieldName, specFile)) + .importList(getImportList(fieldObjectArrayList, specFile.getModelPackage())) + .schemaCombinator(schemaCombinatorType) + .fieldObjectList(fieldObjectArrayList) + .build(); + } + + private static void setFieldType( + final SchemaFieldObject field, final JsonNode schemaProperty, final JsonNode schema, + final CommonSpecFile specFile, final String key) { + field.setRequired(ApiTool.hasRequired(schema) && ApiTool.checkIfRequired(schema, key)); + if (ApiTool.isArray(schemaProperty)) { + final String typeArray; + if (ApiTool.hasItems(schemaProperty)) { + typeArray = MapperUtil.getTypeArray(schemaProperty, specFile); + } else { + typeArray = TypeConstants.OBJECT; + } + field.setDataType(SchemaFieldObjectType.fromTypeList(TypeConstants.ARRAY, typeArray)); + field.setImportClass(getImportClass(typeArray)); + } else if (ApiTool.hasAdditionalProperties(schemaProperty)) { + final String typeObject = getMapTypeObject(schemaProperty, specFile); + field.setDataType(SchemaFieldObjectType.fromTypeList(TypeConstants.MAP, typeObject)); + field.setImportClass(getImportClass(typeObject)); + + } else if (ApiTool.isObject(schemaProperty)) { + var typeObject = ApiTool.getType(schemaProperty); + if (ApiTool.hasRef(schemaProperty)) { + typeObject = MapperUtil.getRef(schema, specFile); + } + field.setImportClass(getImportClass(typeObject)); + field.getDataType().setDeepType(typeObject); } - - private static SchemaFieldObject processRef( - final String fieldName, final JsonNode schema, final SchemaFieldObjectType dataType, - final Map totalSchemas, final Map compositedSchemas, - final Set antiLoopList, final CommonSpecFile specFile, final Path baseDir) { - final var field = SchemaFieldObject.builder() - .baseName(fieldName) - .dataType(dataType) - .build(); - if (!antiLoopList.contains(MapperUtil.getRefSchemaName(schema))) { - antiLoopList.add(MapperUtil.getRefSchemaName(schema)); - final String refSchemaName = MapperUtil.getRef(schema, specFile); - setFieldType(field, schema, schema, specFile, refSchemaName); - - solveRef(schema, totalSchemas, compositedSchemas, antiLoopList, specFile, baseDir); - } - return field; + } + + private static String getMapTypeObject(final JsonNode schema, final CommonSpecFile specFile) { + final String type; + if (ApiTool.isBoolean(ApiTool.getAdditionalProperties(schema))) { + type = TypeConstants.OBJECT; + } else { + final JsonNode additionalProperties = ApiTool.getAdditionalProperties(schema); + if (ApiTool.hasRef(additionalProperties)) { + type = MapperUtil.getRef(additionalProperties, specFile); + } else if (ApiTool.isObject(schema)) { + final var additionalPropertiesField = SchemaFieldObject + .builder() + .baseName(ApiTool.getName(additionalProperties)) + .dataType(new SchemaFieldObjectType(MapperUtil.getSimpleType(additionalProperties, specFile))) + .build(); + setFieldType(additionalPropertiesField, additionalProperties, additionalProperties, specFile, ""); + type = getMapFieldType(additionalPropertiesField); + } else { + type = TypeConstants.OBJECT; + } } - private static SchemaObject solveRef( - final JsonNode schema, final Map totalSchemas, - final Map compositedSchemas, final Set antiLoopList, final CommonSpecFile specFile, - final Path baseDir) { - - final var referredSchema = SchemaUtil.solveRef(ApiTool.getRefValue(schema), totalSchemas, baseDir.resolve(specFile.getFilePath()).getParent()); - - final var schemaObject = buildSchemaObject(totalSchemas, MapperUtil.getRefSchemaName(schema), referredSchema, - antiLoopList, compositedSchemas, MapperUtil.getRefSchemaName(schema), specFile, baseDir); - schemaObject.setEnum(ApiTool.isEnum(referredSchema)); - - compositedSchemas.put(MapperUtil.getRefSchemaName(schema), schemaObject); - return schemaObject; + return type; + } + + private static String getMapFieldType(final SchemaFieldObject schemaFieldObject) { + final String fieldType = schemaFieldObject.getDataType().toString(); + final String type; + switch (fieldType) { + case TypeConstants.BIG_DECIMAL: + case TypeConstants.INTEGER: + case TypeConstants.DOUBLE: + case TypeConstants.FLOAT: + case TypeConstants.LONG: + case TypeConstants.STRING: + type = fieldType; + break; + default: + type = TypeConstants.OBJECT; + break; } - private static SchemaFieldObject processEnumField( - final String name, final JsonNode value, - final CommonSpecFile specFile, final List enumValues, final JsonNode schema) { - final var field = SchemaFieldObject - .builder() - .baseName(name) - .dataType(new SchemaFieldObjectType(TypeConstants.ENUM)) - .build(); - field.setRequired(ApiTool.checkIfRequired(schema, name)); - final var dataType = MapperUtil.getSimpleType(value, specFile); - field.getDataType().setDeepType(dataType); - - final HashMap enumValuesMap = new HashMap<>(); - - for (final var enumValue : enumValues) { - String valueName = enumValue; - valueName = valueName.replace(".", "_DOT_"); - - switch (dataType) { - case TypeConstants.INTEGER: - enumValuesMap.put("INTEGER_" + valueName, enumValue); - break; - case TypeConstants.LONG: - enumValuesMap.put("LONG_" + valueName, enumValue + "l"); - break; - case TypeConstants.DOUBLE: - enumValuesMap.put("DOUBLE_" + valueName, enumValue); - break; - case TypeConstants.FLOAT: - enumValuesMap.put("FLOAT_" + valueName, enumValue + "f"); - break; - case TypeConstants.BIG_DECIMAL: - enumValuesMap.put("BIG_DECIMAL_" + valueName, "new BigDecimal(\"" + enumValue + "\")"); - break; - case TypeConstants.STRING: - default: - enumValuesMap.put(StringUtils.upperCase(valueName), '"' + enumValue + '"'); - break; - } + return type; + } + + private static Set processAllOf( + final Map totalSchemas, final JsonNode schemaList, final CommonSpecFile specFile, + final Map compositedSchemas, final Set antiLoopList, final Path baseDir) { + final Set fieldObjectArrayList = new HashSet<>(); + + for (JsonNode ref : schemaList) { + if (ApiTool.hasRef(ref)) { + final String schemaName = MapperUtil.getRefSchemaName(ref); + final var schemaToProcess = totalSchemas.get(MapperUtil.getRefSchemaKey(ref)); + ApiTool.getProperties(schemaToProcess).forEachRemaining(processProperties("", totalSchemas, compositedSchemas, fieldObjectArrayList, specFile, ref, antiLoopList, baseDir)); + for (var fieldObject : fieldObjectArrayList) { + fieldObject.setRequired(true); } - - if (enumValuesMap.isEmpty()) { - throw new BadDefinedEnumException(name); + } + } + return fieldObjectArrayList; + } + + private static Set processAnyOfOneOf(final String buildingSchema, + final Map totalSchemas, final JsonNode schemaList, final CommonSpecFile specFile, + final Map compositedSchemas, final Set antiLoopList, final Path baseDir) { + final Set fieldObjectArrayList = new HashSet<>(); + + for (JsonNode internalSchema : schemaList) { + if (ApiTool.hasRef(internalSchema)) { + final var schemaName = MapperUtil.getRefSchemaName(internalSchema); + if (!antiLoopList.contains(schemaName)) { + if (compositedSchemas.containsKey(schemaName)) { + antiLoopList.add(schemaName); + fieldObjectArrayList.addAll(compositedSchemas.get(schemaName).getFieldObjectList()); + } else { + final var schemaObject = solveRef(internalSchema, totalSchemas, compositedSchemas, antiLoopList, specFile, baseDir); + compositedSchemas.put(schemaName, schemaObject); + antiLoopList.add(schemaName); + fieldObjectArrayList.addAll(schemaObject.getFieldObjectList()); + } + } else if (compositedSchemas.containsKey(schemaName)) { + fieldObjectArrayList.addAll(compositedSchemas.get(schemaName).getFieldObjectList()); + } else if (!schemaName.equalsIgnoreCase(buildingSchema)) { + fieldObjectArrayList.addAll(getFields(schemaName, totalSchemas, internalSchema, specFile, compositedSchemas, antiLoopList, ApiTool.getName(internalSchema), baseDir)); } - field.setEnumValues(enumValuesMap); - return field; + } else { + fieldObjectArrayList.addAll(getFields(buildingSchema, totalSchemas, internalSchema, specFile, compositedSchemas, antiLoopList, ApiTool.getName(internalSchema), baseDir)); + for (var fieldObject : fieldObjectArrayList) { + if (ApiTool.checkIfRequired(internalSchema, fieldObject.getBaseName())) { + fieldObject.setRequired(true); + } + } + } + } + return fieldObjectArrayList; + } + + private static SchemaFieldObject processRef( + final String fieldName, final JsonNode schema, final SchemaFieldObjectType dataType, + final Map totalSchemas, final Map compositedSchemas, + final Set antiLoopList, final CommonSpecFile specFile, final Path baseDir) { + final var field = SchemaFieldObject.builder() + .baseName(fieldName) + .dataType(dataType) + .build(); + if (!antiLoopList.contains(MapperUtil.getRefSchemaName(schema))) { + antiLoopList.add(MapperUtil.getRefSchemaName(schema)); + final String refSchemaName = MapperUtil.getRef(schema, specFile); + setFieldType(field, schema, schema, specFile, refSchemaName); + + solveRef(schema, totalSchemas, compositedSchemas, antiLoopList, specFile, baseDir); + } + return field; + } + + private static SchemaObject solveRef( + final JsonNode schema, final Map totalSchemas, + final Map compositedSchemas, final Set antiLoopList, final CommonSpecFile specFile, + final Path baseDir) { + + final var referredSchema = SchemaUtil.solveRef(ApiTool.getRefValue(schema), totalSchemas, baseDir.resolve(specFile.getFilePath()).getParent()); + + final var schemaObject = buildSchemaObject(totalSchemas, MapperUtil.getRefSchemaName(schema), referredSchema, + antiLoopList, compositedSchemas, MapperUtil.getRefSchemaName(schema), specFile, baseDir); + schemaObject.setEnum(ApiTool.isEnum(referredSchema)); + + compositedSchemas.put(MapperUtil.getRefSchemaName(schema), schemaObject); + return schemaObject; + } + + private static SchemaFieldObject processEnumField( + final String name, final JsonNode value, + final CommonSpecFile specFile, final List enumValues, final JsonNode schema) { + final var field = SchemaFieldObject + .builder() + .baseName(name) + .dataType(new SchemaFieldObjectType(TypeConstants.ENUM)) + .build(); + field.setRequired(ApiTool.checkIfRequired(schema, name)); + final var dataType = MapperUtil.getSimpleType(value, specFile); + field.getDataType().setDeepType(dataType); + + final HashMap enumValuesMap = new HashMap<>(); + + for (final var enumValue : enumValues) { + String valueName = enumValue; + valueName = valueName.replace(".", "_DOT_"); + + switch (dataType) { + case TypeConstants.INTEGER: + enumValuesMap.put("INTEGER_" + valueName, enumValue); + break; + case TypeConstants.LONG: + enumValuesMap.put("LONG_" + valueName, enumValue + "l"); + break; + case TypeConstants.DOUBLE: + enumValuesMap.put("DOUBLE_" + valueName, enumValue); + break; + case TypeConstants.FLOAT: + enumValuesMap.put("FLOAT_" + valueName, enumValue + "f"); + break; + case TypeConstants.BIG_DECIMAL: + enumValuesMap.put("BIG_DECIMAL_" + valueName, "new BigDecimal(\"" + enumValue + "\")"); + break; + case TypeConstants.STRING: + default: + enumValuesMap.put(StringUtils.upperCase(valueName), '"' + enumValue + '"'); + break; + } } - private static String getImportClass(final String type) { - return StringUtils.isNotBlank(type) && !TypeConstants.NO_IMPORT_TYPE.contains(type) ? StringUtils.capitalize(type) : ""; + if (enumValuesMap.isEmpty()) { + throw new BadDefinedEnumException(name); } + field.setEnumValues(enumValuesMap); + return field; + } + + private static String getImportClass(final String type) { + return StringUtils.isNotBlank(type) && !TypeConstants.NO_IMPORT_TYPE.contains(type) ? StringUtils.capitalize(type) : ""; + } } diff --git a/multiapi-engine/src/main/resources/templates/asyncapi/templateSchema.ftlh b/multiapi-engine/src/main/resources/templates/asyncapi/templateSchema.ftlh index 3b10fa2e..27ff03ca 100644 --- a/multiapi-engine/src/main/resources/templates/asyncapi/templateSchema.ftlh +++ b/multiapi-engine/src/main/resources/templates/asyncapi/templateSchema.ftlh @@ -1,12 +1,27 @@ <#ftl output_format="plainText"> <#assign words = ["abstract", "assert", "boolean", "break", "byte", "case", "catch", "char", "class", "const", "continue", "default", "double", "do", "else", "enum", "extends", "false", "final", "finally", "float", "for", "goto", "if", "implements", "import", "instanceof", "int", "interface", "long", "native", "new", "null", "package", "private", "protected", "public", "return", "short", "static", "strictfp", "super", "switch", "synchronized", "this", "throw", "throws", "transient", "true", "try", "void", "volatile", "while"]> -<#function calculateSafeName propertyName ender> +<#function calculateSafeName propertyName ender const=""> <#if words?seq_contains(propertyName?uncap_first) || propertyName?matches("[0-9].*")> - <#return "_"+propertyName+ender/> + <#if const?has_content> + <#return "_"+propertyName + " = " + const + ender/> + <#else> + <#return "_"+propertyName + ender/> + <#else > - <#return propertyName+ender/> + <#if const?has_content> + <#return propertyName + " = " + const + ender/> + <#else> + <#return propertyName + ender/> + +<#function createSimpleType field> + <#if (field.constValue?has_content)> + ${calculateSafeName (field.baseName, ";", field.constValue)} + <#else > + ${calculateSafeName (field.baseName, ";", "")} + + <#function singularizeName propertyName> <#if propertyName?matches(".*s")> <#return propertyName?remove_ending("s")/> @@ -18,7 +33,7 @@ <#function requireFinal field> <#if field.required == true || field.constValue??> - <#return "final "/> + <#return "final"/> <#else > <#return ""/> @@ -225,17 +240,15 @@ public class ${schema.className} { private ${field.dataType.innerType?cap_first} ${calculateSafeName (field.baseName, ";")} <#else> - <#if field.required> - private final ${field.dataType} ${calculateSafeName (field.baseName, ";")} - <#else> - private ${field.dataType} ${calculateSafeName (field.baseName, ";")} - + private ${requireFinal (field)} ${field.dataType} ${createSimpleType (field)} private ${schema.className}(${schema.className}Builder builder) { <#list schema.fieldObjectList as field> - this.${calculateSafeName (field.baseName, "")} = builder.${calculateSafeName (field.baseName, ";")} + <#if checkIfShouldSet(field)> + this.${calculateSafeName (field.baseName, "")} = builder.${calculateSafeName (field.baseName, ";")} + <#list schema.fieldObjectList as field> @@ -265,7 +278,7 @@ public class ${schema.className} { private ${field.baseName?cap_first} ${calculateSafeName (field.baseName, ";")} <#elseif field.dataType.innerType?has_content && field.dataType.baseType == "object"> private ${field.dataType.innerType?cap_first} ${calculateSafeName (field.baseName, ";")} - <#else> + <#elseif checkIfShouldSet(field)> private ${field.dataType} ${calculateSafeName (field.baseName, ";")} @@ -307,8 +320,7 @@ public class ${schema.className} { this.${calculateSafeName (field.baseName, "")} = ${calculateSafeName (field.baseName, ";")} return this; } - <#else> - + <#elseif checkIfShouldSet(field)> public ${schema.className}.${schema.className}Builder ${calculateSafeName (field.baseName, "")}(${field.dataType} ${calculateSafeName (field.baseName, "")}) { this.${calculateSafeName (field.baseName, "")} = ${calculateSafeName (field.baseName, ";")} return this; @@ -364,7 +376,7 @@ public class ${schema.className} { public ${field.dataType} get${field.baseName?cap_first}() { return ${calculateSafeName (field.baseName, ";")} } - <#if field.required == false> + <#if checkIfShouldSet (field)> public void set${field.baseName?cap_first}(${field.dataType} ${calculateSafeName (field.baseName, "")}) { this.${calculateSafeName (field.baseName, "")} = ${calculateSafeName (field.baseName, ";")} } diff --git a/multiapi-engine/src/main/resources/templates/asyncapi/templateSchemaWithLombok.ftlh b/multiapi-engine/src/main/resources/templates/asyncapi/templateSchemaWithLombok.ftlh index 75fdfb52..2cdafabe 100644 --- a/multiapi-engine/src/main/resources/templates/asyncapi/templateSchemaWithLombok.ftlh +++ b/multiapi-engine/src/main/resources/templates/asyncapi/templateSchemaWithLombok.ftlh @@ -1,4 +1,26 @@ <#ftl output_format="plainText"> +<#function calculateSafeName propertyName ender const=""> + <#if words?seq_contains(propertyName?uncap_first) || propertyName?matches("[0-9].*")> + <#if const?has_content> + <#return "_"+propertyName + " = " + const + ender/> + <#else> + <#return "_"+propertyName + ender/> + + <#else > + <#if const?has_content> + <#return propertyName + " = " + const + ender/> + <#else> + <#return propertyName + ender/> + + + +<#function createSimpleType field> + <#if (field.constValue?has_content)> + ${calculateSafeName (field.baseName, ";", field.const)} + <#else > + ${calculateSafeName (field.baseName, ";", "")} + + package ${packageModel}; <#if schema.schemaCombinator == "anyOf" || schema.schemaCombinator == "oneOf"> @@ -151,7 +173,7 @@ public class ${schema.className} { <#elseif field.dataType.innerType?has_content && field.dataType.baseType == "object"> private ${field.dataType.innerType?cap_first} ${field.baseName?uncap_first}; <#else> - private ${field.dataType} ${field.baseName?uncap_first}; + private ${field.dataType} ${createSimpleType (field)} diff --git a/multiapi-engine/src/test/resources/asyncapigenerator/testConstantGeneration/assets/payload/SomeOtherObject.java b/multiapi-engine/src/test/resources/asyncapigenerator/testConstantGeneration/assets/payload/SomeOtherObject.java index b086d071..ca9231c3 100644 --- a/multiapi-engine/src/test/resources/asyncapigenerator/testConstantGeneration/assets/payload/SomeOtherObject.java +++ b/multiapi-engine/src/test/resources/asyncapigenerator/testConstantGeneration/assets/payload/SomeOtherObject.java @@ -11,13 +11,11 @@ public class SomeOtherObject { @JsonProperty(value ="property2") - private Integer property2; + private final Integer property2 = 6; @JsonProperty(value ="property1") - private Integer property1; + private final Integer property1 = 3; private SomeOtherObject(SomeOtherObjectBuilder builder) { - this.property2 = builder.property2; - this.property1 = builder.property1; } @@ -28,18 +26,6 @@ public static SomeOtherObject.SomeOtherObjectBuilder builder() { @JsonPOJOBuilder(buildMethodName = "build", withPrefix = "") public static class SomeOtherObjectBuilder { - private Integer property2 = 6; - private Integer property1 = 3; - - public SomeOtherObject.SomeOtherObjectBuilder property2(Integer property2) { - this.property2 = property2; - return this; - } - - public SomeOtherObject.SomeOtherObjectBuilder property1(Integer property1) { - this.property1 = property1; - return this; - } public SomeOtherObject build() { SomeOtherObject someOtherObject = new SomeOtherObject(this); @@ -51,17 +37,11 @@ public SomeOtherObject build() { public Integer getProperty2() { return property2; } - public void setProperty2(Integer property2) { - this.property2 = property2; - } @Schema(name = "property1", required = false) public Integer getProperty1() { return property1; } - public void setProperty1(Integer property1) { - this.property1 = property1; - } @Override public boolean equals(Object o) { From f300445e55b4470c91fb65878a48a8648aac0bc0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Enrique=20Garc=C3=ADa=20Maci=C3=B1eiras?= Date: Fri, 16 Aug 2024 15:09:33 +0200 Subject: [PATCH 03/26] Refactor --- .../plugin/common/tools/ApiTool.java | 34 +++++++++--------- .../plugin/common/tools/ModelBuilder.java | 1 - .../templates/asyncapi/templateSchema.ftlh | 35 +++++-------------- .../asyncapi/AsyncApiGeneratorTest.java | 20 +++++------ .../assets/CreateOrderMapper.java | 1 + .../testFileGeneration/assets/OrderDTO.java | 4 +-- .../assets/OrderLineDTO.java | 2 +- 7 files changed, 40 insertions(+), 57 deletions(-) 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 8178c85c..bef56fba 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 @@ -353,22 +353,24 @@ public static Object getConst(final JsonNode fieldBody) { private static Object getValue(final JsonNode aConst) { Object value = null; - if (aConst.isTextual()) { - value = aConst.textValue(); - } else if (aConst.isNumber()) { - value = aConst.numberValue(); - } else if (aConst.isBoolean()) { - value = aConst.booleanValue(); - } else if (aConst.isFloat()) { - value = aConst.floatValue(); - } else if (aConst.isDouble()) { - value = aConst.doubleValue(); - } else if (aConst.isInt()) { - value = aConst.intValue(); - } else if (aConst.isLong()) { - value = aConst.longValue(); - } else if (aConst.isBigDecimal()) { - value = aConst.decimalValue(); + if (Objects.nonNull(value)) { + if (aConst.isTextual()) { + value = aConst.textValue(); + } else if (aConst.isNumber()) { + value = aConst.numberValue(); + } else if (aConst.isBoolean()) { + value = aConst.booleanValue(); + } else if (aConst.isFloat()) { + value = aConst.floatValue(); + } else if (aConst.isDouble()) { + value = aConst.doubleValue(); + } else if (aConst.isInt()) { + value = aConst.intValue(); + } else if (aConst.isLong()) { + value = aConst.longValue(); + } else if (aConst.isBigDecimal()) { + value = aConst.decimalValue(); + } } return value; } diff --git a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/tools/ModelBuilder.java b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/tools/ModelBuilder.java index 70a4bd1e..ae4b040c 100644 --- a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/tools/ModelBuilder.java +++ b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/tools/ModelBuilder.java @@ -297,7 +297,6 @@ private static void addPropertiesToFieldObject(final SchemaFieldObject fieldObje final var restriction = restrictionList.next(); switch (restriction.getKey()) { case "pattern": - case "format": fieldObject.getRestrictions().setPattern(restriction.getValue().asText()); break; case "maxItems": diff --git a/multiapi-engine/src/main/resources/templates/asyncapi/templateSchema.ftlh b/multiapi-engine/src/main/resources/templates/asyncapi/templateSchema.ftlh index 27ff03ca..877a0f11 100644 --- a/multiapi-engine/src/main/resources/templates/asyncapi/templateSchema.ftlh +++ b/multiapi-engine/src/main/resources/templates/asyncapi/templateSchema.ftlh @@ -33,9 +33,9 @@ <#function requireFinal field> <#if field.required == true || field.constValue??> - <#return "final"/> + <#return "final "/> <#else > - <#return ""/> + <#return ""/> <#function checkIfShouldSet field> @@ -191,23 +191,11 @@ public class ${schema.className} { @NotNull <#if field.dataType.baseType == "array"> - <#if field.required> - private final ${field.dataType} ${calculateSafeName (field.baseName, ";")} - <#else> - private ${field.dataType} ${calculateSafeName (field.baseName, "")} = new ${field.dataType?api.getImplementationTypeString()}(); - + private ${requireFinal (field)}${field.dataType} ${calculateSafeName (field.baseName, ";")} <#elseif field.dataType.baseType == "map"> - <#if field.required> - private final ${field.dataType} ${calculateSafeName (field.baseName, ";")} - <#else> - private ${field.dataType} ${calculateSafeName (field.baseName, "")} = new ${field.dataType?api.getImplementationTypeString()}(); - + private ${requireFinal (field)}${field.dataType} ${calculateSafeName (field.baseName, ";")} <#elseif field.dataType.baseType == "enum"> - <#if field.required> - private final ${field.baseName?cap_first} ${calculateSafeName (field.baseName, ";")} - <#else> - private ${field.baseName?cap_first} ${calculateSafeName (field.baseName, ";")} - + private ${requireFinal (field)}${field.baseName?cap_first} ${calculateSafeName (field.baseName, ";")} public enum ${field.baseName?cap_first} { <#list field.enumValues as key, value> <#if key?matches("[0-9].*")> @@ -234,21 +222,15 @@ public class ${schema.className} { } } <#elseif field.dataType.innerType?has_content && field.dataType.baseType == "object"> - <#if field.required> - private final ${field.dataType.innerType?cap_first} ${calculateSafeName (field.baseName, ";")} - <#else> - private ${field.dataType.innerType?cap_first} ${calculateSafeName (field.baseName, ";")} - + private ${requireFinal (field)}${field.dataType.innerType?cap_first} ${calculateSafeName (field.baseName, ";")} <#else> - private ${requireFinal (field)} ${field.dataType} ${createSimpleType (field)} + private ${requireFinal (field)}${field.dataType} ${createSimpleType (field)} private ${schema.className}(${schema.className}Builder builder) { <#list schema.fieldObjectList as field> - <#if checkIfShouldSet(field)> - this.${calculateSafeName (field.baseName, "")} = builder.${calculateSafeName (field.baseName, ";")} - + this.${calculateSafeName (field.baseName, "")} = builder.${calculateSafeName (field.baseName, ";")} <#list schema.fieldObjectList as field> @@ -282,6 +264,7 @@ public class ${schema.className} { private ${field.dataType} ${calculateSafeName (field.baseName, ";")} + <#list schema.fieldObjectList as field> <#if field.dataType.baseType == "array"> <#assign propName>${calculateSafeName (field.baseName, "")} 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 a047c3ee..f1075c81 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 @@ -6,28 +6,28 @@ package com.sngular.api.generator.plugin.asyncapi; -import java.io.File; -import java.nio.file.Path; -import java.util.List; -import java.util.function.Function; -import java.util.stream.Stream; - import com.sngular.api.generator.plugin.asyncapi.exception.InvalidAvroException; import com.sngular.api.generator.plugin.asyncapi.parameter.SpecFile; import com.sngular.api.generator.plugin.exception.InvalidAPIException; +import lombok.extern.slf4j.Slf4j; import org.assertj.core.api.Assertions; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.io.CleanupMode; -import org.junit.jupiter.api.io.TempDir; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.MethodSource; +import java.io.File; +import java.nio.file.Path; +import java.util.List; +import java.util.function.Function; +import java.util.stream.Stream; + +@Slf4j class AsyncApiGeneratorTest { - @TempDir(cleanup = CleanupMode.NEVER) - static Path baseDir; + //@TempDir(cleanup = CleanupMode.NEVER) + static Path baseDir = Path.of("/Users/jegarcia/Developer/repos/generators/scs-multiapi-plugin/multiapi-engine/target"); private static AsyncApiGenerator asyncApiGenerator; diff --git a/multiapi-engine/src/test/resources/asyncapigenerator/testFileGeneration/assets/CreateOrderMapper.java b/multiapi-engine/src/test/resources/asyncapigenerator/testFileGeneration/assets/CreateOrderMapper.java index d931af72..82c974f1 100644 --- a/multiapi-engine/src/test/resources/asyncapigenerator/testFileGeneration/assets/CreateOrderMapper.java +++ b/multiapi-engine/src/test/resources/asyncapigenerator/testFileGeneration/assets/CreateOrderMapper.java @@ -30,6 +30,7 @@ public static class CreateOrderMapperBuilder { private WaiterMapper waiter; private OrderMapper order; + public CreateOrderMapper.CreateOrderMapperBuilder waiter(WaiterMapper waiter) { this.waiter = waiter; return this; diff --git a/multiapi-engine/src/test/resources/asyncapigenerator/testFileGeneration/assets/OrderDTO.java b/multiapi-engine/src/test/resources/asyncapigenerator/testFileGeneration/assets/OrderDTO.java index c1102627..3d0ddaf8 100644 --- a/multiapi-engine/src/test/resources/asyncapigenerator/testFileGeneration/assets/OrderDTO.java +++ b/multiapi-engine/src/test/resources/asyncapigenerator/testFileGeneration/assets/OrderDTO.java @@ -18,7 +18,7 @@ public class OrderDTO { @JsonProperty(value ="amount") private BigDecimal amount; @JsonProperty(value ="lines") - private List lines = new ArrayList(); + private List lines; @JsonProperty(value ="ref") private String ref; @@ -46,7 +46,6 @@ public OrderDTO.OrderDTOBuilder clientRef(String clientRef) { this.clientRef = clientRef; return this; } - public OrderDTO.OrderDTOBuilder amount(BigDecimal amount) { this.amount = amount; return this; @@ -64,7 +63,6 @@ public OrderDTO.OrderDTOBuilder line(OrderLineDTO line) { } return this; } - public OrderDTO.OrderDTOBuilder ref(String ref) { this.ref = ref; return this; diff --git a/multiapi-engine/src/test/resources/asyncapigenerator/testFileGeneration/assets/OrderLineDTO.java b/multiapi-engine/src/test/resources/asyncapigenerator/testFileGeneration/assets/OrderLineDTO.java index fb8f2b64..389210ee 100644 --- a/multiapi-engine/src/test/resources/asyncapigenerator/testFileGeneration/assets/OrderLineDTO.java +++ b/multiapi-engine/src/test/resources/asyncapigenerator/testFileGeneration/assets/OrderLineDTO.java @@ -15,7 +15,7 @@ public class OrderLineDTO { @JsonProperty(value ="products") - private List products = new ArrayList(); + private List products; @JsonProperty(value ="ref") @NotNull private final String ref; From f2da2de40d74370a2ab8e9ae3da87075423909cc Mon Sep 17 00:00:00 2001 From: "joseenrique.garcia" Date: Tue, 20 Aug 2024 20:20:40 +0200 Subject: [PATCH 04/26] Fix test --- multiapi-engine/pom.xml | 23 +++-- .../plugin/common/tools/ApiTool.java | 2 +- .../interfaceConsumerWithKafkaBindings.ftlh | 2 +- .../interfaceSupplierWithKafkaBindings.ftlh | 2 +- .../templateConsumersWithKafkaBindings.ftlh | 2 +- .../templates/asyncapi/templateSchema.ftlh | 45 ++++----- .../templateSuppliersWithKafkaBindings.ftlh | 2 +- .../asyncapi/AsyncApiGeneratorTest.java | 6 +- .../assets/payload/SomeOtherObject.java | 8 +- .../assets/payload/UserSignedUpPayload.java | 91 ++++++------------- .../assets/CreateOrderMapper.java | 1 + .../testFileGeneration/assets/OrderDTO.java | 3 + .../assets/OrderLineDTO.java | 1 + .../assets/OrderLineMapper.java | 3 +- .../assets/OrderMapper.java | 3 +- .../assets/ObjectArrayDTO.java | 3 +- .../assets/CustomerEventPayloadDTO.java | 2 + .../assets/CustomerOrderDTO.java | 9 +- .../assets/CustomerOrderEventPayloadDTO.java | 2 + .../assets/CreateOrderMapper.java | 49 ++++------ .../assets/OrderDTO.java | 67 +++++--------- .../assets/OrderLineDTO.java | 53 +++++------ .../assets/OrderLineMapper.java | 53 +++++------ .../assets/OrderMapper.java | 67 +++++--------- .../assets/OrderProductDTO.java | 65 +++++-------- .../assets/OrderProductMapper.java | 65 +++++-------- .../assets/WaiterMapper.java | 56 +++++------- .../assets/StatusMsgDTO.java | 1 + .../assets/StatusMsgDTO.java | 1 + .../assets/CreateOrderEventDTO.java | 2 + .../assets/OrderDTO.java | 3 +- .../assets/OrderLineDTO.java | 3 +- .../assets/payload/UserSignedUpPayload.java | 1 + .../assets/payload/UserSignedUp.java | 1 + .../assets/CreateOrderDTO.java | 2 + .../assets/OrderDTO.java | 1 + .../assets/CreateOrderDTO.java | 2 + .../assets/OrderDTO.java | 3 +- .../assets/OrderLineDTO.java | 3 +- .../assets/input/model/Input.java | 2 + .../assets/output/model/Output.java | 3 + 41 files changed, 304 insertions(+), 409 deletions(-) diff --git a/multiapi-engine/pom.xml b/multiapi-engine/pom.xml index 402bc19f..f5d772b2 100644 --- a/multiapi-engine/pom.xml +++ b/multiapi-engine/pom.xml @@ -11,16 +11,21 @@ 11 11 2.1.12 - 3.12.0 - 2.11.0 + 3.13.0 + 2.13.0 4.4 - 2.15.0 + 2.15.3 2.3.32 3.24.2 - 5.9.2 + 5.10.1 2.2.9 3.0.0 + 1.10.0 + 1.18.30 + 2.0.11 + 1.16.0 + 3.9.1 @@ -32,7 +37,7 @@ org.apache.commons commons-text - 1.10.0 + ${commons-text.version} commons-io @@ -63,18 +68,18 @@ org.projectlombok lombok - 1.18.30 + ${lombok.version} org.slf4j slf4j-api - 1.7.28 + ${slf4j-api.version} commons-codec commons-codec - 1.15 + ${commons-codec.version} io.swagger.parser.v3 @@ -143,7 +148,7 @@ org.apache.maven maven-artifact - 3.9.1 + ${maven-artifact.version} provided 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 bef56fba..1f5d56ba 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 @@ -353,7 +353,7 @@ public static Object getConst(final JsonNode fieldBody) { private static Object getValue(final JsonNode aConst) { Object value = null; - if (Objects.nonNull(value)) { + if (Objects.nonNull(aConst)) { if (aConst.isTextual()) { value = aConst.textValue(); } else if (aConst.isNumber()) { diff --git a/multiapi-engine/src/main/resources/templates/asyncapi/interfaceConsumerWithKafkaBindings.ftlh b/multiapi-engine/src/main/resources/templates/asyncapi/interfaceConsumerWithKafkaBindings.ftlh index 89751c9f..32ed65d2 100644 --- a/multiapi-engine/src/main/resources/templates/asyncapi/interfaceConsumerWithKafkaBindings.ftlh +++ b/multiapi-engine/src/main/resources/templates/asyncapi/interfaceConsumerWithKafkaBindings.ftlh @@ -8,5 +8,5 @@ import ${subscribePackage}.MessageWrapper; public interface I${method.operationId?cap_first} { - void ${method.operationId?uncap_first}(final MessageWrapper<${method.className}<#if subscribeEntitiesSuffix?has_content>${subscribeEntitiesSuffix}, ${method.keyClassName}> value); + void ${method.operationId?uncap_first}(final MessageWrapper<${method.className}<#if subscribeEntitiesSuffix?has_content>${subscribeEntitiesSuffix}, ${method.keyClassName?cap_first}> value); } \ No newline at end of file diff --git a/multiapi-engine/src/main/resources/templates/asyncapi/interfaceSupplierWithKafkaBindings.ftlh b/multiapi-engine/src/main/resources/templates/asyncapi/interfaceSupplierWithKafkaBindings.ftlh index a15a1c5d..cea22659 100644 --- a/multiapi-engine/src/main/resources/templates/asyncapi/interfaceSupplierWithKafkaBindings.ftlh +++ b/multiapi-engine/src/main/resources/templates/asyncapi/interfaceSupplierWithKafkaBindings.ftlh @@ -8,5 +8,5 @@ import ${supplierPackage}.MessageWrapper; public interface I${method.operationId?cap_first} { - MessageWrapper<${method.className}<#if supplierEntitiesSuffix?has_content>${supplierEntitiesSuffix}, ${method.keyClassName}> ${method.operationId?uncap_first}(); + MessageWrapper<${method.className}<#if supplierEntitiesSuffix?has_content>${supplierEntitiesSuffix}, ${method.keyClassName?cap_first}> ${method.operationId?uncap_first}(); } \ No newline at end of file diff --git a/multiapi-engine/src/main/resources/templates/asyncapi/templateConsumersWithKafkaBindings.ftlh b/multiapi-engine/src/main/resources/templates/asyncapi/templateConsumersWithKafkaBindings.ftlh index 042c8358..13c5f612 100644 --- a/multiapi-engine/src/main/resources/templates/asyncapi/templateConsumersWithKafkaBindings.ftlh +++ b/multiapi-engine/src/main/resources/templates/asyncapi/templateConsumersWithKafkaBindings.ftlh @@ -31,7 +31,7 @@ public class ${subscribeClassName?cap_first} { @Bean public Consumer${subscribeEntitiesSuffix}>> ${method.operationId?uncap_first}() { return value -> { - final var messageWrapper = MessageWrapper.<${method.className}<#if subscribeEntitiesSuffix?has_content>${subscribeEntitiesSuffix}, ${method.keyClassName}>builder().payload(value.getPayload()).key(value.getHeaders().get(KafkaHeaders.MESSAGE_KEY)).build(); + final var messageWrapper = MessageWrapper.<${method.className}<#if subscribeEntitiesSuffix?has_content>${subscribeEntitiesSuffix}, ${method.keyClassName?cap_first}>builder().payload(value.getPayload()).key(value.getHeaders().get(KafkaHeaders.MESSAGE_KEY)).build(); ${method.operationId?uncap_first}.${method.operationId?uncap_first}(messageWrapper); }; } diff --git a/multiapi-engine/src/main/resources/templates/asyncapi/templateSchema.ftlh b/multiapi-engine/src/main/resources/templates/asyncapi/templateSchema.ftlh index 877a0f11..18018366 100644 --- a/multiapi-engine/src/main/resources/templates/asyncapi/templateSchema.ftlh +++ b/multiapi-engine/src/main/resources/templates/asyncapi/templateSchema.ftlh @@ -3,24 +3,16 @@ <#function calculateSafeName propertyName ender const=""> <#if words?seq_contains(propertyName?uncap_first) || propertyName?matches("[0-9].*")> <#if const?has_content> - <#return "_"+propertyName + " = " + const + ender/> + <#return getConstValue("_"+propertyName, ender, const)/> <#else> - <#return "_"+propertyName + ender/> + <#return getConstValue ("_"+propertyName, ender)/> <#else > - <#if const?has_content> - <#return propertyName + " = " + const + ender/> - <#else> - <#return propertyName + ender/> - + <#return getConstValue(propertyName, ender, const)/> <#function createSimpleType field> - <#if (field.constValue?has_content)> ${calculateSafeName (field.baseName, ";", field.constValue)} - <#else > - ${calculateSafeName (field.baseName, ";", "")} - <#function singularizeName propertyName> <#if propertyName?matches(".*s")> @@ -31,25 +23,24 @@ <#return propertyName/> +<#function hasConstValue field> + <#return field.constValue?has_content /> + <#function requireFinal field> - <#if field.required == true || field.constValue??> + <#if field.required == true || hasConstValue(field)> <#return "final "/> <#else > <#return ""/> <#function checkIfShouldSet field> - <#if field.required == true || field.constValue??> - <#return false/> - <#else > - <#return true/> - + <<#return !(field.required == true || hasConstValue(field))> -<#function hasConstValue value=""> +<#function getConstValue fieldName ender value=""> <#if value?has_content> - <#return " = " + renderValue (value) + ";"/> + <#return fieldName +" = " + renderValue (value) + ender/> <#else > - <#return ";"/> + <#return fieldName + ender/> <#function renderValue value=""> @@ -224,7 +215,7 @@ public class ${schema.className} { <#elseif field.dataType.innerType?has_content && field.dataType.baseType == "object"> private ${requireFinal (field)}${field.dataType.innerType?cap_first} ${calculateSafeName (field.baseName, ";")} <#else> - private ${requireFinal (field)}${field.dataType} ${createSimpleType (field)} + private ${requireFinal (field)}${field.dataType} ${calculateSafeName (field.baseName, ";")} @@ -260,8 +251,8 @@ public class ${schema.className} { private ${field.baseName?cap_first} ${calculateSafeName (field.baseName, ";")} <#elseif field.dataType.innerType?has_content && field.dataType.baseType == "object"> private ${field.dataType.innerType?cap_first} ${calculateSafeName (field.baseName, ";")} - <#elseif checkIfShouldSet(field)> - private ${field.dataType} ${calculateSafeName (field.baseName, ";")} + <#else> + private ${field.dataType} ${calculateSafeName (field.baseName, ";", field.constValue)} @@ -282,6 +273,7 @@ public class ${schema.className} { } return this; } + <#elseif field.dataType.baseType == "map"> <#assign propName>${calculateSafeName (field.baseName, "")} public ${schema.className}.${schema.className}Builder ${propName}(${field.dataType} ${propName}) { @@ -293,24 +285,27 @@ public class ${schema.className} { this.${propName}.put(key, value); return this; } + <#elseif field.dataType.baseType == "enum"> public ${schema.className}.${schema.className}Builder ${calculateSafeName (field.baseName, "")}(${field.baseName?cap_first} ${field.baseName}) { this.${calculateSafeName (field.baseName, "")} = ${calculateSafeName (field.baseName, ";")} return this; } + <#elseif field.dataType.innerType?has_content && field.dataType.baseType == "object"> public ${schema.className}.${schema.className}Builder ${calculateSafeName (field.baseName, "")}(${field.dataType.innerType?cap_first} ${calculateSafeName (field.baseName, "")}) { this.${calculateSafeName (field.baseName, "")} = ${calculateSafeName (field.baseName, ";")} return this; } - <#elseif checkIfShouldSet(field)> + + <#elseif !(hasConstValue (field))> public ${schema.className}.${schema.className}Builder ${calculateSafeName (field.baseName, "")}(${field.dataType} ${calculateSafeName (field.baseName, "")}) { this.${calculateSafeName (field.baseName, "")} = ${calculateSafeName (field.baseName, ";")} return this; } + - public ${schema.className} build() { ${schema.className} ${schema.className?uncap_first} = new ${schema.className}(this); return ${schema.className?uncap_first}; diff --git a/multiapi-engine/src/main/resources/templates/asyncapi/templateSuppliersWithKafkaBindings.ftlh b/multiapi-engine/src/main/resources/templates/asyncapi/templateSuppliersWithKafkaBindings.ftlh index ab09d967..6f23baf0 100644 --- a/multiapi-engine/src/main/resources/templates/asyncapi/templateSuppliersWithKafkaBindings.ftlh +++ b/multiapi-engine/src/main/resources/templates/asyncapi/templateSuppliersWithKafkaBindings.ftlh @@ -31,7 +31,7 @@ public class ${supplierClassName?cap_first} { @Bean public Supplier${supplierEntitiesSuffix}>> ${method.operationId?uncap_first}() { final var messageWrapper = ${method.operationId?uncap_first}.${method.operationId?uncap_first}(); - return () -> MessageBuilder.withPayload((${method.className}<#if supplierEntitiesSuffix?has_content>${supplierEntitiesSuffix}) messageWrapper.getPayload()).setHeader(KafkaHeaders.MESSAGE_KEY, (${method.keyClassName}) messageWrapper.getKey()).build(); + return () -> MessageBuilder.withPayload((${method.className}<#if supplierEntitiesSuffix?has_content>${supplierEntitiesSuffix}) messageWrapper.getPayload()).setHeader(KafkaHeaders.MESSAGE_KEY, (${method.keyClassName?cap_first}) messageWrapper.getKey()).build(); } 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 f1075c81..1889f675 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 @@ -13,6 +13,8 @@ import org.assertj.core.api.Assertions; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.CleanupMode; +import org.junit.jupiter.api.io.TempDir; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.MethodSource; @@ -26,8 +28,8 @@ @Slf4j class AsyncApiGeneratorTest { - //@TempDir(cleanup = CleanupMode.NEVER) - static Path baseDir = Path.of("/Users/jegarcia/Developer/repos/generators/scs-multiapi-plugin/multiapi-engine/target"); + @TempDir(cleanup = CleanupMode.NEVER) + static Path baseDir; private static AsyncApiGenerator asyncApiGenerator; diff --git a/multiapi-engine/src/test/resources/asyncapigenerator/testConstantGeneration/assets/payload/SomeOtherObject.java b/multiapi-engine/src/test/resources/asyncapigenerator/testConstantGeneration/assets/payload/SomeOtherObject.java index ca9231c3..2301ae40 100644 --- a/multiapi-engine/src/test/resources/asyncapigenerator/testConstantGeneration/assets/payload/SomeOtherObject.java +++ b/multiapi-engine/src/test/resources/asyncapigenerator/testConstantGeneration/assets/payload/SomeOtherObject.java @@ -11,11 +11,13 @@ public class SomeOtherObject { @JsonProperty(value ="property2") - private final Integer property2 = 6; + private final Integer property2; @JsonProperty(value ="property1") - private final Integer property1 = 3; + private final Integer property1; private SomeOtherObject(SomeOtherObjectBuilder builder) { + this.property2 = builder.property2; + this.property1 = builder.property1; } @@ -26,6 +28,8 @@ public static SomeOtherObject.SomeOtherObjectBuilder builder() { @JsonPOJOBuilder(buildMethodName = "build", withPrefix = "") public static class SomeOtherObjectBuilder { + private Integer property2 = 6; + private Integer property1 = 3; public SomeOtherObject build() { SomeOtherObject someOtherObject = new SomeOtherObject(this); diff --git a/multiapi-engine/src/test/resources/asyncapigenerator/testConstantGeneration/assets/payload/UserSignedUpPayload.java b/multiapi-engine/src/test/resources/asyncapigenerator/testConstantGeneration/assets/payload/UserSignedUpPayload.java index 7f85038e..6cffb715 100644 --- a/multiapi-engine/src/test/resources/asyncapigenerator/testConstantGeneration/assets/payload/UserSignedUpPayload.java +++ b/multiapi-engine/src/test/resources/asyncapigenerator/testConstantGeneration/assets/payload/UserSignedUpPayload.java @@ -8,19 +8,19 @@ import com.fasterxml.jackson.annotation.JsonValue; import io.swagger.v3.oas.annotations.media.Schema; import java.time.LocalDateTime; -import com.fasterxml.jackson.annotation.JsonFormat; @JsonDeserialize(builder = UserSignedUpPayload.UserSignedUpPayloadBuilder.class) public class UserSignedUpPayload { + @JsonProperty(value ="someOtherObject") + private SomeOtherObject someOtherObject; + @JsonProperty(value ="email") + private final String email; @JsonProperty(value ="firstName") private final String firstName; @JsonProperty(value ="lastName") private final String lastName; - @JsonProperty(value ="email") - private final String email; @JsonProperty(value ="createdAt") - @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss") private LocalDateTime createdAt; @JsonProperty(value ="numberEnum") private NumberEnum numberEnum; @@ -45,16 +45,14 @@ public String toString() { return String.valueOf(value); } } - @JsonProperty(value ="someOtherObject") - private SomeOtherObject someOtherObject; private UserSignedUpPayload(UserSignedUpPayloadBuilder builder) { + this.someOtherObject = builder.someOtherObject; + this.email = builder.email; this.firstName = builder.firstName; this.lastName = builder.lastName; - this.email = builder.email; this.createdAt = builder.createdAt; this.numberEnum = builder.numberEnum; - this.someOtherObject = builder.someOtherObject; } @@ -65,17 +63,17 @@ public static UserSignedUpPayload.UserSignedUpPayloadBuilder builder() { @JsonPOJOBuilder(buildMethodName = "build", withPrefix = "") public static class UserSignedUpPayloadBuilder { + private SomeOtherObject someOtherObject; + private String email = "je.garcia@oneemail.com"; private String firstName = "Jose"; - private String lastName = "Garcia"; - - private String email = "je.garcia@oneemail.com"; - private LocalDateTime createdAt; - private NumberEnum numberEnum; - private SomeOtherObject someOtherObject; + public UserSignedUpPayload.UserSignedUpPayloadBuilder someOtherObject(SomeOtherObject someOtherObject) { + this.someOtherObject = someOtherObject; + return this; + } public UserSignedUpPayload.UserSignedUpPayloadBuilder createdAt(LocalDateTime createdAt) { this.createdAt = createdAt; @@ -87,48 +85,35 @@ public UserSignedUpPayload.UserSignedUpPayloadBuilder numberEnum(NumberEnum numb return this; } - public UserSignedUpPayload.UserSignedUpPayloadBuilder someOtherObject(SomeOtherObject someOtherObject) { - this.someOtherObject = someOtherObject; - return this; - } - public UserSignedUpPayload build() { UserSignedUpPayload userSignedUpPayload = new UserSignedUpPayload(this); return userSignedUpPayload; } } - /** - * Get firstName - * @return firstName - */ + @Schema(name = "someOtherObject", required = false) + public SomeOtherObject getSomeOtherObject() { + return someOtherObject; + } + public void setSomeOtherObject(SomeOtherObject someOtherObject) { + this.someOtherObject = someOtherObject; + } + + @Schema(name = "email", required = false) + public String getEmail() { + return email; + } + @Schema(name = "firstName", required = false) public String getFirstName() { return firstName; } - /** - * Get lastName - * @return lastName - */ @Schema(name = "lastName", required = false) public String getLastName() { return lastName; } - /** - * Get email - * @return email - */ - @Schema(name = "email", required = false) - public String getEmail() { - return email; - } - - /** - * Get createdAt - * @return createdAt - */ @Schema(name = "createdAt", required = false) public LocalDateTime getCreatedAt() { return createdAt; @@ -137,10 +122,6 @@ public void setCreatedAt(LocalDateTime createdAt) { this.createdAt = createdAt; } - /** - * Get numberEnum - * @return numberEnum - */ @Schema(name = "numberEnum", required = false) public NumberEnum getNumberEnum() { return numberEnum; @@ -149,18 +130,6 @@ public void setNumberEnum(NumberEnum numberEnum) { this.numberEnum = numberEnum; } - /** - * Get someOtherObject - * @return someOtherObject - */ - @Schema(name = "someOtherObject", required = false) - public SomeOtherObject getSomeOtherObject() { - return someOtherObject; - } - public void setSomeOtherObject(SomeOtherObject someOtherObject) { - this.someOtherObject = someOtherObject; - } - @Override public boolean equals(Object o) { if (this == o) { @@ -170,24 +139,24 @@ public boolean equals(Object o) { return false; } UserSignedUpPayload userSignedUpPayload = (UserSignedUpPayload) o; - return Objects.equals(this.firstName, userSignedUpPayload.firstName) && Objects.equals(this.lastName, userSignedUpPayload.lastName) && Objects.equals(this.email, userSignedUpPayload.email) && Objects.equals(this.createdAt, userSignedUpPayload.createdAt) && Objects.equals(this.numberEnum, userSignedUpPayload.numberEnum) && Objects.equals(this.someOtherObject, userSignedUpPayload.someOtherObject); + return Objects.equals(this.someOtherObject, userSignedUpPayload.someOtherObject) && Objects.equals(this.email, userSignedUpPayload.email) && Objects.equals(this.firstName, userSignedUpPayload.firstName) && Objects.equals(this.lastName, userSignedUpPayload.lastName) && Objects.equals(this.createdAt, userSignedUpPayload.createdAt) && Objects.equals(this.numberEnum, userSignedUpPayload.numberEnum); } @Override public int hashCode() { - return Objects.hash(firstName, lastName, email, createdAt, numberEnum, someOtherObject); + return Objects.hash(someOtherObject, email, firstName, lastName, createdAt, numberEnum); } @Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append("UserSignedUpPayload{"); + sb.append(" someOtherObject:").append(someOtherObject).append(","); + sb.append(" email:").append(email).append(","); sb.append(" firstName:").append(firstName).append(","); sb.append(" lastName:").append(lastName).append(","); - sb.append(" email:").append(email).append(","); sb.append(" createdAt:").append(createdAt).append(","); - sb.append(" numberEnum:").append(numberEnum).append(","); - sb.append(" someOtherObject:").append(someOtherObject); + sb.append(" numberEnum:").append(numberEnum); sb.append("}"); return sb.toString(); } diff --git a/multiapi-engine/src/test/resources/asyncapigenerator/testFileGeneration/assets/CreateOrderMapper.java b/multiapi-engine/src/test/resources/asyncapigenerator/testFileGeneration/assets/CreateOrderMapper.java index 82c974f1..ce62cf34 100644 --- a/multiapi-engine/src/test/resources/asyncapigenerator/testFileGeneration/assets/CreateOrderMapper.java +++ b/multiapi-engine/src/test/resources/asyncapigenerator/testFileGeneration/assets/CreateOrderMapper.java @@ -35,6 +35,7 @@ public CreateOrderMapper.CreateOrderMapperBuilder waiter(WaiterMapper waiter) { this.waiter = waiter; return this; } + public CreateOrderMapper.CreateOrderMapperBuilder order(OrderMapper order) { this.order = order; return this; diff --git a/multiapi-engine/src/test/resources/asyncapigenerator/testFileGeneration/assets/OrderDTO.java b/multiapi-engine/src/test/resources/asyncapigenerator/testFileGeneration/assets/OrderDTO.java index 3d0ddaf8..9e3d144d 100644 --- a/multiapi-engine/src/test/resources/asyncapigenerator/testFileGeneration/assets/OrderDTO.java +++ b/multiapi-engine/src/test/resources/asyncapigenerator/testFileGeneration/assets/OrderDTO.java @@ -46,10 +46,12 @@ public OrderDTO.OrderDTOBuilder clientRef(String clientRef) { this.clientRef = clientRef; return this; } + public OrderDTO.OrderDTOBuilder amount(BigDecimal amount) { this.amount = amount; return this; } + public OrderDTO.OrderDTOBuilder lines(List lines) { if (!lines.isEmpty()) { this.lines.addAll(lines); @@ -63,6 +65,7 @@ public OrderDTO.OrderDTOBuilder line(OrderLineDTO line) { } return this; } + public OrderDTO.OrderDTOBuilder ref(String ref) { this.ref = ref; return this; diff --git a/multiapi-engine/src/test/resources/asyncapigenerator/testFileGeneration/assets/OrderLineDTO.java b/multiapi-engine/src/test/resources/asyncapigenerator/testFileGeneration/assets/OrderLineDTO.java index 389210ee..9bedb67d 100644 --- a/multiapi-engine/src/test/resources/asyncapigenerator/testFileGeneration/assets/OrderLineDTO.java +++ b/multiapi-engine/src/test/resources/asyncapigenerator/testFileGeneration/assets/OrderLineDTO.java @@ -36,6 +36,7 @@ public static class OrderLineDTOBuilder { private List products = new ArrayList(); private String ref; + public OrderLineDTO.OrderLineDTOBuilder products(List products) { if (!products.isEmpty()) { this.products.addAll(products); diff --git a/multiapi-engine/src/test/resources/asyncapigenerator/testFileGeneration/assets/OrderLineMapper.java b/multiapi-engine/src/test/resources/asyncapigenerator/testFileGeneration/assets/OrderLineMapper.java index aefdd51c..b104db2b 100644 --- a/multiapi-engine/src/test/resources/asyncapigenerator/testFileGeneration/assets/OrderLineMapper.java +++ b/multiapi-engine/src/test/resources/asyncapigenerator/testFileGeneration/assets/OrderLineMapper.java @@ -15,7 +15,7 @@ public class OrderLineMapper { @JsonProperty(value ="products") - private List products = new ArrayList(); + private List products; @JsonProperty(value ="ref") @NotNull private final String ref; @@ -36,6 +36,7 @@ public static class OrderLineMapperBuilder { private List products = new ArrayList(); private String ref; + public OrderLineMapper.OrderLineMapperBuilder products(List products) { if (!products.isEmpty()) { this.products.addAll(products); diff --git a/multiapi-engine/src/test/resources/asyncapigenerator/testFileGeneration/assets/OrderMapper.java b/multiapi-engine/src/test/resources/asyncapigenerator/testFileGeneration/assets/OrderMapper.java index 8599cd45..11f18510 100644 --- a/multiapi-engine/src/test/resources/asyncapigenerator/testFileGeneration/assets/OrderMapper.java +++ b/multiapi-engine/src/test/resources/asyncapigenerator/testFileGeneration/assets/OrderMapper.java @@ -18,7 +18,7 @@ public class OrderMapper { @JsonProperty(value ="amount") private BigDecimal amount; @JsonProperty(value ="lines") - private List lines = new ArrayList(); + private List lines; @JsonProperty(value ="ref") private String ref; @@ -51,6 +51,7 @@ public OrderMapper.OrderMapperBuilder amount(BigDecimal amount) { this.amount = amount; return this; } + public OrderMapper.OrderMapperBuilder lines(List lines) { if (!lines.isEmpty()) { this.lines.addAll(lines); diff --git a/multiapi-engine/src/test/resources/asyncapigenerator/testFileGenerationArrayString/assets/ObjectArrayDTO.java b/multiapi-engine/src/test/resources/asyncapigenerator/testFileGenerationArrayString/assets/ObjectArrayDTO.java index 5e7ce75a..c9f7a3b6 100644 --- a/multiapi-engine/src/test/resources/asyncapigenerator/testFileGenerationArrayString/assets/ObjectArrayDTO.java +++ b/multiapi-engine/src/test/resources/asyncapigenerator/testFileGenerationArrayString/assets/ObjectArrayDTO.java @@ -17,7 +17,7 @@ public class ObjectArrayDTO { @JsonProperty(value ="info") private String info; @JsonProperty(value ="players") - private List players = new ArrayList(); + private List players; private ObjectArrayDTO(ObjectArrayDTOBuilder builder) { this.idObject = builder.idObject; @@ -46,6 +46,7 @@ public ObjectArrayDTO.ObjectArrayDTOBuilder info(String info) { this.info = info; return this; } + public ObjectArrayDTO.ObjectArrayDTOBuilder players(List players) { if (!players.isEmpty()) { this.players.addAll(players); diff --git a/multiapi-engine/src/test/resources/asyncapigenerator/testFileGenerationIssue/assets/CustomerEventPayloadDTO.java b/multiapi-engine/src/test/resources/asyncapigenerator/testFileGenerationIssue/assets/CustomerEventPayloadDTO.java index 66bb9e86..9b99323b 100644 --- a/multiapi-engine/src/test/resources/asyncapigenerator/testFileGenerationIssue/assets/CustomerEventPayloadDTO.java +++ b/multiapi-engine/src/test/resources/asyncapigenerator/testFileGenerationIssue/assets/CustomerEventPayloadDTO.java @@ -56,6 +56,7 @@ public static class CustomerEventPayloadDTOBuilder { private EventType eventType; private String customerId; private CustomerDTO customer; + public CustomerEventPayloadDTO.CustomerEventPayloadDTOBuilder eventType(EventType eventType) { this.eventType = eventType; return this; @@ -65,6 +66,7 @@ public CustomerEventPayloadDTO.CustomerEventPayloadDTOBuilder customerId(String this.customerId = customerId; return this; } + public CustomerEventPayloadDTO.CustomerEventPayloadDTOBuilder customer(CustomerDTO customer) { this.customer = customer; return this; 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 0c78ef63..fc1cd6b0 100644 --- a/multiapi-engine/src/test/resources/asyncapigenerator/testFileGenerationIssue/assets/CustomerOrderDTO.java +++ b/multiapi-engine/src/test/resources/asyncapigenerator/testFileGenerationIssue/assets/CustomerOrderDTO.java @@ -42,9 +42,9 @@ public String toString() { @JsonProperty(value ="date") private LocalDateTime date; @JsonProperty(value ="orderedItems") - private List orderedItems = new ArrayList(); + private List orderedItems; @JsonProperty(value ="paymentDetails") - private List paymentDetails = new ArrayList(); + private List paymentDetails; @JsonProperty(value ="customer") private CustomerDTO customer; @JsonProperty(value ="shippingDetails") @@ -75,6 +75,7 @@ public static class CustomerOrderDTOBuilder { private List paymentDetails = new ArrayList(); private CustomerDTO customer; private ShippingDetailsDTO shippingDetails; + public CustomerOrderDTO.CustomerOrderDTOBuilder status(Status status) { this.status = status; return this; @@ -89,6 +90,7 @@ public CustomerOrderDTO.CustomerOrderDTOBuilder date(LocalDateTime date) { this.date = date; return this; } + public CustomerOrderDTO.CustomerOrderDTOBuilder orderedItems(List orderedItems) { if (!orderedItems.isEmpty()) { this.orderedItems.addAll(orderedItems); @@ -102,6 +104,7 @@ public CustomerOrderDTO.CustomerOrderDTOBuilder orderedItem(OrderedItemDTO order } return this; } + public CustomerOrderDTO.CustomerOrderDTOBuilder paymentDetails(List paymentDetails) { if (!paymentDetails.isEmpty()) { this.paymentDetails.addAll(paymentDetails); @@ -115,10 +118,12 @@ public CustomerOrderDTO.CustomerOrderDTOBuilder paymentDetail(PaymentDetailsDTO } return this; } + public CustomerOrderDTO.CustomerOrderDTOBuilder customer(CustomerDTO customer) { this.customer = customer; return this; } + public CustomerOrderDTO.CustomerOrderDTOBuilder shippingDetails(ShippingDetailsDTO shippingDetails) { this.shippingDetails = shippingDetails; return this; diff --git a/multiapi-engine/src/test/resources/asyncapigenerator/testFileGenerationIssue/assets/CustomerOrderEventPayloadDTO.java b/multiapi-engine/src/test/resources/asyncapigenerator/testFileGenerationIssue/assets/CustomerOrderEventPayloadDTO.java index 7a9041c9..c53b4649 100644 --- a/multiapi-engine/src/test/resources/asyncapigenerator/testFileGenerationIssue/assets/CustomerOrderEventPayloadDTO.java +++ b/multiapi-engine/src/test/resources/asyncapigenerator/testFileGenerationIssue/assets/CustomerOrderEventPayloadDTO.java @@ -56,10 +56,12 @@ public static class CustomerOrderEventPayloadDTOBuilder { private EventType eventType; private CustomerOrderDTO customerOrder; private String customerOrderId; + public CustomerOrderEventPayloadDTO.CustomerOrderEventPayloadDTOBuilder eventType(EventType eventType) { this.eventType = eventType; return this; } + public CustomerOrderEventPayloadDTO.CustomerOrderEventPayloadDTOBuilder customerOrder(CustomerOrderDTO customerOrder) { this.customerOrder = customerOrder; return this; diff --git a/multiapi-engine/src/test/resources/asyncapigenerator/testFileGenerationWithKafkaBindings/assets/CreateOrderMapper.java b/multiapi-engine/src/test/resources/asyncapigenerator/testFileGenerationWithKafkaBindings/assets/CreateOrderMapper.java index ef922c19..7df4eabd 100644 --- a/multiapi-engine/src/test/resources/asyncapigenerator/testFileGenerationWithKafkaBindings/assets/CreateOrderMapper.java +++ b/multiapi-engine/src/test/resources/asyncapigenerator/testFileGenerationWithKafkaBindings/assets/CreateOrderMapper.java @@ -10,14 +10,14 @@ @JsonDeserialize(builder = CreateOrderMapper.CreateOrderMapperBuilder.class) public class CreateOrderMapper { - @JsonProperty(value ="order") - private OrderMapper order; @JsonProperty(value ="waiter") private WaiterMapper waiter; + @JsonProperty(value ="order") + private OrderMapper order; private CreateOrderMapper(CreateOrderMapperBuilder builder) { - this.order = builder.order; this.waiter = builder.waiter; + this.order = builder.order; } @@ -28,17 +28,16 @@ public static CreateOrderMapper.CreateOrderMapperBuilder builder() { @JsonPOJOBuilder(buildMethodName = "build", withPrefix = "") public static class CreateOrderMapperBuilder { - private OrderMapper order; - private WaiterMapper waiter; + private OrderMapper order; - public CreateOrderMapper.CreateOrderMapperBuilder order(OrderMapper order) { - this.order = order; + public CreateOrderMapper.CreateOrderMapperBuilder waiter(WaiterMapper waiter) { + this.waiter = waiter; return this; } - public CreateOrderMapper.CreateOrderMapperBuilder waiter(WaiterMapper waiter) { - this.waiter = waiter; + public CreateOrderMapper.CreateOrderMapperBuilder order(OrderMapper order) { + this.order = order; return this; } @@ -48,22 +47,6 @@ public CreateOrderMapper build() { } } - /** - * Get order - * @return order - */ - @Schema(name = "order", required = false) - public OrderMapper getOrder() { - return order; - } - public void setOrder(OrderMapper order) { - this.order = order; - } - - /** - * Get waiter - * @return waiter - */ @Schema(name = "waiter", required = false) public WaiterMapper getWaiter() { return waiter; @@ -72,6 +55,14 @@ public void setWaiter(WaiterMapper waiter) { this.waiter = waiter; } + @Schema(name = "order", required = false) + public OrderMapper getOrder() { + return order; + } + public void setOrder(OrderMapper order) { + this.order = order; + } + @Override public boolean equals(Object o) { if (this == o) { @@ -81,20 +72,20 @@ public boolean equals(Object o) { return false; } CreateOrderMapper createOrderMapper = (CreateOrderMapper) o; - return Objects.equals(this.order, createOrderMapper.order) && Objects.equals(this.waiter, createOrderMapper.waiter); + return Objects.equals(this.waiter, createOrderMapper.waiter) && Objects.equals(this.order, createOrderMapper.order); } @Override public int hashCode() { - return Objects.hash(order, waiter); + return Objects.hash(waiter, order); } @Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append("CreateOrderMapper{"); - sb.append(" order:").append(order).append(","); - sb.append(" waiter:").append(waiter); + sb.append(" waiter:").append(waiter).append(","); + sb.append(" order:").append(order); sb.append("}"); return sb.toString(); } diff --git a/multiapi-engine/src/test/resources/asyncapigenerator/testFileGenerationWithKafkaBindings/assets/OrderDTO.java b/multiapi-engine/src/test/resources/asyncapigenerator/testFileGenerationWithKafkaBindings/assets/OrderDTO.java index 27bdae10..644a9a13 100644 --- a/multiapi-engine/src/test/resources/asyncapigenerator/testFileGenerationWithKafkaBindings/assets/OrderDTO.java +++ b/multiapi-engine/src/test/resources/asyncapigenerator/testFileGenerationWithKafkaBindings/assets/OrderDTO.java @@ -6,27 +6,27 @@ import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder; import com.fasterxml.jackson.annotation.JsonProperty; import io.swagger.v3.oas.annotations.media.Schema; -import java.math.BigDecimal; import java.util.List; import java.util.ArrayList; +import java.math.BigDecimal; @JsonDeserialize(builder = OrderDTO.OrderDTOBuilder.class) public class OrderDTO { - @JsonProperty(value ="ref") - private String ref; @JsonProperty(value ="clientRef") private String clientRef; @JsonProperty(value ="amount") private BigDecimal amount; @JsonProperty(value ="lines") - private List lines = new ArrayList(); + private List lines; + @JsonProperty(value ="ref") + private String ref; private OrderDTO(OrderDTOBuilder builder) { - this.ref = builder.ref; this.clientRef = builder.clientRef; this.amount = builder.amount; - this.lines.addAll(builder.lines); + this.lines = builder.lines; + this.ref = builder.ref; } @@ -37,18 +37,10 @@ public static OrderDTO.OrderDTOBuilder builder() { @JsonPOJOBuilder(buildMethodName = "build", withPrefix = "") public static class OrderDTOBuilder { - private String ref; - private String clientRef; - private BigDecimal amount; - private List lines = new ArrayList(); - - public OrderDTO.OrderDTOBuilder ref(String ref) { - this.ref = ref; - return this; - } + private String ref; public OrderDTO.OrderDTOBuilder clientRef(String clientRef) { this.clientRef = clientRef; @@ -74,28 +66,17 @@ public OrderDTO.OrderDTOBuilder line(OrderLineDTO line) { return this; } + public OrderDTO.OrderDTOBuilder ref(String ref) { + this.ref = ref; + return this; + } + public OrderDTO build() { OrderDTO orderDTO = new OrderDTO(this); return orderDTO; } } - /** - * Get ref - * @return ref - */ - @Schema(name = "ref", required = false) - public String getRef() { - return ref; - } - public void setRef(String ref) { - this.ref = ref; - } - - /** - * Get clientRef - * @return clientRef - */ @Schema(name = "clientRef", required = false) public String getClientRef() { return clientRef; @@ -104,10 +85,6 @@ public void setClientRef(String clientRef) { this.clientRef = clientRef; } - /** - * Get amount - * @return amount - */ @Schema(name = "amount", required = false) public BigDecimal getAmount() { return amount; @@ -116,10 +93,6 @@ public void setAmount(BigDecimal amount) { this.amount = amount; } - /** - * Get lines - * @return lines - */ @Schema(name = "lines", required = false) public List getLines() { return lines; @@ -128,6 +101,14 @@ public void setLines(List lines) { this.lines = lines; } + @Schema(name = "ref", required = false) + public String getRef() { + return ref; + } + public void setRef(String ref) { + this.ref = ref; + } + @Override public boolean equals(Object o) { if (this == o) { @@ -137,22 +118,22 @@ public boolean equals(Object o) { return false; } OrderDTO orderDTO = (OrderDTO) o; - return Objects.equals(this.ref, orderDTO.ref) && Objects.equals(this.clientRef, orderDTO.clientRef) && Objects.equals(this.amount, orderDTO.amount) && Objects.equals(this.lines, orderDTO.lines); + return Objects.equals(this.clientRef, orderDTO.clientRef) && Objects.equals(this.amount, orderDTO.amount) && Objects.equals(this.lines, orderDTO.lines) && Objects.equals(this.ref, orderDTO.ref); } @Override public int hashCode() { - return Objects.hash(ref, clientRef, amount, lines); + return Objects.hash(clientRef, amount, lines, ref); } @Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append("OrderDTO{"); - sb.append(" ref:").append(ref).append(","); sb.append(" clientRef:").append(clientRef).append(","); sb.append(" amount:").append(amount).append(","); - sb.append(" lines:").append(lines); + sb.append(" lines:").append(lines).append(","); + sb.append(" ref:").append(ref); sb.append("}"); return sb.toString(); } diff --git a/multiapi-engine/src/test/resources/asyncapigenerator/testFileGenerationWithKafkaBindings/assets/OrderLineDTO.java b/multiapi-engine/src/test/resources/asyncapigenerator/testFileGenerationWithKafkaBindings/assets/OrderLineDTO.java index 6e7d7dc5..8084a1ef 100644 --- a/multiapi-engine/src/test/resources/asyncapigenerator/testFileGenerationWithKafkaBindings/assets/OrderLineDTO.java +++ b/multiapi-engine/src/test/resources/asyncapigenerator/testFileGenerationWithKafkaBindings/assets/OrderLineDTO.java @@ -14,16 +14,15 @@ @JsonDeserialize(builder = OrderLineDTO.OrderLineDTOBuilder.class) public class OrderLineDTO { + @JsonProperty(value ="products") + private List products; @JsonProperty(value ="ref") @NotNull private final String ref; - @JsonProperty(value ="products") - @NotNull - private final List products = new ArrayList(); private OrderLineDTO(OrderLineDTOBuilder builder) { + this.products = builder.products; this.ref = builder.ref; - this.products.addAll(builder.products); validateRequiredAttributes(); } @@ -35,14 +34,8 @@ public static OrderLineDTO.OrderLineDTOBuilder builder() { @JsonPOJOBuilder(buildMethodName = "build", withPrefix = "") public static class OrderLineDTOBuilder { - private String ref; - private List products = new ArrayList(); - - public OrderLineDTO.OrderLineDTOBuilder ref(String ref) { - this.ref = ref; - return this; - } + private String ref; public OrderLineDTO.OrderLineDTOBuilder products(List products) { if (!products.isEmpty()) { @@ -58,30 +51,30 @@ public OrderLineDTO.OrderLineDTOBuilder product(OrderProductDTO product) { return this; } + public OrderLineDTO.OrderLineDTOBuilder ref(String ref) { + this.ref = ref; + return this; + } + public OrderLineDTO build() { OrderLineDTO orderLineDTO = new OrderLineDTO(this); return orderLineDTO; } } - /** - * Get ref - * @return ref - */ + @Schema(name = "products", required = false) + public List getProducts() { + return products; + } + public void setProducts(List products) { + this.products = products; + } + @Schema(name = "ref", required = true) public String getRef() { return ref; } - /** - * Get products - * @return products - */ - @Schema(name = "products", required = true) - public List getProducts() { - return products; - } - @Override public boolean equals(Object o) { if (this == o) { @@ -91,36 +84,34 @@ public boolean equals(Object o) { return false; } OrderLineDTO orderLineDTO = (OrderLineDTO) o; - return Objects.equals(this.ref, orderLineDTO.ref) && Objects.equals(this.products, orderLineDTO.products); + return Objects.equals(this.products, orderLineDTO.products) && Objects.equals(this.ref, orderLineDTO.ref); } @Override public int hashCode() { - return Objects.hash(ref, products); + return Objects.hash(products, ref); } @Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append("OrderLineDTO{"); - sb.append(" ref:").append(ref).append(","); - sb.append(" products:").append(products); + sb.append(" products:").append(products).append(","); + sb.append(" ref:").append(ref); sb.append("}"); return sb.toString(); } - private void validateRequiredAttributes() { boolean satisfiedCondition = true; if (!Objects.nonNull(this.ref)) { satisfiedCondition = false; - } else if (!Objects.nonNull(this.products)) { - satisfiedCondition = false; } if (!satisfiedCondition) { throw new ModelClassException("OrderLineDTO"); } } + } diff --git a/multiapi-engine/src/test/resources/asyncapigenerator/testFileGenerationWithKafkaBindings/assets/OrderLineMapper.java b/multiapi-engine/src/test/resources/asyncapigenerator/testFileGenerationWithKafkaBindings/assets/OrderLineMapper.java index 973fd697..224c312b 100644 --- a/multiapi-engine/src/test/resources/asyncapigenerator/testFileGenerationWithKafkaBindings/assets/OrderLineMapper.java +++ b/multiapi-engine/src/test/resources/asyncapigenerator/testFileGenerationWithKafkaBindings/assets/OrderLineMapper.java @@ -14,16 +14,15 @@ @JsonDeserialize(builder = OrderLineMapper.OrderLineMapperBuilder.class) public class OrderLineMapper { + @JsonProperty(value ="products") + private List products; @JsonProperty(value ="ref") @NotNull private final String ref; - @JsonProperty(value ="products") - @NotNull - private final List products = new ArrayList(); private OrderLineMapper(OrderLineMapperBuilder builder) { + this.products = builder.products; this.ref = builder.ref; - this.products.addAll(builder.products); validateRequiredAttributes(); } @@ -35,14 +34,8 @@ public static OrderLineMapper.OrderLineMapperBuilder builder() { @JsonPOJOBuilder(buildMethodName = "build", withPrefix = "") public static class OrderLineMapperBuilder { - private String ref; - private List products = new ArrayList(); - - public OrderLineMapper.OrderLineMapperBuilder ref(String ref) { - this.ref = ref; - return this; - } + private String ref; public OrderLineMapper.OrderLineMapperBuilder products(List products) { if (!products.isEmpty()) { @@ -58,30 +51,30 @@ public OrderLineMapper.OrderLineMapperBuilder product(OrderProductMapper product return this; } + public OrderLineMapper.OrderLineMapperBuilder ref(String ref) { + this.ref = ref; + return this; + } + public OrderLineMapper build() { OrderLineMapper orderLineMapper = new OrderLineMapper(this); return orderLineMapper; } } - /** - * Get ref - * @return ref - */ + @Schema(name = "products", required = false) + public List getProducts() { + return products; + } + public void setProducts(List products) { + this.products = products; + } + @Schema(name = "ref", required = true) public String getRef() { return ref; } - /** - * Get products - * @return products - */ - @Schema(name = "products", required = true) - public List getProducts() { - return products; - } - @Override public boolean equals(Object o) { if (this == o) { @@ -91,36 +84,34 @@ public boolean equals(Object o) { return false; } OrderLineMapper orderLineMapper = (OrderLineMapper) o; - return Objects.equals(this.ref, orderLineMapper.ref) && Objects.equals(this.products, orderLineMapper.products); + return Objects.equals(this.products, orderLineMapper.products) && Objects.equals(this.ref, orderLineMapper.ref); } @Override public int hashCode() { - return Objects.hash(ref, products); + return Objects.hash(products, ref); } @Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append("OrderLineMapper{"); - sb.append(" ref:").append(ref).append(","); - sb.append(" products:").append(products); + sb.append(" products:").append(products).append(","); + sb.append(" ref:").append(ref); sb.append("}"); return sb.toString(); } - private void validateRequiredAttributes() { boolean satisfiedCondition = true; if (!Objects.nonNull(this.ref)) { satisfiedCondition = false; - } else if (!Objects.nonNull(this.products)) { - satisfiedCondition = false; } if (!satisfiedCondition) { throw new ModelClassException("OrderLineMapper"); } } + } diff --git a/multiapi-engine/src/test/resources/asyncapigenerator/testFileGenerationWithKafkaBindings/assets/OrderMapper.java b/multiapi-engine/src/test/resources/asyncapigenerator/testFileGenerationWithKafkaBindings/assets/OrderMapper.java index 6e948e73..e4782054 100644 --- a/multiapi-engine/src/test/resources/asyncapigenerator/testFileGenerationWithKafkaBindings/assets/OrderMapper.java +++ b/multiapi-engine/src/test/resources/asyncapigenerator/testFileGenerationWithKafkaBindings/assets/OrderMapper.java @@ -6,27 +6,27 @@ import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder; import com.fasterxml.jackson.annotation.JsonProperty; import io.swagger.v3.oas.annotations.media.Schema; -import java.math.BigDecimal; import java.util.List; import java.util.ArrayList; +import java.math.BigDecimal; @JsonDeserialize(builder = OrderMapper.OrderMapperBuilder.class) public class OrderMapper { - @JsonProperty(value ="ref") - private String ref; @JsonProperty(value ="clientRef") private String clientRef; @JsonProperty(value ="amount") private BigDecimal amount; @JsonProperty(value ="lines") - private List lines = new ArrayList(); + private List lines; + @JsonProperty(value ="ref") + private String ref; private OrderMapper(OrderMapperBuilder builder) { - this.ref = builder.ref; this.clientRef = builder.clientRef; this.amount = builder.amount; - this.lines.addAll(builder.lines); + this.lines = builder.lines; + this.ref = builder.ref; } @@ -37,18 +37,10 @@ public static OrderMapper.OrderMapperBuilder builder() { @JsonPOJOBuilder(buildMethodName = "build", withPrefix = "") public static class OrderMapperBuilder { - private String ref; - private String clientRef; - private BigDecimal amount; - private List lines = new ArrayList(); - - public OrderMapper.OrderMapperBuilder ref(String ref) { - this.ref = ref; - return this; - } + private String ref; public OrderMapper.OrderMapperBuilder clientRef(String clientRef) { this.clientRef = clientRef; @@ -74,28 +66,17 @@ public OrderMapper.OrderMapperBuilder line(OrderLineMapper line) { return this; } + public OrderMapper.OrderMapperBuilder ref(String ref) { + this.ref = ref; + return this; + } + public OrderMapper build() { OrderMapper orderMapper = new OrderMapper(this); return orderMapper; } } - /** - * Get ref - * @return ref - */ - @Schema(name = "ref", required = false) - public String getRef() { - return ref; - } - public void setRef(String ref) { - this.ref = ref; - } - - /** - * Get clientRef - * @return clientRef - */ @Schema(name = "clientRef", required = false) public String getClientRef() { return clientRef; @@ -104,10 +85,6 @@ public void setClientRef(String clientRef) { this.clientRef = clientRef; } - /** - * Get amount - * @return amount - */ @Schema(name = "amount", required = false) public BigDecimal getAmount() { return amount; @@ -116,10 +93,6 @@ public void setAmount(BigDecimal amount) { this.amount = amount; } - /** - * Get lines - * @return lines - */ @Schema(name = "lines", required = false) public List getLines() { return lines; @@ -128,6 +101,14 @@ public void setLines(List lines) { this.lines = lines; } + @Schema(name = "ref", required = false) + public String getRef() { + return ref; + } + public void setRef(String ref) { + this.ref = ref; + } + @Override public boolean equals(Object o) { if (this == o) { @@ -137,22 +118,22 @@ public boolean equals(Object o) { return false; } OrderMapper orderMapper = (OrderMapper) o; - return Objects.equals(this.ref, orderMapper.ref) && Objects.equals(this.clientRef, orderMapper.clientRef) && Objects.equals(this.amount, orderMapper.amount) && Objects.equals(this.lines, orderMapper.lines); + return Objects.equals(this.clientRef, orderMapper.clientRef) && Objects.equals(this.amount, orderMapper.amount) && Objects.equals(this.lines, orderMapper.lines) && Objects.equals(this.ref, orderMapper.ref); } @Override public int hashCode() { - return Objects.hash(ref, clientRef, amount, lines); + return Objects.hash(clientRef, amount, lines, ref); } @Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append("OrderMapper{"); - sb.append(" ref:").append(ref).append(","); sb.append(" clientRef:").append(clientRef).append(","); sb.append(" amount:").append(amount).append(","); - sb.append(" lines:").append(lines); + sb.append(" lines:").append(lines).append(","); + sb.append(" ref:").append(ref); sb.append("}"); return sb.toString(); } diff --git a/multiapi-engine/src/test/resources/asyncapigenerator/testFileGenerationWithKafkaBindings/assets/OrderProductDTO.java b/multiapi-engine/src/test/resources/asyncapigenerator/testFileGenerationWithKafkaBindings/assets/OrderProductDTO.java index 48385569..7bb3c5f3 100644 --- a/multiapi-engine/src/test/resources/asyncapigenerator/testFileGenerationWithKafkaBindings/assets/OrderProductDTO.java +++ b/multiapi-engine/src/test/resources/asyncapigenerator/testFileGenerationWithKafkaBindings/assets/OrderProductDTO.java @@ -12,9 +12,6 @@ @JsonDeserialize(builder = OrderProductDTO.OrderProductDTOBuilder.class) public class OrderProductDTO { - @JsonProperty(value ="ref") - @NotNull - private final String ref; @JsonProperty(value ="productRef") @NotNull private final String productRef; @@ -24,12 +21,15 @@ public class OrderProductDTO { @JsonProperty(value ="quantity") @NotNull private final String quantity; + @JsonProperty(value ="ref") + @NotNull + private final String ref; private OrderProductDTO(OrderProductDTOBuilder builder) { - this.ref = builder.ref; this.productRef = builder.productRef; this.price = builder.price; this.quantity = builder.quantity; + this.ref = builder.ref; validateRequiredAttributes(); } @@ -41,18 +41,10 @@ public static OrderProductDTO.OrderProductDTOBuilder builder() { @JsonPOJOBuilder(buildMethodName = "build", withPrefix = "") public static class OrderProductDTOBuilder { - private String ref; - private String productRef; - private String price; - private String quantity; - - public OrderProductDTO.OrderProductDTOBuilder ref(String ref) { - this.ref = ref; - return this; - } + private String ref; public OrderProductDTO.OrderProductDTOBuilder productRef(String productRef) { this.productRef = productRef; @@ -69,48 +61,37 @@ public OrderProductDTO.OrderProductDTOBuilder quantity(String quantity) { return this; } + public OrderProductDTO.OrderProductDTOBuilder ref(String ref) { + this.ref = ref; + return this; + } + public OrderProductDTO build() { OrderProductDTO orderProductDTO = new OrderProductDTO(this); return orderProductDTO; } } - /** - * Get ref - * @return ref - */ - @Schema(name = "ref", required = true) - public String getRef() { - return ref; - } - - /** - * Get productRef - * @return productRef - */ @Schema(name = "productRef", required = true) public String getProductRef() { return productRef; } - /** - * Get price - * @return price - */ @Schema(name = "price", required = true) public String getPrice() { return price; } - /** - * Get quantity - * @return quantity - */ @Schema(name = "quantity", required = true) public String getQuantity() { return quantity; } + @Schema(name = "ref", required = true) + public String getRef() { + return ref; + } + @Override public boolean equals(Object o) { if (this == o) { @@ -120,42 +101,42 @@ public boolean equals(Object o) { return false; } OrderProductDTO orderProductDTO = (OrderProductDTO) o; - return Objects.equals(this.ref, orderProductDTO.ref) && Objects.equals(this.productRef, orderProductDTO.productRef) && Objects.equals(this.price, orderProductDTO.price) && Objects.equals(this.quantity, orderProductDTO.quantity); + return Objects.equals(this.productRef, orderProductDTO.productRef) && Objects.equals(this.price, orderProductDTO.price) && Objects.equals(this.quantity, orderProductDTO.quantity) && Objects.equals(this.ref, orderProductDTO.ref); } @Override public int hashCode() { - return Objects.hash(ref, productRef, price, quantity); + return Objects.hash(productRef, price, quantity, ref); } @Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append("OrderProductDTO{"); - sb.append(" ref:").append(ref).append(","); sb.append(" productRef:").append(productRef).append(","); sb.append(" price:").append(price).append(","); - sb.append(" quantity:").append(quantity); + sb.append(" quantity:").append(quantity).append(","); + sb.append(" ref:").append(ref); sb.append("}"); return sb.toString(); } - private void validateRequiredAttributes() { boolean satisfiedCondition = true; - if (!Objects.nonNull(this.ref)) { - satisfiedCondition = false; - } else if (!Objects.nonNull(this.productRef)) { + if (!Objects.nonNull(this.productRef)) { satisfiedCondition = false; } else if (!Objects.nonNull(this.price)) { satisfiedCondition = false; } else if (!Objects.nonNull(this.quantity)) { satisfiedCondition = false; + } else if (!Objects.nonNull(this.ref)) { + satisfiedCondition = false; } if (!satisfiedCondition) { throw new ModelClassException("OrderProductDTO"); } } + } diff --git a/multiapi-engine/src/test/resources/asyncapigenerator/testFileGenerationWithKafkaBindings/assets/OrderProductMapper.java b/multiapi-engine/src/test/resources/asyncapigenerator/testFileGenerationWithKafkaBindings/assets/OrderProductMapper.java index 55d8e4f0..8505c097 100644 --- a/multiapi-engine/src/test/resources/asyncapigenerator/testFileGenerationWithKafkaBindings/assets/OrderProductMapper.java +++ b/multiapi-engine/src/test/resources/asyncapigenerator/testFileGenerationWithKafkaBindings/assets/OrderProductMapper.java @@ -12,9 +12,6 @@ @JsonDeserialize(builder = OrderProductMapper.OrderProductMapperBuilder.class) public class OrderProductMapper { - @JsonProperty(value ="ref") - @NotNull - private final String ref; @JsonProperty(value ="productRef") @NotNull private final String productRef; @@ -24,12 +21,15 @@ public class OrderProductMapper { @JsonProperty(value ="quantity") @NotNull private final String quantity; + @JsonProperty(value ="ref") + @NotNull + private final String ref; private OrderProductMapper(OrderProductMapperBuilder builder) { - this.ref = builder.ref; this.productRef = builder.productRef; this.price = builder.price; this.quantity = builder.quantity; + this.ref = builder.ref; validateRequiredAttributes(); } @@ -41,18 +41,10 @@ public static OrderProductMapper.OrderProductMapperBuilder builder() { @JsonPOJOBuilder(buildMethodName = "build", withPrefix = "") public static class OrderProductMapperBuilder { - private String ref; - private String productRef; - private String price; - private String quantity; - - public OrderProductMapper.OrderProductMapperBuilder ref(String ref) { - this.ref = ref; - return this; - } + private String ref; public OrderProductMapper.OrderProductMapperBuilder productRef(String productRef) { this.productRef = productRef; @@ -69,48 +61,37 @@ public OrderProductMapper.OrderProductMapperBuilder quantity(String quantity) { return this; } + public OrderProductMapper.OrderProductMapperBuilder ref(String ref) { + this.ref = ref; + return this; + } + public OrderProductMapper build() { OrderProductMapper orderProductMapper = new OrderProductMapper(this); return orderProductMapper; } } - /** - * Get ref - * @return ref - */ - @Schema(name = "ref", required = true) - public String getRef() { - return ref; - } - - /** - * Get productRef - * @return productRef - */ @Schema(name = "productRef", required = true) public String getProductRef() { return productRef; } - /** - * Get price - * @return price - */ @Schema(name = "price", required = true) public String getPrice() { return price; } - /** - * Get quantity - * @return quantity - */ @Schema(name = "quantity", required = true) public String getQuantity() { return quantity; } + @Schema(name = "ref", required = true) + public String getRef() { + return ref; + } + @Override public boolean equals(Object o) { if (this == o) { @@ -120,42 +101,42 @@ public boolean equals(Object o) { return false; } OrderProductMapper orderProductMapper = (OrderProductMapper) o; - return Objects.equals(this.ref, orderProductMapper.ref) && Objects.equals(this.productRef, orderProductMapper.productRef) && Objects.equals(this.price, orderProductMapper.price) && Objects.equals(this.quantity, orderProductMapper.quantity); + return Objects.equals(this.productRef, orderProductMapper.productRef) && Objects.equals(this.price, orderProductMapper.price) && Objects.equals(this.quantity, orderProductMapper.quantity) && Objects.equals(this.ref, orderProductMapper.ref); } @Override public int hashCode() { - return Objects.hash(ref, productRef, price, quantity); + return Objects.hash(productRef, price, quantity, ref); } @Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append("OrderProductMapper{"); - sb.append(" ref:").append(ref).append(","); sb.append(" productRef:").append(productRef).append(","); sb.append(" price:").append(price).append(","); - sb.append(" quantity:").append(quantity); + sb.append(" quantity:").append(quantity).append(","); + sb.append(" ref:").append(ref); sb.append("}"); return sb.toString(); } - private void validateRequiredAttributes() { boolean satisfiedCondition = true; - if (!Objects.nonNull(this.ref)) { - satisfiedCondition = false; - } else if (!Objects.nonNull(this.productRef)) { + if (!Objects.nonNull(this.productRef)) { satisfiedCondition = false; } else if (!Objects.nonNull(this.price)) { satisfiedCondition = false; } else if (!Objects.nonNull(this.quantity)) { satisfiedCondition = false; + } else if (!Objects.nonNull(this.ref)) { + satisfiedCondition = false; } if (!satisfiedCondition) { throw new ModelClassException("OrderProductMapper"); } } + } diff --git a/multiapi-engine/src/test/resources/asyncapigenerator/testFileGenerationWithKafkaBindings/assets/WaiterMapper.java b/multiapi-engine/src/test/resources/asyncapigenerator/testFileGenerationWithKafkaBindings/assets/WaiterMapper.java index 15912920..6cc3a71b 100644 --- a/multiapi-engine/src/test/resources/asyncapigenerator/testFileGenerationWithKafkaBindings/assets/WaiterMapper.java +++ b/multiapi-engine/src/test/resources/asyncapigenerator/testFileGenerationWithKafkaBindings/assets/WaiterMapper.java @@ -10,17 +10,17 @@ @JsonDeserialize(builder = WaiterMapper.WaiterMapperBuilder.class) public class WaiterMapper { - @JsonProperty(value ="ref") - private String ref; @JsonProperty(value ="timestamp") private String timestamp; @JsonProperty(value ="table") private String table; + @JsonProperty(value ="ref") + private String ref; private WaiterMapper(WaiterMapperBuilder builder) { - this.ref = builder.ref; this.timestamp = builder.timestamp; this.table = builder.table; + this.ref = builder.ref; } @@ -31,16 +31,9 @@ public static WaiterMapper.WaiterMapperBuilder builder() { @JsonPOJOBuilder(buildMethodName = "build", withPrefix = "") public static class WaiterMapperBuilder { - private String ref; - private String timestamp; - private String table; - - public WaiterMapper.WaiterMapperBuilder ref(String ref) { - this.ref = ref; - return this; - } + private String ref; public WaiterMapper.WaiterMapperBuilder timestamp(String timestamp) { this.timestamp = timestamp; @@ -52,28 +45,17 @@ public WaiterMapper.WaiterMapperBuilder table(String table) { return this; } + public WaiterMapper.WaiterMapperBuilder ref(String ref) { + this.ref = ref; + return this; + } + public WaiterMapper build() { WaiterMapper waiterMapper = new WaiterMapper(this); return waiterMapper; } } - /** - * Get ref - * @return ref - */ - @Schema(name = "ref", required = false) - public String getRef() { - return ref; - } - public void setRef(String ref) { - this.ref = ref; - } - - /** - * Get timestamp - * @return timestamp - */ @Schema(name = "timestamp", required = false) public String getTimestamp() { return timestamp; @@ -82,10 +64,6 @@ public void setTimestamp(String timestamp) { this.timestamp = timestamp; } - /** - * Get table - * @return table - */ @Schema(name = "table", required = false) public String getTable() { return table; @@ -94,6 +72,14 @@ public void setTable(String table) { this.table = table; } + @Schema(name = "ref", required = false) + public String getRef() { + return ref; + } + public void setRef(String ref) { + this.ref = ref; + } + @Override public boolean equals(Object o) { if (this == o) { @@ -103,21 +89,21 @@ public boolean equals(Object o) { return false; } WaiterMapper waiterMapper = (WaiterMapper) o; - return Objects.equals(this.ref, waiterMapper.ref) && Objects.equals(this.timestamp, waiterMapper.timestamp) && Objects.equals(this.table, waiterMapper.table); + return Objects.equals(this.timestamp, waiterMapper.timestamp) && Objects.equals(this.table, waiterMapper.table) && Objects.equals(this.ref, waiterMapper.ref); } @Override public int hashCode() { - return Objects.hash(ref, timestamp, table); + return Objects.hash(timestamp, table, ref); } @Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append("WaiterMapper{"); - sb.append(" ref:").append(ref).append(","); sb.append(" timestamp:").append(timestamp).append(","); - sb.append(" table:").append(table); + sb.append(" table:").append(table).append(","); + sb.append(" ref:").append(ref); sb.append("}"); return sb.toString(); } diff --git a/multiapi-engine/src/test/resources/asyncapigenerator/testIssueGeneration/assets/StatusMsgDTO.java b/multiapi-engine/src/test/resources/asyncapigenerator/testIssueGeneration/assets/StatusMsgDTO.java index 849c3884..37d1a919 100644 --- a/multiapi-engine/src/test/resources/asyncapigenerator/testIssueGeneration/assets/StatusMsgDTO.java +++ b/multiapi-engine/src/test/resources/asyncapigenerator/testIssueGeneration/assets/StatusMsgDTO.java @@ -51,6 +51,7 @@ public static class StatusMsgDTOBuilder { private Status status; private Integer clientId; + public StatusMsgDTO.StatusMsgDTOBuilder status(Status status) { this.status = status; return this; 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 f666c9a6..f053678d 100644 --- a/multiapi-engine/src/test/resources/asyncapigenerator/testIssueSimpleTypeGeneration/assets/StatusMsgDTO.java +++ b/multiapi-engine/src/test/resources/asyncapigenerator/testIssueSimpleTypeGeneration/assets/StatusMsgDTO.java @@ -51,6 +51,7 @@ public static class StatusMsgDTOBuilder { private Status status; private Object clientId; + public StatusMsgDTO.StatusMsgDTOBuilder status(Status status) { this.status = status; return this; diff --git a/multiapi-engine/src/test/resources/asyncapigenerator/testModelClassExceptionGeneration/assets/CreateOrderEventDTO.java b/multiapi-engine/src/test/resources/asyncapigenerator/testModelClassExceptionGeneration/assets/CreateOrderEventDTO.java index b4ac4df5..b190cc96 100644 --- a/multiapi-engine/src/test/resources/asyncapigenerator/testModelClassExceptionGeneration/assets/CreateOrderEventDTO.java +++ b/multiapi-engine/src/test/resources/asyncapigenerator/testModelClassExceptionGeneration/assets/CreateOrderEventDTO.java @@ -30,10 +30,12 @@ public static class CreateOrderEventDTOBuilder { private WaiterDTO waiter; private OrderDTO order; + public CreateOrderEventDTO.CreateOrderEventDTOBuilder waiter(WaiterDTO waiter) { this.waiter = waiter; return this; } + public CreateOrderEventDTO.CreateOrderEventDTOBuilder order(OrderDTO order) { this.order = order; return this; diff --git a/multiapi-engine/src/test/resources/asyncapigenerator/testModelClassExceptionGeneration/assets/OrderDTO.java b/multiapi-engine/src/test/resources/asyncapigenerator/testModelClassExceptionGeneration/assets/OrderDTO.java index 0fda2f26..1fe72eb0 100644 --- a/multiapi-engine/src/test/resources/asyncapigenerator/testModelClassExceptionGeneration/assets/OrderDTO.java +++ b/multiapi-engine/src/test/resources/asyncapigenerator/testModelClassExceptionGeneration/assets/OrderDTO.java @@ -17,7 +17,7 @@ public class OrderDTO { @JsonProperty(value ="amount") private String amount; @JsonProperty(value ="lines") - private List lines = new ArrayList(); + private List lines; @JsonProperty(value ="ref") private String ref; @@ -50,6 +50,7 @@ public OrderDTO.OrderDTOBuilder amount(String amount) { this.amount = amount; return this; } + public OrderDTO.OrderDTOBuilder lines(List lines) { if (!lines.isEmpty()) { this.lines.addAll(lines); diff --git a/multiapi-engine/src/test/resources/asyncapigenerator/testModelClassExceptionGeneration/assets/OrderLineDTO.java b/multiapi-engine/src/test/resources/asyncapigenerator/testModelClassExceptionGeneration/assets/OrderLineDTO.java index 6fff7b3a..86698206 100644 --- a/multiapi-engine/src/test/resources/asyncapigenerator/testModelClassExceptionGeneration/assets/OrderLineDTO.java +++ b/multiapi-engine/src/test/resources/asyncapigenerator/testModelClassExceptionGeneration/assets/OrderLineDTO.java @@ -15,7 +15,7 @@ public class OrderLineDTO { @JsonProperty(value ="products") - private List products = new ArrayList(); + private List products; @JsonProperty(value ="ref") @NotNull private final String ref; @@ -36,6 +36,7 @@ public static class OrderLineDTOBuilder { private List products = new ArrayList(); private String ref; + public OrderLineDTO.OrderLineDTOBuilder products(List products) { if (!products.isEmpty()) { this.products.addAll(products); diff --git a/multiapi-engine/src/test/resources/asyncapigenerator/testNestedObjectIssue/assets/payload/UserSignedUpPayload.java b/multiapi-engine/src/test/resources/asyncapigenerator/testNestedObjectIssue/assets/payload/UserSignedUpPayload.java index 6097e3b4..707930a5 100644 --- a/multiapi-engine/src/test/resources/asyncapigenerator/testNestedObjectIssue/assets/payload/UserSignedUpPayload.java +++ b/multiapi-engine/src/test/resources/asyncapigenerator/testNestedObjectIssue/assets/payload/UserSignedUpPayload.java @@ -43,6 +43,7 @@ public static class UserSignedUpPayloadBuilder { private String firstName; private String lastName; private LocalDateTime createdAt; + public UserSignedUpPayload.UserSignedUpPayloadBuilder someOtherObject(SomeOtherObject someOtherObject) { this.someOtherObject = someOtherObject; return this; 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 06a34063..8bac87e4 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 @@ -30,6 +30,7 @@ public static class UserSignedUpBuilder { private UserDetails details; private String id; + public UserSignedUp.UserSignedUpBuilder details(UserDetails details) { this.details = details; return this; diff --git a/multiapi-engine/src/test/resources/asyncapigenerator/testRareCharsGeneration/assets/CreateOrderDTO.java b/multiapi-engine/src/test/resources/asyncapigenerator/testRareCharsGeneration/assets/CreateOrderDTO.java index 8f6c91d9..1075ea0b 100644 --- a/multiapi-engine/src/test/resources/asyncapigenerator/testRareCharsGeneration/assets/CreateOrderDTO.java +++ b/multiapi-engine/src/test/resources/asyncapigenerator/testRareCharsGeneration/assets/CreateOrderDTO.java @@ -30,10 +30,12 @@ public static class CreateOrderDTOBuilder { private WaiterDTO waiter; private OrderDTO order; + public CreateOrderDTO.CreateOrderDTOBuilder waiter(WaiterDTO waiter) { this.waiter = waiter; return this; } + public CreateOrderDTO.CreateOrderDTOBuilder order(OrderDTO order) { this.order = order; return this; diff --git a/multiapi-engine/src/test/resources/asyncapigenerator/testRareCharsGeneration/assets/OrderDTO.java b/multiapi-engine/src/test/resources/asyncapigenerator/testRareCharsGeneration/assets/OrderDTO.java index 270a63c8..ee949f5e 100644 --- a/multiapi-engine/src/test/resources/asyncapigenerator/testRareCharsGeneration/assets/OrderDTO.java +++ b/multiapi-engine/src/test/resources/asyncapigenerator/testRareCharsGeneration/assets/OrderDTO.java @@ -71,6 +71,7 @@ public OrderDTO.OrderDTOBuilder amount(BigDecimal amount) { this.amount = amount; return this; } + public OrderDTO.OrderDTOBuilder _new(New new) { this._new = _new; return this; diff --git a/multiapi-engine/src/test/resources/asyncapigenerator/testReservedWordsGeneration/assets/CreateOrderDTO.java b/multiapi-engine/src/test/resources/asyncapigenerator/testReservedWordsGeneration/assets/CreateOrderDTO.java index 822a7584..da6710ef 100644 --- a/multiapi-engine/src/test/resources/asyncapigenerator/testReservedWordsGeneration/assets/CreateOrderDTO.java +++ b/multiapi-engine/src/test/resources/asyncapigenerator/testReservedWordsGeneration/assets/CreateOrderDTO.java @@ -30,10 +30,12 @@ public static class CreateOrderDTOBuilder { private WaiterDTO waiter; private OrderDTO order; + public CreateOrderDTO.CreateOrderDTOBuilder waiter(WaiterDTO waiter) { this.waiter = waiter; return this; } + public CreateOrderDTO.CreateOrderDTOBuilder order(OrderDTO order) { this.order = order; return this; diff --git a/multiapi-engine/src/test/resources/asyncapigenerator/testReservedWordsGeneration/assets/OrderDTO.java b/multiapi-engine/src/test/resources/asyncapigenerator/testReservedWordsGeneration/assets/OrderDTO.java index a28deef0..6f4a9b30 100644 --- a/multiapi-engine/src/test/resources/asyncapigenerator/testReservedWordsGeneration/assets/OrderDTO.java +++ b/multiapi-engine/src/test/resources/asyncapigenerator/testReservedWordsGeneration/assets/OrderDTO.java @@ -18,7 +18,7 @@ public class OrderDTO { @JsonProperty(value ="amount") private BigDecimal amount; @JsonProperty(value ="_new") - private List _new = new ArrayList(); + private List _new; @JsonProperty(value ="ref") private String ref; @@ -51,6 +51,7 @@ public OrderDTO.OrderDTOBuilder amount(BigDecimal amount) { this.amount = amount; return this; } + public OrderDTO.OrderDTOBuilder _new(List _new) { if (!_new.isEmpty()) { this._new.addAll(_new); diff --git a/multiapi-engine/src/test/resources/asyncapigenerator/testReservedWordsGeneration/assets/OrderLineDTO.java b/multiapi-engine/src/test/resources/asyncapigenerator/testReservedWordsGeneration/assets/OrderLineDTO.java index dc0972f5..f5b80feb 100644 --- a/multiapi-engine/src/test/resources/asyncapigenerator/testReservedWordsGeneration/assets/OrderLineDTO.java +++ b/multiapi-engine/src/test/resources/asyncapigenerator/testReservedWordsGeneration/assets/OrderLineDTO.java @@ -16,7 +16,7 @@ public class OrderLineDTO { @JsonProperty(value ="_continue") - private List _continue = new ArrayList(); + private List _continue; @JsonProperty(value ="_byte") @NotNull private final BigDecimal _byte; @@ -37,6 +37,7 @@ public static class OrderLineDTOBuilder { private List _continue = new ArrayList(); private BigDecimal _byte; + public OrderLineDTO.OrderLineDTOBuilder _continue(List _continue) { if (!_continue.isEmpty()) { this._continue.addAll(_continue); diff --git a/multiapi-engine/src/test/resources/asyncapigenerator/testSubObjectSameName/assets/input/model/Input.java b/multiapi-engine/src/test/resources/asyncapigenerator/testSubObjectSameName/assets/input/model/Input.java index 5a2498a2..dc75e3ef 100644 --- a/multiapi-engine/src/test/resources/asyncapigenerator/testSubObjectSameName/assets/input/model/Input.java +++ b/multiapi-engine/src/test/resources/asyncapigenerator/testSubObjectSameName/assets/input/model/Input.java @@ -50,10 +50,12 @@ public static class InputBuilder { private Source source; private Data data; + public Input.InputBuilder source(Source source) { this.source = source; return this; } + public Input.InputBuilder data(Data data) { this.data = data; return this; diff --git a/multiapi-engine/src/test/resources/asyncapigenerator/testSubObjectSameName/assets/output/model/Output.java b/multiapi-engine/src/test/resources/asyncapigenerator/testSubObjectSameName/assets/output/model/Output.java index efa5c77f..555df75a 100644 --- a/multiapi-engine/src/test/resources/asyncapigenerator/testSubObjectSameName/assets/output/model/Output.java +++ b/multiapi-engine/src/test/resources/asyncapigenerator/testSubObjectSameName/assets/output/model/Output.java @@ -74,14 +74,17 @@ public static class OutputBuilder { private Type type; private Source source; private Data data; + public Output.OutputBuilder type(Type type) { this.type = type; return this; } + public Output.OutputBuilder source(Source source) { this.source = source; return this; } + public Output.OutputBuilder data(Data data) { this.data = data; return this; From 035893c18d20f5844473aa200911750398e5de1f Mon Sep 17 00:00:00 2001 From: "joseenrique.garcia" Date: Tue, 20 Aug 2024 23:37:57 +0200 Subject: [PATCH 05/26] Fix AsyncApi Schema Generator --- .../template/ClasspathTemplateLoader.java | 10 +- .../asyncapi/template/TemplateFactory.java | 32 +++-- .../template/TemplateIndexConstants.java | 44 ++++-- .../plugin/common/tools/ModelBuilder.java | 11 +- .../template/TemplateIndexConstants.java | 8 +- .../templates/asyncapi/templateSchema.ftlh | 135 +++++++++++------- .../templateMaxBigDecimal.ftlh | 18 +++ .../templateMaxBigDecimalValidator.ftlh | 25 ++++ .../customannotations/templateMaxDouble.ftlh | 18 +++ .../templateMaxDoubleValidator.ftlh | 24 ++++ ...templateMax.ftlh => templateMaxFloat.ftlh} | 4 +- .../templateMaxFloatValidator.ftlh | 24 ++++ .../customannotations/templateMaxInteger.ftlh | 18 +++ .../templateMaxIntegerValidator.ftlh | 24 ++++ .../templateMaxValidator.ftlh | 81 ----------- .../templateMaxValidatorAsync.ftlh | 81 ----------- .../templateMinBigDecimal.ftlh | 18 +++ .../templateMinBigDecimalValidator.ftlh | 25 ++++ .../customannotations/templateMinDouble.ftlh | 18 +++ .../templateMinDoubleValidator.ftlh | 24 ++++ ...templateMin.ftlh => templateMinFloat.ftlh} | 4 +- .../templateMinFloatValidator.ftlh | 24 ++++ .../customannotations/templateMinInteger.ftlh | 18 +++ .../templateMinIntegerValidator.ftlh | 24 ++++ .../templateMinValidator.ftlh | 82 ----------- .../templateMinValidatorAsync.ftlh | 81 ----------- .../templateMultipleOfValidatorAsync.ftlh | 83 ----------- .../asyncapi/AsyncApiGeneratorFixtures.java | 20 ++- .../openapi/OpenApiGeneratorFixtures.java | 2 +- .../testCustomValidators/assets/DataDTO.java | 57 +++++--- .../assets/StatusMsgDTO.java | 53 +++---- .../customvalidator/javax/MaxBigDecimal.java | 18 +++ .../javax/MaxBigDecimalValidator.java | 25 ++++ .../customvalidator/javax/MaxDouble.java | 18 +++ .../javax/MaxDoubleValidator.java | 24 ++++ .../customvalidator/javax/MaxFloat.java | 18 +++ .../javax/MaxFloatValidator.java | 24 ++++ .../customvalidator/javax/MaxInteger.java | 18 +++ .../javax/MaxIntegerValidator.java | 24 ++++ .../customvalidator/javax/MinBigDecimal.java | 18 +++ .../javax/MinBigDecimalValidator.java | 25 ++++ .../customvalidator/javax/MinDouble.java | 18 +++ .../javax/MinDoubleValidator.java | 24 ++++ .../javax/{Min.java => MinFloat.java} | 4 +- .../javax/MinFloatValidator.java | 24 ++++ .../customvalidator/javax/MinInteger.java | 18 +++ .../javax/MinIntegerValidator.java | 24 ++++ .../assets/ConfigurationDTO.java | 4 - .../assets/MailRequestDTO.java | 60 +++----- .../assets/ConfigDTO.java | 4 - .../assets/MailRequestInfiniteDTO.java | 4 +- 51 files changed, 872 insertions(+), 614 deletions(-) create mode 100644 multiapi-engine/src/main/resources/templates/customannotations/templateMaxBigDecimal.ftlh create mode 100644 multiapi-engine/src/main/resources/templates/customannotations/templateMaxBigDecimalValidator.ftlh create mode 100644 multiapi-engine/src/main/resources/templates/customannotations/templateMaxDouble.ftlh create mode 100644 multiapi-engine/src/main/resources/templates/customannotations/templateMaxDoubleValidator.ftlh rename multiapi-engine/src/main/resources/templates/customannotations/{templateMax.ftlh => templateMaxFloat.ftlh} (86%) create mode 100644 multiapi-engine/src/main/resources/templates/customannotations/templateMaxFloatValidator.ftlh create mode 100644 multiapi-engine/src/main/resources/templates/customannotations/templateMaxInteger.ftlh create mode 100644 multiapi-engine/src/main/resources/templates/customannotations/templateMaxIntegerValidator.ftlh delete mode 100644 multiapi-engine/src/main/resources/templates/customannotations/templateMaxValidator.ftlh delete mode 100644 multiapi-engine/src/main/resources/templates/customannotations/templateMaxValidatorAsync.ftlh create mode 100644 multiapi-engine/src/main/resources/templates/customannotations/templateMinBigDecimal.ftlh create mode 100644 multiapi-engine/src/main/resources/templates/customannotations/templateMinBigDecimalValidator.ftlh create mode 100644 multiapi-engine/src/main/resources/templates/customannotations/templateMinDouble.ftlh create mode 100644 multiapi-engine/src/main/resources/templates/customannotations/templateMinDoubleValidator.ftlh rename multiapi-engine/src/main/resources/templates/customannotations/{templateMin.ftlh => templateMinFloat.ftlh} (86%) create mode 100644 multiapi-engine/src/main/resources/templates/customannotations/templateMinFloatValidator.ftlh create mode 100644 multiapi-engine/src/main/resources/templates/customannotations/templateMinInteger.ftlh create mode 100644 multiapi-engine/src/main/resources/templates/customannotations/templateMinIntegerValidator.ftlh delete mode 100644 multiapi-engine/src/main/resources/templates/customannotations/templateMinValidator.ftlh delete mode 100644 multiapi-engine/src/main/resources/templates/customannotations/templateMinValidatorAsync.ftlh delete mode 100644 multiapi-engine/src/main/resources/templates/customannotations/templateMultipleOfValidatorAsync.ftlh create mode 100644 multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/javax/MaxBigDecimal.java create mode 100644 multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/javax/MaxBigDecimalValidator.java create mode 100644 multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/javax/MaxDouble.java create mode 100644 multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/javax/MaxDoubleValidator.java create mode 100644 multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/javax/MaxFloat.java create mode 100644 multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/javax/MaxFloatValidator.java create mode 100644 multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/javax/MaxInteger.java create mode 100644 multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/javax/MaxIntegerValidator.java create mode 100644 multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/javax/MinBigDecimal.java create mode 100644 multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/javax/MinBigDecimalValidator.java create mode 100644 multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/javax/MinDouble.java create mode 100644 multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/javax/MinDoubleValidator.java rename multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/javax/{Min.java => MinFloat.java} (86%) create mode 100644 multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/javax/MinFloatValidator.java create mode 100644 multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/javax/MinInteger.java create mode 100644 multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/javax/MinIntegerValidator.java diff --git a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/asyncapi/template/ClasspathTemplateLoader.java b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/asyncapi/template/ClasspathTemplateLoader.java index 7da369b3..6c27659a 100644 --- a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/asyncapi/template/ClasspathTemplateLoader.java +++ b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/asyncapi/template/ClasspathTemplateLoader.java @@ -29,8 +29,14 @@ public class ClasspathTemplateLoader implements TemplateLoader { private static final List TEMPLATE_ANNOTATION_FILES = List.of(TemplateIndexConstants.TEMPLATE_NOT_NULL_ANNOTATION, TemplateIndexConstants.TEMPLATE_NOT_NULL_VALIDATOR_ANNOTATION, - TemplateIndexConstants.TEMPLATE_MAX_ANNOTATION, TemplateIndexConstants.TEMPLATE_MAX_VALIDATOR_ANNOTATION, - TemplateIndexConstants.TEMPLATE_MIN_ANNOTATION, TemplateIndexConstants.TEMPLATE_MIN_VALIDATOR_ANNOTATION, + TemplateIndexConstants.TEMPLATE_MAX_INTEGER_ANNOTATION, TemplateIndexConstants.TEMPLATE_MAX_INTEGER_VALIDATOR_ANNOTATION, + TemplateIndexConstants.TEMPLATE_MAX_BIG_DECIMAL_ANNOTATION, TemplateIndexConstants.TEMPLATE_MAX_BIG_DECIMAL_VALIDATOR_ANNOTATION, + TemplateIndexConstants.TEMPLATE_MAX_DOUBLE_ANNOTATION, TemplateIndexConstants.TEMPLATE_MAX_DOUBLE_VALIDATOR_ANNOTATION, + TemplateIndexConstants.TEMPLATE_MAX_FLOAT_ANNOTATION, TemplateIndexConstants.TEMPLATE_MAX_FLOAT_VALIDATOR_ANNOTATION, + TemplateIndexConstants.TEMPLATE_MIN_INTEGER_ANNOTATION, TemplateIndexConstants.TEMPLATE_MIN_INTEGER_VALIDATOR_ANNOTATION, + TemplateIndexConstants.TEMPLATE_MIN_DOUBLE_ANNOTATION, TemplateIndexConstants.TEMPLATE_MIN_DOUBLE_VALIDATOR_ANNOTATION, + TemplateIndexConstants.TEMPLATE_MIN_FLOAT_ANNOTATION, TemplateIndexConstants.TEMPLATE_MIN_FLOAT_VALIDATOR_ANNOTATION, + TemplateIndexConstants.TEMPLATE_MIN_BIG_DECIMAL_ANNOTATION, TemplateIndexConstants.TEMPLATE_MIN_BIG_DECIMAL_VALIDATOR_ANNOTATION, TemplateIndexConstants.TEMPLATE_SIZE_ANNOTATION, TemplateIndexConstants.TEMPLATE_SIZE_VALIDATOR_ANNOTATION, TemplateIndexConstants.TEMPLATE_PATTERN_ANNOTATION, TemplateIndexConstants.TEMPLATE_PATTERN_VALIDATOR_ANNOTATION, 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 46a054a2..23fc59e4 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 @@ -27,7 +27,6 @@ import com.sngular.api.generator.plugin.common.model.SchemaFieldObject; import com.sngular.api.generator.plugin.common.model.SchemaObject; import com.sngular.api.generator.plugin.common.tools.MapperUtil; -import com.sngular.api.generator.plugin.exception.GeneratorTemplateException; import freemarker.template.Configuration; import freemarker.template.Template; import freemarker.template.TemplateException; @@ -121,22 +120,15 @@ public final void fillTemplates(final boolean generateExceptionTemplate) throws exceptionPackage = null; } - final HashSet propertiesSet = new HashSet<>(); schemaObjectMap.forEach(classTemplate -> { try { - propertiesSet.addAll(fillTemplateSchema(classTemplate, false, exceptionPackage)); + fillTemplates(classTemplate.getPropertiesPath(), classTemplate.getModelPackage(), + fillTemplateSchema(classTemplate, false, exceptionPackage)); } catch (final IOException | TemplateException exception) { throw new FileSystemException(exception); } }); - if (!schemaObjectMap.isEmpty()) { - try { - fillTemplates(schemaObjectMap.get(0).getPropertiesPath(), schemaObjectMap.get(0).getModelPackage(), propertiesSet); - } catch (IOException | TemplateException e) { - throw new GeneratorTemplateException("Generation Error", e); - } - } this.generateInterfaces(); } @@ -157,12 +149,24 @@ private void fillTemplates(final Path filePathToSave, final String modelPackage, "MultipleOfValidator.java", TemplateIndexConstants.TEMPLATE_MULTIPLEOF_VALIDATOR_ANNOTATION); break; case "Maximum": - fillTemplateCustom(filePathToSave, modelPackage, "Max.java", TemplateIndexConstants.TEMPLATE_MAX_ANNOTATION, - "MaxValidator.java", TemplateIndexConstants.TEMPLATE_MAX_VALIDATOR_ANNOTATION); + fillTemplateCustom(filePathToSave, modelPackage, "MaxInteger.java", TemplateIndexConstants.TEMPLATE_MAX_INTEGER_ANNOTATION, + "MaxIntegerValidator.java", TemplateIndexConstants.TEMPLATE_MAX_INTEGER_VALIDATOR_ANNOTATION); + fillTemplateCustom(filePathToSave, modelPackage, "MaxBigDecimal.java", TemplateIndexConstants.TEMPLATE_MAX_BIG_DECIMAL_ANNOTATION, + "MaxBigDecimalValidator.java", TemplateIndexConstants.TEMPLATE_MAX_BIG_DECIMAL_VALIDATOR_ANNOTATION); + fillTemplateCustom(filePathToSave, modelPackage, "MaxDouble.java", TemplateIndexConstants.TEMPLATE_MAX_DOUBLE_ANNOTATION, + "MaxDoubleValidator.java", TemplateIndexConstants.TEMPLATE_MAX_DOUBLE_VALIDATOR_ANNOTATION); + fillTemplateCustom(filePathToSave, modelPackage, "MaxFloat.java", TemplateIndexConstants.TEMPLATE_MAX_FLOAT_ANNOTATION, + "MaxFloatValidator.java", TemplateIndexConstants.TEMPLATE_MAX_FLOAT_VALIDATOR_ANNOTATION); break; case "Minimum": - fillTemplateCustom(filePathToSave, modelPackage, "Min.java", TemplateIndexConstants.TEMPLATE_MIN_ANNOTATION, - "MinValidator.java", TemplateIndexConstants.TEMPLATE_MIN_VALIDATOR_ANNOTATION); + fillTemplateCustom(filePathToSave, modelPackage, "MinInteger.java", TemplateIndexConstants.TEMPLATE_MIN_INTEGER_ANNOTATION, + "MinIntegerValidator.java", TemplateIndexConstants.TEMPLATE_MIN_INTEGER_VALIDATOR_ANNOTATION); + fillTemplateCustom(filePathToSave, modelPackage, "MinDouble.java", TemplateIndexConstants.TEMPLATE_MIN_DOUBLE_ANNOTATION, + "MinDoubleValidator.java", TemplateIndexConstants.TEMPLATE_MIN_DOUBLE_VALIDATOR_ANNOTATION); + fillTemplateCustom(filePathToSave, modelPackage, "MinFloat.java", TemplateIndexConstants.TEMPLATE_MIN_FLOAT_ANNOTATION, + "MinFloatValidator.java", TemplateIndexConstants.TEMPLATE_MIN_FLOAT_VALIDATOR_ANNOTATION); + fillTemplateCustom(filePathToSave, modelPackage, "MinBigDecimal.java", TemplateIndexConstants.TEMPLATE_MIN_BIG_DECIMAL_ANNOTATION, + "MinBigDecimalValidator.java", TemplateIndexConstants.TEMPLATE_MIN_BIG_DECIMAL_VALIDATOR_ANNOTATION); break; case "MaxItems": fillTemplateCustom(filePathToSave, modelPackage, "MaxItems.java", TemplateIndexConstants.TEMPLATE_MAX_ITEMS_ANNOTATION, diff --git a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/asyncapi/template/TemplateIndexConstants.java b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/asyncapi/template/TemplateIndexConstants.java index fe83b7e3..0212f10c 100644 --- a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/asyncapi/template/TemplateIndexConstants.java +++ b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/asyncapi/template/TemplateIndexConstants.java @@ -16,35 +16,49 @@ public class TemplateIndexConstants { public static final String TEMPLATE_API_SUPPLIERS = "templateSuppliers.ftlh"; - public static final String TEMPLATE_API_SUPPLIERS_WITH_KAFKA_BINDINGS = "templateSuppliersWithKafkaBindings.ftlh"; - public static final String TEMPLATE_API_CONSUMERS = "templateConsumers.ftlh"; - public static final String TEMPLATE_API_CONSUMERS_WITH_KAFKA_BINDINGS = "templateConsumersWithKafkaBindings.ftlh"; - public static final String TEMPLATE_API_STREAM_BRIDGE = "templateStreamBridge.ftlh"; - public static final String TEMPLATE_API_STREAM_BRIDGE_WITH_KAFKA_BINDINGS = "templateStreamBridgeWithKafkaBindings.ftlh"; - public static final String TEMPLATE_INTERFACE_SUPPLIERS = "interfaceSupplier.ftlh"; - public static final String TEMPLATE_INTERFACE_SUPPLIERS_WITH_KAFKA_BINDINGS = "interfaceSupplierWithKafkaBindings.ftlh"; - public static final String TEMPLATE_INTERFACE_CONSUMERS = "interfaceConsumer.ftlh"; - public static final String TEMPLATE_INTERFACE_CONSUMERS_WITH_KAFKA_BINDINGS = "interfaceConsumerWithKafkaBindings.ftlh"; - public static final String TEMPLATE_NOT_NULL_ANNOTATION = "templateNotNull.ftlh"; public static final String TEMPLATE_NOT_NULL_VALIDATOR_ANNOTATION = "templateNotNullValidator.ftlh"; - public static final String TEMPLATE_MIN_ANNOTATION = "templateMin.ftlh"; + public static final String TEMPLATE_MIN_INTEGER_ANNOTATION = "templateMinInteger.ftlh"; + + public static final String TEMPLATE_MIN_INTEGER_VALIDATOR_ANNOTATION = "templateMinIntegerValidator.ftlh"; + + public static final String TEMPLATE_MIN_BIG_DECIMAL_ANNOTATION = "templateMinBigDecimal.ftlh"; + + public static final String TEMPLATE_MIN_BIG_DECIMAL_VALIDATOR_ANNOTATION = "templateMinBigDecimalValidator.ftlh"; + + public static final String TEMPLATE_MIN_DOUBLE_ANNOTATION = "templateMinDouble.ftlh"; + + public static final String TEMPLATE_MIN_DOUBLE_VALIDATOR_ANNOTATION = "templateMinDoubleValidator.ftlh"; + + public static final String TEMPLATE_MIN_FLOAT_ANNOTATION = "templateMinFloat.ftlh"; + + public static final String TEMPLATE_MIN_FLOAT_VALIDATOR_ANNOTATION = "templateMinFloatValidator.ftlh"; + + public static final String TEMPLATE_MAX_INTEGER_ANNOTATION = "templateMaxInteger.ftlh"; + + public static final String TEMPLATE_MAX_INTEGER_VALIDATOR_ANNOTATION = "templateMaxIntegerValidator.ftlh"; + + public static final String TEMPLATE_MAX_BIG_DECIMAL_ANNOTATION = "templateMaxBigDecimal.ftlh"; + + public static final String TEMPLATE_MAX_BIG_DECIMAL_VALIDATOR_ANNOTATION = "templateMaxBigDecimalValidator.ftlh"; + + public static final String TEMPLATE_MAX_DOUBLE_ANNOTATION = "templateMaxDouble.ftlh"; - public static final String TEMPLATE_MIN_VALIDATOR_ANNOTATION = "templateMinValidatorAsync.ftlh"; + public static final String TEMPLATE_MAX_DOUBLE_VALIDATOR_ANNOTATION = "templateMaxDoubleValidator.ftlh"; - public static final String TEMPLATE_MAX_ANNOTATION = "templateMax.ftlh"; + public static final String TEMPLATE_MAX_FLOAT_ANNOTATION = "templateMaxFloat.ftlh"; - public static final String TEMPLATE_MAX_VALIDATOR_ANNOTATION = "templateMaxValidatorAsync.ftlh"; + public static final String TEMPLATE_MAX_FLOAT_VALIDATOR_ANNOTATION = "templateMaxFloatValidator.ftlh"; public static final String TEMPLATE_SIZE_ANNOTATION = "templateSize.ftlh"; @@ -56,7 +70,7 @@ public class TemplateIndexConstants { public static final String TEMPLATE_MULTIPLEOF_ANNOTATION = "templateMultipleOf.ftlh"; - public static final String TEMPLATE_MULTIPLEOF_VALIDATOR_ANNOTATION = "templateMultipleOfValidatorAsync.ftlh"; + public static final String TEMPLATE_MULTIPLEOF_VALIDATOR_ANNOTATION = "templateMultipleOfValidator.ftlh"; public static final String TEMPLATE_MAX_ITEMS_ANNOTATION = "templateMaxItems.ftlh"; diff --git a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/tools/ModelBuilder.java b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/tools/ModelBuilder.java index ae4b040c..62d4c4c8 100644 --- a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/tools/ModelBuilder.java +++ b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/tools/ModelBuilder.java @@ -145,7 +145,7 @@ private static Set getFields(final String buildingSchema, fieldObjectArrayList.add(processEnumField(ApiTool.getName(schema), schema, specFile, ApiTool.getEnumValues(schema), schema)); } else if (ApiTool.hasRef(schema)) { final var refSchema = totalSchemas.get(MapperUtil.getRefSchemaKey(schema)); - ApiTool.getProperties(refSchema).forEachRemaining(processProperties(buildingSchema, totalSchemas, compositedSchemas, fieldObjectArrayList, specFile, schema, antiLoopList, + ApiTool.getProperties(refSchema).forEachRemaining(processProperties(buildingSchema, totalSchemas, compositedSchemas, fieldObjectArrayList, specFile, refSchema, antiLoopList, baseDir)); } else { fieldObjectArrayList.add(SchemaFieldObject.builder() @@ -281,10 +281,9 @@ private static SchemaFieldObject processStringProperty(final String propertyName final SchemaFieldObject field = SchemaFieldObject .builder() .baseName(propertyName) - .required(ApiTool.checkIfRequired(schema, propertyName)) + .required(ApiTool.checkIfRequired(schema, propertyName) || ApiTool.hasConst(schema)) .dataType(new SchemaFieldObjectType(resultingType)) .constValue(ApiTool.getConst(schema)) - .required(ApiTool.hasConst(schema)) .build(); addPropertiesToFieldObject(field, schema); return field; @@ -400,14 +399,14 @@ private static Set processObject( if (ObjectUtils.allNull(className, fieldName)) { ApiTool.getProperties(schema).forEachRemaining( processProperties("", totalSchemas, compositedSchemas, fieldObjectArrayList, specFile, schema, antiLoopList, baseDir)); - } else if (antiLoopList.contains(className)) { + } else if (antiLoopList.contains(className) && compositedSchemas.containsKey(className)) { fieldObjectArrayList .add(SchemaFieldObject .builder() .baseName(className) .dataType(SchemaFieldObjectType.fromTypeList(TypeConstants.OBJECT, MapperUtil.getPojoName(className, specFile))) .build()); - } else if (antiLoopList.contains(fieldName)) { + } else if (antiLoopList.contains(fieldName) && compositedSchemas.containsKey(className)) { fieldObjectArrayList .add(SchemaFieldObject .builder() @@ -493,7 +492,7 @@ private static List processAdditionalProperties( .baseName(fieldName) .dataType(SchemaFieldObjectType.fromTypeList(TypeConstants.MAP, type)) .constValue(getConst(addPropObj)) - .required(ApiTool.hasConst(addPropObj)) + .required(ApiTool.checkIfRequired(schema, fieldName) ||ApiTool.hasConst(addPropObj)) .build()); } diff --git a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/openapi/template/TemplateIndexConstants.java b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/openapi/template/TemplateIndexConstants.java index 233a8cf7..01ec3343 100644 --- a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/openapi/template/TemplateIndexConstants.java +++ b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/openapi/template/TemplateIndexConstants.java @@ -42,13 +42,13 @@ public class TemplateIndexConstants { public static final String TEMPLATE_NOT_NULL_VALIDATOR_ANNOTATION = "templateNotNullValidator.ftlh"; - public static final String TEMPLATE_MIN_ANNOTATION = "templateMin.ftlh"; + public static final String TEMPLATE_MIN_ANNOTATION = "templateMinInteger.ftlh"; - public static final String TEMPLATE_MIN_VALIDATOR_ANNOTATION = "templateMinValidator.ftlh"; + public static final String TEMPLATE_MIN_VALIDATOR_ANNOTATION = "templateMinIntegerValidator.ftlh"; - public static final String TEMPLATE_MAX_ANNOTATION = "templateMax.ftlh"; + public static final String TEMPLATE_MAX_ANNOTATION = "templateMaxInteger.ftlh"; - public static final String TEMPLATE_MAX_VALIDATOR_ANNOTATION = "templateMaxValidator.ftlh"; + public static final String TEMPLATE_MAX_VALIDATOR_ANNOTATION = "templateMaxDoubleValidator.ftlh"; public static final String TEMPLATE_SIZE_ANNOTATION = "templateSize.ftlh"; diff --git a/multiapi-engine/src/main/resources/templates/asyncapi/templateSchema.ftlh b/multiapi-engine/src/main/resources/templates/asyncapi/templateSchema.ftlh index 18018366..47344837 100644 --- a/multiapi-engine/src/main/resources/templates/asyncapi/templateSchema.ftlh +++ b/multiapi-engine/src/main/resources/templates/asyncapi/templateSchema.ftlh @@ -52,6 +52,28 @@ <#return '\"${value}\"'> +<#function calculateMaxAnnotation dataType> + <#if dataType.baseType?lower_case == "bigdecimal"> + <#return "@MaxBigDecimal" > + <#elseif dataType.baseType?lower_case == "integer"> + <#return "@MaxInteger" > + <#elseif dataType.baseType?lower_case == "float"> + <#return "@MaxFloat" > + <#elseif dataType.baseType?lower_case == "double"> + <#return "@MaxDouble" > + + +<#function calculateMinAnnotation dataType> + <#if dataType.baseType?lower_case == "bigdecimal"> + <#return "@MinBigDecimal" > + <#elseif dataType.baseType?lower_case == "integer"> + <#return "@MinInteger" > + <#elseif dataType.baseType?lower_case == "float"> + <#return "@MinFloat" > + <#elseif dataType.baseType?lower_case == "double"> + <#return "@MinDouble" > + + package ${packageModel}; import java.util.Objects; @@ -69,71 +91,74 @@ import io.swagger.v3.oas.annotations.media.Schema; <#list schema.importList as import> import ${import}; +<#assign visited = ""> <#list schema.fieldObjectList as field> - <#if field.restrictions.maxLength?has_content || field.restrictions.minLength?has_content> + <#if (field.restrictions.maxLength?has_content || field.restrictions.minLength?has_content) && !(visited?contains("size"))> + <#assign visited += "size," /> import ${packageModel}.customvalidator.Size; - <#break> + + <#if field.restrictions.maximum?has_content> + <#if field.dataType.baseType?lower_case == "bigdecimal" && !(visited?contains("maxBigDecimal"))> + <#assign visited += "maxBigDecimal," /> +import ${packageModel}.customvalidator.MaxBigDecimal; + <#elseif field.dataType.baseType?lower_case == "integer" && !(visited?contains("maxInteger"))> + <#assign visited += "maxInteger," /> +import ${packageModel}.customvalidator.MaxInteger; + <#elseif field.dataType.baseType?lower_case == "float" && !(visited?contains("maxFloat"))> + <#assign visited += "maxFloat," /> +import ${packageModel}.customvalidator.MaxFloat; + <#elseif field.dataType.baseType?lower_case == "double" && !(visited?contains("maxDouble"))> + <#assign visited += "maxDouble," /> +import ${packageModel}.customvalidator.MaxDouble; - -<#list schema.fieldObjectList as field> - <#if field.restrictions.maximum?has_content> -import ${packageModel}.customvalidator.Max; - <#break> + + <#if field.restrictions.minimum?has_content> + <#if field.dataType.baseType?lower_case == "bigdecimal" && !(visited?contains("minBigDecimal"))> + <#assign visited += "minBigDecimal," /> +import ${packageModel}.customvalidator.MinBigDecimal; + <#elseif field.dataType.baseType?lower_case == "integer" && !(visited?contains("minInteger"))> + <#assign visited += "minInteger," /> +import ${packageModel}.customvalidator.MinInteger; + <#elseif field.dataType.baseType?lower_case == "float" && !(visited?contains("minFloat"))> + <#assign visited += "minFloat," /> +import ${packageModel}.customvalidator.MinFloat; + <#elseif field.dataType.baseType?lower_case == "double" && !(visited?contains("minDouble"))> + <#assign visited += "minDouble," /> +import ${packageModel}.customvalidator.MinDouble; - -<#list schema.fieldObjectList as field> - <#if field.restrictions.minimum?has_content> -import ${packageModel}.customvalidator.Min; - <#break> - -<#list schema.fieldObjectList as field> - <#if field.restrictions.maxItems?has_content> + <#if field.restrictions.maxItems?has_content && !(visited?contains("maxItems"))> + <#assign visited += "maxItems," /> import ${packageModel}.customvalidator.MaxItems; - <#break> - -<#list schema.fieldObjectList as field> - <#if field.restrictions.minItems?has_content> + <#if field.restrictions.minItems?has_content && !(visited?contains("minItems"))> + <#assign visited += "minItems," /> import ${packageModel}.customvalidator.MinItems; - <#break> - -<#list schema.fieldObjectList as field> - <#if field.restrictions.format?has_content> + <#if field.restrictions.format?has_content && !(visited?contains("format"))> + <#assign visited += "format," /> import com.fasterxml.jackson.annotation.JsonFormat; - <#break> - -<#list schema.fieldObjectList as field> - <#if field.required || schema.schemaCombinator?has_content && (schema.schemaCombinator == "anyOf" || schema.schemaCombinator == "oneOf")> + <#if (field.required || schema.schemaCombinator?has_content && (schema.schemaCombinator == "anyOf" || schema.schemaCombinator == "oneOf")) && !(visited?contains("schemaCombinator"))> + <#assign visited += "schemaCombinator," /> import ${exceptionPackage}.exception.ModelClassException; - <#break> - -<#list schema.fieldObjectList as field> - <#if field.restrictions.pattern?has_content> + <#if field.restrictions.pattern?has_content && !(visited?contains("pattern"))> + <#assign visited += "pattern," /> import ${packageModel}.customvalidator.Pattern; - <#break> - - -<#list schema.fieldObjectList as field> - <#if field.restrictions.multipleOf?has_content> + + <#if field.restrictions.multipleOf?has_content && !(visited?contains("multipleOf"))> + <#assign visited += "multipleOf," /> import ${packageModel}.customvalidator.MultipleOf; - <#break> - - -<#list schema.fieldObjectList as field> - <#if field.required?has_content && field.required == true> + + <#if field.required?has_content && field.required == true && !(visited?contains("notNull"))> + <#assign visited += "notNull," /> import ${packageModel}.customvalidator.NotNull; - <#break> - -<#list schema.fieldObjectList as field> - <#if field.restrictions.uniqueItems?has_content && field.restrictions.uniqueItems == true> + <#if field.restrictions.uniqueItems?has_content && field.restrictions.uniqueItems == true && !(visited?contains("uniqueItems"))> + <#assign visited += "uniqueItems," /> import ${packageModel}.customvalidator.UniqueItems; - <#break> - + @JsonDeserialize(builder = ${schema.className}.${schema.className}Builder.class) @@ -141,17 +166,17 @@ public class ${schema.className} { <#list schema.fieldObjectList as field> @JsonProperty(value ="${calculateSafeName (field.baseName, "")}") - <#if field.restrictions.minimum?has_content && (!field.restrictions.exclusiveMinimum?has_content || field.restrictions.exclusiveMinimum == false)> - @Min(minimum = "${field.restrictions.minimum}", exclusive = false) + <#if field.restrictions.minimum?has_content && (!field.restrictions.exclusiveMinimum?has_content)> + ${calculateMinAnnotation (field.dataType)}(minimum = "${field.restrictions.minimum}", exclusive = false) - <#if field.restrictions.minimum?has_content && field.restrictions.exclusiveMinimum?has_content && field.restrictions.exclusiveMinimum == true> - @Min(minimum = "${field.restrictions.minimum}", exclusive = ${field.restrictions.exclusiveMinimum?string}) + <#if field.restrictions.minimum?has_content && field.restrictions.exclusiveMinimum?has_content> + ${calculateMinAnnotation (field.dataType)}(minimum = "${field.restrictions.minimum}", exclusive = ${field.restrictions.exclusiveMinimum?string}) - <#if field.restrictions.maximum?has_content && (!field.restrictions.exclusiveMaximum?has_content || field.restrictions.exclusiveMaximum == false)> - @Max(maximum = "${field.restrictions.maximum}", exclusive = false) + <#if field.restrictions.maximum?has_content && (!field.restrictions.exclusiveMaximum?has_content)> + ${calculateMaxAnnotation (field.dataType)}(maximum = "${field.restrictions.maximum}", exclusive = false) - <#if field.restrictions.maximum?has_content && field.restrictions.exclusiveMaximum?has_content && field.restrictions.exclusiveMaximum == true> - @Max(maximum = "${field.restrictions.maximum}", exclusive = ${field.restrictions.exclusiveMaximum?string}) + <#if field.restrictions.maximum?has_content && field.restrictions.exclusiveMaximum?has_content> + ${calculateMaxAnnotation (field.dataType)}(maximum = "${field.restrictions.maximum}", exclusive = ${field.restrictions.exclusiveMaximum?string}) <#if field.restrictions.maxItems?has_content> @MaxItems(maximum = ${field.restrictions.maxItems}) diff --git a/multiapi-engine/src/main/resources/templates/customannotations/templateMaxBigDecimal.ftlh b/multiapi-engine/src/main/resources/templates/customannotations/templateMaxBigDecimal.ftlh new file mode 100644 index 00000000..6c7246ee --- /dev/null +++ b/multiapi-engine/src/main/resources/templates/customannotations/templateMaxBigDecimal.ftlh @@ -0,0 +1,18 @@ +package ${packageModel}.customvalidator; + +import ${javaEEPackage}.validation.Constraint; +import ${javaEEPackage}.validation.Payload; +import java.lang.annotation.*; + +@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, +ElementType.ANNOTATION_TYPE}) +@Retention(RetentionPolicy.RUNTIME) +@Constraint(validatedBy = MaxBigDecimalValidator.class) +@Documented +public @interface MaxBigDecimal { + String maximum(); + boolean exclusive(); + String message() default "Value is bigger than the maximum."; + Class[] groups() default {}; + Class[] payload() default {}; +} \ No newline at end of file diff --git a/multiapi-engine/src/main/resources/templates/customannotations/templateMaxBigDecimalValidator.ftlh b/multiapi-engine/src/main/resources/templates/customannotations/templateMaxBigDecimalValidator.ftlh new file mode 100644 index 00000000..edb040bb --- /dev/null +++ b/multiapi-engine/src/main/resources/templates/customannotations/templateMaxBigDecimalValidator.ftlh @@ -0,0 +1,25 @@ +package ${packageModel}.customvalidator; + +import java.math.BigDecimal; +import java.util.Objects; + +import ${javaEEPackage}.validation.ConstraintValidator; +import ${javaEEPackage}.validation.ConstraintValidatorContext; + +public class MaxBigDecimalValidator implements ConstraintValidator { + + private BigDecimal maximum; + private boolean exclusive; + + @Override + public void initialize(MaxBigDecimal constraintAnnotation) { + ConstraintValidator.super.initialize(constraintAnnotation); + this.maximum = new BigDecimal(constraintAnnotation.maximum()); + this.exclusive = constraintAnnotation.exclusive(); + } + + @Override + public boolean isValid(BigDecimal value, ConstraintValidatorContext context) { + return Objects.isNull(value) || (value < this.maximum || (!exclusive && value == this.maximum)); + } +} \ No newline at end of file diff --git a/multiapi-engine/src/main/resources/templates/customannotations/templateMaxDouble.ftlh b/multiapi-engine/src/main/resources/templates/customannotations/templateMaxDouble.ftlh new file mode 100644 index 00000000..c1f0f088 --- /dev/null +++ b/multiapi-engine/src/main/resources/templates/customannotations/templateMaxDouble.ftlh @@ -0,0 +1,18 @@ +package ${packageModel}.customvalidator; + +import ${javaEEPackage}.validation.Constraint; +import ${javaEEPackage}.validation.Payload; +import java.lang.annotation.*; + +@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, +ElementType.ANNOTATION_TYPE}) +@Retention(RetentionPolicy.RUNTIME) +@Constraint(validatedBy = MaxDoubleValidator.class) +@Documented +public @interface MaxDouble { + String maximum(); + boolean exclusive(); + String message() default "Value is bigger than the maximum."; + Class[] groups() default {}; + Class[] payload() default {}; +} \ No newline at end of file diff --git a/multiapi-engine/src/main/resources/templates/customannotations/templateMaxDoubleValidator.ftlh b/multiapi-engine/src/main/resources/templates/customannotations/templateMaxDoubleValidator.ftlh new file mode 100644 index 00000000..99201613 --- /dev/null +++ b/multiapi-engine/src/main/resources/templates/customannotations/templateMaxDoubleValidator.ftlh @@ -0,0 +1,24 @@ +package ${packageModel}.customvalidator; + +import java.util.Objects; + +import ${javaEEPackage}.validation.ConstraintValidator; +import ${javaEEPackage}.validation.ConstraintValidatorContext; + +public class MaxDoubleValidator implements ConstraintValidator { + + private double maximum; + private boolean exclusive; + + @Override + public void initialize(MaxDouble constraintAnnotation) { + ConstraintValidator.super.initialize(constraintAnnotation); + this.maximum = Double.parseDouble(constraintAnnotation.maximum()); + this.exclusive = constraintAnnotation.exclusive(); + } + + @Override + public boolean isValid(Double value, ConstraintValidatorContext context) { + return Objects.isNull(value) || (value.doubleValue() < this.maximum || (!exclusive && value.doubleValue() == this.maximum)); + } +} \ No newline at end of file diff --git a/multiapi-engine/src/main/resources/templates/customannotations/templateMax.ftlh b/multiapi-engine/src/main/resources/templates/customannotations/templateMaxFloat.ftlh similarity index 86% rename from multiapi-engine/src/main/resources/templates/customannotations/templateMax.ftlh rename to multiapi-engine/src/main/resources/templates/customannotations/templateMaxFloat.ftlh index 96625d74..4364e4b1 100644 --- a/multiapi-engine/src/main/resources/templates/customannotations/templateMax.ftlh +++ b/multiapi-engine/src/main/resources/templates/customannotations/templateMaxFloat.ftlh @@ -7,9 +7,9 @@ import java.lang.annotation.*; @Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, ElementType.ANNOTATION_TYPE}) @Retention(RetentionPolicy.RUNTIME) -@Constraint(validatedBy = MaxValidator.class) +@Constraint(validatedBy = MaxFloatValidator.class) @Documented -public @interface Max { +public @interface MaxFloat { String maximum(); boolean exclusive(); String message() default "Value is bigger than the maximum."; diff --git a/multiapi-engine/src/main/resources/templates/customannotations/templateMaxFloatValidator.ftlh b/multiapi-engine/src/main/resources/templates/customannotations/templateMaxFloatValidator.ftlh new file mode 100644 index 00000000..7a533e4a --- /dev/null +++ b/multiapi-engine/src/main/resources/templates/customannotations/templateMaxFloatValidator.ftlh @@ -0,0 +1,24 @@ +package ${packageModel}.customvalidator; + +import java.util.Objects; + +import ${javaEEPackage}.validation.ConstraintValidator; +import ${javaEEPackage}.validation.ConstraintValidatorContext; + +public class MaxFloatValidator implements ConstraintValidator { + + private float maximum; + private boolean exclusive; + + @Override + public void initialize(MaxFloat constraintAnnotation) { + ConstraintValidator.super.initialize(constraintAnnotation); + this.maximum = Float.parseFloat(constraintAnnotation.maximum()); + this.exclusive = constraintAnnotation.exclusive(); + } + + @Override + public boolean isValid(Float value, ConstraintValidatorContext context) { + return Objects.isNull(value) || (value.floatValue() < this.maximum || (!exclusive && value.floatValue() == this.maximum)); + } +} \ No newline at end of file diff --git a/multiapi-engine/src/main/resources/templates/customannotations/templateMaxInteger.ftlh b/multiapi-engine/src/main/resources/templates/customannotations/templateMaxInteger.ftlh new file mode 100644 index 00000000..3c5ba709 --- /dev/null +++ b/multiapi-engine/src/main/resources/templates/customannotations/templateMaxInteger.ftlh @@ -0,0 +1,18 @@ +package ${packageModel}.customvalidator; + +import ${javaEEPackage}.validation.Constraint; +import ${javaEEPackage}.validation.Payload; +import java.lang.annotation.*; + +@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, +ElementType.ANNOTATION_TYPE}) +@Retention(RetentionPolicy.RUNTIME) +@Constraint(validatedBy = MaxIntegerValidator.class) +@Documented +public @interface MaxInteger { + String maximum(); + boolean exclusive(); + String message() default "Value is bigger than the maximum."; + Class[] groups() default {}; + Class[] payload() default {}; +} \ No newline at end of file diff --git a/multiapi-engine/src/main/resources/templates/customannotations/templateMaxIntegerValidator.ftlh b/multiapi-engine/src/main/resources/templates/customannotations/templateMaxIntegerValidator.ftlh new file mode 100644 index 00000000..8c5df224 --- /dev/null +++ b/multiapi-engine/src/main/resources/templates/customannotations/templateMaxIntegerValidator.ftlh @@ -0,0 +1,24 @@ +package ${packageModel}.customvalidator; + +import java.util.Objects; + +import ${javaEEPackage}.validation.ConstraintValidator; +import ${javaEEPackage}.validation.ConstraintValidatorContext; + +public class MaxIntegerValidator implements ConstraintValidator { + + private int maximum; + private boolean exclusive; + + @Override + public void initialize(MaxInteger constraintAnnotation) { + ConstraintValidator.super.initialize(constraintAnnotation); + this.maximum = Integer.parseInt(constraintAnnotation.maximum()); + this.exclusive = constraintAnnotation.exclusive(); + } + + @Override + public boolean isValid(Integer value, ConstraintValidatorContext context) { + return Objects.isNull(value) || (value.intValue() < this.maximum || (!exclusive && value.intValue() == this.maximum)); + } +} \ No newline at end of file diff --git a/multiapi-engine/src/main/resources/templates/customannotations/templateMaxValidator.ftlh b/multiapi-engine/src/main/resources/templates/customannotations/templateMaxValidator.ftlh deleted file mode 100644 index 042637d6..00000000 --- a/multiapi-engine/src/main/resources/templates/customannotations/templateMaxValidator.ftlh +++ /dev/null @@ -1,81 +0,0 @@ -package ${packageModel}.customvalidator; - -<#list schema.fieldObjectList as field> - <#if field.dataType.baseType?has_content && field.dataType.baseType == "BigDecimal"> -import java.math.BigDecimal; - - -import java.util.Objects; - -import ${javaEEPackage}.validation.ConstraintValidator; -import ${javaEEPackage}.validation.ConstraintValidatorContext; - -<#list schema.fieldObjectList as field> - <#if field.dataType.baseType?has_content && (field.dataType.baseType == "BigDecimal" || field.dataType.baseType == "bigDecimal")> -public class MaxValidator implements ConstraintValidator { - - private BigDecimal maximum; - <#break> - <#elseif field.dataType.baseType?has_content && (field.dataType.baseType == "Integer" || field.dataType.baseType == "integer")> -public class MaxValidator implements ConstraintValidator { - - private int maximum; - <#break> - <#elseif field.dataType.baseType?has_content && (field.dataType.baseType == "Float" || field.dataType.baseType == "float")> -public class MaxValidator implements ConstraintValidator { - - private float maximum; - <#break> - <#elseif field.dataType.baseType?has_content && (field.dataType.baseType == "Double" || field.dataType.baseType == "double")> -public class MaxValidator implements ConstraintValidator { - - private double maximum; - <#break> - - - private boolean exclusive; - - @Override - public void initialize(Max constraintAnnotation) { - ConstraintValidator.super.initialize(constraintAnnotation); -<#list schema.fieldObjectList as field> - <#if field.dataType.baseType?has_content && (field.dataType.baseType == "BigDecimal" || field.dataType.baseType == "bigDecimal")> - this.maximum = new BigDecimal(constraintAnnotation.maximum()); - <#break> - <#elseif field.dataType.baseType?has_content && (field.dataType.baseType == "Integer" || field.dataType.baseType == "integer")> - this.maximum = Integer.parseInt(constraintAnnotation.maximum()); - <#break> - <#elseif field.dataType.baseType?has_content && (field.dataType.baseType == "Float" || field.dataType.baseType == "float")> - this.maximum = Float.parseFloat(constraintAnnotation.maximum()); - <#break> - <#elseif field.dataType.baseType?has_content && (field.dataType.baseType == "Double" || field.dataType.baseType == "double")> - this.maximum = Double.parseDouble(constraintAnnotation.maximum()); - - - this.exclusive = constraintAnnotation.exclusive(); - } - - @Override -<#list schema.fieldObjectList as field> - <#if field.dataType.baseType?has_content && (field.dataType.baseType == "BigDecimal" || field.dataType.baseType == "bigDecimal")> - public boolean isValid(BigDecimal value, ConstraintValidatorContext context) { - return Objects.isNull(value) || (value < this.maximum || (!exclusive && value == this.maximum)); - } - <#break> - <#elseif field.dataType.baseType?has_content && (field.dataType.baseType == "Integer" || field.dataType.baseType == "integer")> - public boolean isValid(Integer value, ConstraintValidatorContext context) { - return Objects.isNull(value) || (value.intValue() < this.maximum || (!exclusive && value.intValue() == this.maximum)); - } - <#break> - <#elseif field.dataType.baseType?has_content && (field.dataType.baseType == "Float" || field.dataType.baseType == "float")> - public boolean isValid(Float value, ConstraintValidatorContext context) { - return Objects.isNull(value) || (value.floatValue() < this.maximum || (!exclusive && value.floatValue() == this.maximum)); - } - <#break> - <#elseif field.dataType.baseType?has_content && (field.dataType.baseType == "Double" || field.dataType.baseType == "double")> - public boolean isValid(Double value, ConstraintValidatorContext context) { - return Objects.isNull(value) || (value.doubleValue() < this.maximum || (!exclusive && value.doubleValue() == this.maximum)); - } - - -} \ No newline at end of file diff --git a/multiapi-engine/src/main/resources/templates/customannotations/templateMaxValidatorAsync.ftlh b/multiapi-engine/src/main/resources/templates/customannotations/templateMaxValidatorAsync.ftlh deleted file mode 100644 index e739d48f..00000000 --- a/multiapi-engine/src/main/resources/templates/customannotations/templateMaxValidatorAsync.ftlh +++ /dev/null @@ -1,81 +0,0 @@ -package ${packageModel}.customvalidator; - -<#list schema.fieldObjectList as field> - <#if field.dataTypeSimple?has_content && field.dataTypeSimple == "BigDecimal"> -import java.math.BigDecimal; - - -import java.util.Objects; - -import ${javaEEPackage}.validation.ConstraintValidator; -import ${javaEEPackage}.validation.ConstraintValidatorContext; - -<#list schema.fieldObjectList as field> - <#if field.dataTypeSimple?has_content && (field.dataTypeSimple == "BigDecimal" || field.dataTypeSimple == "bigDecimal")> -public class MaxValidator implements ConstraintValidator { - - private BigDecimal maximum; - <#break> - <#elseif field.dataTypeSimple?has_content && (field.dataTypeSimple == "Integer" || field.dataTypeSimple == "integer")> -public class MaxValidator implements ConstraintValidator { - - private int maximum; - <#break> - <#elseif field.dataTypeSimple?has_content && (field.dataTypeSimple == "Float" || field.dataTypeSimple == "float")> -public class MaxValidator implements ConstraintValidator { - - private float maximum; - <#break> - <#elseif field.dataTypeSimple?has_content && (field.dataTypeSimple == "Double" || field.dataTypeSimple == "double")> - public class MaxValidator implements ConstraintValidator { - - private double maximum; - <#break> - - - private boolean exclusive; - - @Override - public void initialize(Max constraintAnnotation) { - ConstraintValidator.super.initialize(constraintAnnotation); -<#list schema.fieldObjectList as field> - <#if field.dataTypeSimple?has_content && (field.dataTypeSimple == "BigDecimal" || field.dataTypeSimple == "bigDecimal")> - this.maximum = new BigDecimal(constraintAnnotation.maximum()); - <#break> - <#elseif field.dataTypeSimple?has_content && (field.dataTypeSimple == "Integer" || field.dataTypeSimple == "integer")> - this.maximum = Integer.parseInt(constraintAnnotation.maximum()); - <#break> - <#elseif field.dataTypeSimple?has_content && (field.dataTypeSimple == "Float" || field.dataTypeSimple == "float")> - this.maximum = Float.parseFloat(constraintAnnotation.maximum()); - <#break> - <#elseif field.dataTypeSimple?has_content && (field.dataTypeSimple == "Double" || field.dataTypeSimple == "double")> - this.maximum = Double.parseDouble(constraintAnnotation.maximum()); - - - this.exclusive = constraintAnnotation.exclusive(); - } - - @Override -<#list schema.fieldObjectList as field> - <#if field.dataTypeSimple?has_content && (field.dataTypeSimple == "BigDecimal" || field.dataTypeSimple == "bigDecimal")> - public boolean isValid(BigDecimal value, ConstraintValidatorContext context) { - return Objects.isNull(value) || (value < this.maximum || (!exclusive && value == this.maximum)); - } - <#break> - <#elseif field.dataTypeSimple?has_content && (field.dataTypeSimple == "Integer" || field.dataTypeSimple == "integer")> - public boolean isValid(Integer value, ConstraintValidatorContext context) { - return Objects.isNull(value) || (value.intValue() < this.maximum || (!exclusive && value.intValue() == this.maximum)); - } - <#break> - <#elseif field.dataTypeSimple?has_content && (field.dataTypeSimple == "Float" || field.dataTypeSimple == "float")> - public boolean isValid(Float value, ConstraintValidatorContext context) { - return Objects.isNull(value) || (value.floatValue() < this.maximum || (!exclusive && value.floatValue() == this.maximum)); - } - <#break> - <#elseif field.dataTypeSimple?has_content && (field.dataTypeSimple == "Double" || field.dataTypeSimple == "double")> - public boolean isValid(Double value, ConstraintValidatorContext context) { - return Objects.isNull(value) || (value.doubleValue() < this.maximum || (!exclusive && value.doubleValue() == this.maximum)); - } - - -} \ No newline at end of file diff --git a/multiapi-engine/src/main/resources/templates/customannotations/templateMinBigDecimal.ftlh b/multiapi-engine/src/main/resources/templates/customannotations/templateMinBigDecimal.ftlh new file mode 100644 index 00000000..a0cb4159 --- /dev/null +++ b/multiapi-engine/src/main/resources/templates/customannotations/templateMinBigDecimal.ftlh @@ -0,0 +1,18 @@ +package ${packageModel}.customvalidator; + +import ${javaEEPackage}.validation.Constraint; +import ${javaEEPackage}.validation.Payload; +import java.lang.annotation.*; + +@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, + ElementType.ANNOTATION_TYPE}) +@Retention(RetentionPolicy.RUNTIME) +@Constraint(validatedBy = MinBigDecimalValidator.class) +@Documented +public @interface MinBigDecimal { + String minimum(); + boolean exclusive(); + String message() default "Value is smaller than the minimum."; + Class[] groups() default {}; + Class[] payload() default {}; +} \ No newline at end of file diff --git a/multiapi-engine/src/main/resources/templates/customannotations/templateMinBigDecimalValidator.ftlh b/multiapi-engine/src/main/resources/templates/customannotations/templateMinBigDecimalValidator.ftlh new file mode 100644 index 00000000..b28cef61 --- /dev/null +++ b/multiapi-engine/src/main/resources/templates/customannotations/templateMinBigDecimalValidator.ftlh @@ -0,0 +1,25 @@ +package ${packageModel}.customvalidator; + +import java.math.BigDecimal; +import java.util.Objects; + +import ${javaEEPackage}.validation.ConstraintValidator; +import ${javaEEPackage}.validation.ConstraintValidatorContext; + +public class MinValidator implements ConstraintValidator { + + private BigDecimal minimum; + private boolean exclusive; + + @Override + public void initialize(Min constraintAnnotation) { + ConstraintValidator.super.initialize(constraintAnnotation); + this.minimum = new BigDecimal(constraintAnnotation.minimum()); + this.exclusive = constraintAnnotation.exclusive(); + } + + @Override + public boolean isValid(BigDecimal value, ConstraintValidatorContext context) { + return Objects.isNull(value) || (value > this.minimum || (!exclusive && value == this.minimum)); + } +} \ No newline at end of file diff --git a/multiapi-engine/src/main/resources/templates/customannotations/templateMinDouble.ftlh b/multiapi-engine/src/main/resources/templates/customannotations/templateMinDouble.ftlh new file mode 100644 index 00000000..857a8306 --- /dev/null +++ b/multiapi-engine/src/main/resources/templates/customannotations/templateMinDouble.ftlh @@ -0,0 +1,18 @@ +package ${packageModel}.customvalidator; + +import ${javaEEPackage}.validation.Constraint; +import ${javaEEPackage}.validation.Payload; +import java.lang.annotation.*; + +@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, + ElementType.ANNOTATION_TYPE}) +@Retention(RetentionPolicy.RUNTIME) +@Constraint(validatedBy = MinDoubleValidator.class) +@Documented +public @interface MinDouble { + String minimum(); + boolean exclusive(); + String message() default "Value is smaller than the minimum."; + Class[] groups() default {}; + Class[] payload() default {}; +} \ No newline at end of file diff --git a/multiapi-engine/src/main/resources/templates/customannotations/templateMinDoubleValidator.ftlh b/multiapi-engine/src/main/resources/templates/customannotations/templateMinDoubleValidator.ftlh new file mode 100644 index 00000000..24145ffc --- /dev/null +++ b/multiapi-engine/src/main/resources/templates/customannotations/templateMinDoubleValidator.ftlh @@ -0,0 +1,24 @@ +package ${packageModel}.customvalidator; + +import java.util.Objects; + +import ${javaEEPackage}.validation.ConstraintValidator; +import ${javaEEPackage}.validation.ConstraintValidatorContext; + +public class MinValidator implements ConstraintValidator { + + private double minimum; + private boolean exclusive; + + @Override + public void initialize(MinDouble constraintAnnotation) { + ConstraintValidator.super.initialize(constraintAnnotation); + this.minimum = Double.parseDouble(constraintAnnotation.minimum()); + this.exclusive = constraintAnnotation.exclusive(); + } + + @Override + public boolean isValid(Double value, ConstraintValidatorContext context) { + return Objects.isNull(value) || (value.doubleValue() > this.minimum || (!exclusive && value.doubleValue() == this.minimum)); + } +} \ No newline at end of file diff --git a/multiapi-engine/src/main/resources/templates/customannotations/templateMin.ftlh b/multiapi-engine/src/main/resources/templates/customannotations/templateMinFloat.ftlh similarity index 86% rename from multiapi-engine/src/main/resources/templates/customannotations/templateMin.ftlh rename to multiapi-engine/src/main/resources/templates/customannotations/templateMinFloat.ftlh index 7a421176..b6648ee5 100644 --- a/multiapi-engine/src/main/resources/templates/customannotations/templateMin.ftlh +++ b/multiapi-engine/src/main/resources/templates/customannotations/templateMinFloat.ftlh @@ -7,9 +7,9 @@ import java.lang.annotation.*; @Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, ElementType.ANNOTATION_TYPE}) @Retention(RetentionPolicy.RUNTIME) -@Constraint(validatedBy = MinValidator.class) +@Constraint(validatedBy = MinFloatValidator.class) @Documented -public @interface Min { +public @interface MinFloat { String minimum(); boolean exclusive(); String message() default "Value is smaller than the minimum."; diff --git a/multiapi-engine/src/main/resources/templates/customannotations/templateMinFloatValidator.ftlh b/multiapi-engine/src/main/resources/templates/customannotations/templateMinFloatValidator.ftlh new file mode 100644 index 00000000..cc3fe233 --- /dev/null +++ b/multiapi-engine/src/main/resources/templates/customannotations/templateMinFloatValidator.ftlh @@ -0,0 +1,24 @@ +package ${packageModel}.customvalidator; + +import java.util.Objects; + +import ${javaEEPackage}.validation.ConstraintValidator; +import ${javaEEPackage}.validation.ConstraintValidatorContext; + +public class MinValidator implements ConstraintValidator { + + private float minimum; + private boolean exclusive; + + @Override + public void initialize(MinFloat constraintAnnotation) { + ConstraintValidator.super.initialize(constraintAnnotation); + this.minimum = Float.parseFloat(constraintAnnotation.minimum()); + this.exclusive = constraintAnnotation.exclusive(); + } + + @Override + public boolean isValid(Float value, ConstraintValidatorContext context) { + return Objects.isNull(value) || (value.floatValue() > this.minimum || (!exclusive && value.floatValue() == this.minimum)); + } +} \ No newline at end of file diff --git a/multiapi-engine/src/main/resources/templates/customannotations/templateMinInteger.ftlh b/multiapi-engine/src/main/resources/templates/customannotations/templateMinInteger.ftlh new file mode 100644 index 00000000..dab3b538 --- /dev/null +++ b/multiapi-engine/src/main/resources/templates/customannotations/templateMinInteger.ftlh @@ -0,0 +1,18 @@ +package ${packageModel}.customvalidator; + +import ${javaEEPackage}.validation.Constraint; +import ${javaEEPackage}.validation.Payload; +import java.lang.annotation.*; + +@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, + ElementType.ANNOTATION_TYPE}) +@Retention(RetentionPolicy.RUNTIME) +@Constraint(validatedBy = MinIntegerValidator.class) +@Documented +public @interface MinInteger { + String minimum(); + boolean exclusive(); + String message() default "Value is smaller than the minimum."; + Class[] groups() default {}; + Class[] payload() default {}; +} \ No newline at end of file diff --git a/multiapi-engine/src/main/resources/templates/customannotations/templateMinIntegerValidator.ftlh b/multiapi-engine/src/main/resources/templates/customannotations/templateMinIntegerValidator.ftlh new file mode 100644 index 00000000..9a9bdf1e --- /dev/null +++ b/multiapi-engine/src/main/resources/templates/customannotations/templateMinIntegerValidator.ftlh @@ -0,0 +1,24 @@ +package ${packageModel}.customvalidator; + +import java.util.Objects; + +import ${javaEEPackage}.validation.ConstraintValidator; +import ${javaEEPackage}.validation.ConstraintValidatorContext; + +public class MinValidator implements ConstraintValidator { + + private int minimum; + private boolean exclusive; + + @Override + public void initialize(MinInteger constraintAnnotation) { + ConstraintValidator.super.initialize(constraintAnnotation); + this.minimum = Integer.parseInt(constraintAnnotation.minimum()); + this.exclusive = constraintAnnotation.exclusive(); + } + + @Override + public boolean isValid(Integer value, ConstraintValidatorContext context) { + return Objects.isNull(value) || (value.intValue() > this.minimum || (!exclusive && value.intValue() == this.minimum)); + } +} \ No newline at end of file diff --git a/multiapi-engine/src/main/resources/templates/customannotations/templateMinValidator.ftlh b/multiapi-engine/src/main/resources/templates/customannotations/templateMinValidator.ftlh deleted file mode 100644 index 5e8ce821..00000000 --- a/multiapi-engine/src/main/resources/templates/customannotations/templateMinValidator.ftlh +++ /dev/null @@ -1,82 +0,0 @@ -package ${packageModel}.customvalidator; - -<#list schema.fieldObjectList as field> - <#if field.dataType.baseType?has_content && field.dataType.baseType == "BigDecimal"> - import java.math.BigDecimal; - - -import java.util.Objects; - -import ${javaEEPackage}.validation.ConstraintValidator; -import ${javaEEPackage}.validation.ConstraintValidatorContext; - -<#list schema.fieldObjectList as field> - <#if field.dataType.baseType?has_content && (field.dataType.baseType == "BigDecimal" || field.dataType.baseType == "bigDecimal")> -public class MinValidator implements ConstraintValidator { - - private BigDecimal minimum; - <#break> - <#elseif field.dataType.baseType?has_content && (field.dataType.baseType == "Integer" || field.dataType.baseType == "integer")> -public class MinValidator implements ConstraintValidator { - - private int minimum; - <#break> - <#elseif field.dataType.baseType?has_content && (field.dataType.baseType == "Float" || field.dataType.baseType == "float")> -public class MinValidator implements ConstraintValidator { - - private float minimum; - <#break> - <#elseif field.dataType.baseType?has_content && (field.dataType.baseType == "Double" || field.dataType.baseType == "double")> -public class MinValidator implements ConstraintValidator { - - private double minimum; - <#break> - - - private boolean exclusive; - - @Override - public void initialize(Min constraintAnnotation) { - ConstraintValidator.super.initialize(constraintAnnotation); -<#list schema.fieldObjectList as field> - <#if field.dataType.baseType?has_content && (field.dataType.baseType == "BigDecimal" || field.dataType.baseType == "bigDecimal")> - this.minimum = new BigDecimal(constraintAnnotation.minimum()); - <#break> - <#elseif field.dataType.baseType?has_content && (field.dataType.baseType == "Integer" || field.dataType.baseType == "integer")> - this.minimum = Integer.parseInt(constraintAnnotation.minimum()); - <#break> - <#elseif field.dataType.baseType?has_content && (field.dataType.baseType == "Float" || field.dataType.baseType == "float")> - this.minimum = Float.parseFloat(constraintAnnotation.minimum()); - <#break> - <#elseif field.dataType.baseType?has_content && (field.dataType.baseType == "Double" || field.dataType.baseType == "double")> - this.minimum = Double.parseDouble(constraintAnnotation.minimum()); - <#break> - - - this.exclusive = constraintAnnotation.exclusive(); - } - - @Override -<#list schema.fieldObjectList as field> - <#if field.dataType.baseType?has_content && (field.dataType.baseType == "BigDecimal" || field.dataType.baseType == "bigDecimal")> - public boolean isValid(BigDecimal value, ConstraintValidatorContext context) { - return Objects.isNull(value) || (value > this.minimum || (!exclusive && value == this.minimum)); - } - <#break> - <#elseif field.dataType.baseType?has_content && (field.dataType.baseType == "Integer" || field.dataType.baseType == "integer")> - public boolean isValid(Integer value, ConstraintValidatorContext context) { - return Objects.isNull(value) || (value.intValue() > this.minimum || (!exclusive && value.intValue() == this.minimum)); - } - <#break> - <#elseif field.dataType.baseType?has_content && (field.dataType.baseType == "Float" || field.dataType.baseType == "float")> - public boolean isValid(Float value, ConstraintValidatorContext context) { - return Objects.isNull(value) || (value.floatValue() > this.minimum || (!exclusive && value.floatValue() == this.minimum)); - } - <#break> - <#elseif field.dataType.baseType?has_content && (field.dataType.baseType == "Double" || field.dataType.baseType == "double")> - public boolean isValid(Double value, ConstraintValidatorContext context) { - return Objects.isNull(value) || (value.doubleValue() > this.minimum || (!exclusive && value.doubleValue() == this.minimum)); - } - - -} \ No newline at end of file diff --git a/multiapi-engine/src/main/resources/templates/customannotations/templateMinValidatorAsync.ftlh b/multiapi-engine/src/main/resources/templates/customannotations/templateMinValidatorAsync.ftlh deleted file mode 100644 index 99923b37..00000000 --- a/multiapi-engine/src/main/resources/templates/customannotations/templateMinValidatorAsync.ftlh +++ /dev/null @@ -1,81 +0,0 @@ -package ${packageModel}.customvalidator; - -<#list schema.fieldObjectList as field> - <#if field.dataTypeSimple?has_content && field.dataTypeSimple == "BigDecimal"> - import java.math.BigDecimal; - - -import java.util.Objects; - -import ${javaEEPackage}.validation.ConstraintValidator; -import ${javaEEPackage}.validation.ConstraintValidatorContext; - -<#list schema.fieldObjectList as field> - <#if field.dataTypeSimple?has_content && (field.dataTypeSimple == "BigDecimal" || field.dataTypeSimple == "bigDecimal")> -public class MinValidator implements ConstraintValidator { - - private BigDecimal minimum; - <#break> - <#elseif field.dataTypeSimple?has_content && (field.dataTypeSimple == "Integer" || field.dataTypeSimple == "integer")> -public class MinValidator implements ConstraintValidator { - - private int minimum; - <#break> - <#elseif field.dataTypeSimple?has_content && (field.dataTypeSimple == "Float" || field.dataTypeSimple == "float")> -public class MinValidator implements ConstraintValidator { - - private float minimum; - <#break> - <#elseif field.dataTypeSimple?has_content && (field.dataTypeSimple == "Double" || field.dataTypeSimple == "double")> -public class MinValidator implements ConstraintValidator { - - private double minimum; - <#break> - - - private boolean exclusive; - - @Override - public void initialize(Min constraintAnnotation) { - ConstraintValidator.super.initialize(constraintAnnotation); -<#list schema.fieldObjectList as field> - <#if field.dataTypeSimple?has_content && (field.dataTypeSimple == "BigDecimal" || field.dataTypeSimple == "bigDecimal")> - this.minimum = new BigDecimal(constraintAnnotation.minimum()); - <#break> - <#elseif field.dataTypeSimple?has_content && (field.dataTypeSimple == "Integer" || field.dataTypeSimple == "integer")> - this.minimum = Integer.parseInt(constraintAnnotation.minimum()); - <#break> - <#elseif field.dataTypeSimple?has_content && (field.dataTypeSimple == "Float" || field.dataTypeSimple == "float")> - this.minimum = Float.parseFloat(constraintAnnotation.minimum()); - <#break> - <#elseif field.dataTypeSimple?has_content && (field.dataTypeSimple == "Double" || field.dataTypeSimple == "double")> - this.minimum = Double.parseDouble(constraintAnnotation.minimum()); - - - this.exclusive = constraintAnnotation.exclusive(); - } - - @Override -<#list schema.fieldObjectList as field> - <#if field.dataTypeSimple?has_content && (field.dataTypeSimple == "BigDecimal" || field.dataTypeSimple == "bigDecimal")> - public boolean isValid(BigDecimal value, ConstraintValidatorContext context) { - return Objects.isNull(value) || (value > this.minimum || (!exclusive && value == this.minimum)); - } - <#break> - <#elseif field.dataTypeSimple?has_content && (field.dataTypeSimple == "Integer" || field.dataTypeSimple == "integer")> - public boolean isValid(Integer value, ConstraintValidatorContext context) { - return Objects.isNull(value) || (value.intValue() > this.minimum || (!exclusive && value.intValue() == this.minimum)); - } - <#break> - <#elseif field.dataTypeSimple?has_content && (field.dataTypeSimple == "Float" || field.dataTypeSimple == "float")> - public boolean isValid(Float value, ConstraintValidatorContext context) { - return Objects.isNull(value) || (value.floatValue() > this.minimum || (!exclusive && value.floatValue() == this.minimum)); - } - <#break> - <#elseif field.dataTypeSimple?has_content && (field.dataTypeSimple == "Double" || field.dataTypeSimple == "double")> - public boolean isValid(Double value, ConstraintValidatorContext context) { - return Objects.isNull(value) || (value.doubleValue() > this.minimum || (!exclusive && value.doubleValue() == this.minimum)); - } - - -} \ No newline at end of file diff --git a/multiapi-engine/src/main/resources/templates/customannotations/templateMultipleOfValidatorAsync.ftlh b/multiapi-engine/src/main/resources/templates/customannotations/templateMultipleOfValidatorAsync.ftlh deleted file mode 100644 index b18d0494..00000000 --- a/multiapi-engine/src/main/resources/templates/customannotations/templateMultipleOfValidatorAsync.ftlh +++ /dev/null @@ -1,83 +0,0 @@ -package ${packageModel}.customvalidator; - -<#list schema.fieldObjectList as field> - <#if field.dataTypeSimple?has_content && field.dataTypeSimple == "BigDecimal"> -import java.math.BigDecimal; - - -import java.util.Objects; - -import ${javaEEPackage}.validation.ConstraintValidator; -import ${javaEEPackage}.validation.ConstraintValidatorContext; - -<#list schema.fieldObjectList as field> - <#if field.dataTypeSimple?has_content && (field.dataTypeSimple == "BigDecimal" || field.dataTypeSimple == "bigDecimal")> -public class MultipleOfValidator implements ConstraintValidator { - - private BigDecimal multiple; - <#break> - <#elseif field.dataTypeSimple?has_content && (field.dataTypeSimple == "Integer" || field.dataTypeSimple == "integer")> -public class MultipleOfValidator implements ConstraintValidator { - - private int multiple; - <#break> - <#elseif field.dataTypeSimple?has_content && (field.dataTypeSimple == "Float" || field.dataTypeSimple == "float")> -public class MultipleOfValidator implements ConstraintValidator { - - private float multiple; - <#break> - <#elseif field.dataTypeSimple?has_content && (field.dataTypeSimple == "Double" || field.dataTypeSimple == "double")> -public class MultipleOfValidator implements ConstraintValidator { - - private double multiple; - <#break> - - - - @Override - public void initialize(final MultipleOf constraintAnnotation) { - ConstraintValidator.super.initialize(constraintAnnotation); -<#list schema.fieldObjectList as field> - <#if field.dataTypeSimple?has_content && (field.dataTypeSimple == "BigDecimal" || field.dataTypeSimple == "bigDecimal")> - this.multiple = new BigDecimal(constraintAnnotation.multiple()); - <#break> - <#elseif field.dataTypeSimple?has_content && (field.dataTypeSimple == "Integer" || field.dataTypeSimple == "integer")> - this.multiple = Integer.parseInt(constraintAnnotation.multiple()); - <#break> - <#elseif field.dataTypeSimple?has_content && (field.dataTypeSimple == "Float" || field.dataTypeSimple == "float")> - this.multiple = Float.parseFloat(constraintAnnotation.multiple()); - <#break> - <#elseif field.dataTypeSimple?has_content && (field.dataTypeSimple == "Double" || field.dataTypeSimple == "double")> - this.multiple = Double.parseDouble(constraintAnnotation.multiple()); - <#break> - - - } - - @Override -<#list schema.fieldObjectList as field> - <#if field.dataTypeSimple?has_content && (field.dataTypeSimple == "BigDecimal" || field.dataTypeSimple == "bigDecimal")> - public boolean isValid(final BigDecimal value, final ConstraintValidatorContext constraintValidatorContext) { - BigDecimal[] divisionResult = value.divideAndRemainder(multiple); - - return Objects.equals(divisionResult[1], new BigDecimal(0)); - } - <#break> - <#elseif field.dataTypeSimple?has_content && (field.dataTypeSimple == "Integer" || field.dataTypeSimple == "integer")> - public boolean isValid(final Integer value, final ConstraintValidatorContext constraintValidatorContext) { - return value.intValue() % multiple == 0; - } - <#break> - <#elseif field.dataTypeSimple?has_content && (field.dataTypeSimple == "Float" || field.dataTypeSimple == "float")> - public boolean isValid(final Float value, final ConstraintValidatorContext constraintValidatorContext) { - return value.floatValue() % multiple == 0; - } - <#break> - <#elseif field.dataTypeSimple?has_content && (field.dataTypeSimple == "Double" || field.dataTypeSimple == "double")> - public boolean isValid(final Double value, final ConstraintValidatorContext constraintValidatorContext) { - return value.doubleValue() % multiple == 0; - } - <#break> - - -} \ No newline at end of file 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 666e8a58..7b5e038e 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 @@ -676,14 +676,26 @@ static Function validateCustomValidators(final int springBootVers ); final List expectedValidatorFiles = List.of( - CUSTOM_VALIDATOR_PATH + "Max.java", + CUSTOM_VALIDATOR_PATH + "MaxBigDecimal.java", + CUSTOM_VALIDATOR_PATH + "MaxBigDecimalValidator.java", + CUSTOM_VALIDATOR_PATH + "MaxDouble.java", + CUSTOM_VALIDATOR_PATH + "MaxDoubleValidator.java", + CUSTOM_VALIDATOR_PATH + "MaxFloat.java", + CUSTOM_VALIDATOR_PATH + "MaxFloatValidator.java", + CUSTOM_VALIDATOR_PATH + "MaxInteger.java", + CUSTOM_VALIDATOR_PATH + "MaxIntegerValidator.java", CUSTOM_VALIDATOR_PATH + "MaxItems.java", CUSTOM_VALIDATOR_PATH + "MaxItemsValidator.java", - CUSTOM_VALIDATOR_PATH + "MaxValidator.java", - CUSTOM_VALIDATOR_PATH + "Min.java", + CUSTOM_VALIDATOR_PATH + "MinBigDecimal.java", + CUSTOM_VALIDATOR_PATH + "MinBigDecimalValidator.java", + CUSTOM_VALIDATOR_PATH + "MinDouble.java", + CUSTOM_VALIDATOR_PATH + "MinDoubleValidator.java", + CUSTOM_VALIDATOR_PATH + "MinFloat.java", + CUSTOM_VALIDATOR_PATH + "MinFloatValidator.java", + CUSTOM_VALIDATOR_PATH + "MinInteger.java", + CUSTOM_VALIDATOR_PATH + "MinIntegerValidator.java", CUSTOM_VALIDATOR_PATH + "MinItems.java", CUSTOM_VALIDATOR_PATH + "MinItemsValidator.java", - CUSTOM_VALIDATOR_PATH + "MinValidator.java", CUSTOM_VALIDATOR_PATH + "MultipleOf.java", CUSTOM_VALIDATOR_PATH + "MultipleOfValidator.java", CUSTOM_VALIDATOR_PATH + "NotNull.java", diff --git a/multiapi-engine/src/test/java/com/sngular/api/generator/plugin/openapi/OpenApiGeneratorFixtures.java b/multiapi-engine/src/test/java/com/sngular/api/generator/plugin/openapi/OpenApiGeneratorFixtures.java index 7d4280d9..4b0f3ea1 100644 --- a/multiapi-engine/src/test/java/com/sngular/api/generator/plugin/openapi/OpenApiGeneratorFixtures.java +++ b/multiapi-engine/src/test/java/com/sngular/api/generator/plugin/openapi/OpenApiGeneratorFixtures.java @@ -1270,7 +1270,7 @@ static Function validateValidationAnnotations(int springBootVersi CUSTOM_VALIDATOR_PATH + "MaxItems.java", CUSTOM_VALIDATOR_PATH + "MaxItemsValidator.java", CUSTOM_VALIDATOR_PATH + "MaxValidator.java", - CUSTOM_VALIDATOR_PATH + "Min.java", + CUSTOM_VALIDATOR_PATH + "MinInteger.java", CUSTOM_VALIDATOR_PATH + "MinItems.java", CUSTOM_VALIDATOR_PATH + "MinItemsValidator.java", CUSTOM_VALIDATOR_PATH + "MinValidator.java", diff --git a/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/assets/DataDTO.java b/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/assets/DataDTO.java index 13bca324..b6f50518 100644 --- a/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/assets/DataDTO.java +++ b/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/assets/DataDTO.java @@ -9,12 +9,14 @@ import java.util.List; import java.util.ArrayList; import com.sngular.scsplugin.customvalidator.model.event.customvalidator.Size; -import com.sngular.scsplugin.customvalidator.model.event.customvalidator.Max; -import com.sngular.scsplugin.customvalidator.model.event.customvalidator.Min; -import com.sngular.scsplugin.customvalidator.model.event.customvalidator.MaxItems; -import com.sngular.scsplugin.customvalidator.model.event.customvalidator.MinItems; +import com.sngular.scsplugin.customvalidator.model.event.exception.ModelClassException; import com.sngular.scsplugin.customvalidator.model.event.customvalidator.Pattern; +import com.sngular.scsplugin.customvalidator.model.event.customvalidator.NotNull; +import com.sngular.scsplugin.customvalidator.model.event.customvalidator.MaxInteger; +import com.sngular.scsplugin.customvalidator.model.event.customvalidator.MinInteger; import com.sngular.scsplugin.customvalidator.model.event.customvalidator.MultipleOf; +import com.sngular.scsplugin.customvalidator.model.event.customvalidator.MaxItems; +import com.sngular.scsplugin.customvalidator.model.event.customvalidator.MinItems; import com.sngular.scsplugin.customvalidator.model.event.customvalidator.UniqueItems; @JsonDeserialize(builder = DataDTO.DataDTOBuilder.class) @@ -23,19 +25,22 @@ public class DataDTO { @JsonProperty(value ="clientName") @Size(min =50, max =200) @Pattern(regex = "^[a-zA-Z0-9_.-]*$") - private String clientName; + @NotNull + private final String clientName; @JsonProperty(value ="flightNumber") - private String flightNumber; + @NotNull + private final String flightNumber; @JsonProperty(value ="clientId") - @Min(minimum = "10", exclusive = false) - @Max(maximum = "200", exclusive = true) + @MinInteger(minimum = "10", exclusive = false) + @MaxInteger(maximum = "200", exclusive = true) @MultipleOf(multiple = "10") - private Integer clientId; + @NotNull + private final Integer clientId; @JsonProperty(value ="test") @MaxItems(maximum = 10) @MinItems(minimum = 5) @UniqueItems - private List test = new ArrayList(); + private List test; private DataDTO(DataDTOBuilder builder) { this.clientName = builder.clientName; @@ -43,6 +48,7 @@ private DataDTO(DataDTOBuilder builder) { this.clientId = builder.clientId; this.test = builder.test; + validateRequiredAttributes(); } public static DataDTO.DataDTOBuilder builder() { @@ -71,6 +77,7 @@ public DataDTO.DataDTOBuilder clientId(Integer clientId) { this.clientId = clientId; return this; } + public DataDTO.DataDTOBuilder test(List test) { if (!test.isEmpty()) { this.test.addAll(test); @@ -91,29 +98,20 @@ public DataDTO build() { } } - @Schema(name = "clientName", required = false) + @Schema(name = "clientName", required = true) public String getClientName() { return clientName; } - public void setClientName(String clientName) { - this.clientName = clientName; - } - @Schema(name = "flightNumber", required = false) + @Schema(name = "flightNumber", required = true) public String getFlightNumber() { return flightNumber; } - public void setFlightNumber(String flightNumber) { - this.flightNumber = flightNumber; - } - @Schema(name = "clientId", required = false) + @Schema(name = "clientId", required = true) public Integer getClientId() { return clientId; } - public void setClientId(Integer clientId) { - this.clientId = clientId; - } @Schema(name = "test", required = false) public List getTest() { @@ -152,5 +150,20 @@ public String toString() { return sb.toString(); } + private void validateRequiredAttributes() { + boolean satisfiedCondition = true; + + if (!Objects.nonNull(this.clientName)) { + satisfiedCondition = false; + } else if (!Objects.nonNull(this.flightNumber)) { + satisfiedCondition = false; + } else if (!Objects.nonNull(this.clientId)) { + satisfiedCondition = false; + } + + if (!satisfiedCondition) { + throw new ModelClassException("DataDTO"); + } + } } diff --git a/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/assets/StatusMsgDTO.java b/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/assets/StatusMsgDTO.java index 5733cf55..6142677f 100644 --- a/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/assets/StatusMsgDTO.java +++ b/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/assets/StatusMsgDTO.java @@ -11,13 +11,11 @@ @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"); + KO("KO"), + OK("OK"); private String value; @@ -35,10 +33,12 @@ public String toString() { return String.valueOf(value); } } + @JsonProperty(value ="clientId") + private Integer clientId; private StatusMsgDTO(StatusMsgDTOBuilder builder) { - this.clientId = builder.clientId; this.status = builder.status; + this.clientId = builder.clientId; } @@ -49,17 +49,16 @@ public static StatusMsgDTO.StatusMsgDTOBuilder builder() { @JsonPOJOBuilder(buildMethodName = "build", withPrefix = "") public static class StatusMsgDTOBuilder { - private Integer clientId; - private Status status; + private Integer clientId; - public StatusMsgDTO.StatusMsgDTOBuilder clientId(Integer clientId) { - this.clientId = clientId; + public StatusMsgDTO.StatusMsgDTOBuilder status(Status status) { + this.status = status; return this; } - public StatusMsgDTO.StatusMsgDTOBuilder status(Status status) { - this.status = status; + public StatusMsgDTO.StatusMsgDTOBuilder clientId(Integer clientId) { + this.clientId = clientId; return this; } @@ -69,22 +68,6 @@ public StatusMsgDTO build() { } } - /** - * 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; @@ -93,6 +76,14 @@ public void setStatus(Status status) { this.status = status; } + @Schema(name = "clientId", required = false) + public Integer getClientId() { + return clientId; + } + public void setClientId(Integer clientId) { + this.clientId = clientId; + } + @Override public boolean equals(Object o) { if (this == o) { @@ -102,20 +93,20 @@ public boolean equals(Object o) { return false; } StatusMsgDTO statusMsgDTO = (StatusMsgDTO) o; - return Objects.equals(this.clientId, statusMsgDTO.clientId) && Objects.equals(this.status, statusMsgDTO.status); + return Objects.equals(this.status, statusMsgDTO.status) && Objects.equals(this.clientId, statusMsgDTO.clientId); } @Override public int hashCode() { - return Objects.hash(clientId, status); + return Objects.hash(status, clientId); } @Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append("StatusMsgDTO{"); - sb.append(" clientId:").append(clientId).append(","); - sb.append(" status:").append(status); + sb.append(" status:").append(status).append(","); + sb.append(" clientId:").append(clientId); sb.append("}"); return sb.toString(); } diff --git a/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/javax/MaxBigDecimal.java b/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/javax/MaxBigDecimal.java new file mode 100644 index 00000000..28212b72 --- /dev/null +++ b/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/javax/MaxBigDecimal.java @@ -0,0 +1,18 @@ +package com.sngular.scsplugin.customvalidator.model.event.customvalidator; + +import javax.validation.Constraint; +import javax.validation.Payload; +import java.lang.annotation.*; + +@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, +ElementType.ANNOTATION_TYPE}) +@Retention(RetentionPolicy.RUNTIME) +@Constraint(validatedBy = MaxBigDecimalValidator.class) +@Documented +public @interface MaxBigDecimal { + String maximum(); + boolean exclusive(); + String message() default "Value is bigger than the maximum."; + Class[] groups() default {}; + Class[] payload() default {}; +} \ No newline at end of file diff --git a/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/javax/MaxBigDecimalValidator.java b/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/javax/MaxBigDecimalValidator.java new file mode 100644 index 00000000..6f02d12e --- /dev/null +++ b/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/javax/MaxBigDecimalValidator.java @@ -0,0 +1,25 @@ +package com.sngular.scsplugin.customvalidator.model.event.customvalidator; + +import java.math.BigDecimal; +import java.util.Objects; + +import javax.validation.ConstraintValidator; +import javax.validation.ConstraintValidatorContext; + +public class MaxBigDecimalValidator implements ConstraintValidator { + + private BigDecimal maximum; + private boolean exclusive; + + @Override + public void initialize(MaxBigDecimal constraintAnnotation) { + ConstraintValidator.super.initialize(constraintAnnotation); + this.maximum = new BigDecimal(constraintAnnotation.maximum()); + this.exclusive = constraintAnnotation.exclusive(); + } + + @Override + public boolean isValid(BigDecimal value, ConstraintValidatorContext context) { + return Objects.isNull(value) || (value < this.maximum || (!exclusive && value == this.maximum)); + } +} \ No newline at end of file diff --git a/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/javax/MaxDouble.java b/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/javax/MaxDouble.java new file mode 100644 index 00000000..dcc674dd --- /dev/null +++ b/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/javax/MaxDouble.java @@ -0,0 +1,18 @@ +package com.sngular.scsplugin.customvalidator.model.event.customvalidator; + +import javax.validation.Constraint; +import javax.validation.Payload; +import java.lang.annotation.*; + +@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, +ElementType.ANNOTATION_TYPE}) +@Retention(RetentionPolicy.RUNTIME) +@Constraint(validatedBy = MaxDoubleValidator.class) +@Documented +public @interface MaxDouble { + String maximum(); + boolean exclusive(); + String message() default "Value is bigger than the maximum."; + Class[] groups() default {}; + Class[] payload() default {}; +} \ No newline at end of file diff --git a/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/javax/MaxDoubleValidator.java b/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/javax/MaxDoubleValidator.java new file mode 100644 index 00000000..eb56b3c7 --- /dev/null +++ b/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/javax/MaxDoubleValidator.java @@ -0,0 +1,24 @@ +package com.sngular.scsplugin.customvalidator.model.event.customvalidator; + +import java.util.Objects; + +import javax.validation.ConstraintValidator; +import javax.validation.ConstraintValidatorContext; + +public class MaxDoubleValidator implements ConstraintValidator { + + private double maximum; + private boolean exclusive; + + @Override + public void initialize(MaxDouble constraintAnnotation) { + ConstraintValidator.super.initialize(constraintAnnotation); + this.maximum = Double.parseDouble(constraintAnnotation.maximum()); + this.exclusive = constraintAnnotation.exclusive(); + } + + @Override + public boolean isValid(Double value, ConstraintValidatorContext context) { + return Objects.isNull(value) || (value.doubleValue() < this.maximum || (!exclusive && value.doubleValue() == this.maximum)); + } +} \ No newline at end of file diff --git a/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/javax/MaxFloat.java b/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/javax/MaxFloat.java new file mode 100644 index 00000000..514504b3 --- /dev/null +++ b/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/javax/MaxFloat.java @@ -0,0 +1,18 @@ +package com.sngular.scsplugin.customvalidator.model.event.customvalidator; + +import javax.validation.Constraint; +import javax.validation.Payload; +import java.lang.annotation.*; + +@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, +ElementType.ANNOTATION_TYPE}) +@Retention(RetentionPolicy.RUNTIME) +@Constraint(validatedBy = MaxFloatValidator.class) +@Documented +public @interface MaxFloat { + String maximum(); + boolean exclusive(); + String message() default "Value is bigger than the maximum."; + Class[] groups() default {}; + Class[] payload() default {}; +} \ No newline at end of file diff --git a/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/javax/MaxFloatValidator.java b/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/javax/MaxFloatValidator.java new file mode 100644 index 00000000..fc8d7654 --- /dev/null +++ b/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/javax/MaxFloatValidator.java @@ -0,0 +1,24 @@ +package com.sngular.scsplugin.customvalidator.model.event.customvalidator; + +import java.util.Objects; + +import javax.validation.ConstraintValidator; +import javax.validation.ConstraintValidatorContext; + +public class MaxFloatValidator implements ConstraintValidator { + + private float maximum; + private boolean exclusive; + + @Override + public void initialize(MaxFloat constraintAnnotation) { + ConstraintValidator.super.initialize(constraintAnnotation); + this.maximum = Float.parseFloat(constraintAnnotation.maximum()); + this.exclusive = constraintAnnotation.exclusive(); + } + + @Override + public boolean isValid(Float value, ConstraintValidatorContext context) { + return Objects.isNull(value) || (value.floatValue() < this.maximum || (!exclusive && value.floatValue() == this.maximum)); + } +} \ No newline at end of file diff --git a/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/javax/MaxInteger.java b/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/javax/MaxInteger.java new file mode 100644 index 00000000..28e6684c --- /dev/null +++ b/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/javax/MaxInteger.java @@ -0,0 +1,18 @@ +package com.sngular.scsplugin.customvalidator.model.event.customvalidator; + +import javax.validation.Constraint; +import javax.validation.Payload; +import java.lang.annotation.*; + +@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, +ElementType.ANNOTATION_TYPE}) +@Retention(RetentionPolicy.RUNTIME) +@Constraint(validatedBy = MaxIntegerValidator.class) +@Documented +public @interface MaxInteger { + String maximum(); + boolean exclusive(); + String message() default "Value is bigger than the maximum."; + Class[] groups() default {}; + Class[] payload() default {}; +} \ No newline at end of file diff --git a/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/javax/MaxIntegerValidator.java b/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/javax/MaxIntegerValidator.java new file mode 100644 index 00000000..a9ba9401 --- /dev/null +++ b/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/javax/MaxIntegerValidator.java @@ -0,0 +1,24 @@ +package com.sngular.scsplugin.customvalidator.model.event.customvalidator; + +import java.util.Objects; + +import javax.validation.ConstraintValidator; +import javax.validation.ConstraintValidatorContext; + +public class MaxIntegerValidator implements ConstraintValidator { + + private int maximum; + private boolean exclusive; + + @Override + public void initialize(MaxInteger constraintAnnotation) { + ConstraintValidator.super.initialize(constraintAnnotation); + this.maximum = Integer.parseInt(constraintAnnotation.maximum()); + this.exclusive = constraintAnnotation.exclusive(); + } + + @Override + public boolean isValid(Integer value, ConstraintValidatorContext context) { + return Objects.isNull(value) || (value.intValue() < this.maximum || (!exclusive && value.intValue() == this.maximum)); + } +} \ No newline at end of file diff --git a/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/javax/MinBigDecimal.java b/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/javax/MinBigDecimal.java new file mode 100644 index 00000000..e8463b29 --- /dev/null +++ b/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/javax/MinBigDecimal.java @@ -0,0 +1,18 @@ +package com.sngular.scsplugin.customvalidator.model.event.customvalidator; + +import javax.validation.Constraint; +import javax.validation.Payload; +import java.lang.annotation.*; + +@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, + ElementType.ANNOTATION_TYPE}) +@Retention(RetentionPolicy.RUNTIME) +@Constraint(validatedBy = MinBigDecimalValidator.class) +@Documented +public @interface MinBigDecimal { + String minimum(); + boolean exclusive(); + String message() default "Value is smaller than the minimum."; + Class[] groups() default {}; + Class[] payload() default {}; +} \ No newline at end of file diff --git a/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/javax/MinBigDecimalValidator.java b/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/javax/MinBigDecimalValidator.java new file mode 100644 index 00000000..b7ccfa5d --- /dev/null +++ b/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/javax/MinBigDecimalValidator.java @@ -0,0 +1,25 @@ +package com.sngular.scsplugin.customvalidator.model.event.customvalidator; + +import java.math.BigDecimal; +import java.util.Objects; + +import javax.validation.ConstraintValidator; +import javax.validation.ConstraintValidatorContext; + +public class MinValidator implements ConstraintValidator { + + private BigDecimal minimum; + private boolean exclusive; + + @Override + public void initialize(Min constraintAnnotation) { + ConstraintValidator.super.initialize(constraintAnnotation); + this.minimum = new BigDecimal(constraintAnnotation.minimum()); + this.exclusive = constraintAnnotation.exclusive(); + } + + @Override + public boolean isValid(BigDecimal value, ConstraintValidatorContext context) { + return Objects.isNull(value) || (value > this.minimum || (!exclusive && value == this.minimum)); + } +} \ No newline at end of file diff --git a/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/javax/MinDouble.java b/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/javax/MinDouble.java new file mode 100644 index 00000000..ad351134 --- /dev/null +++ b/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/javax/MinDouble.java @@ -0,0 +1,18 @@ +package com.sngular.scsplugin.customvalidator.model.event.customvalidator; + +import javax.validation.Constraint; +import javax.validation.Payload; +import java.lang.annotation.*; + +@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, + ElementType.ANNOTATION_TYPE}) +@Retention(RetentionPolicy.RUNTIME) +@Constraint(validatedBy = MinDoubleValidator.class) +@Documented +public @interface MinDouble { + String minimum(); + boolean exclusive(); + String message() default "Value is smaller than the minimum."; + Class[] groups() default {}; + Class[] payload() default {}; +} \ No newline at end of file diff --git a/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/javax/MinDoubleValidator.java b/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/javax/MinDoubleValidator.java new file mode 100644 index 00000000..df0f160b --- /dev/null +++ b/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/javax/MinDoubleValidator.java @@ -0,0 +1,24 @@ +package com.sngular.scsplugin.customvalidator.model.event.customvalidator; + +import java.util.Objects; + +import javax.validation.ConstraintValidator; +import javax.validation.ConstraintValidatorContext; + +public class MinValidator implements ConstraintValidator { + + private double minimum; + private boolean exclusive; + + @Override + public void initialize(MinDouble constraintAnnotation) { + ConstraintValidator.super.initialize(constraintAnnotation); + this.minimum = Double.parseDouble(constraintAnnotation.minimum()); + this.exclusive = constraintAnnotation.exclusive(); + } + + @Override + public boolean isValid(Double value, ConstraintValidatorContext context) { + return Objects.isNull(value) || (value.doubleValue() > this.minimum || (!exclusive && value.doubleValue() == this.minimum)); + } +} \ No newline at end of file diff --git a/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/javax/Min.java b/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/javax/MinFloat.java similarity index 86% rename from multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/javax/Min.java rename to multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/javax/MinFloat.java index b9b27471..dc72bbc1 100644 --- a/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/javax/Min.java +++ b/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/javax/MinFloat.java @@ -7,9 +7,9 @@ @Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, ElementType.ANNOTATION_TYPE}) @Retention(RetentionPolicy.RUNTIME) -@Constraint(validatedBy = MinValidator.class) +@Constraint(validatedBy = MinFloatValidator.class) @Documented -public @interface Min { +public @interface MinFloat { String minimum(); boolean exclusive(); String message() default "Value is smaller than the minimum."; diff --git a/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/javax/MinFloatValidator.java b/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/javax/MinFloatValidator.java new file mode 100644 index 00000000..29d09a52 --- /dev/null +++ b/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/javax/MinFloatValidator.java @@ -0,0 +1,24 @@ +package com.sngular.scsplugin.customvalidator.model.event.customvalidator; + +import java.util.Objects; + +import javax.validation.ConstraintValidator; +import javax.validation.ConstraintValidatorContext; + +public class MinValidator implements ConstraintValidator { + + private float minimum; + private boolean exclusive; + + @Override + public void initialize(MinFloat constraintAnnotation) { + ConstraintValidator.super.initialize(constraintAnnotation); + this.minimum = Float.parseFloat(constraintAnnotation.minimum()); + this.exclusive = constraintAnnotation.exclusive(); + } + + @Override + public boolean isValid(Float value, ConstraintValidatorContext context) { + return Objects.isNull(value) || (value.floatValue() > this.minimum || (!exclusive && value.floatValue() == this.minimum)); + } +} \ No newline at end of file diff --git a/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/javax/MinInteger.java b/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/javax/MinInteger.java new file mode 100644 index 00000000..b63a25cf --- /dev/null +++ b/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/javax/MinInteger.java @@ -0,0 +1,18 @@ +package com.sngular.scsplugin.customvalidator.model.event.customvalidator; + +import javax.validation.Constraint; +import javax.validation.Payload; +import java.lang.annotation.*; + +@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, + ElementType.ANNOTATION_TYPE}) +@Retention(RetentionPolicy.RUNTIME) +@Constraint(validatedBy = MinIntegerValidator.class) +@Documented +public @interface MinInteger { + String minimum(); + boolean exclusive(); + String message() default "Value is smaller than the minimum."; + Class[] groups() default {}; + Class[] payload() default {}; +} \ No newline at end of file diff --git a/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/javax/MinIntegerValidator.java b/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/javax/MinIntegerValidator.java new file mode 100644 index 00000000..96d6450f --- /dev/null +++ b/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/javax/MinIntegerValidator.java @@ -0,0 +1,24 @@ +package com.sngular.scsplugin.customvalidator.model.event.customvalidator; + +import java.util.Objects; + +import javax.validation.ConstraintValidator; +import javax.validation.ConstraintValidatorContext; + +public class MinValidator implements ConstraintValidator { + + private int minimum; + private boolean exclusive; + + @Override + public void initialize(MinInteger constraintAnnotation) { + ConstraintValidator.super.initialize(constraintAnnotation); + this.minimum = Integer.parseInt(constraintAnnotation.minimum()); + this.exclusive = constraintAnnotation.exclusive(); + } + + @Override + public boolean isValid(Integer value, ConstraintValidatorContext context) { + return Objects.isNull(value) || (value.intValue() > this.minimum || (!exclusive && value.intValue() == this.minimum)); + } +} \ No newline at end of file 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 b838ff8f..10835f26 100644 --- a/multiapi-engine/src/test/resources/asyncapigenerator/testIssueGenerateSupplier/assets/ConfigurationDTO.java +++ b/multiapi-engine/src/test/resources/asyncapigenerator/testIssueGenerateSupplier/assets/ConfigurationDTO.java @@ -38,10 +38,6 @@ public ConfigurationDTO build() { } } - /** - * Get name - * @return name - */ @Schema(name = "name", required = false) public String getName() { return name; 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 2965c22b..b50398b1 100644 --- a/multiapi-engine/src/test/resources/asyncapigenerator/testIssueGenerateSupplier/assets/MailRequestDTO.java +++ b/multiapi-engine/src/test/resources/asyncapigenerator/testIssueGenerateSupplier/assets/MailRequestDTO.java @@ -14,15 +14,15 @@ public class MailRequestDTO { @JsonProperty(value ="sender") private String sender; + @JsonProperty(value ="configuration") + private ConfigurationDTO configuration; @JsonProperty(value ="recipients") - private List recipients = new ArrayList(); - @JsonProperty(value ="config") - private ConfigurationDTO config; + private List recipients; private MailRequestDTO(MailRequestDTOBuilder builder) { this.sender = builder.sender; - this.recipients.addAll(builder.recipients); - this.config = builder.config; + this.configuration = builder.configuration; + this.recipients = builder.recipients; } @@ -34,16 +34,19 @@ public static MailRequestDTO.MailRequestDTOBuilder builder() { public static class MailRequestDTOBuilder { private String sender; - + private ConfigurationDTO configuration; private List recipients = new ArrayList(); - private ConfigurationDTO config; - public MailRequestDTO.MailRequestDTOBuilder sender(String sender) { this.sender = sender; return this; } + public MailRequestDTO.MailRequestDTOBuilder configuration(ConfigurationDTO configuration) { + this.configuration = configuration; + return this; + } + public MailRequestDTO.MailRequestDTOBuilder recipients(List recipients) { if (!recipients.isEmpty()) { this.recipients.addAll(recipients); @@ -58,21 +61,12 @@ public MailRequestDTO.MailRequestDTOBuilder recipient(String recipient) { return this; } - public MailRequestDTO.MailRequestDTOBuilder config(ConfigurationDTO config) { - this.config = config; - return this; - } - public MailRequestDTO build() { MailRequestDTO mailRequestDTO = new MailRequestDTO(this); return mailRequestDTO; } } - /** - * Get sender - * @return sender - */ @Schema(name = "sender", required = false) public String getSender() { return sender; @@ -81,10 +75,14 @@ public void setSender(String sender) { this.sender = sender; } - /** - * Get recipients - * @return recipients - */ + @Schema(name = "configuration", required = false) + public ConfigurationDTO getConfiguration() { + return configuration; + } + public void setConfiguration(ConfigurationDTO configuration) { + this.configuration = configuration; + } + @Schema(name = "recipients", required = false) public List getRecipients() { return recipients; @@ -93,18 +91,6 @@ public void setRecipients(List recipients) { this.recipients = recipients; } - /** - * Get config - * @return config - */ - @Schema(name = "config", required = false) - public ConfigurationDTO getConfig() { - return config; - } - public void setConfig(ConfigurationDTO config) { - this.config = config; - } - @Override public boolean equals(Object o) { if (this == o) { @@ -114,12 +100,12 @@ public boolean equals(Object o) { return false; } MailRequestDTO mailRequestDTO = (MailRequestDTO) o; - return Objects.equals(this.sender, mailRequestDTO.sender) && Objects.equals(this.recipients, mailRequestDTO.recipients) && Objects.equals(this.config, mailRequestDTO.config); + return Objects.equals(this.sender, mailRequestDTO.sender) && Objects.equals(this.configuration, mailRequestDTO.configuration) && Objects.equals(this.recipients, mailRequestDTO.recipients); } @Override public int hashCode() { - return Objects.hash(sender, recipients, config); + return Objects.hash(sender, configuration, recipients); } @Override @@ -127,8 +113,8 @@ public String toString() { StringBuilder sb = new StringBuilder(); sb.append("MailRequestDTO{"); sb.append(" sender:").append(sender).append(","); - sb.append(" recipients:").append(recipients).append(","); - sb.append(" config:").append(config); + sb.append(" configuration:").append(configuration).append(","); + sb.append(" recipients:").append(recipients); sb.append("}"); return sb.toString(); } diff --git a/multiapi-engine/src/test/resources/asyncapigenerator/testIssueInfiniteLoop/assets/ConfigDTO.java b/multiapi-engine/src/test/resources/asyncapigenerator/testIssueInfiniteLoop/assets/ConfigDTO.java index 317a7cc8..7fccb09a 100644 --- a/multiapi-engine/src/test/resources/asyncapigenerator/testIssueInfiniteLoop/assets/ConfigDTO.java +++ b/multiapi-engine/src/test/resources/asyncapigenerator/testIssueInfiniteLoop/assets/ConfigDTO.java @@ -38,10 +38,6 @@ public ConfigDTO build() { } } - /** - * Get name - * @return name - */ @Schema(name = "name", required = false) public String getName() { return name; diff --git a/multiapi-engine/src/test/resources/asyncapigenerator/testIssueInfiniteLoop/assets/MailRequestInfiniteDTO.java b/multiapi-engine/src/test/resources/asyncapigenerator/testIssueInfiniteLoop/assets/MailRequestInfiniteDTO.java index 8e0f6b7b..1aaa2f74 100644 --- a/multiapi-engine/src/test/resources/asyncapigenerator/testIssueInfiniteLoop/assets/MailRequestInfiniteDTO.java +++ b/multiapi-engine/src/test/resources/asyncapigenerator/testIssueInfiniteLoop/assets/MailRequestInfiniteDTO.java @@ -17,7 +17,7 @@ public class MailRequestInfiniteDTO { @JsonProperty(value ="config") private ConfigDTO config; @JsonProperty(value ="recipients") - private List recipients = new ArrayList(); + private List recipients; private MailRequestInfiniteDTO(MailRequestInfiniteDTOBuilder builder) { this.sender = builder.sender; @@ -41,10 +41,12 @@ public MailRequestInfiniteDTO.MailRequestInfiniteDTOBuilder sender(String sender this.sender = sender; return this; } + public MailRequestInfiniteDTO.MailRequestInfiniteDTOBuilder config(ConfigDTO config) { this.config = config; return this; } + public MailRequestInfiniteDTO.MailRequestInfiniteDTOBuilder recipients(List recipients) { if (!recipients.isEmpty()) { this.recipients.addAll(recipients); From 8bed01b3a2392ac82dd8edf943b6784eb6461300 Mon Sep 17 00:00:00 2001 From: "joseenrique.garcia" Date: Fri, 23 Aug 2024 12:11:22 +0200 Subject: [PATCH 06/26] Fix OpenApi generator --- multiapi-engine/pom.xml | 2 +- .../template/ClasspathTemplateLoader.java | 13 +- .../asyncapi/template/TemplateFactory.java | 18 +- .../plugin/common/tools/ApiTool.java | 4 +- .../plugin/common/tools/MapperUtil.java | 9 +- .../plugin/common/tools/StringCaseUtils.java | 29 ++ .../plugin/openapi/OpenApiGenerator.java | 15 +- .../template/ClasspathTemplateLoader.java | 17 +- .../openapi/template/TemplateFactory.java | 8 +- .../templateModelClassException.ftlh | 0 .../{asyncapi => model}/templateSchema.ftlh | 2 +- .../templateSchemaWithLombok.ftlh | 0 .../openapi/templateModelClassException.ftlh | 10 - .../templates/openapi/templateSchema.ftlh | 453 ------------------ .../openapi/templateSchemaWithLombok.ftlh | 187 -------- .../asyncapi/AsyncApiGeneratorTest.java | 2 +- .../openapi/OpenApiGeneratorFixtures.java | 2 +- .../testCustomValidators/assets/DataDTO.java | 4 +- .../jakarta/MaxBigDecimal.java | 18 + .../jakarta/MaxBigDecimalValidator.java | 24 + .../jakarta/{Max.java => MaxInteger.java} | 4 +- .../assets/OrderProductDTO.java | 6 +- .../assets/OrderProductMapper.java | 6 +- .../assets/CustomerDTO.java | 8 +- .../assets/OrderedItemDTO.java | 2 +- .../assets/OrderProductDTO.java | 6 +- .../assets/OrderProductMapper.java | 6 +- .../assets/OrderProductDTO.java | 6 +- .../assets/lombok/ApiTestAllOfDTO.java | 2 +- .../testAllOf/assets/lombok/ApiTestDTO.java | 2 +- .../assets/lombok/ApiTestInfoDTO.java | 2 +- .../testAllOf/assets/testApi/ApiErrorDTO.java | 7 - .../assets/testApi/ApiTestAllOfDTO.java | 9 +- .../testAllOf/assets/testApi/ApiTestDTO.java | 8 +- .../assets/testApi/ApiTestInfoDTO.java | 10 +- .../testAllOf/assets/testApi/ApiTestsDTO.java | 100 ++-- .../assets/ApiTestInfoDTO.java | 2 +- .../assets/ApiErrorDTO.java | 7 - .../assets/ApiTestInfoDTO.java | 9 +- .../assets/ApiTestInfoDTO.java | 2 +- .../assets/ApiErrorDTO.java | 7 - .../assets/ApiTestDTO.java | 7 - .../assets/ApiTestInfoDTO.java | 2 +- .../assets/TestInfoDTO.java | 9 +- .../assets/ApiErrorDTO.java | 7 - .../assets/ApiTestDTO.java | 7 - .../assets/ApiTestInfoDTO.java | 9 +- .../assets/TestInfoDTO.java | 9 +- .../assets/ApiErrorDTO.java | 7 - .../assets/ApiTestDTO.java | 7 - .../assets/ApiTestInfoDTO.java | 9 +- .../assets/TestInfoDTO.java | 9 +- .../assets/TestInfoDTO.java | 9 +- .../assets/ApiTestDTO.java | 7 - .../assets/ApiErrorDTO.java | 6 - .../assets/ApiErrorDTO.java | 7 - .../assets/ApiTestDTO.java | 7 - .../assets/ApiTestInfoDTO.java | 9 +- .../assets/ApiErrorDTO.java | 7 - .../assets/ApiTestDTO.java | 7 - .../assets/ApiErrorDTO.java | 7 - .../assets/ApiTestDTO.java | 7 - .../assets/lombok/ApiTestAllOfDTO.java | 2 +- .../assets/lombok/ApiTestDTO.java | 2 +- .../assets/lombok/ApiTestInfoDTO.java | 2 +- .../assets/testApi/ApiTestAllOfDTO.java | 8 +- .../assets/testApi/ApiTestDTO.java | 7 - .../assets/testApi/ApiTestInfoDTO.java | 9 +- .../assets/ApiErrorDTO.java | 7 - .../assets/ApiTestDTO.java | 7 - .../assets/ApiTestInfoDTO.java | 9 +- 71 files changed, 248 insertions(+), 988 deletions(-) create mode 100644 multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/tools/StringCaseUtils.java rename multiapi-engine/src/main/resources/templates/{asyncapi => model}/templateModelClassException.ftlh (100%) rename multiapi-engine/src/main/resources/templates/{asyncapi => model}/templateSchema.ftlh (99%) rename multiapi-engine/src/main/resources/templates/{asyncapi => model}/templateSchemaWithLombok.ftlh (100%) delete mode 100644 multiapi-engine/src/main/resources/templates/openapi/templateModelClassException.ftlh delete mode 100644 multiapi-engine/src/main/resources/templates/openapi/templateSchema.ftlh delete mode 100644 multiapi-engine/src/main/resources/templates/openapi/templateSchemaWithLombok.ftlh create mode 100644 multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/jakarta/MaxBigDecimal.java create mode 100644 multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/jakarta/MaxBigDecimalValidator.java rename multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/jakarta/{Max.java => MaxInteger.java} (86%) diff --git a/multiapi-engine/pom.xml b/multiapi-engine/pom.xml index f5d772b2..a7f67a9a 100644 --- a/multiapi-engine/pom.xml +++ b/multiapi-engine/pom.xml @@ -21,7 +21,7 @@ 2.2.9 3.0.0 - 1.10.0 + 1.12.0 1.18.30 2.0.11 1.16.0 diff --git a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/asyncapi/template/ClasspathTemplateLoader.java b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/asyncapi/template/ClasspathTemplateLoader.java index 6c27659a..14019dec 100644 --- a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/asyncapi/template/ClasspathTemplateLoader.java +++ b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/asyncapi/template/ClasspathTemplateLoader.java @@ -20,10 +20,13 @@ public class ClasspathTemplateLoader implements TemplateLoader { + private static final List TEMPLATE_MODEL_FILES = List.of( "templateSchema.ftlh", + "templateSchemaWithLombok.ftlh", "templateModelClassException.ftlh"); + + private static final List TEMPLATE_FILES = List.of("templateSuppliers.ftlh", "interfaceConsumer.ftlh", "templateConsumers.ftlh", - "interfaceSupplier.ftlh", "templateStreamBridge.ftlh", "templateSchema.ftlh", - "templateSchemaWithLombok.ftlh", "templateModelClassException.ftlh", - "interfaceSupplierWithKafkaBindings.ftlh", "templateSuppliersWithKafkaBindings.ftlh", + "interfaceSupplier.ftlh", "templateStreamBridge.ftlh", + "interfaceSupplierWithKafkaBindings.ftlh", "templateSuppliersWithKafkaBindings.ftlh", "interfaceConsumerWithKafkaBindings.ftlh", "templateConsumersWithKafkaBindings.ftlh", "templateStreamBridgeWithKafkaBindings.ftlh", "templateMessageWrapper.ftlh"); @@ -80,6 +83,10 @@ public void closeTemplateSource(final Object o) { private Map getResourceFolderFiles() { final Map templates = new HashMap<>(); try { + for (var templateFile : TEMPLATE_MODEL_FILES) { + templates.put(templateFile, + readFile((InputStream) Objects.requireNonNull(LOADER.getResource("templates/model/" + templateFile)).getContent())); + } for (var templateFile : TEMPLATE_FILES) { templates.put(templateFile, readFile((InputStream) Objects.requireNonNull(LOADER.getResource("templates/asyncapi/" + templateFile)).getContent())); 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 23fc59e4..63facba8 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 @@ -34,23 +34,23 @@ public class TemplateFactory { - public static final String SUBSCRIBE_PACKAGE = "subscribePackage"; + private static final String SUBSCRIBE_PACKAGE = "subscribePackage"; - public static final String WRAPPER_PACKAGE = "wrapperPackage"; + private static final String WRAPPER_PACKAGE = "wrapperPackage"; - public static final String SUPPLIER_PACKAGE = "supplierPackage"; + private static final String SUPPLIER_PACKAGE = "supplierPackage"; - public static final String STREAM_BRIDGE_PACKAGE = "streamBridgePackage"; + private static final String STREAM_BRIDGE_PACKAGE = "streamBridgePackage"; - public static final String SUPPLIER_ENTITIES_SUFFIX = "supplierEntitiesSuffix"; + private static final String SUPPLIER_ENTITIES_SUFFIX = "supplierEntitiesSuffix"; - public static final String STREAM_BRIDGE_ENTITIES_SUFFIX = "streamBridgeEntitiesSuffix"; + private static final String STREAM_BRIDGE_ENTITIES_SUFFIX = "streamBridgeEntitiesSuffix"; - public static final String SUBSCRIBE_ENTITIES_SUFFIX = "subscribeEntitiesSuffix"; + private static final String SUBSCRIBE_ENTITIES_SUFFIX = "subscribeEntitiesSuffix"; - public static final String FILE_TYPE_JAVA = ".java"; + private static final String FILE_TYPE_JAVA = ".java"; - public static final String EXCEPTION_PACKAGE = "exceptionPackage"; + private static final String EXCEPTION_PACKAGE = "exceptionPackage"; private final Configuration cfg = new Configuration(Configuration.VERSION_2_3_32); 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 1f5d56ba..5d931733 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 @@ -10,6 +10,7 @@ import org.apache.commons.collections4.IteratorUtils; import org.apache.commons.collections4.Transformer; import org.apache.commons.lang3.StringUtils; +import org.apache.commons.text.CaseUtils; import java.io.FileInputStream; import java.io.IOException; @@ -140,7 +141,8 @@ private static Map getComponentSchemasByType(final JsonNode op if (hasNode(components, schemaType)) { final var schemas = getNode(components, schemaType); final var schemasIt = schemas.fieldNames(); - schemasIt.forEachRemaining(name -> schemasMap.put(name, getNode(schemas, name))); + schemasIt.forEachRemaining(name -> schemasMap.put(schemaType.toUpperCase() + "/"+ StringCaseUtils.titleToSnakeCase(name), + getNode(schemas, name))); } } diff --git a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/tools/MapperUtil.java b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/tools/MapperUtil.java index 988e4dbe..e4f39b4d 100644 --- a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/tools/MapperUtil.java +++ b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/tools/MapperUtil.java @@ -12,6 +12,7 @@ import org.apache.commons.lang3.ArrayUtils; import org.apache.commons.lang3.ObjectUtils; import org.apache.commons.lang3.StringUtils; +import org.apache.commons.text.CaseUtils; public class MapperUtil { @@ -78,17 +79,17 @@ public static String getRefSchemaName(final JsonNode parameter) { public static String getRefSchemaKey(final JsonNode parameter) { final String[] pathObjectRef = ApiTool.getRefValue(parameter).split("/"); - return StringUtils.upperCase(pathObjectRef[pathObjectRef.length - 2] + "/" + pathObjectRef[pathObjectRef.length - 1]); + return StringUtils.upperCase(pathObjectRef[pathObjectRef.length - 2] + "/" + StringCaseUtils.titleToSnakeCase(pathObjectRef[pathObjectRef.length - 1])); } - public static String getRefSchemaName(final String parameter) { + public static String getKeySchemaName(final String parameter) { final String[] pathObjectRef = parameter.split("/"); - return pathObjectRef[pathObjectRef.length - 1]; + return StringCaseUtils.toCamelCase(pathObjectRef[pathObjectRef.length - 1]); } public static String getRefSchemaKey(final String parameter) { final String[] pathObjectRef = parameter.split("/"); - return StringUtils.upperCase(pathObjectRef[pathObjectRef.length - 2] + "/" + pathObjectRef[pathObjectRef.length - 1]); + return StringUtils.upperCase(pathObjectRef[pathObjectRef.length - 2] + "/" + StringCaseUtils.titleToSnakeCase(pathObjectRef[pathObjectRef.length - 1])); } private static boolean checkIfNumber(final String nodeType) { diff --git a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/tools/StringCaseUtils.java b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/tools/StringCaseUtils.java new file mode 100644 index 00000000..8107da85 --- /dev/null +++ b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/tools/StringCaseUtils.java @@ -0,0 +1,29 @@ +package com.sngular.api.generator.plugin.common.tools; + +import org.apache.commons.text.CaseUtils; + +public class StringCaseUtils { + + public static String titleToSnakeCase(String titleCase) { + StringBuilder sb = new StringBuilder(); + for (int i = 0; i < titleCase.length(); i++) { + char c = titleCase.charAt(i); + if (Character.isUpperCase(c)) { + if (i > 0) { + sb.append("_"); + } + sb.append(c); + } else { + sb.append(Character.toUpperCase(c)); + } + } + return sb.toString(); + } + + public static String toCamelCase(final String toCamelCase) { + return CaseUtils.toCamelCase(toCamelCase, true, '_'); + } + + private StringCaseUtils() { + } +} 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 b75b5c1c..17027ead 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 @@ -257,10 +257,10 @@ private void processModels( basicSchemaMap.forEach((schemaName, basicSchema) -> { if (ApiTool.hasType(basicSchema)) { if (validType(ApiTool.getType(basicSchema))) { - processModel(specFile, fileModelToSave, modelPackage, basicSchemaMap, overwrite, schemaName, basicSchema, builtSchemasMap); + processModel(specFile, fileModelToSave, modelPackage, basicSchemaMap, overwrite, MapperUtil.getKeySchemaName(schemaName), basicSchema, builtSchemasMap); } } else { - processModel(specFile, fileModelToSave, modelPackage, basicSchemaMap, overwrite, schemaName, basicSchema, builtSchemasMap); + processModel(specFile, fileModelToSave, modelPackage, basicSchemaMap, overwrite, MapperUtil.getKeySchemaName(schemaName), basicSchema, builtSchemasMap); } }); } @@ -278,18 +278,19 @@ private void processModel( if (ApiTool.hasRef(basicSchema)) { final var refSchema = MapperUtil.getRefSchemaName(basicSchema); - builtSchemasMap.putAll(fillTemplateFactory(specFile, fileModelToSave, refSchema, basicSchemaMap.get(refSchema), basicSchemaMap, builtSchemasMap)); + builtSchemasMap.putAll(fillTemplateFactory(specFile, fileModelToSave, refSchema, basicSchemaMap.get(refSchema), basicSchemaMap, builtSchemasMap, modelPackage)); } else if (!ApiTool.isArray(basicSchema) && !TypeConstants.STRING.equalsIgnoreCase(ApiTool.getType(basicSchema))) { - builtSchemasMap.putAll(fillTemplateFactory(specFile, fileModelToSave, schemaName, basicSchema, basicSchemaMap, builtSchemasMap)); + builtSchemasMap.putAll(fillTemplateFactory(specFile, fileModelToSave, schemaName, basicSchema, basicSchemaMap, builtSchemasMap, modelPackage)); } } private Map fillTemplateFactory( - final SpecFile specFile, final String fileModelToSave, final String schemaName, final JsonNode basicSchema, final Map basicSchemaMap, - final Map builtSchemasMap) { + final SpecFile specFile, final String fileModelToSave, final String schemaName, final JsonNode basicSchema, final Map basicSchemaMap, + final Map builtSchemasMap, String modelPackage) { final var schemaObjectMap = MapperContentUtil .mapComponentToSchemaObject(basicSchemaMap, builtSchemasMap, basicSchema, schemaName, specFile, baseDir); checkRequiredOrCombinatorExists(schemaObjectMap); + //TODO: Create only required classes schemaObjectMap.values().forEach(schemaObject -> { try { final Set propertiesSet = new HashSet<>(); @@ -302,7 +303,7 @@ private Map fillTemplateFactory( if (Boolean.TRUE.equals(generateExceptionTemplate)) { try { - templateFactory.fillTemplateModelClassException(fileModelToSave, true); + templateFactory.fillTemplateModelClassException(fileModelToSave, true, modelPackage); } catch (IOException | TemplateException e) { throw new GeneratedSourcesException(fileModelToSave, e); } diff --git a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/openapi/template/ClasspathTemplateLoader.java b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/openapi/template/ClasspathTemplateLoader.java index 53e76474..8c72d322 100644 --- a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/openapi/template/ClasspathTemplateLoader.java +++ b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/openapi/template/ClasspathTemplateLoader.java @@ -19,11 +19,13 @@ public class ClasspathTemplateLoader implements TemplateLoader { - private static final List TEMPLATE_FILES = List.of(TemplateIndexConstants.TEMPLATE_INTERFACE_API, TemplateIndexConstants.TEMPLATE_CONTENT_SCHEMA, - TemplateIndexConstants.TEMPLATE_CONTENT_SCHEMA_LOMBOK, TemplateIndexConstants.TEMPLATE_CALL_WEB_API, + private static final List TEMPLATE_MODEL_FILES = List.of( TemplateIndexConstants.TEMPLATE_CONTENT_SCHEMA, + TemplateIndexConstants.TEMPLATE_CONTENT_SCHEMA_LOMBOK, + TemplateIndexConstants.TEMPLATE_MODEL_EXCEPTION); + + private static final List TEMPLATE_FILES = List.of(TemplateIndexConstants.TEMPLATE_INTERFACE_API, TemplateIndexConstants.TEMPLATE_CALL_WEB_API, TemplateIndexConstants.TEMPLATE_WEB_CLIENT, TemplateIndexConstants.TEMPLATE_CALL_REST_API, - TemplateIndexConstants.TEMPLATE_REST_CLIENT, TemplateIndexConstants.TEMPLATE_REACTIVE_API, - TemplateIndexConstants.TEMPLATE_MODEL_EXCEPTION, TemplateIndexConstants.TEMPLATE_CONTENT_ENUM_SCHEMA); + TemplateIndexConstants.TEMPLATE_REST_CLIENT, TemplateIndexConstants.TEMPLATE_REACTIVE_API); private static final List TEMPLATE_AUTH_FILES = List.of(TemplateIndexConstants.TEMPLATE_API_KEY, TemplateIndexConstants.TEMPLATE_AUTHENTICATION, TemplateIndexConstants.TEMPLATE_HTTP_BASIC, TemplateIndexConstants.TEMPLATE_HTTP_BEARER, @@ -75,6 +77,13 @@ public void closeTemplateSource(final Object o) { private Map getResourceFolderFiles() { final Map templates = new HashMap<>(); + TEMPLATE_MODEL_FILES.forEach(templateFile -> { + try { + templates.put(templateFile, readFile((InputStream) Objects.requireNonNull(LOADER.getResource("templates/model/" + templateFile)).getContent())); + } catch (final IOException e) { + e.printStackTrace(); + } + }); TEMPLATE_FILES.forEach(templateFile -> { try { templates.put(templateFile, readFile((InputStream) Objects.requireNonNull(LOADER.getResource("templates/openapi/" + templateFile)).getContent())); 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 231724a3..6aae677a 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 @@ -28,10 +28,13 @@ import freemarker.template.Template; import freemarker.template.TemplateException; import freemarker.template.TemplateExceptionHandler; +import org.apache.commons.lang3.StringUtils; public class TemplateFactory { - public static final String JAVA_EXTENSION = ".java"; + private static final String JAVA_EXTENSION = ".java"; + + private static final String EXCEPTION_PACKAGE = "exceptionPackage"; private final Configuration cfg = new Configuration(Configuration.VERSION_2_3_32); @@ -82,7 +85,7 @@ private static String templateSelector(final Boolean useLombok, final SchemaObje return template; } - public final void fillTemplateModelClassException(final String filePathToSave, final boolean overwriteEnabled) throws IOException, TemplateException { + public final void fillTemplateModelClassException(final String filePathToSave, final boolean overwriteEnabled, String modelPackage) throws IOException, TemplateException { final File fileToSave = new File(filePathToSave); final Path pathToExceptionPackage = fileToSave.toPath().resolve("exception"); pathToExceptionPackage.toFile().mkdirs(); @@ -139,6 +142,7 @@ public final void fillTemplate( } if (Objects.nonNull(specFile.getModelPackage())) { root.put("packageModel", specFile.getModelPackage()); + root.put("exceptionPackage", specFile.getModelPackage()); } final File fileToSave = new File(filePathToSave); diff --git a/multiapi-engine/src/main/resources/templates/asyncapi/templateModelClassException.ftlh b/multiapi-engine/src/main/resources/templates/model/templateModelClassException.ftlh similarity index 100% rename from multiapi-engine/src/main/resources/templates/asyncapi/templateModelClassException.ftlh rename to multiapi-engine/src/main/resources/templates/model/templateModelClassException.ftlh diff --git a/multiapi-engine/src/main/resources/templates/asyncapi/templateSchema.ftlh b/multiapi-engine/src/main/resources/templates/model/templateSchema.ftlh similarity index 99% rename from multiapi-engine/src/main/resources/templates/asyncapi/templateSchema.ftlh rename to multiapi-engine/src/main/resources/templates/model/templateSchema.ftlh index 47344837..64b73ade 100644 --- a/multiapi-engine/src/main/resources/templates/asyncapi/templateSchema.ftlh +++ b/multiapi-engine/src/main/resources/templates/model/templateSchema.ftlh @@ -444,7 +444,7 @@ public class ${schema.className} { <#if field?index == 0> if (!Objects.nonNull(this.${calculateSafeName (field.baseName, "")})) { <#else> - else if (!Objects.nonNull(this.${calculateSafeName (field.baseName, "")})) { + else if (!Objects.nonNull(this.${calculateSafeName (field.baseName, "")})) { satisfiedCondition = false; } diff --git a/multiapi-engine/src/main/resources/templates/asyncapi/templateSchemaWithLombok.ftlh b/multiapi-engine/src/main/resources/templates/model/templateSchemaWithLombok.ftlh similarity index 100% rename from multiapi-engine/src/main/resources/templates/asyncapi/templateSchemaWithLombok.ftlh rename to multiapi-engine/src/main/resources/templates/model/templateSchemaWithLombok.ftlh diff --git a/multiapi-engine/src/main/resources/templates/openapi/templateModelClassException.ftlh b/multiapi-engine/src/main/resources/templates/openapi/templateModelClassException.ftlh deleted file mode 100644 index de407e4d..00000000 --- a/multiapi-engine/src/main/resources/templates/openapi/templateModelClassException.ftlh +++ /dev/null @@ -1,10 +0,0 @@ -package ${packageModel}.exception; - -public class ModelClassException extends RuntimeException { - - private static final String ERROR_MESSAGE = "There are some problems related to the entity called %s. Maybe could be caused by required fields or anyOf/oneOf restrictions"; - - public ModelClassException(final String modelEntity) { - super(String.format(ERROR_MESSAGE, modelEntity)); - } -} \ No newline at end of file diff --git a/multiapi-engine/src/main/resources/templates/openapi/templateSchema.ftlh b/multiapi-engine/src/main/resources/templates/openapi/templateSchema.ftlh deleted file mode 100644 index bf2cb362..00000000 --- a/multiapi-engine/src/main/resources/templates/openapi/templateSchema.ftlh +++ /dev/null @@ -1,453 +0,0 @@ -<#ftl output_format="plainText"> -<#assign words = ["abstract", "assert", "boolean", "break", "byte", "case", "catch", "char", "class", "const", "continue", "default", "double", "do", "else", "enum", "extends", "false", "final", "finally", "float", "for", "goto", "if", "implements", "import", "instanceof", "int", "interface", "long", "native", "new", "null", "package", "private", "protected", "public", "return", "short", "static", "strictfp", "super", "switch", "synchronized", "this", "throw", "throws", "transient", "true", "try", "void", "volatile", "while"]> -<#function calculateSafeName propertyName ender> - <#if words?seq_contains(propertyName?uncap_first) || propertyName?matches("[0-9].*")> - <#return "_"+propertyName+ender/> - <#else > - <#return propertyName+ender/> - - -<#function singularizeName propertyName> - <#if propertyName?matches(".*s")> - <#return propertyName?remove_ending("s")/> - <#elseif propertyName?matches(".*List")> - <#return propertyName?remove_ending("List")/> - <#else > - <#return propertyName/> - - -<#function requireFinal field> - <#if field.required == true || field.constValue??> - <#return "final "/> - <#else > - <#return ""/> - - -<#function checkIfShouldSet field> - <#if field.required == true || field.constValue??> - <#return false/> - <#else > - <#return true/> - - -<#function hasConstValue value=""> - <#if value?has_content> - <#return " = " + renderValue (value) + ";"/> - <#else > - <#return ";"/> - - -<#function renderValue value=""> - <#if value?is_boolean> - <#return value == true> - <#elseif value?is_number> - <#return value> - <#elseif value?is_string> - <#return '\"${value}\"'?no_esc> - - -package ${packageModel}; - -import java.util.Objects; - -import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder; -import com.fasterxml.jackson.annotation.JsonProperty; -<#list schema.fieldObjectList as field> - <#if field.enumValues?has_content> -import com.fasterxml.jackson.annotation.JsonValue; - <#break> - - -import io.swagger.v3.oas.annotations.media.Schema; -<#list schema.importList as import> -import ${import}; - -<#list schema.fieldObjectList as field> - <#if field.restrictions.maxLength?has_content || field.restrictions.minLength?has_content> -import ${packageModel}.customvalidator.Size; - <#break> - - -<#list schema.fieldObjectList as field> - <#if field.restrictions.maximum?has_content> -import ${packageModel}.customvalidator.Max; - <#break> - - -<#list schema.fieldObjectList as field> - <#if field.restrictions.minimum?has_content> -import ${packageModel}.customvalidator.Min; - <#break> - - -<#list schema.fieldObjectList as field> - <#if field.restrictions.maxItems?has_content> -import ${packageModel}.customvalidator.MaxItems; - <#break> - - -<#list schema.fieldObjectList as field> - <#if field.restrictions.minItems?has_content> -import ${packageModel}.customvalidator.MinItems; - <#break> - - -<#list schema.fieldObjectList as field> - <#if field.required || schema.schemaCombinator == "anyOf" || schema.schemaCombinator == "oneOf"> -import ${packageModel}.exception.ModelClassException; - <#break> - - -<#list schema.fieldObjectList as field> - <#if field.restrictions.pattern?has_content> -import ${packageModel}.customvalidator.Pattern; - <#break> - - -<#list schema.fieldObjectList as field> - <#if field.restrictions.multipleOf?has_content> -import ${packageModel}.customvalidator.MultipleOf; - <#break> - - -<#list schema.fieldObjectList as field> - <#if field.required?has_content && field.required == true> -import ${packageModel}.customvalidator.NotNull; - <#break> - - -<#list schema.fieldObjectList as field> - <#if field.restrictions.uniqueItems?has_content && field.restrictions.uniqueItems == true> -import ${packageModel}.customvalidator.UniqueItems; - <#break> - - - -@JsonDeserialize(builder = ${schema.className}.${schema.className}Builder.class) -public class ${schema.className} { - -<#list schema.fieldObjectList as field> - @JsonProperty(value ="${calculateSafeName (field.baseName, "")}") - <#if field.restrictions.minimum?has_content && (!field.restrictions.exclusiveMinimum?has_content || field.restrictions.exclusiveMinimum == false)> - @Min(minimum = "${field.restrictions.minimum}", exclusive = false) - - <#if field.restrictions.minimum?has_content && field.restrictions.exclusiveMinimum?has_content && field.restrictions.exclusiveMinimum == true> - @Min(minimum = "${field.restrictions.minimum}", exclusive = ${field.restrictions.exclusiveMinimum?string}) - - <#if field.restrictions.maximum?has_content && (!field.restrictions.exclusiveMaximum?has_content || field.restrictions.exclusiveMaximum == false)> - @Max(maximum = "${field.restrictions.maximum}", exclusive = false) - - <#if field.restrictions.maximum?has_content && field.restrictions.exclusiveMaximum?has_content && field.restrictions.exclusiveMaximum == true> - @Max(maximum = "${field.restrictions.maximum}", exclusive = ${field.restrictions.exclusiveMaximum?string}) - - <#if field.restrictions.maxItems?has_content> - @MaxItems(maximum = ${field.restrictions.maxItems}) - - <#if field.restrictions.minItems?has_content> - @MinItems(minimum = ${field.restrictions.minItems}) - - <#if field.restrictions.uniqueItems?has_content && field.restrictions.uniqueItems == true> - @UniqueItems - - <#if field.restrictions.maxLength?has_content && field.restrictions.minLength?has_content> - @Size(min =${field.restrictions.minLength}, max =${field.restrictions.maxLength}) - <#elseif field.restrictions.maxLength?has_content && !field.restrictions.minLength?has_content> - @Size(max =${field.restrictions.maxLength}, min =0) - <#elseif !field.restrictions.maxLength?has_content && field.restrictions.minLength?has_content> - @Size(max =0, min =${field.restrictions.minLength}) - - <#if field.restrictions.pattern?has_content> - @Pattern(regex = "${field.restrictions.pattern}") - - <#if field.restrictions.multipleOf?has_content> - @MultipleOf(multiple = "${field.restrictions.multipleOf}") - - <#if field.required?has_content && field.required == true> - @NotNull - - <#if field.dataType.baseType == "array"> - <#if field.required> - private final ${field.dataType} ${calculateSafeName (field.baseName, ";")} - <#else> - private ${field.dataType} ${calculateSafeName (field.baseName, "")} = new ${field.dataType?api.getImplementationTypeString()}(); - - <#elseif field.dataType.baseType == "map"> - <#if field.required> - private final ${field.dataType} ${calculateSafeName (field.baseName, ";")} - <#else> - private ${field.dataType} ${calculateSafeName (field.baseName, "")} = new ${field.dataType?api.getImplementationTypeString()}(); - - <#elseif field.dataType.baseType == "enum"> - <#if field.required> - private final ${field.baseName?cap_first} ${calculateSafeName (field.baseName, ";")} - <#else> - private ${field.baseName?cap_first} ${calculateSafeName (field.baseName, ";")} - - public enum ${field.baseName?cap_first} { -<#list field.enumValues as key, value> - <#if key?matches("[0-9].*")> - ${"_"+key}(${value})<#sep>, - <#else> - ${key}(${value})<#sep>, - -; - - private ${field.dataType.innerType?cap_first} value; - - ${field.baseName?cap_first}(${field.dataType.innerType?cap_first} value) { - this.value = value; - } - - @JsonValue - public ${field.dataType.innerType?cap_first} getValue() { - return value; - } - - @Override - public String toString() { - return String.valueOf(value); - } - } - <#elseif field.dataType.innerType?has_content && field.dataType.baseType == "object"> - <#if field.required> - private final ${field.dataType.innerType?cap_first} ${calculateSafeName (field.baseName, ";")} - <#else> - private ${field.dataType.innerType?cap_first} ${calculateSafeName (field.baseName, ";")} - - <#else> - <#if field.required> - private final ${field.dataType} ${calculateSafeName (field.baseName, ";")} - <#else> - private ${field.dataType} ${calculateSafeName (field.baseName, ";")} - - - - - private ${schema.className}(<@compress single_line=true><#list schema.fieldObjectList as field> - <#if field.dataType.baseType == "enum">${field.baseName?cap_first} ${calculateSafeName (field.baseName, "")}<#elseif field.dataType.baseType == "array">${field.dataType} ${calculateSafeName (field.baseName, "")}<#elseif field.dataType.baseType == "map">${field.dataType} ${calculateSafeName (field.baseName, "")}<#elseif field.dataType.innerType?has_content && field.dataType.baseType == "object">${field.dataType.innerType?cap_first} ${calculateSafeName (field.baseName, "")}<#else>${field.dataType} ${calculateSafeName (field.baseName, "")}<#sep>, ) { - <#list schema.fieldObjectList as field> - this.${calculateSafeName (field.baseName, "")} = ${calculateSafeName (field.baseName, ";")} - - - <#list schema.fieldObjectList as field> - <#if field.required> - validateRequiredAttributes(); - <#break> - - - <#if schema.schemaCombinator == "anyOf" || schema.schemaCombinator == "oneOf"> - validatePartialCombinations(); - - } - - private ${schema.className}(${schema.className}Builder builder) { - <#list schema.fieldObjectList as field> - this.${calculateSafeName (field.baseName, "")} = builder.${calculateSafeName (field.baseName, ";")} - - - <#list schema.fieldObjectList as field> - <#if field.required> - validateRequiredAttributes(); - <#break> - - - <#if schema.schemaCombinator == "anyOf" || schema.schemaCombinator == "oneOf"> - validatePartialCombinations(); - - } - - public static ${schema.className}.${schema.className}Builder builder() { - return new ${schema.className}.${schema.className}Builder(); - } - - @JsonPOJOBuilder(buildMethodName = "build", withPrefix = "") - public static class ${schema.className}Builder { - -<#list schema.fieldObjectList as field> - <#if field.dataType.baseType == "array"> - private ${field.dataType} ${calculateSafeName (field.baseName, "")} = new ${field.dataType?api.getImplementationTypeString()}(); - <#elseif field.dataType.baseType == "map"> - private ${field.dataType} ${calculateSafeName (field.baseName, "")} = new ${field.dataType?api.getImplementationTypeString()}(); - <#elseif field.dataType.baseType == "enum"> - private ${field.baseName?cap_first} ${calculateSafeName (field.baseName, ";")} - <#elseif field.dataType.innerType?has_content && field.dataType.baseType == "object"> - private ${field.dataType.innerType?cap_first} ${calculateSafeName (field.baseName, ";")} - <#else> - private ${field.dataType} ${calculateSafeName (field.baseName, ";")} - - -<#list schema.fieldObjectList as field> - <#if field.dataType.baseType == "array"> - <#assign propName>${calculateSafeName (field.baseName, "")} - public ${schema.className}.${schema.className}Builder ${propName}(${field.dataType} ${propName}) { - if (!${propName}.isEmpty()) { - this.${propName}.addAll(${propName}); - } - return this; - } - - <#assign singName>${singularizeName (calculateSafeName (field.baseName, ""))} - public ${schema.className}.${schema.className}Builder ${singName}(${field.dataType.innerType} ${singName}) { - if (${singName} != null) { - this.${propName}.add(${singName}); - } - return this; - } - <#elseif field.dataType.baseType == "map"> - <#assign propName>${calculateSafeName (field.baseName, "")} - public ${schema.className}.${schema.className}Builder ${propName}(${field.dataType} ${propName}) { - this.${propName} = ${propName}; - return this; - } - - public ${schema.className}.${schema.className}Builder ${propName}Value(String key, ${field.dataType.innerType} value) { - this.${propName}.put(key, value); - return this; - } - <#elseif field.dataType.baseType == "enum"> - public ${schema.className}.${schema.className}Builder ${calculateSafeName (field.baseName, "")}(${field.baseName?cap_first} ${field.baseName}) { - this.${calculateSafeName (field.baseName, "")} = ${calculateSafeName (field.baseName, ";")} - return this; - } - <#elseif field.dataType.innerType?has_content && field.dataType.baseType == "object"> - public ${schema.className}.${schema.className}Builder ${calculateSafeName (field.baseName, "")}(${field.dataType.innerType?cap_first} ${calculateSafeName (field.baseName, "")}) { - this.${calculateSafeName (field.baseName, "")} = ${calculateSafeName (field.baseName, ";")} - return this; - } - <#else> - - public ${schema.className}.${schema.className}Builder ${calculateSafeName (field.baseName, "")}(${field.dataType} ${calculateSafeName (field.baseName, "")}) { - this.${calculateSafeName (field.baseName, "")} = ${calculateSafeName (field.baseName, ";")} - return this; - } - - - - public ${schema.className} build() { - ${schema.className} ${schema.className?uncap_first} = new ${schema.className}(this); - return ${schema.className?uncap_first}; - } - } - -<#list schema.fieldObjectList as field> - @Schema(name = "${field.baseName?uncap_first}", required = <#if field.required?has_content && field.required == true>true<#else>false) - <#if field.dataType.baseType == "array"> - public ${field.dataType} get${field.baseName?cap_first}() { - return ${calculateSafeName (field.baseName, ";")} - } - <#if checkIfShouldSet (field)> - public void set${field.baseName?cap_first}(${field.dataType} ${calculateSafeName (field.baseName, "")}) { - this.${calculateSafeName (field.baseName, "")} = ${calculateSafeName (field.baseName, ";")} - } - - <#elseif field.dataType.baseType == "map"> - public ${field.dataType} get${field.baseName?cap_first}() { - return ${calculateSafeName (field.baseName, ";")} - } - <#if checkIfShouldSet (field)> - public void set${field.baseName?cap_first}(${field.dataType} ${calculateSafeName (field.baseName, "")}) { - this.${calculateSafeName (field.baseName, "")} = ${calculateSafeName (field.baseName, ";")} - } - - <#elseif field.dataType.baseType == "enum"> - public ${field.baseName?cap_first} get${field.baseName?cap_first}() { - return ${calculateSafeName (field.baseName, ";")} - } - <#if checkIfShouldSet (field)> - public void set${field.baseName?cap_first}(${field.baseName?cap_first} ${calculateSafeName (field.baseName, "")}) { - this.${calculateSafeName (field.baseName, "")} = ${calculateSafeName (field.baseName, ";")} - } - - <#elseif field.dataType.innerType?has_content && field.dataType.baseType == "object"> - public ${field.dataType.innerType?cap_first} get${field.baseName?cap_first}() { - return ${calculateSafeName (field.baseName, ";")} - } - <#if checkIfShouldSet (field)> - public void set${field.baseName?cap_first}(${field.dataType.innerType?cap_first} ${calculateSafeName (field.baseName, "")}) { - this.${calculateSafeName (field.baseName, "")} = ${calculateSafeName (field.baseName, ";")} - } - - <#else> - public ${field.dataType} get${field.baseName?cap_first}() { - return ${calculateSafeName (field.baseName, ";")} - } - <#if field.required == false> - public void set${field.baseName?cap_first}(${field.dataType} ${calculateSafeName (field.baseName, "")}) { - this.${calculateSafeName (field.baseName, "")} = ${calculateSafeName (field.baseName, ";")} - } - - - - - @Override - public boolean equals(Object o) { - if (this == o) { - return true; - } - if (o == null || getClass() != o.getClass()) { - return false; - } - ${schema.className} ${schema.className?uncap_first} = (${schema.className}) o; - return <#compress><#list schema.fieldObjectList as field> Objects.equals(this.${calculateSafeName (field.baseName, "")}, ${schema.className?uncap_first}.${calculateSafeName (field.baseName, "")})<#if field?has_next> && ; - } - - @Override - public int hashCode() { - return Objects.hash(<#list schema.fieldObjectList as field>${calculateSafeName (field.baseName, "")}<#if field?has_next>, ); - } - - @Override - public String toString() { - StringBuilder sb = new StringBuilder(); - sb.append("${schema.className}{"); -<#list schema.fieldObjectList as field> - <#if field_has_next> - sb.append(" ${field.baseName?uncap_first}:").append(${calculateSafeName (field.baseName, "")}).append(","); - <#else> - sb.append(" ${field.baseName?uncap_first}:").append(${calculateSafeName (field.baseName, "")}); - - - sb.append("}"); - return sb.toString(); - } - - <#if schema.schemaCombinator == "anyOf" || schema.schemaCombinator == "oneOf"> - private void validatePartialCombinations() { - boolean satisfiedCondition = false; - - <#list schema.fieldObjectList as field> - <#if field == schema.fieldObjectList?first> - if (Objects.nonNull(this.${calculateSafeName (field.baseName, "")})) { - <#else> else if (Objects.nonNull(this.${calculateSafeName (field.baseName, "")})) { - satisfiedCondition = true; - } - - if (!satisfiedCondition) { - throw new ModelClassException("${schema.className}"); - } - } - - <#list schema.fieldObjectList as field> - <#if field.required> - private void validateRequiredAttributes() { - boolean satisfiedCondition = true; - - <#list schema.fieldObjectList?filter(f -> f.required) as field> - <#if field?index == 0> - if (!Objects.nonNull(this.${calculateSafeName (field.baseName, "")})) { - <#else> - else if (!Objects.nonNull(this.${calculateSafeName (field.baseName, "")})) { - - satisfiedCondition = false; - } - - if (!satisfiedCondition) { - throw new ModelClassException("${schema.className}"); - } - } - <#break> - - - -} diff --git a/multiapi-engine/src/main/resources/templates/openapi/templateSchemaWithLombok.ftlh b/multiapi-engine/src/main/resources/templates/openapi/templateSchemaWithLombok.ftlh deleted file mode 100644 index 9ee88262..00000000 --- a/multiapi-engine/src/main/resources/templates/openapi/templateSchemaWithLombok.ftlh +++ /dev/null @@ -1,187 +0,0 @@ -<#ftl output_format="plainText"> -package ${packageModel}; - -<#if schema.schemaCombinator == "anyOf" || schema.schemaCombinator == "oneOf"> -import java.util.Objects; - -import com.fasterxml.jackson.annotation.JsonProperty; -<#list schema.fieldObjectList as field> - <#if field.dataType.baseType == "enum"> -import com.fasterxml.jackson.annotation.JsonValue; - <#break> - - -<#list schema.importList as import> -import ${import}; - -<#list schema.fieldObjectList as field> - <#if field.restrictionProperties.maxLength?has_content || field.restrictionProperties.minLength?has_content> -import ${packageModel}.customvalidator.Size; - <#break> - - -<#list schema.fieldObjectList as field> - <#if field.restrictionProperties.maximum?has_content> -import ${packageModel}.customvalidator.Max; - <#break> - - -<#list schema.fieldObjectList as field> - <#if field.restrictionProperties.minimum?has_content> -import ${packageModel}.customvalidator.Min; - <#break> - - -<#list schema.fieldObjectList as field> - <#if field.restrictionProperties.pattern?has_content> -import ${packageModel}.customvalidator.Pattern; - - -<#list schema.fieldObjectList as field> - <#if field.restrictionProperties.multipleOf?has_content> -import ${packageModel}.customvalidator.MultipleOf; - <#break> - - -<#list schema.fieldObjectList as field> - <#if field.restrictionProperties.maxItems?has_content> -import ${packageModel}.customvalidator.MaxItems; - <#break> - - -<#list schema.fieldObjectList as field> - <#if field.restrictionProperties.minItems?has_content> -import ${packageModel}.customvalidator.MinItems; - <#break> - - -<#list schema.fieldObjectList as field> - <#if field.restrictionProperties.uniqueItems?has_content && field.restrictionProperties.uniqueItems == true> -import ${packageModel}.customvalidator.UniqueItems; - <#break> - - -import lombok.Builder; -import lombok.Data; -<#list schema.fieldObjectList as field> - <#if field.required> -import lombok.NonNull; - <#break> - - -import lombok.extern.jackson.Jacksonized; -<#if schema.schemaCombinator == "anyOf" || schema.schemaCombinator == "oneOf"> -import ${packageModel}.exception.ModelClassException; - - -@Data -public class ${schema.className} { - -<#list schema.fieldObjectList as field> - @JsonProperty(value ="${field.baseName?uncap_first}") - <#if field.restrictionProperties.minimum?has_content && (!field.restrictionProperties.exclusiveMinimum?has_content || field.restrictionProperties.exclusiveMinimum == false)> - @Min(minimum = "${field.restrictionProperties.minimum}", exclusive = false) - - <#if field.restrictionProperties.minimum?has_content && field.restrictionProperties.exclusiveMinimum?has_content && field.restrictionProperties.exclusiveMinimum == true> - @Min(minimum = "${field.restrictionProperties.minimum}", exclusive = ${field.restrictionProperties.exclusiveMinimum?string}) - - <#if field.restrictionProperties.maximum?has_content && (!field.restrictionProperties.exclusiveMaximum?has_content || field.restrictionProperties.exclusiveMaximum == false)> - @Max(maximum = "${field.restrictionProperties.maximum}", exclusive = false) - - <#if field.restrictionProperties.maximum?has_content && field.restrictionProperties.exclusiveMaximum?has_content && field.restrictionProperties.exclusiveMaximum == true> - @Max(maximum = "${field.restrictionProperties.maximum}", exclusive = ${field.restrictionProperties.exclusiveMaximum?string}) - - <#if field.restrictionProperties.maxItems?has_content> - @MaxItems(maximum = ${field.restrictionProperties.maxItems}) - - <#if field.restrictionProperties.minItems?has_content> - @MinItems(minimum = ${field.restrictionProperties.minItems}) - - <#if field.restrictionProperties.uniqueItems?has_content && field.restrictionProperties.uniqueItems == true> - @UniqueItems - - <#if field.restrictionProperties.maxLength?has_content && field.restrictionProperties.minLength?has_content> - @Size(min =${field.restrictionProperties.minLength}, max =${field.restrictionProperties.maxLength}) - <#elseif field.restrictionProperties.maxLength?has_content && !field.restrictionProperties.minLength?has_content> - @Size(min =0, max =${field.restrictionProperties.maxLength}) - <#elseif !field.restrictionProperties.maxLength?has_content && field.restrictionProperties.minLength?has_content> - @Size(min =${field.restrictionProperties.minLength}, max =0) - - <#if field.restrictionProperties.pattern?has_content> - @Pattern(regex = "${field.restrictionProperties.pattern}") - - <#if field.restrictionProperties.multipleOf?has_content> - @MultipleOf(multiple = "${field.restrictionProperties.multipleOf}") - - <#if field.required?has_content && field.required == true> - @NonNull - - <#if field.dataType.baseType == "array"> - private ${field.dataType} ${field.baseName?uncap_first} = new ${field.dataType?api.getImplementationTypeString()}(); - <#elseif field.dataType.baseType == "map"> - private ${field.dataType} ${field.baseName?uncap_first} = new ${field.dataType?api.getImplementationTypeString()}(); - <#elseif field.dataType.baseType == "enum"> - private ${field.baseName?cap_first} ${field.baseName?uncap_first}; - - public enum ${field.baseName?cap_first} { -<#list field.enumValues as key, value> - <#if key?matches("[0-9].*")> - ${"_"+key}(${value})<#sep>, - <#else> - ${key}(${value})<#sep>, - -; - - private ${field.dataType.innerType?cap_first} value; - - ${field.baseName?cap_first}(${field.dataType.innerType?cap_first} value) { - this.value = value; - } - - @JsonValue - public ${field.dataType.innerType?cap_first} getValue() { - return value; - } - - @Override - public String toString() { - return String.valueOf(value); - } - } - <#elseif field.dataType.innerType?has_content && field.dataType.baseType == "object"> - private ${field.dataType.innerType?cap_first} ${field.baseName?uncap_first}; - <#else> - private ${field.dataType} ${field.baseName?uncap_first}; - - - - - @Builder - @Jacksonized - private ${schema.className}(<@compress single_line=true><#list schema.fieldObjectList as field> - <#if field.required>@NonNull <#if field.dataType.baseType == "enum">${field.baseName?cap_first} ${field.baseName?uncap_first}<#elseif field.dataType.baseType == "array">${field.dataType} ${field.baseName?uncap_first}<#elseif field.dataType.baseType == "map">${field.dataType} ${field.baseName?uncap_first}<#elseif field.dataType.innerType?has_content && field.dataType.baseType == "object">${field.dataType.innerType?cap_first} ${field.baseName?uncap_first}<#else>${field.dataType} ${field.baseName?uncap_first}<#sep>, ) { - <#list schema.fieldObjectList as field> - this.${field.baseName?uncap_first} = ${field.baseName?uncap_first}; - - - <#if schema.schemaCombinator == "anyOf" || schema.schemaCombinator == "oneOf"> - validatePartialCombinations(); - - } - - <#if schema.schemaCombinator == "anyOf" || schema.schemaCombinator == "oneOf"> - private void validatePartialCombinations() { - boolean satisfiedCondition = false; - - <#list schema.fieldObjectList as field> - <#if field == schema.fieldObjectList?first> - if (Objects.nonNull(this.${field.baseName?uncap_first})) {<#else> else if (Objects.nonNull(this.${field.baseName?uncap_first})) { - satisfiedCondition = true; - } - - if (!satisfiedCondition) { - throw new ModelClassException("${schema.className}"); - } - } - -} 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 1889f675..ef75a7d3 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 @@ -28,7 +28,7 @@ @Slf4j class AsyncApiGeneratorTest { - @TempDir(cleanup = CleanupMode.NEVER) + @TempDir(cleanup = CleanupMode.ALWAYS) static Path baseDir; private static AsyncApiGenerator asyncApiGenerator; diff --git a/multiapi-engine/src/test/java/com/sngular/api/generator/plugin/openapi/OpenApiGeneratorFixtures.java b/multiapi-engine/src/test/java/com/sngular/api/generator/plugin/openapi/OpenApiGeneratorFixtures.java index 4b0f3ea1..5d36afa3 100644 --- a/multiapi-engine/src/test/java/com/sngular/api/generator/plugin/openapi/OpenApiGeneratorFixtures.java +++ b/multiapi-engine/src/test/java/com/sngular/api/generator/plugin/openapi/OpenApiGeneratorFixtures.java @@ -1266,7 +1266,7 @@ static Function validateValidationAnnotations(int springBootVersi ASSETS_PATH + "ModelClassException.java"); final List expectedValidatorFiles = List.of( - CUSTOM_VALIDATOR_PATH + "Max.java", + CUSTOM_VALIDATOR_PATH + "MaxInteger.java", CUSTOM_VALIDATOR_PATH + "MaxItems.java", CUSTOM_VALIDATOR_PATH + "MaxItemsValidator.java", CUSTOM_VALIDATOR_PATH + "MaxValidator.java", diff --git a/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/assets/DataDTO.java b/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/assets/DataDTO.java index b6f50518..457ee5bc 100644 --- a/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/assets/DataDTO.java +++ b/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/assets/DataDTO.java @@ -155,9 +155,9 @@ private void validateRequiredAttributes() { if (!Objects.nonNull(this.clientName)) { satisfiedCondition = false; - } else if (!Objects.nonNull(this.flightNumber)) { + } else if (!Objects.nonNull(this.flightNumber)) { satisfiedCondition = false; - } else if (!Objects.nonNull(this.clientId)) { + } else if (!Objects.nonNull(this.clientId)) { satisfiedCondition = false; } diff --git a/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/jakarta/MaxBigDecimal.java b/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/jakarta/MaxBigDecimal.java new file mode 100644 index 00000000..8c0f7d77 --- /dev/null +++ b/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/jakarta/MaxBigDecimal.java @@ -0,0 +1,18 @@ +package com.sngular.scsplugin.customvalidator.model.event.customvalidator; + +import jakarta.validation.Constraint; +import jakarta.validation.Payload; +import java.lang.annotation.*; + +@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, +ElementType.ANNOTATION_TYPE}) +@Retention(RetentionPolicy.RUNTIME) +@Constraint(validatedBy = MaxBigDecimalValidator.class) +@Documented +public @interface MaxBigDecimal { + String maximum(); + boolean exclusive(); + String message() default "Value is bigger than the maximum."; + Class[] groups() default {}; + Class[] payload() default {}; +} \ No newline at end of file diff --git a/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/jakarta/MaxBigDecimalValidator.java b/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/jakarta/MaxBigDecimalValidator.java new file mode 100644 index 00000000..c424983c --- /dev/null +++ b/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/jakarta/MaxBigDecimalValidator.java @@ -0,0 +1,24 @@ +package com.sngular.scsplugin.customvalidator.model.event.customvalidator; + +import java.util.Objects; + +import jakarta.validation.ConstraintValidator; +import jakarta.validation.ConstraintValidatorContext; + +public class MaxValidator implements ConstraintValidator { + + private int maximum; + private boolean exclusive; + + @Override + public void initialize(Max constraintAnnotation) { + ConstraintValidator.super.initialize(constraintAnnotation); + this.maximum = Integer.parseInt(constraintAnnotation.maximum()); + this.exclusive = constraintAnnotation.exclusive(); + } + + @Override + public boolean isValid(Integer value, ConstraintValidatorContext context) { + return Objects.isNull(value) || (value.intValue() < this.maximum || (!exclusive && value.intValue() == this.maximum)); + } +} \ No newline at end of file diff --git a/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/jakarta/Max.java b/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/jakarta/MaxInteger.java similarity index 86% rename from multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/jakarta/Max.java rename to multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/jakarta/MaxInteger.java index b0ab6009..8ada1624 100644 --- a/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/jakarta/Max.java +++ b/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/jakarta/MaxInteger.java @@ -7,9 +7,9 @@ @Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, ElementType.ANNOTATION_TYPE}) @Retention(RetentionPolicy.RUNTIME) -@Constraint(validatedBy = MaxValidator.class) +@Constraint(validatedBy = MaxIntegerValidator.class) @Documented -public @interface Max { +public @interface MaxInteger { String maximum(); boolean exclusive(); String message() default "Value is bigger than the maximum."; diff --git a/multiapi-engine/src/test/resources/asyncapigenerator/testFileGeneration/assets/OrderProductDTO.java b/multiapi-engine/src/test/resources/asyncapigenerator/testFileGeneration/assets/OrderProductDTO.java index e9930c03..3bb3ffe2 100644 --- a/multiapi-engine/src/test/resources/asyncapigenerator/testFileGeneration/assets/OrderProductDTO.java +++ b/multiapi-engine/src/test/resources/asyncapigenerator/testFileGeneration/assets/OrderProductDTO.java @@ -126,11 +126,11 @@ private void validateRequiredAttributes() { if (!Objects.nonNull(this.productRef)) { satisfiedCondition = false; - } else if (!Objects.nonNull(this.price)) { + } else if (!Objects.nonNull(this.price)) { satisfiedCondition = false; - } else if (!Objects.nonNull(this.quantity)) { + } else if (!Objects.nonNull(this.quantity)) { satisfiedCondition = false; - } else if (!Objects.nonNull(this.ref)) { + } else if (!Objects.nonNull(this.ref)) { satisfiedCondition = false; } diff --git a/multiapi-engine/src/test/resources/asyncapigenerator/testFileGeneration/assets/OrderProductMapper.java b/multiapi-engine/src/test/resources/asyncapigenerator/testFileGeneration/assets/OrderProductMapper.java index 90153fe6..263e0920 100644 --- a/multiapi-engine/src/test/resources/asyncapigenerator/testFileGeneration/assets/OrderProductMapper.java +++ b/multiapi-engine/src/test/resources/asyncapigenerator/testFileGeneration/assets/OrderProductMapper.java @@ -126,11 +126,11 @@ private void validateRequiredAttributes() { if (!Objects.nonNull(this.productRef)) { satisfiedCondition = false; - } else if (!Objects.nonNull(this.price)) { + } else if (!Objects.nonNull(this.price)) { satisfiedCondition = false; - } else if (!Objects.nonNull(this.quantity)) { + } else if (!Objects.nonNull(this.quantity)) { satisfiedCondition = false; - } else if (!Objects.nonNull(this.ref)) { + } else if (!Objects.nonNull(this.ref)) { satisfiedCondition = false; } diff --git a/multiapi-engine/src/test/resources/asyncapigenerator/testFileGenerationIssue/assets/CustomerDTO.java b/multiapi-engine/src/test/resources/asyncapigenerator/testFileGenerationIssue/assets/CustomerDTO.java index 4d7222e2..b0925d90 100644 --- a/multiapi-engine/src/test/resources/asyncapigenerator/testFileGenerationIssue/assets/CustomerDTO.java +++ b/multiapi-engine/src/test/resources/asyncapigenerator/testFileGenerationIssue/assets/CustomerDTO.java @@ -166,13 +166,13 @@ private void validateRequiredAttributes() { if (!Objects.nonNull(this.email)) { satisfiedCondition = false; - } else if (!Objects.nonNull(this.username)) { + } else if (!Objects.nonNull(this.username)) { satisfiedCondition = false; - } else if (!Objects.nonNull(this.firstName)) { + } else if (!Objects.nonNull(this.firstName)) { satisfiedCondition = false; - } else if (!Objects.nonNull(this.lastName)) { + } else if (!Objects.nonNull(this.lastName)) { satisfiedCondition = false; - } else if (!Objects.nonNull(this.password)) { + } else if (!Objects.nonNull(this.password)) { satisfiedCondition = false; } diff --git a/multiapi-engine/src/test/resources/asyncapigenerator/testFileGenerationIssue/assets/OrderedItemDTO.java b/multiapi-engine/src/test/resources/asyncapigenerator/testFileGenerationIssue/assets/OrderedItemDTO.java index 41dbd6d8..f5842151 100644 --- a/multiapi-engine/src/test/resources/asyncapigenerator/testFileGenerationIssue/assets/OrderedItemDTO.java +++ b/multiapi-engine/src/test/resources/asyncapigenerator/testFileGenerationIssue/assets/OrderedItemDTO.java @@ -132,7 +132,7 @@ private void validateRequiredAttributes() { if (!Objects.nonNull(this.name)) { satisfiedCondition = false; - } else if (!Objects.nonNull(this.price)) { + } else if (!Objects.nonNull(this.price)) { satisfiedCondition = false; } diff --git a/multiapi-engine/src/test/resources/asyncapigenerator/testFileGenerationWithKafkaBindings/assets/OrderProductDTO.java b/multiapi-engine/src/test/resources/asyncapigenerator/testFileGenerationWithKafkaBindings/assets/OrderProductDTO.java index 7bb3c5f3..4fa4cafa 100644 --- a/multiapi-engine/src/test/resources/asyncapigenerator/testFileGenerationWithKafkaBindings/assets/OrderProductDTO.java +++ b/multiapi-engine/src/test/resources/asyncapigenerator/testFileGenerationWithKafkaBindings/assets/OrderProductDTO.java @@ -126,11 +126,11 @@ private void validateRequiredAttributes() { if (!Objects.nonNull(this.productRef)) { satisfiedCondition = false; - } else if (!Objects.nonNull(this.price)) { + } else if (!Objects.nonNull(this.price)) { satisfiedCondition = false; - } else if (!Objects.nonNull(this.quantity)) { + } else if (!Objects.nonNull(this.quantity)) { satisfiedCondition = false; - } else if (!Objects.nonNull(this.ref)) { + } else if (!Objects.nonNull(this.ref)) { satisfiedCondition = false; } diff --git a/multiapi-engine/src/test/resources/asyncapigenerator/testFileGenerationWithKafkaBindings/assets/OrderProductMapper.java b/multiapi-engine/src/test/resources/asyncapigenerator/testFileGenerationWithKafkaBindings/assets/OrderProductMapper.java index 8505c097..bc0bda51 100644 --- a/multiapi-engine/src/test/resources/asyncapigenerator/testFileGenerationWithKafkaBindings/assets/OrderProductMapper.java +++ b/multiapi-engine/src/test/resources/asyncapigenerator/testFileGenerationWithKafkaBindings/assets/OrderProductMapper.java @@ -126,11 +126,11 @@ private void validateRequiredAttributes() { if (!Objects.nonNull(this.productRef)) { satisfiedCondition = false; - } else if (!Objects.nonNull(this.price)) { + } else if (!Objects.nonNull(this.price)) { satisfiedCondition = false; - } else if (!Objects.nonNull(this.quantity)) { + } else if (!Objects.nonNull(this.quantity)) { satisfiedCondition = false; - } else if (!Objects.nonNull(this.ref)) { + } else if (!Objects.nonNull(this.ref)) { satisfiedCondition = false; } diff --git a/multiapi-engine/src/test/resources/asyncapigenerator/testModelClassExceptionGeneration/assets/OrderProductDTO.java b/multiapi-engine/src/test/resources/asyncapigenerator/testModelClassExceptionGeneration/assets/OrderProductDTO.java index 04d3071d..e9387fdf 100644 --- a/multiapi-engine/src/test/resources/asyncapigenerator/testModelClassExceptionGeneration/assets/OrderProductDTO.java +++ b/multiapi-engine/src/test/resources/asyncapigenerator/testModelClassExceptionGeneration/assets/OrderProductDTO.java @@ -126,11 +126,11 @@ private void validateRequiredAttributes() { if (!Objects.nonNull(this.productRef)) { satisfiedCondition = false; - } else if (!Objects.nonNull(this.price)) { + } else if (!Objects.nonNull(this.price)) { satisfiedCondition = false; - } else if (!Objects.nonNull(this.quantity)) { + } else if (!Objects.nonNull(this.quantity)) { satisfiedCondition = false; - } else if (!Objects.nonNull(this.ref)) { + } else if (!Objects.nonNull(this.ref)) { satisfiedCondition = false; } diff --git a/multiapi-engine/src/test/resources/openapigenerator/testAllOf/assets/lombok/ApiTestAllOfDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testAllOf/assets/lombok/ApiTestAllOfDTO.java index 4a799d8c..44fae21e 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testAllOf/assets/lombok/ApiTestAllOfDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testAllOf/assets/lombok/ApiTestAllOfDTO.java @@ -11,7 +11,7 @@ public class ApiTestAllOfDTO { @JsonProperty(value ="testers") - private List testers = new ArrayList(); + private List testers; @JsonProperty(value ="testName") private String testName; diff --git a/multiapi-engine/src/test/resources/openapigenerator/testAllOf/assets/lombok/ApiTestDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testAllOf/assets/lombok/ApiTestDTO.java index 85b68845..9d9e9e27 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testAllOf/assets/lombok/ApiTestDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testAllOf/assets/lombok/ApiTestDTO.java @@ -13,7 +13,7 @@ public class ApiTestDTO { @JsonProperty(value ="testers") @NonNull - private List testers = new ArrayList(); + private List testers; @JsonProperty(value ="testName") @NonNull diff --git a/multiapi-engine/src/test/resources/openapigenerator/testAllOf/assets/lombok/ApiTestInfoDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testAllOf/assets/lombok/ApiTestInfoDTO.java index 87407a3f..740549d2 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testAllOf/assets/lombok/ApiTestInfoDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testAllOf/assets/lombok/ApiTestInfoDTO.java @@ -12,7 +12,7 @@ public class ApiTestInfoDTO { @JsonProperty(value ="testers") - private List testers = new ArrayList(); + private List testers; @JsonProperty(value ="testName") @NonNull diff --git a/multiapi-engine/src/test/resources/openapigenerator/testAllOf/assets/testApi/ApiErrorDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testAllOf/assets/testApi/ApiErrorDTO.java index ddb14ec6..c063653c 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testAllOf/assets/testApi/ApiErrorDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testAllOf/assets/testApi/ApiErrorDTO.java @@ -19,13 +19,6 @@ public class ApiErrorDTO { @NotNull private final String message; - private ApiErrorDTO(Integer code, String message) { - this.code = code; - this.message = message; - - validateRequiredAttributes(); - } - private ApiErrorDTO(ApiErrorDTOBuilder builder) { this.code = builder.code; this.message = builder.message; diff --git a/multiapi-engine/src/test/resources/openapigenerator/testAllOf/assets/testApi/ApiTestAllOfDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testAllOf/assets/testApi/ApiTestAllOfDTO.java index d4bb48f1..eaee11fe 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testAllOf/assets/testApi/ApiTestAllOfDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testAllOf/assets/testApi/ApiTestAllOfDTO.java @@ -13,16 +13,10 @@ public class ApiTestAllOfDTO { @JsonProperty(value ="testers") - private List testers = new ArrayList(); + private List testers; @JsonProperty(value ="testName") private String testName; - private ApiTestAllOfDTO(List testers, String testName) { - this.testers = testers; - this.testName = testName; - - } - private ApiTestAllOfDTO(ApiTestAllOfDTOBuilder builder) { this.testers = builder.testers; this.testName = builder.testName; @@ -38,6 +32,7 @@ public static class ApiTestAllOfDTOBuilder { private List testers = new ArrayList(); private String testName; + public ApiTestAllOfDTO.ApiTestAllOfDTOBuilder testers(List testers) { if (!testers.isEmpty()) { this.testers.addAll(testers); diff --git a/multiapi-engine/src/test/resources/openapigenerator/testAllOf/assets/testApi/ApiTestDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testAllOf/assets/testApi/ApiTestDTO.java index e996a8ad..af64704d 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testAllOf/assets/testApi/ApiTestDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testAllOf/assets/testApi/ApiTestDTO.java @@ -21,13 +21,6 @@ public class ApiTestDTO { @NotNull private final String testName; - private ApiTestDTO(List testers, String testName) { - this.testers = testers; - this.testName = testName; - - validateRequiredAttributes(); - } - private ApiTestDTO(ApiTestDTOBuilder builder) { this.testers = builder.testers; this.testName = builder.testName; @@ -44,6 +37,7 @@ public static class ApiTestDTOBuilder { private List testers = new ArrayList(); private String testName; + public ApiTestDTO.ApiTestDTOBuilder testers(List testers) { if (!testers.isEmpty()) { this.testers.addAll(testers); diff --git a/multiapi-engine/src/test/resources/openapigenerator/testAllOf/assets/testApi/ApiTestInfoDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testAllOf/assets/testApi/ApiTestInfoDTO.java index 37f92f5e..d1bba8fa 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testAllOf/assets/testApi/ApiTestInfoDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testAllOf/assets/testApi/ApiTestInfoDTO.java @@ -15,18 +15,11 @@ public class ApiTestInfoDTO { @JsonProperty(value ="testers") - private List testers = new ArrayList(); + private List testers; @JsonProperty(value ="testName") @NotNull private final String testName; - private ApiTestInfoDTO(List testers, String testName) { - this.testers = testers; - this.testName = testName; - - validateRequiredAttributes(); - } - private ApiTestInfoDTO(ApiTestInfoDTOBuilder builder) { this.testers = builder.testers; this.testName = builder.testName; @@ -43,6 +36,7 @@ public static class ApiTestInfoDTOBuilder { private List testers = new ArrayList(); private String testName; + public ApiTestInfoDTO.ApiTestInfoDTOBuilder testers(List testers) { if (!testers.isEmpty()) { this.testers.addAll(testers); diff --git a/multiapi-engine/src/test/resources/openapigenerator/testAllOf/assets/testApi/ApiTestsDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testAllOf/assets/testApi/ApiTestsDTO.java index 3ae51469..af64704d 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testAllOf/assets/testApi/ApiTestsDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testAllOf/assets/testApi/ApiTestsDTO.java @@ -2,46 +2,75 @@ 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; +import java.util.List; +import java.util.ArrayList; +import com.sngular.multifileplugin.testapi.model.exception.ModelClassException; +import com.sngular.multifileplugin.testapi.model.customvalidator.NotNull; + +@JsonDeserialize(builder = ApiTestDTO.ApiTestDTOBuilder.class) +public class ApiTestDTO { + + @JsonProperty(value ="testers") + @NotNull + private final List testers; + @JsonProperty(value ="testName") + @NotNull + private final String testName; + + private ApiTestDTO(ApiTestDTOBuilder builder) { + this.testers = builder.testers; + this.testName = builder.testName; + + validateRequiredAttributes(); + } -public class ApiTestsDTO { - - @JsonProperty(value ="apiTestDTO") - private ApiTestDTO apiTestDTO; - - private ApiTestsDTO(ApiTestDTO apiTestDTO) { - this.apiTestDTO = apiTestDTO; - + public static ApiTestDTO.ApiTestDTOBuilder builder() { + return new ApiTestDTO.ApiTestDTOBuilder(); } - private ApiTestsDTO(ApiTestsDTOBuilder builder) { - this.apiTestDTO = builder.apiTestDTO; + @JsonPOJOBuilder(buildMethodName = "build", withPrefix = "") + public static class ApiTestDTOBuilder { - } + private List testers = new ArrayList(); + private String testName; - public static class ApiTestsDTOBuilder { + public ApiTestDTO.ApiTestDTOBuilder testers(List testers) { + if (!testers.isEmpty()) { + this.testers.addAll(testers); + } + return this; + } - private ApiTestDTO apiTestDTO; + public ApiTestDTO.ApiTestDTOBuilder tester(String tester) { + if (tester != null) { + this.testers.add(tester); + } + return this; + } - public ApiTestsDTO.ApiTestsDTOBuilder apiTestDTO(ApiTestDTO apiTestDTO) { - this.apiTestDTO = apiTestDTO; + public ApiTestDTO.ApiTestDTOBuilder testName(String testName) { + this.testName = testName; return this; } - public ApiTestsDTO build() { - ApiTestsDTO apiTestsDTO = new ApiTestsDTO(this); - return apiTestsDTO; + public ApiTestDTO build() { + ApiTestDTO apiTestDTO = new ApiTestDTO(this); + return apiTestDTO; } } - - @Schema(name = "apiTestDTO", required = false) - public ApiTestDTO getApiTestDTO() { - return apiTestDTO; + @Schema(name = "testers", required = true) + public List getTesters() { + return testers; } - public void setApiTestDTO(ApiTestDTO apiTestDTO) { - this.apiTestDTO = apiTestDTO; + + @Schema(name = "testName", required = true) + public String getTestName() { + return testName; } @Override @@ -52,26 +81,37 @@ public boolean equals(Object o) { if (o == null || getClass() != o.getClass()) { return false; } - ApiTestsDTO apiTestsDTO = (ApiTestsDTO) o; - return Objects.equals(this.apiTestDTO, apiTestsDTO.apiTestDTO); + ApiTestDTO apiTestDTO = (ApiTestDTO) o; + return Objects.equals(this.testers, apiTestDTO.testers) && Objects.equals(this.testName, apiTestDTO.testName); } @Override public int hashCode() { - return Objects.hash(apiTestDTO); + return Objects.hash(testers, testName); } @Override public String toString() { StringBuilder sb = new StringBuilder(); - sb.append("ApiTestsDTO{"); - sb.append(" apiTestDTO:").append(apiTestDTO); + sb.append("ApiTestDTO{"); + sb.append(" testers:").append(testers).append(","); + sb.append(" testName:").append(testName); sb.append("}"); return sb.toString(); } + private void validateRequiredAttributes() { + boolean satisfiedCondition = true; + if (!Objects.nonNull(this.testers)) { + satisfiedCondition = false; + } else if (!Objects.nonNull(this.testName)) { + satisfiedCondition = false; + } - + if (!satisfiedCondition) { + throw new ModelClassException("ApiTestDTO"); + } + } } diff --git a/multiapi-engine/src/test/resources/openapigenerator/testApiClientGeneration/assets/ApiTestInfoDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testApiClientGeneration/assets/ApiTestInfoDTO.java index f74c3ec6..e2cb107e 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testApiClientGeneration/assets/ApiTestInfoDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testApiClientGeneration/assets/ApiTestInfoDTO.java @@ -12,7 +12,7 @@ public class ApiTestInfoDTO { @JsonProperty(value ="testers") - private List testers = new ArrayList(); + private List testers; @JsonProperty(value ="testName") @NonNull diff --git a/multiapi-engine/src/test/resources/openapigenerator/testApiEnumsGeneration/assets/ApiErrorDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testApiEnumsGeneration/assets/ApiErrorDTO.java index bf15caa7..9c1761c0 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testApiEnumsGeneration/assets/ApiErrorDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testApiEnumsGeneration/assets/ApiErrorDTO.java @@ -19,13 +19,6 @@ public class ApiErrorDTO { @NotNull private final String message; - private ApiErrorDTO(Integer code, String message) { - this.code = code; - this.message = message; - - validateRequiredAttributes(); - } - private ApiErrorDTO(ApiErrorDTOBuilder builder) { this.code = builder.code; this.message = builder.message; diff --git a/multiapi-engine/src/test/resources/openapigenerator/testApiEnumsGeneration/assets/ApiTestInfoDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testApiEnumsGeneration/assets/ApiTestInfoDTO.java index 71555f1e..1b1f3286 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testApiEnumsGeneration/assets/ApiTestInfoDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testApiEnumsGeneration/assets/ApiTestInfoDTO.java @@ -15,18 +15,11 @@ public class ApiTestInfoDTO { @JsonProperty(value ="testers") - private List testers = new ArrayList(); + private List testers; @JsonProperty(value ="testName") @NotNull private final String testName; - private ApiTestInfoDTO(List testers, String testName) { - this.testers = testers; - this.testName = testName; - - validateRequiredAttributes(); - } - private ApiTestInfoDTO(ApiTestInfoDTOBuilder builder) { this.testers = builder.testers; this.testName = builder.testName; diff --git a/multiapi-engine/src/test/resources/openapigenerator/testApiEnumsLombokGeneration/assets/ApiTestInfoDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testApiEnumsLombokGeneration/assets/ApiTestInfoDTO.java index 0b902c35..f7d8606f 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testApiEnumsLombokGeneration/assets/ApiTestInfoDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testApiEnumsLombokGeneration/assets/ApiTestInfoDTO.java @@ -12,7 +12,7 @@ public class ApiTestInfoDTO { @JsonProperty(value ="testers") - private List testers = new ArrayList(); + private List testers; @JsonProperty(value ="testName") @NonNull diff --git a/multiapi-engine/src/test/resources/openapigenerator/testApiParametersWithContentGeneration/assets/ApiErrorDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testApiParametersWithContentGeneration/assets/ApiErrorDTO.java index 369f83e6..ecf6b61f 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testApiParametersWithContentGeneration/assets/ApiErrorDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testApiParametersWithContentGeneration/assets/ApiErrorDTO.java @@ -19,13 +19,6 @@ public class ApiErrorDTO { @NotNull private final String message; - private ApiErrorDTO(Integer code, String message) { - this.code = code; - this.message = message; - - validateRequiredAttributes(); - } - private ApiErrorDTO(ApiErrorDTOBuilder builder) { this.code = builder.code; this.message = builder.message; diff --git a/multiapi-engine/src/test/resources/openapigenerator/testApiParametersWithContentGeneration/assets/ApiTestDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testApiParametersWithContentGeneration/assets/ApiTestDTO.java index df0fd9e0..5f208301 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testApiParametersWithContentGeneration/assets/ApiTestDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testApiParametersWithContentGeneration/assets/ApiTestDTO.java @@ -19,13 +19,6 @@ public class ApiTestDTO { @NotNull private final Integer id; - private ApiTestDTO(String name, Integer id) { - this.name = name; - this.id = id; - - validateRequiredAttributes(); - } - private ApiTestDTO(ApiTestDTOBuilder builder) { this.name = builder.name; this.id = builder.id; diff --git a/multiapi-engine/src/test/resources/openapigenerator/testApiParametersWithContentGeneration/assets/ApiTestInfoDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testApiParametersWithContentGeneration/assets/ApiTestInfoDTO.java index a0ad5f7f..38bbbfb2 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testApiParametersWithContentGeneration/assets/ApiTestInfoDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testApiParametersWithContentGeneration/assets/ApiTestInfoDTO.java @@ -15,7 +15,7 @@ public class ApiTestInfoDTO { @JsonProperty(value ="testers") - private List testers = new ArrayList(); + private List testers; @JsonProperty(value ="testName") @NotNull private final String testName; diff --git a/multiapi-engine/src/test/resources/openapigenerator/testApiPathParameterGeneration/assets/TestInfoDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testApiPathParameterGeneration/assets/TestInfoDTO.java index 143b5a94..a82dd168 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testApiPathParameterGeneration/assets/TestInfoDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testApiPathParameterGeneration/assets/TestInfoDTO.java @@ -15,18 +15,11 @@ public class TestInfoDTO { @JsonProperty(value ="testers") - private List testers = new ArrayList(); + private List testers; @JsonProperty(value ="testName") @NotNull private final String testName; - private TestInfoDTO(List testers, String testName) { - this.testers = testers; - this.testName = testName; - - validateRequiredAttributes(); - } - private TestInfoDTO(TestInfoDTOBuilder builder) { this.testers = builder.testers; this.testName = builder.testName; diff --git a/multiapi-engine/src/test/resources/openapigenerator/testApiPathWithSpecialCharGeneration/assets/ApiErrorDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testApiPathWithSpecialCharGeneration/assets/ApiErrorDTO.java index f9e220d1..4a91bc2a 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testApiPathWithSpecialCharGeneration/assets/ApiErrorDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testApiPathWithSpecialCharGeneration/assets/ApiErrorDTO.java @@ -19,13 +19,6 @@ public class ApiErrorDTO { @NotNull private final String message; - private ApiErrorDTO(Integer code, String message) { - this.code = code; - this.message = message; - - validateRequiredAttributes(); - } - private ApiErrorDTO(ApiErrorDTOBuilder builder) { this.code = builder.code; this.message = builder.message; diff --git a/multiapi-engine/src/test/resources/openapigenerator/testApiPathWithSpecialCharGeneration/assets/ApiTestDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testApiPathWithSpecialCharGeneration/assets/ApiTestDTO.java index b3260e39..e3f4c5aa 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testApiPathWithSpecialCharGeneration/assets/ApiTestDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testApiPathWithSpecialCharGeneration/assets/ApiTestDTO.java @@ -19,13 +19,6 @@ public class ApiTestDTO { @NotNull private final Integer id; - private ApiTestDTO(String name, Integer id) { - this.name = name; - this.id = id; - - validateRequiredAttributes(); - } - private ApiTestDTO(ApiTestDTOBuilder builder) { this.name = builder.name; this.id = builder.id; diff --git a/multiapi-engine/src/test/resources/openapigenerator/testApiPathWithSpecialCharGeneration/assets/ApiTestInfoDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testApiPathWithSpecialCharGeneration/assets/ApiTestInfoDTO.java index c6c7abc2..d69c7433 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testApiPathWithSpecialCharGeneration/assets/ApiTestInfoDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testApiPathWithSpecialCharGeneration/assets/ApiTestInfoDTO.java @@ -15,18 +15,11 @@ public class ApiTestInfoDTO { @JsonProperty(value ="testers") - private List testers = new ArrayList(); + private List testers; @JsonProperty(value ="testName") @NotNull private final String testName; - private ApiTestInfoDTO(List testers, String testName) { - this.testers = testers; - this.testName = testName; - - validateRequiredAttributes(); - } - private ApiTestInfoDTO(ApiTestInfoDTOBuilder builder) { this.testers = builder.testers; this.testName = builder.testName; diff --git a/multiapi-engine/src/test/resources/openapigenerator/testApiQueryParameterGeneration/assets/TestInfoDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testApiQueryParameterGeneration/assets/TestInfoDTO.java index 59bda2b5..3f4fbae4 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testApiQueryParameterGeneration/assets/TestInfoDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testApiQueryParameterGeneration/assets/TestInfoDTO.java @@ -15,18 +15,11 @@ public class TestInfoDTO { @JsonProperty(value ="testers") - private List testers = new ArrayList(); + private List testers; @JsonProperty(value ="testName") @NotNull private final String testName; - private TestInfoDTO(List testers, String testName) { - this.testers = testers; - this.testName = testName; - - validateRequiredAttributes(); - } - private TestInfoDTO(TestInfoDTOBuilder builder) { this.testers = builder.testers; this.testName = builder.testName; diff --git a/multiapi-engine/src/test/resources/openapigenerator/testApiReactiveGeneration/assets/ApiErrorDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testApiReactiveGeneration/assets/ApiErrorDTO.java index 10128ff3..19117e1f 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testApiReactiveGeneration/assets/ApiErrorDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testApiReactiveGeneration/assets/ApiErrorDTO.java @@ -19,13 +19,6 @@ public class ApiErrorDTO { @NotNull private final String message; - private ApiErrorDTO(Integer code, String message) { - this.code = code; - this.message = message; - - validateRequiredAttributes(); - } - private ApiErrorDTO(ApiErrorDTOBuilder builder) { this.code = builder.code; this.message = builder.message; diff --git a/multiapi-engine/src/test/resources/openapigenerator/testApiReactiveGeneration/assets/ApiTestDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testApiReactiveGeneration/assets/ApiTestDTO.java index 204f3f28..ecf8885c 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testApiReactiveGeneration/assets/ApiTestDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testApiReactiveGeneration/assets/ApiTestDTO.java @@ -19,13 +19,6 @@ public class ApiTestDTO { @NotNull private final Integer id; - private ApiTestDTO(String name, Integer id) { - this.name = name; - this.id = id; - - validateRequiredAttributes(); - } - private ApiTestDTO(ApiTestDTOBuilder builder) { this.name = builder.name; this.id = builder.id; diff --git a/multiapi-engine/src/test/resources/openapigenerator/testApiReactiveGeneration/assets/ApiTestInfoDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testApiReactiveGeneration/assets/ApiTestInfoDTO.java index c9b9ba6d..1396ceab 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testApiReactiveGeneration/assets/ApiTestInfoDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testApiReactiveGeneration/assets/ApiTestInfoDTO.java @@ -15,18 +15,11 @@ public class ApiTestInfoDTO { @JsonProperty(value ="testers") - private List testers = new ArrayList(); + private List testers; @JsonProperty(value ="testName") @NotNull private final String testName; - private ApiTestInfoDTO(List testers, String testName) { - this.testers = testers; - this.testName = testName; - - validateRequiredAttributes(); - } - private ApiTestInfoDTO(ApiTestInfoDTOBuilder builder) { this.testers = builder.testers; this.testName = builder.testName; diff --git a/multiapi-engine/src/test/resources/openapigenerator/testApiTagsGeneration/assets/TestInfoDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testApiTagsGeneration/assets/TestInfoDTO.java index 962a85e1..3a87139d 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testApiTagsGeneration/assets/TestInfoDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testApiTagsGeneration/assets/TestInfoDTO.java @@ -15,18 +15,11 @@ public class TestInfoDTO { @JsonProperty(value ="testers") - private List testers = new ArrayList(); + private List testers; @JsonProperty(value ="testName") @NotNull private final String testName; - private TestInfoDTO(List testers, String testName) { - this.testers = testers; - this.testName = testName; - - validateRequiredAttributes(); - } - private TestInfoDTO(TestInfoDTOBuilder builder) { this.testers = builder.testers; this.testName = builder.testName; diff --git a/multiapi-engine/src/test/resources/openapigenerator/testClientPackageWebClientApiGeneration/assets/TestInfoDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testClientPackageWebClientApiGeneration/assets/TestInfoDTO.java index 16885c80..f003d1bf 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testClientPackageWebClientApiGeneration/assets/TestInfoDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testClientPackageWebClientApiGeneration/assets/TestInfoDTO.java @@ -11,17 +11,10 @@ public class TestInfoDTO { @JsonProperty(value ="testers") - private List testers = new ArrayList(); + private List testers; @JsonProperty(value ="testName") private final String testName; - private TestInfoDTO(List testers, String testName) { - this.testers = testers; - this.testName = testName; - - validateRequiredAttributes(); - } - private TestInfoDTO(TestInfoDTOBuilder builder) { this.testers = builder.testers; this.testName = builder.testName; diff --git a/multiapi-engine/src/test/resources/openapigenerator/testExternalRefsGeneration/assets/ApiTestDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testExternalRefsGeneration/assets/ApiTestDTO.java index 523d7605..5b03557d 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testExternalRefsGeneration/assets/ApiTestDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testExternalRefsGeneration/assets/ApiTestDTO.java @@ -19,13 +19,6 @@ public class ApiTestDTO { @NotNull private final Integer id; - private ApiTestDTO(String name, Integer id) { - this.name = name; - this.id = id; - - validateRequiredAttributes(); - } - private ApiTestDTO(ApiTestDTOBuilder builder) { this.name = builder.name; this.id = builder.id; diff --git a/multiapi-engine/src/test/resources/openapigenerator/testInlineSchemaCreation/assets/ApiErrorDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testInlineSchemaCreation/assets/ApiErrorDTO.java index 5e9a4a52..9c0de079 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testInlineSchemaCreation/assets/ApiErrorDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testInlineSchemaCreation/assets/ApiErrorDTO.java @@ -15,12 +15,6 @@ public class ApiErrorDTO { @JsonProperty(value ="message") private String message; - private ApiErrorDTO(Integer code, String message) { - this.code = code; - this.message = message; - - } - private ApiErrorDTO(ApiErrorDTOBuilder builder) { this.code = builder.code; this.message = builder.message; diff --git a/multiapi-engine/src/test/resources/openapigenerator/testOverWriteModelTrue/assets/ApiErrorDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testOverWriteModelTrue/assets/ApiErrorDTO.java index bc6d83aa..e2605f2d 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testOverWriteModelTrue/assets/ApiErrorDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testOverWriteModelTrue/assets/ApiErrorDTO.java @@ -19,13 +19,6 @@ public class ApiErrorDTO { @NotNull private final String message; - private ApiErrorDTO(Integer code, String message) { - this.code = code; - this.message = message; - - validateRequiredAttributes(); - } - private ApiErrorDTO(ApiErrorDTOBuilder builder) { this.code = builder.code; this.message = builder.message; diff --git a/multiapi-engine/src/test/resources/openapigenerator/testOverWriteModelTrue/assets/ApiTestDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testOverWriteModelTrue/assets/ApiTestDTO.java index 9fa2d721..372c80e6 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testOverWriteModelTrue/assets/ApiTestDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testOverWriteModelTrue/assets/ApiTestDTO.java @@ -19,13 +19,6 @@ public class ApiTestDTO { @NotNull private final Integer id; - private ApiTestDTO(String name, Integer id) { - this.name = name; - this.id = id; - - validateRequiredAttributes(); - } - private ApiTestDTO(ApiTestDTOBuilder builder) { this.name = builder.name; this.id = builder.id; diff --git a/multiapi-engine/src/test/resources/openapigenerator/testOverWriteModelTrue/assets/ApiTestInfoDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testOverWriteModelTrue/assets/ApiTestInfoDTO.java index e47ae7b8..d5257e83 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testOverWriteModelTrue/assets/ApiTestInfoDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testOverWriteModelTrue/assets/ApiTestInfoDTO.java @@ -15,18 +15,11 @@ public class ApiTestInfoDTO { @JsonProperty(value ="testers") - private List testers = new ArrayList(); + private List testers; @JsonProperty(value ="testName") @NotNull private final String testName; - private ApiTestInfoDTO(List testers, String testName) { - this.testers = testers; - this.testName = testName; - - validateRequiredAttributes(); - } - private ApiTestInfoDTO(ApiTestInfoDTOBuilder builder) { this.testers = builder.testers; this.testName = builder.testName; diff --git a/multiapi-engine/src/test/resources/openapigenerator/testRestClientApiGeneration/assets/ApiErrorDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testRestClientApiGeneration/assets/ApiErrorDTO.java index 113772c2..79c590b7 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testRestClientApiGeneration/assets/ApiErrorDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testRestClientApiGeneration/assets/ApiErrorDTO.java @@ -13,13 +13,6 @@ public class ApiErrorDTO { @JsonProperty(value ="message") private final String message; - private ApiErrorDTO(Integer code, String message) { - this.code = code; - this.message = message; - - validateRequiredAttributes(); - } - private ApiErrorDTO(ApiErrorDTOBuilder builder) { this.code = builder.code; this.message = builder.message; diff --git a/multiapi-engine/src/test/resources/openapigenerator/testRestClientApiGeneration/assets/ApiTestDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testRestClientApiGeneration/assets/ApiTestDTO.java index 2a010065..16ae301e 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testRestClientApiGeneration/assets/ApiTestDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testRestClientApiGeneration/assets/ApiTestDTO.java @@ -13,13 +13,6 @@ public class ApiTestDTO { @JsonProperty(value ="id") private final Integer id; - private ApiTestDTO(String name, Integer id) { - this.name = name; - this.id = id; - - validateRequiredAttributes(); - } - private ApiTestDTO(ApiTestDTOBuilder builder) { this.name = builder.name; this.id = builder.id; diff --git a/multiapi-engine/src/test/resources/openapigenerator/testRestClientApiWithRequestObjectGeneration/assets/ApiErrorDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testRestClientApiWithRequestObjectGeneration/assets/ApiErrorDTO.java index 113772c2..79c590b7 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testRestClientApiWithRequestObjectGeneration/assets/ApiErrorDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testRestClientApiWithRequestObjectGeneration/assets/ApiErrorDTO.java @@ -13,13 +13,6 @@ public class ApiErrorDTO { @JsonProperty(value ="message") private final String message; - private ApiErrorDTO(Integer code, String message) { - this.code = code; - this.message = message; - - validateRequiredAttributes(); - } - private ApiErrorDTO(ApiErrorDTOBuilder builder) { this.code = builder.code; this.message = builder.message; diff --git a/multiapi-engine/src/test/resources/openapigenerator/testRestClientApiWithRequestObjectGeneration/assets/ApiTestDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testRestClientApiWithRequestObjectGeneration/assets/ApiTestDTO.java index 2a010065..16ae301e 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testRestClientApiWithRequestObjectGeneration/assets/ApiTestDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testRestClientApiWithRequestObjectGeneration/assets/ApiTestDTO.java @@ -13,13 +13,6 @@ public class ApiTestDTO { @JsonProperty(value ="id") private final Integer id; - private ApiTestDTO(String name, Integer id) { - this.name = name; - this.id = id; - - validateRequiredAttributes(); - } - private ApiTestDTO(ApiTestDTOBuilder builder) { this.name = builder.name; this.id = builder.id; diff --git a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/assets/lombok/ApiTestAllOfDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/assets/lombok/ApiTestAllOfDTO.java index 4a799d8c..44fae21e 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/assets/lombok/ApiTestAllOfDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/assets/lombok/ApiTestAllOfDTO.java @@ -11,7 +11,7 @@ public class ApiTestAllOfDTO { @JsonProperty(value ="testers") - private List testers = new ArrayList(); + private List testers; @JsonProperty(value ="testName") private String testName; diff --git a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/assets/lombok/ApiTestDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/assets/lombok/ApiTestDTO.java index 85b68845..9d9e9e27 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/assets/lombok/ApiTestDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/assets/lombok/ApiTestDTO.java @@ -13,7 +13,7 @@ public class ApiTestDTO { @JsonProperty(value ="testers") @NonNull - private List testers = new ArrayList(); + private List testers; @JsonProperty(value ="testName") @NonNull diff --git a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/assets/lombok/ApiTestInfoDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/assets/lombok/ApiTestInfoDTO.java index 87407a3f..740549d2 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/assets/lombok/ApiTestInfoDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/assets/lombok/ApiTestInfoDTO.java @@ -12,7 +12,7 @@ public class ApiTestInfoDTO { @JsonProperty(value ="testers") - private List testers = new ArrayList(); + private List testers; @JsonProperty(value ="testName") @NonNull diff --git a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/assets/testApi/ApiTestAllOfDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/assets/testApi/ApiTestAllOfDTO.java index d4bb48f1..6519b3a0 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/assets/testApi/ApiTestAllOfDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/assets/testApi/ApiTestAllOfDTO.java @@ -13,16 +13,10 @@ public class ApiTestAllOfDTO { @JsonProperty(value ="testers") - private List testers = new ArrayList(); + private List testers; @JsonProperty(value ="testName") private String testName; - private ApiTestAllOfDTO(List testers, String testName) { - this.testers = testers; - this.testName = testName; - - } - private ApiTestAllOfDTO(ApiTestAllOfDTOBuilder builder) { this.testers = builder.testers; this.testName = builder.testName; diff --git a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/assets/testApi/ApiTestDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/assets/testApi/ApiTestDTO.java index e996a8ad..cb7c0571 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/assets/testApi/ApiTestDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/assets/testApi/ApiTestDTO.java @@ -21,13 +21,6 @@ public class ApiTestDTO { @NotNull private final String testName; - private ApiTestDTO(List testers, String testName) { - this.testers = testers; - this.testName = testName; - - validateRequiredAttributes(); - } - private ApiTestDTO(ApiTestDTOBuilder builder) { this.testers = builder.testers; this.testName = builder.testName; diff --git a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/assets/testApi/ApiTestInfoDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/assets/testApi/ApiTestInfoDTO.java index 37f92f5e..921badfd 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/assets/testApi/ApiTestInfoDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/assets/testApi/ApiTestInfoDTO.java @@ -15,18 +15,11 @@ public class ApiTestInfoDTO { @JsonProperty(value ="testers") - private List testers = new ArrayList(); + private List testers; @JsonProperty(value ="testName") @NotNull private final String testName; - private ApiTestInfoDTO(List testers, String testName) { - this.testers = testers; - this.testName = testName; - - validateRequiredAttributes(); - } - private ApiTestInfoDTO(ApiTestInfoDTOBuilder builder) { this.testers = builder.testers; this.testName = builder.testName; diff --git a/multiapi-engine/src/test/resources/openapigenerator/testWebClientApiGeneration/assets/ApiErrorDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testWebClientApiGeneration/assets/ApiErrorDTO.java index 8c99c192..d223f3f7 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testWebClientApiGeneration/assets/ApiErrorDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testWebClientApiGeneration/assets/ApiErrorDTO.java @@ -19,13 +19,6 @@ public class ApiErrorDTO { @NotNull private final String message; - private ApiErrorDTO(Integer code, String message) { - this.code = code; - this.message = message; - - validateRequiredAttributes(); - } - private ApiErrorDTO(ApiErrorDTOBuilder builder) { this.code = builder.code; this.message = builder.message; diff --git a/multiapi-engine/src/test/resources/openapigenerator/testWebClientApiGeneration/assets/ApiTestDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testWebClientApiGeneration/assets/ApiTestDTO.java index 74f93860..17d79e2d 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testWebClientApiGeneration/assets/ApiTestDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testWebClientApiGeneration/assets/ApiTestDTO.java @@ -19,13 +19,6 @@ public class ApiTestDTO { @NotNull private final Integer id; - private ApiTestDTO(String name, Integer id) { - this.name = name; - this.id = id; - - validateRequiredAttributes(); - } - private ApiTestDTO(ApiTestDTOBuilder builder) { this.name = builder.name; this.id = builder.id; diff --git a/multiapi-engine/src/test/resources/openapigenerator/testWebClientApiGeneration/assets/ApiTestInfoDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testWebClientApiGeneration/assets/ApiTestInfoDTO.java index 501c0364..127fae2a 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testWebClientApiGeneration/assets/ApiTestInfoDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testWebClientApiGeneration/assets/ApiTestInfoDTO.java @@ -15,18 +15,11 @@ public class ApiTestInfoDTO { @JsonProperty(value ="testers") - private List testers = new ArrayList(); + private List testers; @JsonProperty(value ="testName") @NotNull private final String testName; - private ApiTestInfoDTO(List testers, String testName) { - this.testers = testers; - this.testName = testName; - - validateRequiredAttributes(); - } - private ApiTestInfoDTO(ApiTestInfoDTOBuilder builder) { this.testers = builder.testers; this.testName = builder.testName; From 582c4c31a28fa5b6791a1fb0c7cffc9a270ef761 Mon Sep 17 00:00:00 2001 From: "joseenrique.garcia" Date: Mon, 26 Aug 2024 08:53:12 +0200 Subject: [PATCH 07/26] Fix OpenApi generator --- .../templates/model/templateSchemaWithLombok.ftlh | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/multiapi-engine/src/main/resources/templates/model/templateSchemaWithLombok.ftlh b/multiapi-engine/src/main/resources/templates/model/templateSchemaWithLombok.ftlh index 2cdafabe..348e5baa 100644 --- a/multiapi-engine/src/main/resources/templates/model/templateSchemaWithLombok.ftlh +++ b/multiapi-engine/src/main/resources/templates/model/templateSchemaWithLombok.ftlh @@ -96,7 +96,7 @@ import lombok.extern.jackson.Jacksonized; import ${packageModel}.exception.ModelClassException; -@Data +@Value public class ${schema.className} { <#list schema.fieldObjectList as field> @@ -139,9 +139,13 @@ public class ${schema.className} { @NonNull <#if field.dataType.baseType == "array"> - private ${field.dataType} ${field.baseName?uncap_first} = new ${field.dataType?api.getImplementationTypeString()}(); + <#assign singName>${singularizeName (calculateSafeName (field.baseName, ""))} + @Singular(${singName}) + private ${field.dataType} ${field.baseName?uncap_first}; <#elseif field.dataType.baseType == "map"> - private ${field.dataType} ${field.baseName?uncap_first} = new ${field.dataType?api.getImplementationTypeString()}(); + <#assign singName>${singularizeName (calculateSafeName (field.baseName, ""))} + @Singular(${singName}) + private ${field.dataType} ${field.baseName?uncap_first}; <#elseif field.dataType.baseType == "enum"> private ${field.baseName?cap_first} ${field.baseName?uncap_first}; From bef65c4543c80186f103dd2e0c00e56df0fa48d5 Mon Sep 17 00:00:00 2001 From: "joseenrique.garcia" Date: Wed, 28 Aug 2024 18:02:24 +0200 Subject: [PATCH 08/26] Fix OpenApi generator --- .../plugin/asyncapi/AsyncApiGenerator.java | 8 +- .../asyncapi/util/ReferenceProcessor.java | 6 +- .../plugin/common/tools/MapperUtil.java | 6 +- .../templateMaxBigDecimal.ftlh | 3 +- .../templateMaxBigDecimalValidator.ftlh | 2 +- .../customannotations/templateMaxDouble.ftlh | 3 +- .../customannotations/templateMaxFloat.ftlh | 3 +- .../customannotations/templateMaxInteger.ftlh | 3 +- .../customannotations/templateMaxItems.ftlh | 3 +- .../templateMinBigDecimal.ftlh | 3 +- .../templateMinBigDecimalValidator.ftlh | 6 +- .../customannotations/templateMinDouble.ftlh | 3 +- .../templateMinDoubleValidator.ftlh | 2 +- .../customannotations/templateMinFloat.ftlh | 3 +- .../templateMinFloatValidator.ftlh | 2 +- .../customannotations/templateMinInteger.ftlh | 3 +- .../templateMinIntegerValidator.ftlh | 2 +- .../customannotations/templateMinItems.ftlh | 3 +- .../customannotations/templateMultipleOf.ftlh | 3 +- .../customannotations/templateNotNull.ftlh | 3 +- .../customannotations/templatePattern.ftlh | 3 +- .../customannotations/templateSize.ftlh | 3 +- .../templateUniqueItems.ftlh | 3 +- .../templates/model/templateSchema.ftlh | 6 +- .../model/templateSchemaWithLombok.ftlh | 318 ++++++++++-------- .../jakarta/MaxBigDecimal.java | 3 +- .../jakarta/MaxBigDecimalValidator.java | 13 +- .../customvalidator/jakarta/MaxDouble.java | 17 + .../jakarta/MaxDoubleValidator.java | 24 ++ .../{javax/Max.java => jakarta/MaxFloat.java} | 11 +- .../jakarta/MaxFloatValidator.java | 24 ++ .../customvalidator/jakarta/MaxInteger.java | 3 +- .../jakarta/MaxIntegerValidator.java | 24 ++ .../customvalidator/jakarta/MaxItems.java | 3 +- .../jakarta/MinBigDecimal.java | 17 + .../jakarta/MinBigDecimalValidator.java | 25 ++ .../customvalidator/jakarta/MinDouble.java | 17 + .../jakarta/MinDoubleValidator.java | 24 ++ .../jakarta/{Min.java => MinFloat.java} | 7 +- .../jakarta/MinFloatValidator.java | 24 ++ .../customvalidator/jakarta/MinInteger.java | 17 + .../MinIntegerValidator.java} | 8 +- .../customvalidator/jakarta/MinItems.java | 3 +- .../customvalidator/jakarta/MultipleOf.java | 3 +- .../customvalidator/jakarta/NotNull.java | 3 +- .../customvalidator/jakarta/Pattern.java | 3 +- .../customvalidator/jakarta/Size.java | 3 +- .../customvalidator/jakarta/UniqueItems.java | 3 +- .../customvalidator/javax/MaxBigDecimal.java | 3 +- .../javax/MaxBigDecimalValidator.java | 2 +- .../customvalidator/javax/MaxDouble.java | 3 +- .../customvalidator/javax/MaxFloat.java | 3 +- .../customvalidator/javax/MaxInteger.java | 3 +- .../customvalidator/javax/MaxItems.java | 3 +- .../customvalidator/javax/MinBigDecimal.java | 3 +- .../javax/MinBigDecimalValidator.java | 6 +- .../customvalidator/javax/MinDouble.java | 3 +- .../javax/MinDoubleValidator.java | 2 +- .../customvalidator/javax/MinFloat.java | 3 +- .../javax/MinFloatValidator.java | 2 +- .../customvalidator/javax/MinInteger.java | 3 +- .../javax/MinIntegerValidator.java | 2 +- .../customvalidator/javax/MinItems.java | 3 +- .../customvalidator/javax/MultipleOf.java | 3 +- .../customvalidator/javax/NotNull.java | 3 +- .../customvalidator/javax/Pattern.java | 3 +- .../customvalidator/javax/Size.java | 3 +- .../customvalidator/javax/UniqueItems.java | 3 +- .../customvalidator/NotNull.java | 3 +- .../customvalidator/NotNull.java | 3 +- .../customvalidator/Size.java | 3 +- .../customvalidator/NotNull.java | 3 +- .../customvalidator/NotNull.java | 3 +- .../assets/TestDTO.java | 4 +- .../assets/SubtestDTO.java | 4 +- .../assets/TestDTO.java | 4 +- .../assets/ArraySchemaDTO.java | 4 +- .../assets/SecondTestDTO.java | 4 +- .../assets/TestDTO.java | 4 +- .../assets/TestValueDTO.java | 4 +- .../assets/TestValueValueDTO.java | 4 +- .../assets/ThirdTestDTO.java | 4 +- .../testAllOf/assets/lombok/ApiErrorDTO.java | 5 +- .../assets/lombok/ApiTestAllOfDTO.java | 6 +- .../testAllOf/assets/lombok/ApiTestDTO.java | 6 +- .../assets/lombok/ApiTestInfoDTO.java | 6 +- .../testAllOf/assets/lombok/ApiTestsDTO.java | 4 +- .../testAnyOfInResponse/assets/GameDTO.java | 4 +- .../assets/GameInfoDTO.java | 8 +- .../InlineResponse200ListGamesAnyOfDTO.java | 8 +- .../assets/ApiErrorDTO.java | 4 +- .../assets/ApiTestDTO.java | 4 +- .../assets/ApiTestInfoDTO.java | 4 +- .../assets/ApiTestDTO.java | 10 - .../assets/ApiTestInfoDTO.java | 1 + .../assets/ApiErrorDTO.java | 4 +- .../assets/ApiTestDTO.java | 4 +- .../assets/ApiTestInfoDTO.java | 4 +- .../assets/ApiTestInfoDTO.java | 1 + .../assets/ApiTestInfoDTO.java | 1 + .../assets/ApiTestInfoDTO.java | 1 + .../assets/model/ArrayFieldDTO.java | 10 +- .../assets/model/BooleanFieldDTO.java | 4 +- .../assets/model/DateFieldDTO.java | 4 +- .../assets/model/EnumFieldDTO.java | 10 +- .../assets/model/FieldDTO.java | 25 +- .../assets/model/MapFieldDTO.java | 10 +- .../assets/model/NumberFieldDTO.java | 7 +- .../assets/model/ObjectFieldDTO.java | 13 +- .../assets/model/SchemaDTO.java | 4 +- .../assets/model/SequenceFieldDTO.java | 10 +- .../assets/model/StringFieldDTO.java | 10 +- .../assets/model/UnionFieldDTO.java | 7 +- .../assets/ApiArrayFieldDTO.java | 6 +- .../assets/ApiDefaultItemDTO.java | 8 +- .../assets/ApiEnumFieldDTO.java | 6 +- .../assets/ApiMapFieldDTO.java | 6 +- .../assets/ApiNumberFieldDTO.java | 3 +- .../assets/ApiObjectFieldDTO.java | 6 +- .../testComplexAnyOf/assets/ApiSchemaDTO.java | 2 +- .../assets/ApiSequenceFieldDTO.java | 4 +- .../assets/ApiStringFieldDTO.java | 4 +- .../assets/ApiTypeArrayDTO.java | 12 +- .../assets/model/AddressDTO.java | 4 +- .../assets/model/TestDTO.java | 4 +- .../assets/model/AddressDTO.java | 4 +- .../assets/model/PropertiesDTO.java | 4 +- .../testCreateDTO/assets/model/TestDTO.java | 7 +- .../assets/model/TestDateDTO.java | 4 +- .../assets/model/TestDateDTO.java | 4 +- .../assets/model/TestDateDTO.java | 4 +- .../assets/ApiTestDTO.java | 19 +- .../assets/model/ConfigurationDTO.java | 8 +- .../assets/model/FakerFieldDTO.java | 5 +- .../assets/model/FakerSchemaDTO.java | 14 +- .../testIssueFaker/assets/model/FieldDTO.java | 5 +- .../assets/model/SchemaDTO.java | 14 +- .../testOneOfInResponse/assets/GameDTO.java | 4 +- .../assets/GameInfoDTO.java | 4 +- .../InlineResponse200ListGamesOneOfDTO.java | 4 +- .../assets/ApiTestInfoDTO.java | 1 + .../testReferenceFile/assets/TestDTO.java | 4 +- .../assets/ApiTestInfoDTO.java | 1 + .../assets/model/ArrayFieldDTO.java | 4 +- .../assets/model/BooleanFieldDTO.java | 4 +- .../assets/model/DateFieldDTO.java | 4 +- .../assets/model/EnumFieldDTO.java | 4 +- .../assets/model/FieldDTO.java | 4 +- .../assets/model/FieldValueDTO.java | 4 +- .../assets/model/MapFieldDTO.java | 4 +- .../assets/model/NumberFieldDTO.java | 4 +- .../assets/model/ObjectFieldDTO.java | 4 +- .../assets/model/SchemaDTO.java | 4 +- .../assets/model/SequenceFieldDTO.java | 4 +- .../assets/model/StringFieldDTO.java | 4 +- .../assets/model/UUIDFieldDTO.java | 4 +- .../assets/model/UnionFieldDTO.java | 4 +- .../assets/model/ActivatePolicyDTO.java | 4 +- .../assets/model/AddressDTO.java | 4 +- .../assets/model/CompanyDTO.java | 4 +- .../assets/model/ContactDTO.java | 4 +- .../assets/model/CreditLimitDTO.java | 4 +- .../assets/model/DocumentDTO.java | 4 +- .../assets/model/ErrorResponseDTO.java | 4 +- .../assets/model/InsuredCreditObjectDTO.java | 4 +- .../assets/model/PolicyActivationDTO.java | 4 +- .../assets/model/PolicyClaimDTO.java | 4 +- .../assets/model/PolicySettlementDTO.java | 4 +- .../assets/model/QuoteRequestDTO.java | 4 +- .../assets/model/QuoteResponseDTO.java | 4 +- .../assets/model/QuoteUpdateResponseDTO.java | 4 +- .../assets/model/UpdateQuoteDTO.java | 4 +- .../assets/lombok/ApiErrorDTO.java | 4 +- .../assets/lombok/ApiTestAllOfDTO.java | 4 +- .../assets/lombok/ApiTestDTO.java | 4 +- .../assets/lombok/ApiTestInfoDTO.java | 4 +- .../assets/lombok/ApiTestsDTO.java | 4 +- .../assets/testApi/ApiTestInfoDTO.java | 1 + .../assets/ApiTestInfoDTO.java | 1 + 179 files changed, 774 insertions(+), 530 deletions(-) create mode 100644 multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/jakarta/MaxDouble.java create mode 100644 multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/jakarta/MaxDoubleValidator.java rename multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/{javax/Max.java => jakarta/MaxFloat.java} (69%) create mode 100644 multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/jakarta/MaxFloatValidator.java create mode 100644 multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/jakarta/MaxIntegerValidator.java create mode 100644 multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/jakarta/MinBigDecimal.java create mode 100644 multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/jakarta/MinBigDecimalValidator.java create mode 100644 multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/jakarta/MinDouble.java create mode 100644 multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/jakarta/MinDoubleValidator.java rename multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/jakarta/{Min.java => MinFloat.java} (80%) create mode 100644 multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/jakarta/MinFloatValidator.java create mode 100644 multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/jakarta/MinInteger.java rename multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/{javax/MinValidator.java => jakarta/MinIntegerValidator.java} (70%) 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 85d8b203..63ac6fc6 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 @@ -204,7 +204,7 @@ private Map getAllSchemas(final FileLocation ymlParent, final }); ApiTool.getComponent(node, SCHEMAS).forEachRemaining( - schema -> totalSchemas.putIfAbsent((SCHEMAS + SLASH + schema.getKey()).toUpperCase(), schema.getValue()) + schema -> totalSchemas.putIfAbsent(SCHEMAS.toUpperCase() + SLASH + MapperUtil.getSchemaKey(schema.getKey()), schema.getValue()) ); ApiTool.getComponent(node, MESSAGES).forEachRemaining( @@ -227,7 +227,7 @@ private void getMessageSchemas( if (ApiTool.hasNode(message, PAYLOAD)) { final JsonNode payload = message.get(PAYLOAD); if (!payload.has(REF)) { - final String key = (EVENT + SLASH + calculateMessageName(messageName, message)).toUpperCase(); + final String key = EVENT.toUpperCase() + SLASH + MapperUtil.getSchemaKey(calculateMessageName(messageName, message)); totalSchemas.putIfAbsent(key, payload); } } else if (ApiTool.hasRef(message)) { @@ -237,7 +237,7 @@ private void getMessageSchemas( } private String calculateMessageName(final String messageName, final JsonNode message) { - return StringUtils.defaultString(ApiTool.getName(message), messageName); + return Objects.toString(ApiTool.getName(message), messageName); } private void getChannelSchemas(final JsonNode channel, final Map totalSchemas, final FileLocation ymlParent) { @@ -544,7 +544,7 @@ private Pair processMethodRef( final ProcessBindingsResultBuilder bindingsResult, final String messageRef, final OperationParameterObject operationObject, final FileLocation ymlParent, final Map totalSchemas, final JsonNode method) throws IOException { - final var message = totalSchemas.get(MapperUtil.buildKey(MapperUtil.splitName(messageRef))); + final var message = totalSchemas.get(MapperUtil.getRefSchemaKey(messageRef)); if (ApiTool.hasNode(message, BINDINGS)) { processBindings(bindingsResult, message, operationObject); } diff --git a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/asyncapi/util/ReferenceProcessor.java b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/asyncapi/util/ReferenceProcessor.java index 21d34420..d04d00f3 100644 --- a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/asyncapi/util/ReferenceProcessor.java +++ b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/asyncapi/util/ReferenceProcessor.java @@ -47,7 +47,7 @@ public void processReference( } final String[] path = MapperUtil.splitName(referenceLink); final JsonNode component; - final var calculatedKey = calculateKey(path); + final var calculatedKey = MapperUtil.getRefSchemaKey(referenceLink); if (!totalSchemas.containsKey(calculatedKey) && !alreadyProcessed.contains(calculatedKey)) { alreadyProcessed.add(calculatedKey); try { @@ -72,10 +72,6 @@ public void processReference( } } - private String calculateKey(final String[] path) { - return (path[path.length - 2] + SLASH + path[path.length - 1]).toUpperCase(); - } - private JsonNode solveRef(final FileLocation ymlParent, final String[] path, final String reference, final Map totalSchemas) throws IOException { final String[] pathToFile = reference.split("#"); final String filePath = pathToFile[0]; diff --git a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/tools/MapperUtil.java b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/tools/MapperUtil.java index e4f39b4d..50659064 100644 --- a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/tools/MapperUtil.java +++ b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/tools/MapperUtil.java @@ -89,7 +89,11 @@ public static String getKeySchemaName(final String parameter) { public static String getRefSchemaKey(final String parameter) { final String[] pathObjectRef = parameter.split("/"); - return StringUtils.upperCase(pathObjectRef[pathObjectRef.length - 2] + "/" + StringCaseUtils.titleToSnakeCase(pathObjectRef[pathObjectRef.length - 1])); + return StringUtils.upperCase(pathObjectRef[pathObjectRef.length - 2] + "/" + getSchemaKey(pathObjectRef[pathObjectRef.length - 1])); + } + + public static String getSchemaKey(final String schemaName) { + return StringCaseUtils.titleToSnakeCase(schemaName); } private static boolean checkIfNumber(final String nodeType) { diff --git a/multiapi-engine/src/main/resources/templates/customannotations/templateMaxBigDecimal.ftlh b/multiapi-engine/src/main/resources/templates/customannotations/templateMaxBigDecimal.ftlh index 6c7246ee..a9eacd78 100644 --- a/multiapi-engine/src/main/resources/templates/customannotations/templateMaxBigDecimal.ftlh +++ b/multiapi-engine/src/main/resources/templates/customannotations/templateMaxBigDecimal.ftlh @@ -4,8 +4,7 @@ import ${javaEEPackage}.validation.Constraint; import ${javaEEPackage}.validation.Payload; import java.lang.annotation.*; -@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, -ElementType.ANNOTATION_TYPE}) +@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, ElementType.ANNOTATION_TYPE}) @Retention(RetentionPolicy.RUNTIME) @Constraint(validatedBy = MaxBigDecimalValidator.class) @Documented diff --git a/multiapi-engine/src/main/resources/templates/customannotations/templateMaxBigDecimalValidator.ftlh b/multiapi-engine/src/main/resources/templates/customannotations/templateMaxBigDecimalValidator.ftlh index edb040bb..5556ae44 100644 --- a/multiapi-engine/src/main/resources/templates/customannotations/templateMaxBigDecimalValidator.ftlh +++ b/multiapi-engine/src/main/resources/templates/customannotations/templateMaxBigDecimalValidator.ftlh @@ -20,6 +20,6 @@ public class MaxBigDecimalValidator implements ConstraintValidator { +public class MinBigDecimalValidator implements ConstraintValidator { private BigDecimal minimum; private boolean exclusive; @Override - public void initialize(Min constraintAnnotation) { + public void initialize(MinBigDecimal constraintAnnotation) { ConstraintValidator.super.initialize(constraintAnnotation); this.minimum = new BigDecimal(constraintAnnotation.minimum()); this.exclusive = constraintAnnotation.exclusive(); @@ -20,6 +20,6 @@ public class MinValidator implements ConstraintValidator this.minimum || (!exclusive && value == this.minimum)); + return Objects.isNull(value) || (value.compareTo(this.minimum) > 0 || (!exclusive && value.compareTo(this.minimum) == 0); } } \ No newline at end of file diff --git a/multiapi-engine/src/main/resources/templates/customannotations/templateMinDouble.ftlh b/multiapi-engine/src/main/resources/templates/customannotations/templateMinDouble.ftlh index 857a8306..08884a23 100644 --- a/multiapi-engine/src/main/resources/templates/customannotations/templateMinDouble.ftlh +++ b/multiapi-engine/src/main/resources/templates/customannotations/templateMinDouble.ftlh @@ -4,8 +4,7 @@ import ${javaEEPackage}.validation.Constraint; import ${javaEEPackage}.validation.Payload; import java.lang.annotation.*; -@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, - ElementType.ANNOTATION_TYPE}) +@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, ElementType.ANNOTATION_TYPE}) @Retention(RetentionPolicy.RUNTIME) @Constraint(validatedBy = MinDoubleValidator.class) @Documented diff --git a/multiapi-engine/src/main/resources/templates/customannotations/templateMinDoubleValidator.ftlh b/multiapi-engine/src/main/resources/templates/customannotations/templateMinDoubleValidator.ftlh index 24145ffc..508c5ba3 100644 --- a/multiapi-engine/src/main/resources/templates/customannotations/templateMinDoubleValidator.ftlh +++ b/multiapi-engine/src/main/resources/templates/customannotations/templateMinDoubleValidator.ftlh @@ -5,7 +5,7 @@ import java.util.Objects; import ${javaEEPackage}.validation.ConstraintValidator; import ${javaEEPackage}.validation.ConstraintValidatorContext; -public class MinValidator implements ConstraintValidator { +public class MinDoubleValidator implements ConstraintValidator { private double minimum; private boolean exclusive; diff --git a/multiapi-engine/src/main/resources/templates/customannotations/templateMinFloat.ftlh b/multiapi-engine/src/main/resources/templates/customannotations/templateMinFloat.ftlh index b6648ee5..ebee86b3 100644 --- a/multiapi-engine/src/main/resources/templates/customannotations/templateMinFloat.ftlh +++ b/multiapi-engine/src/main/resources/templates/customannotations/templateMinFloat.ftlh @@ -4,8 +4,7 @@ import ${javaEEPackage}.validation.Constraint; import ${javaEEPackage}.validation.Payload; import java.lang.annotation.*; -@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, - ElementType.ANNOTATION_TYPE}) +@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, ElementType.ANNOTATION_TYPE}) @Retention(RetentionPolicy.RUNTIME) @Constraint(validatedBy = MinFloatValidator.class) @Documented diff --git a/multiapi-engine/src/main/resources/templates/customannotations/templateMinFloatValidator.ftlh b/multiapi-engine/src/main/resources/templates/customannotations/templateMinFloatValidator.ftlh index cc3fe233..364879e4 100644 --- a/multiapi-engine/src/main/resources/templates/customannotations/templateMinFloatValidator.ftlh +++ b/multiapi-engine/src/main/resources/templates/customannotations/templateMinFloatValidator.ftlh @@ -5,7 +5,7 @@ import java.util.Objects; import ${javaEEPackage}.validation.ConstraintValidator; import ${javaEEPackage}.validation.ConstraintValidatorContext; -public class MinValidator implements ConstraintValidator { +public class MinFloatValidator implements ConstraintValidator { private float minimum; private boolean exclusive; diff --git a/multiapi-engine/src/main/resources/templates/customannotations/templateMinInteger.ftlh b/multiapi-engine/src/main/resources/templates/customannotations/templateMinInteger.ftlh index dab3b538..1b2a7aea 100644 --- a/multiapi-engine/src/main/resources/templates/customannotations/templateMinInteger.ftlh +++ b/multiapi-engine/src/main/resources/templates/customannotations/templateMinInteger.ftlh @@ -4,8 +4,7 @@ import ${javaEEPackage}.validation.Constraint; import ${javaEEPackage}.validation.Payload; import java.lang.annotation.*; -@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, - ElementType.ANNOTATION_TYPE}) +@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, ElementType.ANNOTATION_TYPE}) @Retention(RetentionPolicy.RUNTIME) @Constraint(validatedBy = MinIntegerValidator.class) @Documented diff --git a/multiapi-engine/src/main/resources/templates/customannotations/templateMinIntegerValidator.ftlh b/multiapi-engine/src/main/resources/templates/customannotations/templateMinIntegerValidator.ftlh index 9a9bdf1e..69763ff3 100644 --- a/multiapi-engine/src/main/resources/templates/customannotations/templateMinIntegerValidator.ftlh +++ b/multiapi-engine/src/main/resources/templates/customannotations/templateMinIntegerValidator.ftlh @@ -5,7 +5,7 @@ import java.util.Objects; import ${javaEEPackage}.validation.ConstraintValidator; import ${javaEEPackage}.validation.ConstraintValidatorContext; -public class MinValidator implements ConstraintValidator { +public class MinIntegerValidator implements ConstraintValidator { private int minimum; private boolean exclusive; diff --git a/multiapi-engine/src/main/resources/templates/customannotations/templateMinItems.ftlh b/multiapi-engine/src/main/resources/templates/customannotations/templateMinItems.ftlh index 99e1aba4..21962606 100644 --- a/multiapi-engine/src/main/resources/templates/customannotations/templateMinItems.ftlh +++ b/multiapi-engine/src/main/resources/templates/customannotations/templateMinItems.ftlh @@ -4,8 +4,7 @@ import ${javaEEPackage}.validation.Constraint; import ${javaEEPackage}.validation.Payload; import java.lang.annotation.*; -@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, - ElementType.ANNOTATION_TYPE}) +@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, ElementType.ANNOTATION_TYPE}) @Retention(RetentionPolicy.RUNTIME) @Constraint(validatedBy = MinItemsValidator.class) @Documented diff --git a/multiapi-engine/src/main/resources/templates/customannotations/templateMultipleOf.ftlh b/multiapi-engine/src/main/resources/templates/customannotations/templateMultipleOf.ftlh index 21a6a923..4abdeb4a 100644 --- a/multiapi-engine/src/main/resources/templates/customannotations/templateMultipleOf.ftlh +++ b/multiapi-engine/src/main/resources/templates/customannotations/templateMultipleOf.ftlh @@ -4,8 +4,7 @@ import ${javaEEPackage}.validation.Constraint; import ${javaEEPackage}.validation.Payload; import java.lang.annotation.*; -@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, - ElementType.ANNOTATION_TYPE}) +@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, ElementType.ANNOTATION_TYPE}) @Retention(RetentionPolicy.RUNTIME) @Constraint(validatedBy = MultipleOfValidator.class) @Documented diff --git a/multiapi-engine/src/main/resources/templates/customannotations/templateNotNull.ftlh b/multiapi-engine/src/main/resources/templates/customannotations/templateNotNull.ftlh index 11260c71..062162c3 100644 --- a/multiapi-engine/src/main/resources/templates/customannotations/templateNotNull.ftlh +++ b/multiapi-engine/src/main/resources/templates/customannotations/templateNotNull.ftlh @@ -4,8 +4,7 @@ import ${javaEEPackage}.validation.Constraint; import ${javaEEPackage}.validation.Payload; import java.lang.annotation.*; -@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, - ElementType.ANNOTATION_TYPE}) +@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, ElementType.ANNOTATION_TYPE}) @Retention(RetentionPolicy.RUNTIME) @Constraint(validatedBy = NotNullValidator.class) @Documented diff --git a/multiapi-engine/src/main/resources/templates/customannotations/templatePattern.ftlh b/multiapi-engine/src/main/resources/templates/customannotations/templatePattern.ftlh index 4709043d..cf58d942 100644 --- a/multiapi-engine/src/main/resources/templates/customannotations/templatePattern.ftlh +++ b/multiapi-engine/src/main/resources/templates/customannotations/templatePattern.ftlh @@ -5,8 +5,7 @@ import ${javaEEPackage}.validation.Payload; import java.lang.annotation.*; -@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, - ElementType.ANNOTATION_TYPE}) +@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, ElementType.ANNOTATION_TYPE}) @Retention(RetentionPolicy.RUNTIME) @Constraint(validatedBy = PatternValidator.class) @Documented diff --git a/multiapi-engine/src/main/resources/templates/customannotations/templateSize.ftlh b/multiapi-engine/src/main/resources/templates/customannotations/templateSize.ftlh index edb97d5c..f8e42e2a 100644 --- a/multiapi-engine/src/main/resources/templates/customannotations/templateSize.ftlh +++ b/multiapi-engine/src/main/resources/templates/customannotations/templateSize.ftlh @@ -4,8 +4,7 @@ import ${javaEEPackage}.validation.Constraint; import ${javaEEPackage}.validation.Payload; import java.lang.annotation.*; -@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, - ElementType.ANNOTATION_TYPE}) +@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, ElementType.ANNOTATION_TYPE}) @Retention(RetentionPolicy.RUNTIME) @Constraint(validatedBy = SizeValidator.class) @Documented diff --git a/multiapi-engine/src/main/resources/templates/customannotations/templateUniqueItems.ftlh b/multiapi-engine/src/main/resources/templates/customannotations/templateUniqueItems.ftlh index 0fe13197..8d01e159 100644 --- a/multiapi-engine/src/main/resources/templates/customannotations/templateUniqueItems.ftlh +++ b/multiapi-engine/src/main/resources/templates/customannotations/templateUniqueItems.ftlh @@ -4,8 +4,7 @@ import ${javaEEPackage}.validation.Constraint; import ${javaEEPackage}.validation.Payload; import java.lang.annotation.*; -@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, - ElementType.ANNOTATION_TYPE}) +@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, ElementType.ANNOTATION_TYPE}) @Retention(RetentionPolicy.RUNTIME) @Constraint(validatedBy = UniqueItemsValidator.class) @Documented diff --git a/multiapi-engine/src/main/resources/templates/model/templateSchema.ftlh b/multiapi-engine/src/main/resources/templates/model/templateSchema.ftlh index 64b73ade..c4ff1c19 100644 --- a/multiapi-engine/src/main/resources/templates/model/templateSchema.ftlh +++ b/multiapi-engine/src/main/resources/templates/model/templateSchema.ftlh @@ -15,7 +15,9 @@ ${calculateSafeName (field.baseName, ";", field.constValue)} <#function singularizeName propertyName> - <#if propertyName?matches(".*s")> + <#if propertyName?matches(".*ies")> + <#return propertyName?remove_ending("ies")+"y"/> + <#elseif propertyName?matches(".*s")> <#return propertyName?remove_ending("s")/> <#elseif propertyName?matches(".*List")> <#return propertyName?remove_ending("List")/> @@ -139,7 +141,7 @@ import ${packageModel}.customvalidator.MinItems; <#assign visited += "format," /> import com.fasterxml.jackson.annotation.JsonFormat; - <#if (field.required || schema.schemaCombinator?has_content && (schema.schemaCombinator == "anyOf" || schema.schemaCombinator == "oneOf")) && !(visited?contains("schemaCombinator"))> + <#if (field.required || schema.schemaCombinator?has_content && (schema.schemaCombinator == "anyOf" || schema.schemaCombinator == "oneOf")) && !(visited?contains("schemaCombinator"))> <#assign visited += "schemaCombinator," /> import ${exceptionPackage}.exception.ModelClassException; diff --git a/multiapi-engine/src/main/resources/templates/model/templateSchemaWithLombok.ftlh b/multiapi-engine/src/main/resources/templates/model/templateSchemaWithLombok.ftlh index 348e5baa..4e4d779c 100644 --- a/multiapi-engine/src/main/resources/templates/model/templateSchemaWithLombok.ftlh +++ b/multiapi-engine/src/main/resources/templates/model/templateSchemaWithLombok.ftlh @@ -1,16 +1,17 @@ <#ftl output_format="plainText"> +<#assign words = ["abstract", "assert", "boolean", "break", "byte", "case", "catch", "char", "class", "const", "continue", "default", "double", "do", "else", "enum", "extends", "false", "final", "finally", "float", "for", "goto", "if", "implements", "import", "instanceof", "int", "interface", "long", "native", "new", "null", "package", "private", "protected", "public", "return", "short", "static", "strictfp", "super", "switch", "synchronized", "this", "throw", "throws", "transient", "true", "try", "void", "volatile", "while"]> <#function calculateSafeName propertyName ender const=""> <#if words?seq_contains(propertyName?uncap_first) || propertyName?matches("[0-9].*")> <#if const?has_content> - <#return "_"+propertyName + " = " + const + ender/> + <#return "_"+propertyName?uncap_first + " = " + const + ender/> <#else> - <#return "_"+propertyName + ender/> + <#return "_"+propertyName?uncap_first + ender/> <#else > <#if const?has_content> - <#return propertyName + " = " + const + ender/> + <#return propertyName?uncap_first + " = " + const + ender/> <#else> - <#return propertyName + ender/> + <#return propertyName?uncap_first + ender/> @@ -21,186 +22,219 @@ ${calculateSafeName (field.baseName, ";", "")} +<#function singularizeName propertyName> + <#if propertyName?matches(".*ies")> + <#return propertyName?remove_ending("ies")+"y"/> + <#elseif propertyName?matches(".*s")> + <#return propertyName?remove_ending("s")/> + <#elseif propertyName?matches(".*List")> + <#return propertyName?remove_ending("List")/> + <#else > + <#return "_"+propertyName/> + + package ${packageModel}; <#if schema.schemaCombinator == "anyOf" || schema.schemaCombinator == "oneOf"> - import java.util.Objects; +import java.util.Objects; import com.fasterxml.jackson.annotation.JsonProperty; <#list schema.fieldObjectList as field> <#if field.dataType.baseType == "enum"> - import com.fasterxml.jackson.annotation.JsonValue; +import com.fasterxml.jackson.annotation.JsonValue; <#break> <#list schema.importList as import> - import ${import}; - -<#list schema.fieldObjectList as field> - <#if field.restrictionProperties.maxLength?has_content || field.restrictionProperties.minLength?has_content> - import ${packageModel}.customvalidator.Size; - <#break> - +import ${import}; +<#assign visited = ""> <#list schema.fieldObjectList as field> - <#if field.restrictionProperties.maximum?has_content> - import ${packageModel}.customvalidator.Max; - <#break> - - -<#list schema.fieldObjectList as field> - <#if field.restrictionProperties.minimum?has_content> - import ${packageModel}.customvalidator.Min; - <#break> - - -<#list schema.fieldObjectList as field> - <#if field.restrictionProperties.pattern?has_content> - import ${packageModel}.customvalidator.Pattern; - - -<#list schema.fieldObjectList as field> - <#if field.restrictionProperties.multipleOf?has_content> - import ${packageModel}.customvalidator.MultipleOf; - <#break> - - -<#list schema.fieldObjectList as field> - <#if field.restrictionProperties.maxItems?has_content> - import ${packageModel}.customvalidator.MaxItems; - <#break> - - -<#list schema.fieldObjectList as field> - <#if field.restrictionProperties.minItems?has_content> - import ${packageModel}.customvalidator.MinItems; - <#break> - - -<#list schema.fieldObjectList as field> - <#if field.restrictionProperties.uniqueItems?has_content && field.restrictionProperties.uniqueItems == true> - import ${packageModel}.customvalidator.UniqueItems; - <#break> +<#if (field.restrictions.maxLength?has_content || field.restrictions.minLength?has_content) && !(visited?contains("size"))> + <#assign visited += "size," /> +import ${packageModel}.customvalidator.Size; + +<#if field.restrictions.maximum?has_content> + <#if field.dataType.baseType?lower_case == "bigdecimal" && !(visited?contains("maxBigDecimal"))> + <#assign visited += "maxBigDecimal," /> +import ${packageModel}.customvalidator.MaxBigDecimal; + <#elseif field.dataType.baseType?lower_case == "integer" && !(visited?contains("maxInteger"))> + <#assign visited += "maxInteger," /> +import ${packageModel}.customvalidator.MaxInteger; + <#elseif field.dataType.baseType?lower_case == "float" && !(visited?contains("maxFloat"))> + <#assign visited += "maxFloat," /> +import ${packageModel}.customvalidator.MaxFloat; + <#elseif field.dataType.baseType?lower_case == "double" && !(visited?contains("maxDouble"))> + <#assign visited += "maxDouble," /> +import ${packageModel}.customvalidator.MaxDouble; + + <#if field.restrictions.minimum?has_content> + <#if field.dataType.baseType?lower_case == "bigdecimal" && !(visited?contains("minBigDecimal"))> + <#assign visited += "minBigDecimal," /> +import ${packageModel}.customvalidator.MinBigDecimal; + <#elseif field.dataType.baseType?lower_case == "integer" && !(visited?contains("minInteger"))> + <#assign visited += "minInteger," /> +import ${packageModel}.customvalidator.MinInteger; + <#elseif field.dataType.baseType?lower_case == "float" && !(visited?contains("minFloat"))> + <#assign visited += "minFloat," /> +import ${packageModel}.customvalidator.MinFloat; + <#elseif field.dataType.baseType?lower_case == "double" && !(visited?contains("minDouble"))> + <#assign visited += "minDouble," /> +import ${packageModel}.customvalidator.MinDouble; + + + <#if field.restrictions.maxItems?has_content && !(visited?contains("maxItems"))> + <#assign visited += "maxItems," /> +import ${packageModel}.customvalidator.MaxItems; + + <#if field.restrictions.minItems?has_content && !(visited?contains("minItems"))> + <#assign visited += "minItems," /> +import ${packageModel}.customvalidator.MinItems; + + <#if field.restrictions.format?has_content && !(visited?contains("format"))> + <#assign visited += "format," /> +import com.fasterxml.jackson.annotation.JsonFormat; + + <#if (schema.schemaCombinator?has_content && (schema.schemaCombinator == "anyOf" || schema.schemaCombinator == "oneOf")) && !(visited?contains("schemaCombinator"))> + <#assign visited += "schemaCombinator," /> +import ${exceptionPackage}.exception.ModelClassException; + + <#if field.restrictions.pattern?has_content && !(visited?contains("pattern"))> + <#assign visited += "pattern," /> +import ${packageModel}.customvalidator.Pattern; + + <#if field.restrictions.multipleOf?has_content && !(visited?contains("multipleOf"))> + <#assign visited += "multipleOf," /> +import ${packageModel}.customvalidator.MultipleOf; + + <#if field.restrictions.uniqueItems?has_content && field.restrictions.uniqueItems == true && !(visited?contains("uniqueItems"))> + <#assign visited += "uniqueItems," /> +import ${packageModel}.customvalidator.UniqueItems; + import lombok.Builder; -import lombok.Data; +import lombok.Value; +import lombok.Singular; <#list schema.fieldObjectList as field> - <#if field.required> - import lombok.NonNull; - <#break> - + <#if field.required> +import lombok.NonNull; + <#break> + import lombok.extern.jackson.Jacksonized; <#if schema.schemaCombinator == "anyOf" || schema.schemaCombinator == "oneOf"> - import ${packageModel}.exception.ModelClassException; +import ${packageModel}.exception.ModelClassException; @Value public class ${schema.className} { <#list schema.fieldObjectList as field> - @JsonProperty(value ="${field.baseName?uncap_first}") - <#if field.restrictionProperties.minimum?has_content && (!field.restrictionProperties.exclusiveMinimum?has_content || field.restrictionProperties.exclusiveMinimum == false)> - @Min(minimum = "${field.restrictionProperties.minimum}", exclusive = false) - - <#if field.restrictionProperties.minimum?has_content && field.restrictionProperties.exclusiveMinimum?has_content && field.restrictionProperties.exclusiveMinimum == true> - @Min(minimum = "${field.restrictionProperties.minimum}", exclusive = ${field.restrictionProperties.exclusiveMinimum?string}) - - <#if field.restrictionProperties.maximum?has_content && (!field.restrictionProperties.exclusiveMaximum?has_content || field.restrictionProperties.exclusiveMaximum == false)> - @Max(maximum = "${field.restrictionProperties.maximum}", exclusive = false) - - <#if field.restrictionProperties.maximum?has_content && field.restrictionProperties.exclusiveMaximum?has_content && field.restrictionProperties.exclusiveMaximum == true> - @Max(maximum = "${field.restrictionProperties.maximum}", exclusive = ${field.restrictionProperties.exclusiveMaximum?string}) - - <#if field.restrictionProperties.maxItems?has_content> - @MaxItems(maximum = ${field.restrictionProperties.maxItems}) - - <#if field.restrictionProperties.minItems?has_content> - @MinItems(minimum = ${field.restrictionProperties.minItems}) - - <#if field.restrictionProperties.uniqueItems?has_content && field.restrictionProperties.uniqueItems == true> - @UniqueItems - - <#if field.restrictionProperties.maxLength?has_content && field.restrictionProperties.minLength?has_content> - @Size(min =${field.restrictionProperties.minLength}, max =${field.restrictionProperties.maxLength}) - <#elseif field.restrictionProperties.maxLength?has_content && !field.restrictionProperties.minLength?has_content> - @Size(min =0, max =${field.restrictionProperties.maxLength}) - <#elseif !field.restrictionProperties.maxLength?has_content && field.restrictionProperties.minLength?has_content> - @Size(min =${field.restrictionProperties.minLength}, max =0) - - <#if field.restrictionProperties.pattern?has_content> - @Pattern(regex = "${field.restrictionProperties.pattern}") - - <#if field.restrictionProperties.multipleOf?has_content> - @MultipleOf(multiple = "${field.restrictionProperties.multipleOf}") - - <#if field.required?has_content && field.required == true> - @NonNull - - <#if field.dataType.baseType == "array"> - <#assign singName>${singularizeName (calculateSafeName (field.baseName, ""))} - @Singular(${singName}) - private ${field.dataType} ${field.baseName?uncap_first}; - <#elseif field.dataType.baseType == "map"> - <#assign singName>${singularizeName (calculateSafeName (field.baseName, ""))} - @Singular(${singName}) - private ${field.dataType} ${field.baseName?uncap_first}; - <#elseif field.dataType.baseType == "enum"> - private ${field.baseName?cap_first} ${field.baseName?uncap_first}; + @JsonProperty(value ="${calculateSafeName (field.baseName, "")}") +<#if field.restrictions.minimum?has_content && (!field.restrictions.exclusiveMinimum?has_content)> + ${calculateMinAnnotation (field.dataType)}(minimum = "${field.restrictions.minimum}", exclusive = false) + +<#if field.restrictions.minimum?has_content && field.restrictions.exclusiveMinimum?has_content> + ${calculateMinAnnotation (field.dataType)}(minimum = "${field.restrictions.minimum}", exclusive = ${field.restrictions.exclusiveMinimum?string}) + +<#if field.restrictions.maximum?has_content && (!field.restrictions.exclusiveMaximum?has_content)> + ${calculateMaxAnnotation (field.dataType)}(maximum = "${field.restrictions.maximum}", exclusive = false) + +<#if field.restrictions.maximum?has_content && field.restrictions.exclusiveMaximum?has_content> + ${calculateMaxAnnotation (field.dataType)}(maximum = "${field.restrictions.maximum}", exclusive = ${field.restrictions.exclusiveMaximum?string}) + +<#if field.restrictions.maxItems?has_content> + @MaxItems(maximum = ${field.restrictions.maxItems}) + +<#if field.restrictions.minItems?has_content> + @MinItems(minimum = ${field.restrictions.minItems}) + +<#if field.restrictions.format?has_content> + @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "${field.restrictions.format}") + +<#if field.restrictions.uniqueItems?has_content && field.restrictions.uniqueItems == true> + @UniqueItems + +<#if field.restrictions.maxLength?has_content && field.restrictions.minLength?has_content> + @Size(min =${field.restrictions.minLength}, max =${field.restrictions.maxLength}) +<#elseif field.restrictions.maxLength?has_content && !field.restrictions.minLength?has_content> + @Size(max =${field.restrictions.maxLength}, min =0) +<#elseif !field.restrictions.maxLength?has_content && field.restrictions.minLength?has_content> + @Size(max =0, min =${field.restrictions.minLength}) + +<#if field.restrictions.pattern?has_content> + @Pattern(regex = "${field.restrictions.pattern}") + +<#if field.restrictions.multipleOf?has_content> + @MultipleOf(multiple = "${field.restrictions.multipleOf}") + +<#if field.required?has_content && field.required == true> + @NonNull + +<#if field.dataType.baseType == "array"> +<#assign singName>${singularizeName (calculateSafeName (field.baseName, ""))} + @Singular("${singName}") + private ${field.dataType} ${field.baseName?uncap_first}; + <#elseif field.dataType.baseType == "map"> +<#assign singName>${singularizeName (calculateSafeName (field.baseName, ""))} + @Singular("${singName}") + private ${field.dataType} ${field.baseName?uncap_first}; +<#elseif field.dataType.baseType == "enum"> + private ${field.baseName?cap_first} ${field.baseName?uncap_first}; - public enum ${field.baseName?cap_first} { - <#list field.enumValues as key, value> - <#if key?matches("[0-9].*")> - ${"_"+key}(${value})<#sep>, - <#else> - ${key}(${value})<#sep>, - - ; + public enum ${field.baseName?cap_first} { + <#list field.enumValues as key, value> + <#if key?matches("[0-9].*")> + ${"_"+key}(${value})<#sep>, + <#else> + ${key}(${value})<#sep>, + + ; - private ${field.dataType.innerType?cap_first} value; + private ${field.dataType.innerType?cap_first} value; - ${field.baseName?cap_first}(${field.dataType.innerType?cap_first} value) { - this.value = value; - } + ${field.baseName?cap_first}(${field.dataType.innerType?cap_first} value) { + this.value = value; + } - @JsonValue - public ${field.dataType.innerType?cap_first} getValue() { - return value; - } + @JsonValue + public ${field.dataType.innerType?cap_first} getValue() { + return value; + } - @Override - public String toString() { - return String.valueOf(value); - } - } - <#elseif field.dataType.innerType?has_content && field.dataType.baseType == "object"> - private ${field.dataType.innerType?cap_first} ${field.baseName?uncap_first}; - <#else> - private ${field.dataType} ${createSimpleType (field)} - + @Override + public String toString() { + return String.valueOf(value); + } + } + <#elseif field.dataType.innerType?has_content && field.dataType.baseType == "object"> + private ${field.dataType.innerType?cap_first} ${field.baseName?uncap_first}; + <#else> + private ${field.dataType} ${createSimpleType (field)} + -@Builder -@Jacksonized -private ${schema.className}(<@compress single_line=true><#list schema.fieldObjectList as field> - <#if field.required>@NonNull <#if field.dataType.baseType == "enum">${field.baseName?cap_first} ${field.baseName?uncap_first}<#elseif field.dataType.baseType == "array">${field.dataType} ${field.baseName?uncap_first}<#elseif field.dataType.baseType == "map">${field.dataType} ${field.baseName?uncap_first}<#elseif field.dataType.innerType?has_content && field.dataType.baseType == "object">${field.dataType.innerType?cap_first} ${field.baseName?uncap_first}<#else>${field.dataType} ${field.baseName?uncap_first}<#sep>, ) { -<#list schema.fieldObjectList as field> + @Builder + @Jacksonized + private ${schema.className}(<@compress single_line=true><#list schema.fieldObjectList as field> + <#if field.required>@NonNull <#if field.dataType.baseType == "enum">${field.baseName?cap_first} ${field.baseName?uncap_first}<#elseif field.dataType.baseType == "array">${field.dataType} ${field.baseName?uncap_first}<#elseif field.dataType.baseType == "map">${field.dataType} ${field.baseName?uncap_first}<#elseif field.dataType.innerType?has_content && field.dataType.baseType == "object">${field.dataType.innerType?cap_first} ${field.baseName?uncap_first}<#else>${field.dataType} ${field.baseName?uncap_first}<#sep>, ) { + <#list schema.fieldObjectList as field> this.${field.baseName?uncap_first} = ${field.baseName?uncap_first}; - + -<#if schema.schemaCombinator == "anyOf" || schema.schemaCombinator == "oneOf"> + <#if schema.schemaCombinator == "anyOf" || schema.schemaCombinator == "oneOf"> validatePartialCombinations(); - -} + + } <#if schema.schemaCombinator == "anyOf" || schema.schemaCombinator == "oneOf"> private void validatePartialCombinations() { boolean satisfiedCondition = false; - <#list schema.fieldObjectList as field> - <#if field == schema.fieldObjectList?first> + <#list schema.fieldObjectList as field> + <#if field == schema.fieldObjectList?first> if (Objects.nonNull(this.${field.baseName?uncap_first})) {<#else> else if (Objects.nonNull(this.${field.baseName?uncap_first})) { satisfiedCondition = true; } diff --git a/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/jakarta/MaxBigDecimal.java b/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/jakarta/MaxBigDecimal.java index 8c0f7d77..6d1f353b 100644 --- a/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/jakarta/MaxBigDecimal.java +++ b/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/jakarta/MaxBigDecimal.java @@ -4,8 +4,7 @@ import jakarta.validation.Payload; import java.lang.annotation.*; -@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, -ElementType.ANNOTATION_TYPE}) +@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, ElementType.ANNOTATION_TYPE}) @Retention(RetentionPolicy.RUNTIME) @Constraint(validatedBy = MaxBigDecimalValidator.class) @Documented diff --git a/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/jakarta/MaxBigDecimalValidator.java b/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/jakarta/MaxBigDecimalValidator.java index c424983c..01488825 100644 --- a/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/jakarta/MaxBigDecimalValidator.java +++ b/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/jakarta/MaxBigDecimalValidator.java @@ -1,24 +1,25 @@ package com.sngular.scsplugin.customvalidator.model.event.customvalidator; +import java.math.BigDecimal; import java.util.Objects; import jakarta.validation.ConstraintValidator; import jakarta.validation.ConstraintValidatorContext; -public class MaxValidator implements ConstraintValidator { +public class MaxBigDecimalValidator implements ConstraintValidator { - private int maximum; + private BigDecimal maximum; private boolean exclusive; @Override - public void initialize(Max constraintAnnotation) { + public void initialize(MaxBigDecimal constraintAnnotation) { ConstraintValidator.super.initialize(constraintAnnotation); - this.maximum = Integer.parseInt(constraintAnnotation.maximum()); + this.maximum = new BigDecimal(constraintAnnotation.maximum()); this.exclusive = constraintAnnotation.exclusive(); } @Override - public boolean isValid(Integer value, ConstraintValidatorContext context) { - return Objects.isNull(value) || (value.intValue() < this.maximum || (!exclusive && value.intValue() == this.maximum)); + public boolean isValid(BigDecimal value, ConstraintValidatorContext context) { + return Objects.isNull(value) || (value.compareTo(this.maximum) < 0 || (!exclusive && value.compareTo(this.maximum) == 0); } } \ No newline at end of file diff --git a/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/jakarta/MaxDouble.java b/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/jakarta/MaxDouble.java new file mode 100644 index 00000000..d237bb56 --- /dev/null +++ b/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/jakarta/MaxDouble.java @@ -0,0 +1,17 @@ +package com.sngular.scsplugin.customvalidator.model.event.customvalidator; + +import jakarta.validation.Constraint; +import jakarta.validation.Payload; +import java.lang.annotation.*; + +@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, ElementType.ANNOTATION_TYPE}) +@Retention(RetentionPolicy.RUNTIME) +@Constraint(validatedBy = MaxDoubleValidator.class) +@Documented +public @interface MaxDouble { + String maximum(); + boolean exclusive(); + String message() default "Value is bigger than the maximum."; + Class[] groups() default {}; + Class[] payload() default {}; +} \ No newline at end of file diff --git a/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/jakarta/MaxDoubleValidator.java b/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/jakarta/MaxDoubleValidator.java new file mode 100644 index 00000000..146291eb --- /dev/null +++ b/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/jakarta/MaxDoubleValidator.java @@ -0,0 +1,24 @@ +package com.sngular.scsplugin.customvalidator.model.event.customvalidator; + +import java.util.Objects; + +import jakarta.validation.ConstraintValidator; +import jakarta.validation.ConstraintValidatorContext; + +public class MaxDoubleValidator implements ConstraintValidator { + + private double maximum; + private boolean exclusive; + + @Override + public void initialize(MaxDouble constraintAnnotation) { + ConstraintValidator.super.initialize(constraintAnnotation); + this.maximum = Double.parseDouble(constraintAnnotation.maximum()); + this.exclusive = constraintAnnotation.exclusive(); + } + + @Override + public boolean isValid(Double value, ConstraintValidatorContext context) { + return Objects.isNull(value) || (value.doubleValue() < this.maximum || (!exclusive && value.doubleValue() == this.maximum)); + } +} \ No newline at end of file diff --git a/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/javax/Max.java b/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/jakarta/MaxFloat.java similarity index 69% rename from multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/javax/Max.java rename to multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/jakarta/MaxFloat.java index ab6fef10..18dfe0d9 100644 --- a/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/javax/Max.java +++ b/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/jakarta/MaxFloat.java @@ -1,15 +1,14 @@ package com.sngular.scsplugin.customvalidator.model.event.customvalidator; -import javax.validation.Constraint; -import javax.validation.Payload; +import jakarta.validation.Constraint; +import jakarta.validation.Payload; import java.lang.annotation.*; -@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, -ElementType.ANNOTATION_TYPE}) +@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, ElementType.ANNOTATION_TYPE}) @Retention(RetentionPolicy.RUNTIME) -@Constraint(validatedBy = MaxValidator.class) +@Constraint(validatedBy = MaxFloatValidator.class) @Documented -public @interface Max { +public @interface MaxFloat { String maximum(); boolean exclusive(); String message() default "Value is bigger than the maximum."; diff --git a/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/jakarta/MaxFloatValidator.java b/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/jakarta/MaxFloatValidator.java new file mode 100644 index 00000000..2d00f74c --- /dev/null +++ b/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/jakarta/MaxFloatValidator.java @@ -0,0 +1,24 @@ +package com.sngular.scsplugin.customvalidator.model.event.customvalidator; + +import java.util.Objects; + +import jakarta.validation.ConstraintValidator; +import jakarta.validation.ConstraintValidatorContext; + +public class MaxFloatValidator implements ConstraintValidator { + + private float maximum; + private boolean exclusive; + + @Override + public void initialize(MaxFloat constraintAnnotation) { + ConstraintValidator.super.initialize(constraintAnnotation); + this.maximum = Float.parseFloat(constraintAnnotation.maximum()); + this.exclusive = constraintAnnotation.exclusive(); + } + + @Override + public boolean isValid(Float value, ConstraintValidatorContext context) { + return Objects.isNull(value) || (value.floatValue() < this.maximum || (!exclusive && value.floatValue() == this.maximum)); + } +} \ No newline at end of file diff --git a/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/jakarta/MaxInteger.java b/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/jakarta/MaxInteger.java index 8ada1624..9cf2a83c 100644 --- a/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/jakarta/MaxInteger.java +++ b/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/jakarta/MaxInteger.java @@ -4,8 +4,7 @@ import jakarta.validation.Payload; import java.lang.annotation.*; -@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, -ElementType.ANNOTATION_TYPE}) +@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, ElementType.ANNOTATION_TYPE}) @Retention(RetentionPolicy.RUNTIME) @Constraint(validatedBy = MaxIntegerValidator.class) @Documented diff --git a/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/jakarta/MaxIntegerValidator.java b/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/jakarta/MaxIntegerValidator.java new file mode 100644 index 00000000..f1019412 --- /dev/null +++ b/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/jakarta/MaxIntegerValidator.java @@ -0,0 +1,24 @@ +package com.sngular.scsplugin.customvalidator.model.event.customvalidator; + +import java.util.Objects; + +import jakarta.validation.ConstraintValidator; +import jakarta.validation.ConstraintValidatorContext; + +public class MaxIntegerValidator implements ConstraintValidator { + + private int maximum; + private boolean exclusive; + + @Override + public void initialize(MaxInteger constraintAnnotation) { + ConstraintValidator.super.initialize(constraintAnnotation); + this.maximum = Integer.parseInt(constraintAnnotation.maximum()); + this.exclusive = constraintAnnotation.exclusive(); + } + + @Override + public boolean isValid(Integer value, ConstraintValidatorContext context) { + return Objects.isNull(value) || (value.intValue() < this.maximum || (!exclusive && value.intValue() == this.maximum)); + } +} \ No newline at end of file diff --git a/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/jakarta/MaxItems.java b/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/jakarta/MaxItems.java index 5f52be34..25211dea 100644 --- a/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/jakarta/MaxItems.java +++ b/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/jakarta/MaxItems.java @@ -4,8 +4,7 @@ import jakarta.validation.Payload; import java.lang.annotation.*; -@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, - ElementType.ANNOTATION_TYPE}) +@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, ElementType.ANNOTATION_TYPE}) @Retention(RetentionPolicy.RUNTIME) @Constraint(validatedBy = MaxItemsValidator.class) @Documented diff --git a/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/jakarta/MinBigDecimal.java b/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/jakarta/MinBigDecimal.java new file mode 100644 index 00000000..86ca48f9 --- /dev/null +++ b/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/jakarta/MinBigDecimal.java @@ -0,0 +1,17 @@ +package com.sngular.scsplugin.customvalidator.model.event.customvalidator; + +import jakarta.validation.Constraint; +import jakarta.validation.Payload; +import java.lang.annotation.*; + +@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, ElementType.ANNOTATION_TYPE}) +@Retention(RetentionPolicy.RUNTIME) +@Constraint(validatedBy = MinBigDecimalValidator.class) +@Documented +public @interface MinBigDecimal { + String minimum(); + boolean exclusive(); + String message() default "Value is smaller than the minimum."; + Class[] groups() default {}; + Class[] payload() default {}; +} \ No newline at end of file diff --git a/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/jakarta/MinBigDecimalValidator.java b/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/jakarta/MinBigDecimalValidator.java new file mode 100644 index 00000000..d3178994 --- /dev/null +++ b/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/jakarta/MinBigDecimalValidator.java @@ -0,0 +1,25 @@ +package com.sngular.scsplugin.customvalidator.model.event.customvalidator; + +import java.math.BigDecimal; +import java.util.Objects; + +import jakarta.validation.ConstraintValidator; +import jakarta.validation.ConstraintValidatorContext; + +public class MinBigDecimalValidator implements ConstraintValidator { + + private BigDecimal minimum; + private boolean exclusive; + + @Override + public void initialize(MinBigDecimal constraintAnnotation) { + ConstraintValidator.super.initialize(constraintAnnotation); + this.minimum = new BigDecimal(constraintAnnotation.minimum()); + this.exclusive = constraintAnnotation.exclusive(); + } + + @Override + public boolean isValid(BigDecimal value, ConstraintValidatorContext context) { + return Objects.isNull(value) || (value.compareTo(this.minimum) > 0 || (!exclusive && value.compareTo(this.minimum) == 0); + } +} \ No newline at end of file diff --git a/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/jakarta/MinDouble.java b/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/jakarta/MinDouble.java new file mode 100644 index 00000000..895cdf28 --- /dev/null +++ b/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/jakarta/MinDouble.java @@ -0,0 +1,17 @@ +package com.sngular.scsplugin.customvalidator.model.event.customvalidator; + +import jakarta.validation.Constraint; +import jakarta.validation.Payload; +import java.lang.annotation.*; + +@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, ElementType.ANNOTATION_TYPE}) +@Retention(RetentionPolicy.RUNTIME) +@Constraint(validatedBy = MinDoubleValidator.class) +@Documented +public @interface MinDouble { + String minimum(); + boolean exclusive(); + String message() default "Value is smaller than the minimum."; + Class[] groups() default {}; + Class[] payload() default {}; +} \ No newline at end of file diff --git a/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/jakarta/MinDoubleValidator.java b/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/jakarta/MinDoubleValidator.java new file mode 100644 index 00000000..8e738ca2 --- /dev/null +++ b/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/jakarta/MinDoubleValidator.java @@ -0,0 +1,24 @@ +package com.sngular.scsplugin.customvalidator.model.event.customvalidator; + +import java.util.Objects; + +import jakarta.validation.ConstraintValidator; +import jakarta.validation.ConstraintValidatorContext; + +public class MinDoubleValidator implements ConstraintValidator { + + private double minimum; + private boolean exclusive; + + @Override + public void initialize(MinDouble constraintAnnotation) { + ConstraintValidator.super.initialize(constraintAnnotation); + this.minimum = Double.parseDouble(constraintAnnotation.minimum()); + this.exclusive = constraintAnnotation.exclusive(); + } + + @Override + public boolean isValid(Double value, ConstraintValidatorContext context) { + return Objects.isNull(value) || (value.doubleValue() > this.minimum || (!exclusive && value.doubleValue() == this.minimum)); + } +} \ No newline at end of file diff --git a/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/jakarta/Min.java b/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/jakarta/MinFloat.java similarity index 80% rename from multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/jakarta/Min.java rename to multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/jakarta/MinFloat.java index 4b7970ca..cabada96 100644 --- a/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/jakarta/Min.java +++ b/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/jakarta/MinFloat.java @@ -4,12 +4,11 @@ import jakarta.validation.Payload; import java.lang.annotation.*; -@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, - ElementType.ANNOTATION_TYPE}) +@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, ElementType.ANNOTATION_TYPE}) @Retention(RetentionPolicy.RUNTIME) -@Constraint(validatedBy = MinValidator.class) +@Constraint(validatedBy = MinFloatValidator.class) @Documented -public @interface Min { +public @interface MinFloat { String minimum(); boolean exclusive(); String message() default "Value is smaller than the minimum."; diff --git a/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/jakarta/MinFloatValidator.java b/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/jakarta/MinFloatValidator.java new file mode 100644 index 00000000..9bcd4236 --- /dev/null +++ b/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/jakarta/MinFloatValidator.java @@ -0,0 +1,24 @@ +package com.sngular.scsplugin.customvalidator.model.event.customvalidator; + +import java.util.Objects; + +import jakarta.validation.ConstraintValidator; +import jakarta.validation.ConstraintValidatorContext; + +public class MinFloatValidator implements ConstraintValidator { + + private float minimum; + private boolean exclusive; + + @Override + public void initialize(MinFloat constraintAnnotation) { + ConstraintValidator.super.initialize(constraintAnnotation); + this.minimum = Float.parseFloat(constraintAnnotation.minimum()); + this.exclusive = constraintAnnotation.exclusive(); + } + + @Override + public boolean isValid(Float value, ConstraintValidatorContext context) { + return Objects.isNull(value) || (value.floatValue() > this.minimum || (!exclusive && value.floatValue() == this.minimum)); + } +} \ No newline at end of file diff --git a/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/jakarta/MinInteger.java b/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/jakarta/MinInteger.java new file mode 100644 index 00000000..ace8f5a8 --- /dev/null +++ b/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/jakarta/MinInteger.java @@ -0,0 +1,17 @@ +package com.sngular.scsplugin.customvalidator.model.event.customvalidator; + +import jakarta.validation.Constraint; +import jakarta.validation.Payload; +import java.lang.annotation.*; + +@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, ElementType.ANNOTATION_TYPE}) +@Retention(RetentionPolicy.RUNTIME) +@Constraint(validatedBy = MinIntegerValidator.class) +@Documented +public @interface MinInteger { + String minimum(); + boolean exclusive(); + String message() default "Value is smaller than the minimum."; + Class[] groups() default {}; + Class[] payload() default {}; +} \ No newline at end of file diff --git a/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/javax/MinValidator.java b/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/jakarta/MinIntegerValidator.java similarity index 70% rename from multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/javax/MinValidator.java rename to multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/jakarta/MinIntegerValidator.java index 3b2c2899..035bb134 100644 --- a/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/javax/MinValidator.java +++ b/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/jakarta/MinIntegerValidator.java @@ -2,16 +2,16 @@ import java.util.Objects; -import javax.validation.ConstraintValidator; -import javax.validation.ConstraintValidatorContext; +import jakarta.validation.ConstraintValidator; +import jakarta.validation.ConstraintValidatorContext; -public class MinValidator implements ConstraintValidator { +public class MinIntegerValidator implements ConstraintValidator { private int minimum; private boolean exclusive; @Override - public void initialize(Min constraintAnnotation) { + public void initialize(MinInteger constraintAnnotation) { ConstraintValidator.super.initialize(constraintAnnotation); this.minimum = Integer.parseInt(constraintAnnotation.minimum()); this.exclusive = constraintAnnotation.exclusive(); diff --git a/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/jakarta/MinItems.java b/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/jakarta/MinItems.java index 4e0ff6a9..14ae2a76 100644 --- a/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/jakarta/MinItems.java +++ b/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/jakarta/MinItems.java @@ -4,8 +4,7 @@ import jakarta.validation.Payload; import java.lang.annotation.*; -@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, - ElementType.ANNOTATION_TYPE}) +@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, ElementType.ANNOTATION_TYPE}) @Retention(RetentionPolicy.RUNTIME) @Constraint(validatedBy = MinItemsValidator.class) @Documented diff --git a/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/jakarta/MultipleOf.java b/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/jakarta/MultipleOf.java index 1286c28f..c71f17e3 100644 --- a/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/jakarta/MultipleOf.java +++ b/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/jakarta/MultipleOf.java @@ -4,8 +4,7 @@ import jakarta.validation.Payload; import java.lang.annotation.*; -@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, - ElementType.ANNOTATION_TYPE}) +@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, ElementType.ANNOTATION_TYPE}) @Retention(RetentionPolicy.RUNTIME) @Constraint(validatedBy = MultipleOfValidator.class) @Documented diff --git a/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/jakarta/NotNull.java b/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/jakarta/NotNull.java index 6f7244d0..f8883a65 100644 --- a/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/jakarta/NotNull.java +++ b/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/jakarta/NotNull.java @@ -4,8 +4,7 @@ import jakarta.validation.Payload; import java.lang.annotation.*; -@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, - ElementType.ANNOTATION_TYPE}) +@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, ElementType.ANNOTATION_TYPE}) @Retention(RetentionPolicy.RUNTIME) @Constraint(validatedBy = NotNullValidator.class) @Documented diff --git a/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/jakarta/Pattern.java b/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/jakarta/Pattern.java index 809e10bb..da3dafa0 100644 --- a/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/jakarta/Pattern.java +++ b/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/jakarta/Pattern.java @@ -5,8 +5,7 @@ import java.lang.annotation.*; -@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, - ElementType.ANNOTATION_TYPE}) +@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, ElementType.ANNOTATION_TYPE}) @Retention(RetentionPolicy.RUNTIME) @Constraint(validatedBy = PatternValidator.class) @Documented diff --git a/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/jakarta/Size.java b/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/jakarta/Size.java index 7be3d653..60f17575 100644 --- a/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/jakarta/Size.java +++ b/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/jakarta/Size.java @@ -4,8 +4,7 @@ import jakarta.validation.Payload; import java.lang.annotation.*; -@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, - ElementType.ANNOTATION_TYPE}) +@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, ElementType.ANNOTATION_TYPE}) @Retention(RetentionPolicy.RUNTIME) @Constraint(validatedBy = SizeValidator.class) @Documented diff --git a/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/jakarta/UniqueItems.java b/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/jakarta/UniqueItems.java index c63afc3c..2bafc875 100644 --- a/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/jakarta/UniqueItems.java +++ b/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/jakarta/UniqueItems.java @@ -4,8 +4,7 @@ import jakarta.validation.Payload; import java.lang.annotation.*; -@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, - ElementType.ANNOTATION_TYPE}) +@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, ElementType.ANNOTATION_TYPE}) @Retention(RetentionPolicy.RUNTIME) @Constraint(validatedBy = UniqueItemsValidator.class) @Documented diff --git a/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/javax/MaxBigDecimal.java b/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/javax/MaxBigDecimal.java index 28212b72..d485557e 100644 --- a/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/javax/MaxBigDecimal.java +++ b/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/javax/MaxBigDecimal.java @@ -4,8 +4,7 @@ import javax.validation.Payload; import java.lang.annotation.*; -@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, -ElementType.ANNOTATION_TYPE}) +@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, ElementType.ANNOTATION_TYPE}) @Retention(RetentionPolicy.RUNTIME) @Constraint(validatedBy = MaxBigDecimalValidator.class) @Documented diff --git a/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/javax/MaxBigDecimalValidator.java b/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/javax/MaxBigDecimalValidator.java index 6f02d12e..a9ba4b20 100644 --- a/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/javax/MaxBigDecimalValidator.java +++ b/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/javax/MaxBigDecimalValidator.java @@ -20,6 +20,6 @@ public void initialize(MaxBigDecimal constraintAnnotation) { @Override public boolean isValid(BigDecimal value, ConstraintValidatorContext context) { - return Objects.isNull(value) || (value < this.maximum || (!exclusive && value == this.maximum)); + return Objects.isNull(value) || (value.compareTo(this.maximum) < 0 || (!exclusive && value.compareTo(this.maximum) == 0); } } \ No newline at end of file diff --git a/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/javax/MaxDouble.java b/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/javax/MaxDouble.java index dcc674dd..0c6be029 100644 --- a/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/javax/MaxDouble.java +++ b/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/javax/MaxDouble.java @@ -4,8 +4,7 @@ import javax.validation.Payload; import java.lang.annotation.*; -@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, -ElementType.ANNOTATION_TYPE}) +@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, ElementType.ANNOTATION_TYPE}) @Retention(RetentionPolicy.RUNTIME) @Constraint(validatedBy = MaxDoubleValidator.class) @Documented diff --git a/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/javax/MaxFloat.java b/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/javax/MaxFloat.java index 514504b3..cf4a8569 100644 --- a/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/javax/MaxFloat.java +++ b/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/javax/MaxFloat.java @@ -4,8 +4,7 @@ import javax.validation.Payload; import java.lang.annotation.*; -@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, -ElementType.ANNOTATION_TYPE}) +@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, ElementType.ANNOTATION_TYPE}) @Retention(RetentionPolicy.RUNTIME) @Constraint(validatedBy = MaxFloatValidator.class) @Documented diff --git a/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/javax/MaxInteger.java b/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/javax/MaxInteger.java index 28e6684c..d25cd630 100644 --- a/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/javax/MaxInteger.java +++ b/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/javax/MaxInteger.java @@ -4,8 +4,7 @@ import javax.validation.Payload; import java.lang.annotation.*; -@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, -ElementType.ANNOTATION_TYPE}) +@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, ElementType.ANNOTATION_TYPE}) @Retention(RetentionPolicy.RUNTIME) @Constraint(validatedBy = MaxIntegerValidator.class) @Documented diff --git a/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/javax/MaxItems.java b/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/javax/MaxItems.java index 8f27b373..1276bd0f 100644 --- a/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/javax/MaxItems.java +++ b/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/javax/MaxItems.java @@ -4,8 +4,7 @@ import javax.validation.Payload; import java.lang.annotation.*; -@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, - ElementType.ANNOTATION_TYPE}) +@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, ElementType.ANNOTATION_TYPE}) @Retention(RetentionPolicy.RUNTIME) @Constraint(validatedBy = MaxItemsValidator.class) @Documented diff --git a/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/javax/MinBigDecimal.java b/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/javax/MinBigDecimal.java index e8463b29..e937d5dc 100644 --- a/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/javax/MinBigDecimal.java +++ b/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/javax/MinBigDecimal.java @@ -4,8 +4,7 @@ import javax.validation.Payload; import java.lang.annotation.*; -@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, - ElementType.ANNOTATION_TYPE}) +@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, ElementType.ANNOTATION_TYPE}) @Retention(RetentionPolicy.RUNTIME) @Constraint(validatedBy = MinBigDecimalValidator.class) @Documented diff --git a/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/javax/MinBigDecimalValidator.java b/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/javax/MinBigDecimalValidator.java index b7ccfa5d..68c26936 100644 --- a/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/javax/MinBigDecimalValidator.java +++ b/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/javax/MinBigDecimalValidator.java @@ -6,13 +6,13 @@ import javax.validation.ConstraintValidator; import javax.validation.ConstraintValidatorContext; -public class MinValidator implements ConstraintValidator { +public class MinBigDecimalValidator implements ConstraintValidator { private BigDecimal minimum; private boolean exclusive; @Override - public void initialize(Min constraintAnnotation) { + public void initialize(MinBigDecimal constraintAnnotation) { ConstraintValidator.super.initialize(constraintAnnotation); this.minimum = new BigDecimal(constraintAnnotation.minimum()); this.exclusive = constraintAnnotation.exclusive(); @@ -20,6 +20,6 @@ public void initialize(Min constraintAnnotation) { @Override public boolean isValid(BigDecimal value, ConstraintValidatorContext context) { - return Objects.isNull(value) || (value > this.minimum || (!exclusive && value == this.minimum)); + return Objects.isNull(value) || (value.compareTo(this.minimum) > 0 || (!exclusive && value.compareTo(this.minimum) == 0); } } \ No newline at end of file diff --git a/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/javax/MinDouble.java b/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/javax/MinDouble.java index ad351134..2bac555c 100644 --- a/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/javax/MinDouble.java +++ b/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/javax/MinDouble.java @@ -4,8 +4,7 @@ import javax.validation.Payload; import java.lang.annotation.*; -@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, - ElementType.ANNOTATION_TYPE}) +@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, ElementType.ANNOTATION_TYPE}) @Retention(RetentionPolicy.RUNTIME) @Constraint(validatedBy = MinDoubleValidator.class) @Documented diff --git a/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/javax/MinDoubleValidator.java b/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/javax/MinDoubleValidator.java index df0f160b..4a1917e7 100644 --- a/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/javax/MinDoubleValidator.java +++ b/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/javax/MinDoubleValidator.java @@ -5,7 +5,7 @@ import javax.validation.ConstraintValidator; import javax.validation.ConstraintValidatorContext; -public class MinValidator implements ConstraintValidator { +public class MinDoubleValidator implements ConstraintValidator { private double minimum; private boolean exclusive; diff --git a/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/javax/MinFloat.java b/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/javax/MinFloat.java index dc72bbc1..82de58ff 100644 --- a/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/javax/MinFloat.java +++ b/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/javax/MinFloat.java @@ -4,8 +4,7 @@ import javax.validation.Payload; import java.lang.annotation.*; -@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, - ElementType.ANNOTATION_TYPE}) +@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, ElementType.ANNOTATION_TYPE}) @Retention(RetentionPolicy.RUNTIME) @Constraint(validatedBy = MinFloatValidator.class) @Documented diff --git a/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/javax/MinFloatValidator.java b/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/javax/MinFloatValidator.java index 29d09a52..e54f541c 100644 --- a/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/javax/MinFloatValidator.java +++ b/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/javax/MinFloatValidator.java @@ -5,7 +5,7 @@ import javax.validation.ConstraintValidator; import javax.validation.ConstraintValidatorContext; -public class MinValidator implements ConstraintValidator { +public class MinFloatValidator implements ConstraintValidator { private float minimum; private boolean exclusive; diff --git a/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/javax/MinInteger.java b/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/javax/MinInteger.java index b63a25cf..9c255914 100644 --- a/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/javax/MinInteger.java +++ b/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/javax/MinInteger.java @@ -4,8 +4,7 @@ import javax.validation.Payload; import java.lang.annotation.*; -@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, - ElementType.ANNOTATION_TYPE}) +@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, ElementType.ANNOTATION_TYPE}) @Retention(RetentionPolicy.RUNTIME) @Constraint(validatedBy = MinIntegerValidator.class) @Documented diff --git a/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/javax/MinIntegerValidator.java b/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/javax/MinIntegerValidator.java index 96d6450f..c22fc055 100644 --- a/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/javax/MinIntegerValidator.java +++ b/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/javax/MinIntegerValidator.java @@ -5,7 +5,7 @@ import javax.validation.ConstraintValidator; import javax.validation.ConstraintValidatorContext; -public class MinValidator implements ConstraintValidator { +public class MinIntegerValidator implements ConstraintValidator { private int minimum; private boolean exclusive; diff --git a/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/javax/MinItems.java b/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/javax/MinItems.java index 2c340200..dcdb11b8 100644 --- a/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/javax/MinItems.java +++ b/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/javax/MinItems.java @@ -4,8 +4,7 @@ import javax.validation.Payload; import java.lang.annotation.*; -@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, - ElementType.ANNOTATION_TYPE}) +@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, ElementType.ANNOTATION_TYPE}) @Retention(RetentionPolicy.RUNTIME) @Constraint(validatedBy = MinItemsValidator.class) @Documented diff --git a/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/javax/MultipleOf.java b/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/javax/MultipleOf.java index 56c07937..6076d4ce 100644 --- a/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/javax/MultipleOf.java +++ b/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/javax/MultipleOf.java @@ -4,8 +4,7 @@ import javax.validation.Payload; import java.lang.annotation.*; -@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, - ElementType.ANNOTATION_TYPE}) +@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, ElementType.ANNOTATION_TYPE}) @Retention(RetentionPolicy.RUNTIME) @Constraint(validatedBy = MultipleOfValidator.class) @Documented diff --git a/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/javax/NotNull.java b/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/javax/NotNull.java index 66aba9fe..dc7a8f6c 100644 --- a/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/javax/NotNull.java +++ b/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/javax/NotNull.java @@ -4,8 +4,7 @@ import javax.validation.Payload; import java.lang.annotation.*; -@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, - ElementType.ANNOTATION_TYPE}) +@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, ElementType.ANNOTATION_TYPE}) @Retention(RetentionPolicy.RUNTIME) @Constraint(validatedBy = NotNullValidator.class) @Documented diff --git a/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/javax/Pattern.java b/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/javax/Pattern.java index 11e41b62..c6338579 100644 --- a/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/javax/Pattern.java +++ b/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/javax/Pattern.java @@ -5,8 +5,7 @@ import java.lang.annotation.*; -@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, - ElementType.ANNOTATION_TYPE}) +@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, ElementType.ANNOTATION_TYPE}) @Retention(RetentionPolicy.RUNTIME) @Constraint(validatedBy = PatternValidator.class) @Documented diff --git a/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/javax/Size.java b/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/javax/Size.java index 5d388e71..93056210 100644 --- a/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/javax/Size.java +++ b/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/javax/Size.java @@ -4,8 +4,7 @@ import javax.validation.Payload; import java.lang.annotation.*; -@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, - ElementType.ANNOTATION_TYPE}) +@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, ElementType.ANNOTATION_TYPE}) @Retention(RetentionPolicy.RUNTIME) @Constraint(validatedBy = SizeValidator.class) @Documented diff --git a/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/javax/UniqueItems.java b/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/javax/UniqueItems.java index 95f8a018..6dcc083d 100644 --- a/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/javax/UniqueItems.java +++ b/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/javax/UniqueItems.java @@ -4,8 +4,7 @@ import javax.validation.Payload; import java.lang.annotation.*; -@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, - ElementType.ANNOTATION_TYPE}) +@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, ElementType.ANNOTATION_TYPE}) @Retention(RetentionPolicy.RUNTIME) @Constraint(validatedBy = UniqueItemsValidator.class) @Documented diff --git a/multiapi-engine/src/test/resources/asyncapigenerator/testFileGeneration/customvalidator/NotNull.java b/multiapi-engine/src/test/resources/asyncapigenerator/testFileGeneration/customvalidator/NotNull.java index 855a4117..cf49f161 100644 --- a/multiapi-engine/src/test/resources/asyncapigenerator/testFileGeneration/customvalidator/NotNull.java +++ b/multiapi-engine/src/test/resources/asyncapigenerator/testFileGeneration/customvalidator/NotNull.java @@ -4,8 +4,7 @@ import javax.validation.Payload; import java.lang.annotation.*; -@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, - ElementType.ANNOTATION_TYPE}) +@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, ElementType.ANNOTATION_TYPE}) @Retention(RetentionPolicy.RUNTIME) @Constraint(validatedBy = NotNullValidator.class) @Documented diff --git a/multiapi-engine/src/test/resources/asyncapigenerator/testFileGenerationIssue/customvalidator/NotNull.java b/multiapi-engine/src/test/resources/asyncapigenerator/testFileGenerationIssue/customvalidator/NotNull.java index ef6ea8a4..697b1703 100644 --- a/multiapi-engine/src/test/resources/asyncapigenerator/testFileGenerationIssue/customvalidator/NotNull.java +++ b/multiapi-engine/src/test/resources/asyncapigenerator/testFileGenerationIssue/customvalidator/NotNull.java @@ -4,8 +4,7 @@ import javax.validation.Payload; import java.lang.annotation.*; -@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, - ElementType.ANNOTATION_TYPE}) +@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, ElementType.ANNOTATION_TYPE}) @Retention(RetentionPolicy.RUNTIME) @Constraint(validatedBy = NotNullValidator.class) @Documented diff --git a/multiapi-engine/src/test/resources/asyncapigenerator/testFileGenerationIssue/customvalidator/Size.java b/multiapi-engine/src/test/resources/asyncapigenerator/testFileGenerationIssue/customvalidator/Size.java index 427d3bd0..fe04089a 100644 --- a/multiapi-engine/src/test/resources/asyncapigenerator/testFileGenerationIssue/customvalidator/Size.java +++ b/multiapi-engine/src/test/resources/asyncapigenerator/testFileGenerationIssue/customvalidator/Size.java @@ -4,8 +4,7 @@ import javax.validation.Payload; import java.lang.annotation.*; -@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, - ElementType.ANNOTATION_TYPE}) +@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, ElementType.ANNOTATION_TYPE}) @Retention(RetentionPolicy.RUNTIME) @Constraint(validatedBy = SizeValidator.class) @Documented diff --git a/multiapi-engine/src/test/resources/asyncapigenerator/testFileGenerationWithKafkaBindings/customvalidator/NotNull.java b/multiapi-engine/src/test/resources/asyncapigenerator/testFileGenerationWithKafkaBindings/customvalidator/NotNull.java index 7a586aab..4908ea75 100644 --- a/multiapi-engine/src/test/resources/asyncapigenerator/testFileGenerationWithKafkaBindings/customvalidator/NotNull.java +++ b/multiapi-engine/src/test/resources/asyncapigenerator/testFileGenerationWithKafkaBindings/customvalidator/NotNull.java @@ -4,8 +4,7 @@ import javax.validation.Payload; import java.lang.annotation.*; -@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, - ElementType.ANNOTATION_TYPE}) +@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, ElementType.ANNOTATION_TYPE}) @Retention(RetentionPolicy.RUNTIME) @Constraint(validatedBy = NotNullValidator.class) @Documented diff --git a/multiapi-engine/src/test/resources/asyncapigenerator/testModelClassExceptionGeneration/customvalidator/NotNull.java b/multiapi-engine/src/test/resources/asyncapigenerator/testModelClassExceptionGeneration/customvalidator/NotNull.java index 0ddb9a23..3c9ba787 100644 --- a/multiapi-engine/src/test/resources/asyncapigenerator/testModelClassExceptionGeneration/customvalidator/NotNull.java +++ b/multiapi-engine/src/test/resources/asyncapigenerator/testModelClassExceptionGeneration/customvalidator/NotNull.java @@ -4,8 +4,7 @@ import javax.validation.Payload; import java.lang.annotation.*; -@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, - ElementType.ANNOTATION_TYPE}) +@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, ElementType.ANNOTATION_TYPE}) @Retention(RetentionPolicy.RUNTIME) @Constraint(validatedBy = NotNullValidator.class) @Documented diff --git a/multiapi-engine/src/test/resources/openapigenerator/testAdditionalProperties/assets/TestDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testAdditionalProperties/assets/TestDTO.java index 76be5806..652036fb 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testAdditionalProperties/assets/TestDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testAdditionalProperties/assets/TestDTO.java @@ -4,11 +4,11 @@ import java.util.Map; import java.util.HashMap; import lombok.Builder; -import lombok.Data; +import lombok.Value; import lombok.NonNull; import lombok.extern.jackson.Jacksonized; -@Data +@Value public class TestDTO { @JsonProperty(value ="additionalProperties") diff --git a/multiapi-engine/src/test/resources/openapigenerator/testAdditionalPropertiesWithSchema/assets/SubtestDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testAdditionalPropertiesWithSchema/assets/SubtestDTO.java index 9b9f3972..3ad59e6e 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testAdditionalPropertiesWithSchema/assets/SubtestDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testAdditionalPropertiesWithSchema/assets/SubtestDTO.java @@ -2,11 +2,11 @@ import com.fasterxml.jackson.annotation.JsonProperty; import lombok.Builder; -import lombok.Data; +import lombok.Value; import lombok.NonNull; import lombok.extern.jackson.Jacksonized; -@Data +@Value public class SubtestDTO { @JsonProperty(value ="name") diff --git a/multiapi-engine/src/test/resources/openapigenerator/testAdditionalPropertiesWithSchema/assets/TestDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testAdditionalPropertiesWithSchema/assets/TestDTO.java index c3220017..a9e023c5 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testAdditionalPropertiesWithSchema/assets/TestDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testAdditionalPropertiesWithSchema/assets/TestDTO.java @@ -4,11 +4,11 @@ import java.util.Map; import java.util.HashMap; import lombok.Builder; -import lombok.Data; +import lombok.Value; import lombok.NonNull; import lombok.extern.jackson.Jacksonized; -@Data +@Value public class TestDTO { @JsonProperty(value ="additionalProperties") diff --git a/multiapi-engine/src/test/resources/openapigenerator/testAdditionalPropertiesWithUnnamedObject/assets/ArraySchemaDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testAdditionalPropertiesWithUnnamedObject/assets/ArraySchemaDTO.java index ddc1c1f5..b4f5913f 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testAdditionalPropertiesWithUnnamedObject/assets/ArraySchemaDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testAdditionalPropertiesWithUnnamedObject/assets/ArraySchemaDTO.java @@ -2,10 +2,10 @@ import com.fasterxml.jackson.annotation.JsonProperty; import lombok.Builder; -import lombok.Data; +import lombok.Value; import lombok.extern.jackson.Jacksonized; -@Data +@Value public class ArraySchemaDTO { @JsonProperty(value ="name") diff --git a/multiapi-engine/src/test/resources/openapigenerator/testAdditionalPropertiesWithUnnamedObject/assets/SecondTestDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testAdditionalPropertiesWithUnnamedObject/assets/SecondTestDTO.java index 30e113a3..9147c5e5 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testAdditionalPropertiesWithUnnamedObject/assets/SecondTestDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testAdditionalPropertiesWithUnnamedObject/assets/SecondTestDTO.java @@ -4,11 +4,11 @@ import java.util.Map; import java.util.HashMap; import lombok.Builder; -import lombok.Data; +import lombok.Value; import lombok.NonNull; import lombok.extern.jackson.Jacksonized; -@Data +@Value public class SecondTestDTO { @JsonProperty(value ="additionalProperties") diff --git a/multiapi-engine/src/test/resources/openapigenerator/testAdditionalPropertiesWithUnnamedObject/assets/TestDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testAdditionalPropertiesWithUnnamedObject/assets/TestDTO.java index c47ecef4..4625de60 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testAdditionalPropertiesWithUnnamedObject/assets/TestDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testAdditionalPropertiesWithUnnamedObject/assets/TestDTO.java @@ -4,11 +4,11 @@ import java.util.Map; import java.util.HashMap; import lombok.Builder; -import lombok.Data; +import lombok.Value; import lombok.NonNull; import lombok.extern.jackson.Jacksonized; -@Data +@Value public class TestDTO { @JsonProperty(value ="additionalProperties") diff --git a/multiapi-engine/src/test/resources/openapigenerator/testAdditionalPropertiesWithUnnamedObject/assets/TestValueDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testAdditionalPropertiesWithUnnamedObject/assets/TestValueDTO.java index 6f672915..ee99a77b 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testAdditionalPropertiesWithUnnamedObject/assets/TestValueDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testAdditionalPropertiesWithUnnamedObject/assets/TestValueDTO.java @@ -4,11 +4,11 @@ import java.util.Map; import java.util.HashMap; import lombok.Builder; -import lombok.Data; +import lombok.Value; import lombok.NonNull; import lombok.extern.jackson.Jacksonized; -@Data +@Value public class TestValueDTO { @JsonProperty(value ="additionalProperties") diff --git a/multiapi-engine/src/test/resources/openapigenerator/testAdditionalPropertiesWithUnnamedObject/assets/TestValueValueDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testAdditionalPropertiesWithUnnamedObject/assets/TestValueValueDTO.java index 0a362b1f..2864e7a0 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testAdditionalPropertiesWithUnnamedObject/assets/TestValueValueDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testAdditionalPropertiesWithUnnamedObject/assets/TestValueValueDTO.java @@ -6,11 +6,11 @@ import java.util.Map; import java.util.HashMap; import lombok.Builder; -import lombok.Data; +import lombok.Value; import lombok.NonNull; import lombok.extern.jackson.Jacksonized; -@Data +@Value public class TestValueValueDTO { @JsonProperty(value ="additionalProperties") diff --git a/multiapi-engine/src/test/resources/openapigenerator/testAdditionalPropertiesWithUnnamedObject/assets/ThirdTestDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testAdditionalPropertiesWithUnnamedObject/assets/ThirdTestDTO.java index 918c54f6..57a0884a 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testAdditionalPropertiesWithUnnamedObject/assets/ThirdTestDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testAdditionalPropertiesWithUnnamedObject/assets/ThirdTestDTO.java @@ -4,11 +4,11 @@ import java.util.Map; import java.util.HashMap; import lombok.Builder; -import lombok.Data; +import lombok.Value; import lombok.NonNull; import lombok.extern.jackson.Jacksonized; -@Data +@Value public class ThirdTestDTO { @JsonProperty(value ="additionalProperties") diff --git a/multiapi-engine/src/test/resources/openapigenerator/testAllOf/assets/lombok/ApiErrorDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testAllOf/assets/lombok/ApiErrorDTO.java index bfb32e90..e0958c6b 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testAllOf/assets/lombok/ApiErrorDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testAllOf/assets/lombok/ApiErrorDTO.java @@ -2,11 +2,12 @@ import com.fasterxml.jackson.annotation.JsonProperty; import lombok.Builder; -import lombok.Data; +import lombok.Value; +import lombok.Singular; import lombok.NonNull; import lombok.extern.jackson.Jacksonized; -@Data +@Value public class ApiErrorDTO { @JsonProperty(value ="code") diff --git a/multiapi-engine/src/test/resources/openapigenerator/testAllOf/assets/lombok/ApiTestAllOfDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testAllOf/assets/lombok/ApiTestAllOfDTO.java index 44fae21e..4d215b03 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testAllOf/assets/lombok/ApiTestAllOfDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testAllOf/assets/lombok/ApiTestAllOfDTO.java @@ -4,13 +4,15 @@ import java.util.List; import java.util.ArrayList; import lombok.Builder; -import lombok.Data; +import lombok.Value; +import lombok.Singular; import lombok.extern.jackson.Jacksonized; -@Data +@Value public class ApiTestAllOfDTO { @JsonProperty(value ="testers") + @Singular("tester") private List testers; @JsonProperty(value ="testName") diff --git a/multiapi-engine/src/test/resources/openapigenerator/testAllOf/assets/lombok/ApiTestDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testAllOf/assets/lombok/ApiTestDTO.java index 9d9e9e27..4c220189 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testAllOf/assets/lombok/ApiTestDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testAllOf/assets/lombok/ApiTestDTO.java @@ -4,15 +4,17 @@ import java.util.List; import java.util.ArrayList; import lombok.Builder; -import lombok.Data; +import lombok.Value; +import lombok.Singular; import lombok.NonNull; import lombok.extern.jackson.Jacksonized; -@Data +@Value public class ApiTestDTO { @JsonProperty(value ="testers") @NonNull + @Singular("tester") private List testers; @JsonProperty(value ="testName") diff --git a/multiapi-engine/src/test/resources/openapigenerator/testAllOf/assets/lombok/ApiTestInfoDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testAllOf/assets/lombok/ApiTestInfoDTO.java index 740549d2..7d0330c9 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testAllOf/assets/lombok/ApiTestInfoDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testAllOf/assets/lombok/ApiTestInfoDTO.java @@ -4,14 +4,16 @@ import java.util.List; import java.util.ArrayList; import lombok.Builder; -import lombok.Data; +import lombok.Value; +import lombok.Singular; import lombok.NonNull; import lombok.extern.jackson.Jacksonized; -@Data +@Value public class ApiTestInfoDTO { @JsonProperty(value ="testers") + @Singular("tester") private List testers; @JsonProperty(value ="testName") diff --git a/multiapi-engine/src/test/resources/openapigenerator/testAllOf/assets/lombok/ApiTestsDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testAllOf/assets/lombok/ApiTestsDTO.java index cfefde1c..9775510a 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testAllOf/assets/lombok/ApiTestsDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testAllOf/assets/lombok/ApiTestsDTO.java @@ -2,9 +2,9 @@ import com.fasterxml.jackson.annotation.JsonProperty; import lombok.Builder; -import lombok.Data; +import lombok.Value; -@Data +@Value public class ApiTestsDTO { @JsonProperty(value ="apiTestDTO") diff --git a/multiapi-engine/src/test/resources/openapigenerator/testAnyOfInResponse/assets/GameDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testAnyOfInResponse/assets/GameDTO.java index 32208088..93085c93 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testAnyOfInResponse/assets/GameDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testAnyOfInResponse/assets/GameDTO.java @@ -2,11 +2,11 @@ import com.fasterxml.jackson.annotation.JsonProperty; import lombok.Builder; -import lombok.Data; +import lombok.Value; import lombok.NonNull; import lombok.extern.jackson.Jacksonized; -@Data +@Value public class GameDTO { @JsonProperty(value ="name") diff --git a/multiapi-engine/src/test/resources/openapigenerator/testAnyOfInResponse/assets/GameInfoDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testAnyOfInResponse/assets/GameInfoDTO.java index 8eea91f1..02d822c4 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testAnyOfInResponse/assets/GameInfoDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testAnyOfInResponse/assets/GameInfoDTO.java @@ -4,11 +4,12 @@ import java.util.List; import java.util.ArrayList; import lombok.Builder; -import lombok.Data; +import lombok.Value; import lombok.NonNull; +import lombok.Singular; import lombok.extern.jackson.Jacksonized; -@Data +@Value public class GameInfoDTO { @JsonProperty(value ="gameName") @@ -20,7 +21,8 @@ public class GameInfoDTO { private Integer rooms; @JsonProperty(value ="players") - private List players = new ArrayList(); + @Singular("player") + private List players; @Builder diff --git a/multiapi-engine/src/test/resources/openapigenerator/testAnyOfInResponse/assets/InlineResponse200ListGamesAnyOfDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testAnyOfInResponse/assets/InlineResponse200ListGamesAnyOfDTO.java index 0c124cfc..284bdacb 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testAnyOfInResponse/assets/InlineResponse200ListGamesAnyOfDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testAnyOfInResponse/assets/InlineResponse200ListGamesAnyOfDTO.java @@ -5,12 +5,13 @@ import java.util.List; import java.util.ArrayList; import lombok.Builder; -import lombok.Data; +import lombok.Value; import lombok.NonNull; +import lombok.Singular; import lombok.extern.jackson.Jacksonized; import com.sngular.multifileplugin.testanyofinresponse.model.exception.ModelClassException; -@Data +@Value public class InlineResponse200ListGamesAnyOfDTO { @JsonProperty(value ="gameName") @@ -30,7 +31,8 @@ public class InlineResponse200ListGamesAnyOfDTO { private Integer rooms; @JsonProperty(value ="players") - private List players = new ArrayList(); + @Singular("player") + private List players; @Builder diff --git a/multiapi-engine/src/test/resources/openapigenerator/testApiClientGeneration/assets/ApiErrorDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testApiClientGeneration/assets/ApiErrorDTO.java index 5c4482cc..cfa4426d 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testApiClientGeneration/assets/ApiErrorDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testApiClientGeneration/assets/ApiErrorDTO.java @@ -2,11 +2,11 @@ import com.fasterxml.jackson.annotation.JsonProperty; import lombok.Builder; -import lombok.Data; +import lombok.Value; import lombok.NonNull; import lombok.extern.jackson.Jacksonized; -@Data +@Value public class ApiErrorDTO { @JsonProperty(value ="code") diff --git a/multiapi-engine/src/test/resources/openapigenerator/testApiClientGeneration/assets/ApiTestDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testApiClientGeneration/assets/ApiTestDTO.java index eeef519d..4e5913d3 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testApiClientGeneration/assets/ApiTestDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testApiClientGeneration/assets/ApiTestDTO.java @@ -2,11 +2,11 @@ import com.fasterxml.jackson.annotation.JsonProperty; import lombok.Builder; -import lombok.Data; +import lombok.Value; import lombok.NonNull; import lombok.extern.jackson.Jacksonized; -@Data +@Value public class ApiTestDTO { @JsonProperty(value ="name") diff --git a/multiapi-engine/src/test/resources/openapigenerator/testApiClientGeneration/assets/ApiTestInfoDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testApiClientGeneration/assets/ApiTestInfoDTO.java index e2cb107e..1776ca56 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testApiClientGeneration/assets/ApiTestInfoDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testApiClientGeneration/assets/ApiTestInfoDTO.java @@ -4,11 +4,11 @@ import java.util.List; import java.util.ArrayList; import lombok.Builder; -import lombok.Data; +import lombok.Value; import lombok.NonNull; import lombok.extern.jackson.Jacksonized; -@Data +@Value public class ApiTestInfoDTO { @JsonProperty(value ="testers") diff --git a/multiapi-engine/src/test/resources/openapigenerator/testApiEnumsGeneration/assets/ApiTestDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testApiEnumsGeneration/assets/ApiTestDTO.java index aee06fb5..bcd8e6f6 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testApiEnumsGeneration/assets/ApiTestDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testApiEnumsGeneration/assets/ApiTestDTO.java @@ -91,16 +91,6 @@ public String toString() { } } - private ApiTestDTO(UnionEnum unionEnum, String name, Integer id, UnionIntegerEnum unionIntegerEnum, UnionNumberEnum unionNumberEnum) { - this.unionEnum = unionEnum; - this.name = name; - this.id = id; - this.unionIntegerEnum = unionIntegerEnum; - this.unionNumberEnum = unionNumberEnum; - - validateRequiredAttributes(); - } - private ApiTestDTO(ApiTestDTOBuilder builder) { this.unionEnum = builder.unionEnum; this.name = builder.name; diff --git a/multiapi-engine/src/test/resources/openapigenerator/testApiEnumsGeneration/assets/ApiTestInfoDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testApiEnumsGeneration/assets/ApiTestInfoDTO.java index 1b1f3286..a8b86a97 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testApiEnumsGeneration/assets/ApiTestInfoDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testApiEnumsGeneration/assets/ApiTestInfoDTO.java @@ -36,6 +36,7 @@ public static class ApiTestInfoDTOBuilder { private List testers = new ArrayList(); private String testName; + public ApiTestInfoDTO.ApiTestInfoDTOBuilder testers(List testers) { if (!testers.isEmpty()) { this.testers.addAll(testers); diff --git a/multiapi-engine/src/test/resources/openapigenerator/testApiEnumsLombokGeneration/assets/ApiErrorDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testApiEnumsLombokGeneration/assets/ApiErrorDTO.java index c50f5348..fbcd779f 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testApiEnumsLombokGeneration/assets/ApiErrorDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testApiEnumsLombokGeneration/assets/ApiErrorDTO.java @@ -2,11 +2,11 @@ import com.fasterxml.jackson.annotation.JsonProperty; import lombok.Builder; -import lombok.Data; +import lombok.Value; import lombok.NonNull; import lombok.extern.jackson.Jacksonized; -@Data +@Value public class ApiErrorDTO { @JsonProperty(value ="code") diff --git a/multiapi-engine/src/test/resources/openapigenerator/testApiEnumsLombokGeneration/assets/ApiTestDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testApiEnumsLombokGeneration/assets/ApiTestDTO.java index 8a8fe833..6fb67359 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testApiEnumsLombokGeneration/assets/ApiTestDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testApiEnumsLombokGeneration/assets/ApiTestDTO.java @@ -4,11 +4,11 @@ import com.fasterxml.jackson.annotation.JsonValue; import java.math.BigDecimal; import lombok.Builder; -import lombok.Data; +import lombok.Value; import lombok.NonNull; import lombok.extern.jackson.Jacksonized; -@Data +@Value public class ApiTestDTO { @JsonProperty(value ="unionEnum") diff --git a/multiapi-engine/src/test/resources/openapigenerator/testApiEnumsLombokGeneration/assets/ApiTestInfoDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testApiEnumsLombokGeneration/assets/ApiTestInfoDTO.java index f7d8606f..eebef7ad 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testApiEnumsLombokGeneration/assets/ApiTestInfoDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testApiEnumsLombokGeneration/assets/ApiTestInfoDTO.java @@ -4,11 +4,11 @@ import java.util.List; import java.util.ArrayList; import lombok.Builder; -import lombok.Data; +import lombok.Value; import lombok.NonNull; import lombok.extern.jackson.Jacksonized; -@Data +@Value public class ApiTestInfoDTO { @JsonProperty(value ="testers") diff --git a/multiapi-engine/src/test/resources/openapigenerator/testApiParametersWithContentGeneration/assets/ApiTestInfoDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testApiParametersWithContentGeneration/assets/ApiTestInfoDTO.java index 38bbbfb2..05edc58b 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testApiParametersWithContentGeneration/assets/ApiTestInfoDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testApiParametersWithContentGeneration/assets/ApiTestInfoDTO.java @@ -43,6 +43,7 @@ public static class ApiTestInfoDTOBuilder { private List testers = new ArrayList(); private String testName; + public ApiTestInfoDTO.ApiTestInfoDTOBuilder testers(List testers) { if (!testers.isEmpty()) { this.testers.addAll(testers); diff --git a/multiapi-engine/src/test/resources/openapigenerator/testApiPathWithSpecialCharGeneration/assets/ApiTestInfoDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testApiPathWithSpecialCharGeneration/assets/ApiTestInfoDTO.java index d69c7433..99e7093d 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testApiPathWithSpecialCharGeneration/assets/ApiTestInfoDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testApiPathWithSpecialCharGeneration/assets/ApiTestInfoDTO.java @@ -36,6 +36,7 @@ public static class ApiTestInfoDTOBuilder { private List testers = new ArrayList(); private String testName; + public ApiTestInfoDTO.ApiTestInfoDTOBuilder testers(List testers) { if (!testers.isEmpty()) { this.testers.addAll(testers); diff --git a/multiapi-engine/src/test/resources/openapigenerator/testApiReactiveGeneration/assets/ApiTestInfoDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testApiReactiveGeneration/assets/ApiTestInfoDTO.java index 1396ceab..60fd9aea 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testApiReactiveGeneration/assets/ApiTestInfoDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testApiReactiveGeneration/assets/ApiTestInfoDTO.java @@ -36,6 +36,7 @@ public static class ApiTestInfoDTOBuilder { private List testers = new ArrayList(); private String testName; + public ApiTestInfoDTO.ApiTestInfoDTOBuilder testers(List testers) { if (!testers.isEmpty()) { this.testers.addAll(testers); diff --git a/multiapi-engine/src/test/resources/openapigenerator/testCoconutSchema/assets/model/ArrayFieldDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testCoconutSchema/assets/model/ArrayFieldDTO.java index e232520c..b2f5b0f9 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testCoconutSchema/assets/model/ArrayFieldDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testCoconutSchema/assets/model/ArrayFieldDTO.java @@ -4,10 +4,10 @@ import java.util.List; import java.util.ArrayList; import lombok.Builder; -import lombok.Data; +import lombok.Value; import lombok.extern.jackson.Jacksonized; -@Data +@Value public class ArrayFieldDTO { @JsonProperty(value ="uniqueItems") @@ -17,7 +17,8 @@ public class ArrayFieldDTO { private String type; @JsonProperty(value ="defaultValues") - private List defaultValues = new ArrayList(); + @Singular("defaultValue") + private List defaultValues; @JsonProperty(value ="name") private String name; @@ -32,7 +33,8 @@ public class ArrayFieldDTO { private Integer minItems; @JsonProperty(value ="values") - private List values = new ArrayList(); + @Singular("value") + private List values; @Builder diff --git a/multiapi-engine/src/test/resources/openapigenerator/testCoconutSchema/assets/model/BooleanFieldDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testCoconutSchema/assets/model/BooleanFieldDTO.java index 7ec8af36..ac2e6780 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testCoconutSchema/assets/model/BooleanFieldDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testCoconutSchema/assets/model/BooleanFieldDTO.java @@ -2,10 +2,10 @@ import com.fasterxml.jackson.annotation.JsonProperty; import lombok.Builder; -import lombok.Data; +import lombok.Value; import lombok.extern.jackson.Jacksonized; -@Data +@Value public class BooleanFieldDTO { @JsonProperty(value ="type") diff --git a/multiapi-engine/src/test/resources/openapigenerator/testCoconutSchema/assets/model/DateFieldDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testCoconutSchema/assets/model/DateFieldDTO.java index 07c7dbd5..115602e7 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testCoconutSchema/assets/model/DateFieldDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testCoconutSchema/assets/model/DateFieldDTO.java @@ -2,10 +2,10 @@ import com.fasterxml.jackson.annotation.JsonProperty; import lombok.Builder; -import lombok.Data; +import lombok.Value; import lombok.extern.jackson.Jacksonized; -@Data +@Value public class DateFieldDTO { @JsonProperty(value ="type") diff --git a/multiapi-engine/src/test/resources/openapigenerator/testCoconutSchema/assets/model/EnumFieldDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testCoconutSchema/assets/model/EnumFieldDTO.java index fd8e6b8c..d4e722a1 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testCoconutSchema/assets/model/EnumFieldDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testCoconutSchema/assets/model/EnumFieldDTO.java @@ -4,20 +4,22 @@ import java.util.List; import java.util.ArrayList; import lombok.Builder; -import lombok.Data; +import lombok.Value; import lombok.extern.jackson.Jacksonized; -@Data +@Value public class EnumFieldDTO { @JsonProperty(value ="enumValues") - private List enumValues = new ArrayList(); + @Singular("enumValue") + private List enumValues; @JsonProperty(value ="type") private String type; @JsonProperty(value ="defaultValues") - private List defaultValues = new ArrayList(); + @Singular("defaultValue") + private List defaultValues; @JsonProperty(value ="name") private String name; diff --git a/multiapi-engine/src/test/resources/openapigenerator/testCoconutSchema/assets/model/FieldDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testCoconutSchema/assets/model/FieldDTO.java index 86699752..3ecac5d8 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testCoconutSchema/assets/model/FieldDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testCoconutSchema/assets/model/FieldDTO.java @@ -6,18 +6,19 @@ import java.util.List; import java.util.ArrayList; import lombok.Builder; -import lombok.Data; +import lombok.Value; import lombok.extern.jackson.Jacksonized; import com.sngular.multifileplugin.testCoconutSchema.model.exception.ModelClassException; -@Data +@Value public class FieldDTO { @JsonProperty(value ="precision") private Integer precision; @JsonProperty(value ="defaultItem") - private List defaultItem = new ArrayList(); + @Singular("defaultItem") + private List defaultItem); @JsonProperty(value ="maximum") private Integer maximum; @@ -38,7 +39,8 @@ public class FieldDTO { private String keyType; @JsonProperty(value ="requiredValues") - private List requiredValues = new ArrayList(); + @Singular("requiredValue") + private List requiredValues; @JsonProperty(value ="optionalUnion") private Boolean optionalUnion; @@ -56,13 +58,16 @@ public class FieldDTO { private Boolean defaultValue; @JsonProperty(value ="enumValues") - private List enumValues = new ArrayList(); + @Singular("enumValue") + private List enumValues; @JsonProperty(value ="properties") - private List properties = new ArrayList(); + @Singular("property") + private List properties; @JsonProperty(value ="defaultValues") - private List defaultValues = new ArrayList(); + @Singular("defaultValue") + private List defaultValues; @JsonProperty(value ="unionEnum") private UnionEnum unionEnum; @@ -127,7 +132,8 @@ public String toString() { private Integer mapSize; @JsonProperty(value ="mapTypes") - private List mapTypes = new ArrayList(); + @Singular("mapType") + private List mapTypes; @JsonProperty(value ="format") private String format; @@ -154,7 +160,8 @@ public String toString() { private Integer minItems; @JsonProperty(value ="values") - private List values = new ArrayList(); + @Singular("value") + private List values; @JsonProperty(value ="minimum") private Integer minimum; diff --git a/multiapi-engine/src/test/resources/openapigenerator/testCoconutSchema/assets/model/MapFieldDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testCoconutSchema/assets/model/MapFieldDTO.java index 1bfd9444..5f5303f1 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testCoconutSchema/assets/model/MapFieldDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testCoconutSchema/assets/model/MapFieldDTO.java @@ -4,10 +4,10 @@ import java.util.List; import java.util.ArrayList; import lombok.Builder; -import lombok.Data; +import lombok.Value; import lombok.extern.jackson.Jacksonized; -@Data +@Value public class MapFieldDTO { @JsonProperty(value ="keyType") @@ -17,7 +17,8 @@ public class MapFieldDTO { private String type; @JsonProperty(value ="defaultValues") - private List defaultValues = new ArrayList(); + @Singular("defaultValue") + private List defaultValues; @JsonProperty(value ="name") private String name; @@ -26,7 +27,8 @@ public class MapFieldDTO { private Integer mapSize; @JsonProperty(value ="mapTypes") - private List mapTypes = new ArrayList(); + @Singular("mapType") + private List mapTypes; @Builder diff --git a/multiapi-engine/src/test/resources/openapigenerator/testCoconutSchema/assets/model/NumberFieldDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testCoconutSchema/assets/model/NumberFieldDTO.java index 40e475ef..1d33d3b3 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testCoconutSchema/assets/model/NumberFieldDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testCoconutSchema/assets/model/NumberFieldDTO.java @@ -5,10 +5,10 @@ import java.util.List; import java.util.ArrayList; import lombok.Builder; -import lombok.Data; +import lombok.Value; import lombok.extern.jackson.Jacksonized; -@Data +@Value public class NumberFieldDTO { @JsonProperty(value ="precision") @@ -21,7 +21,8 @@ public class NumberFieldDTO { private String type; @JsonProperty(value ="defaultValues") - private List defaultValues = new ArrayList(); + @Singular("defaultValue") + private List defaultValues; @JsonProperty(value ="name") private String name; diff --git a/multiapi-engine/src/test/resources/openapigenerator/testCoconutSchema/assets/model/ObjectFieldDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testCoconutSchema/assets/model/ObjectFieldDTO.java index b4d27251..87bc2596 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testCoconutSchema/assets/model/ObjectFieldDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testCoconutSchema/assets/model/ObjectFieldDTO.java @@ -4,23 +4,26 @@ import java.util.List; import java.util.ArrayList; import lombok.Builder; -import lombok.Data; +import lombok.Value; import lombok.extern.jackson.Jacksonized; -@Data +@Value public class ObjectFieldDTO { @JsonProperty(value ="requiredValues") - private List requiredValues = new ArrayList(); + @Singular("requiredValue") + private List requiredValues; @JsonProperty(value ="type") private String type; @JsonProperty(value ="properties") - private List properties = new ArrayList(); + @Singular("property") + private List properties; @JsonProperty(value ="defaultValues") - private List defaultValues = new ArrayList(); + @Singular("defaultValue") + private List defaultValues; @JsonProperty(value ="name") private String name; diff --git a/multiapi-engine/src/test/resources/openapigenerator/testCoconutSchema/assets/model/SchemaDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testCoconutSchema/assets/model/SchemaDTO.java index b48823f7..18aad1f2 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testCoconutSchema/assets/model/SchemaDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testCoconutSchema/assets/model/SchemaDTO.java @@ -6,11 +6,11 @@ import java.util.Map; import java.util.HashMap; import lombok.Builder; -import lombok.Data; +import lombok.Value; import lombok.NonNull; import lombok.extern.jackson.Jacksonized; -@Data +@Value public class SchemaDTO { @JsonProperty(value ="type") diff --git a/multiapi-engine/src/test/resources/openapigenerator/testCoconutSchema/assets/model/SequenceFieldDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testCoconutSchema/assets/model/SequenceFieldDTO.java index fa7c6bce..6a21ab64 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testCoconutSchema/assets/model/SequenceFieldDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testCoconutSchema/assets/model/SequenceFieldDTO.java @@ -5,10 +5,10 @@ import java.util.List; import java.util.ArrayList; import lombok.Builder; -import lombok.Data; +import lombok.Value; import lombok.extern.jackson.Jacksonized; -@Data +@Value public class SequenceFieldDTO { @JsonProperty(value ="elements") @@ -18,10 +18,12 @@ public class SequenceFieldDTO { private String type; @JsonProperty(value ="properties") - private List properties = new ArrayList(); + @Singular("property") + private List properties; @JsonProperty(value ="defaultValues") - private List defaultValues = new ArrayList(); + @Singular("defaultValue") + private List defaultValues; @JsonProperty(value ="seqEnum") private SeqEnum seqEnum; diff --git a/multiapi-engine/src/test/resources/openapigenerator/testCoconutSchema/assets/model/StringFieldDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testCoconutSchema/assets/model/StringFieldDTO.java index 72a8dd0c..14808885 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testCoconutSchema/assets/model/StringFieldDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testCoconutSchema/assets/model/StringFieldDTO.java @@ -4,10 +4,10 @@ import java.util.List; import java.util.ArrayList; import lombok.Builder; -import lombok.Data; +import lombok.Value; import lombok.extern.jackson.Jacksonized; -@Data +@Value public class StringFieldDTO { @JsonProperty(value ="maxLength") @@ -17,10 +17,12 @@ public class StringFieldDTO { private String type; @JsonProperty(value ="properties") - private List properties = new ArrayList(); + @Singular("property") + private List properties; @JsonProperty(value ="defaultValues") - private List defaultValues = new ArrayList(); + @Singular("defaultValue") + private List defaultValues; @JsonProperty(value ="name") private String name; diff --git a/multiapi-engine/src/test/resources/openapigenerator/testCoconutSchema/assets/model/UnionFieldDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testCoconutSchema/assets/model/UnionFieldDTO.java index 7f5cca10..c4a0d0bf 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testCoconutSchema/assets/model/UnionFieldDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testCoconutSchema/assets/model/UnionFieldDTO.java @@ -5,14 +5,15 @@ import java.util.List; import java.util.ArrayList; import lombok.Builder; -import lombok.Data; +import lombok.Value; import lombok.extern.jackson.Jacksonized; -@Data +@Value public class UnionFieldDTO { @JsonProperty(value ="defaultItem") - private List defaultItem = new ArrayList(); + @Singular("defaultItem") + private List defaultItem; @JsonProperty(value ="generatedFlag") private Boolean generatedFlag; diff --git a/multiapi-engine/src/test/resources/openapigenerator/testComplexAnyOf/assets/ApiArrayFieldDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testComplexAnyOf/assets/ApiArrayFieldDTO.java index 98ca0795..84a90430 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testComplexAnyOf/assets/ApiArrayFieldDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testComplexAnyOf/assets/ApiArrayFieldDTO.java @@ -17,7 +17,8 @@ public class ApiArrayFieldDTO { @JsonProperty(value ="type") private String type; @JsonProperty(value ="defaultValues") - private List defaultValues = new ArrayList(); + @Singular("defaultValue") + private List defaultValues; @JsonProperty(value ="name") private String name; @JsonProperty(value ="arraySize") @@ -27,7 +28,8 @@ public class ApiArrayFieldDTO { @JsonProperty(value ="minItems") private Integer minItems; @JsonProperty(value ="values") - private List values = new ArrayList(); + @Singular("value") + private List values; private ApiArrayFieldDTO(Boolean uniqueItems, String type, List defaultValues, String name, Integer arraySize, String regex, Integer minItems, List values) { this.uniqueItems = uniqueItems; diff --git a/multiapi-engine/src/test/resources/openapigenerator/testComplexAnyOf/assets/ApiDefaultItemDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testComplexAnyOf/assets/ApiDefaultItemDTO.java index 7a188df5..8b1ed1da 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testComplexAnyOf/assets/ApiDefaultItemDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testComplexAnyOf/assets/ApiDefaultItemDTO.java @@ -31,7 +31,7 @@ public class ApiDefaultItemDTO { @JsonProperty(value ="keyType") private String keyType; @JsonProperty(value ="requiredValues") - private List requiredValues = new ArrayList(); + private List requiredValues; @JsonProperty(value ="optionalUnion") private Boolean optionalUnion; @JsonProperty(value ="initialValue") @@ -43,11 +43,11 @@ public class ApiDefaultItemDTO { @JsonProperty(value ="defaultValue") private Boolean defaultValue; @JsonProperty(value ="enumValues") - private List enumValues = new ArrayList(); + private List enumValues; @JsonProperty(value ="properties") - private List properties = new ArrayList(); + private List properties; @JsonProperty(value ="defaultValues") - private List defaultValues = new ArrayList(); + private List defaultValues; @JsonProperty(value ="unionEnum") private UnionEnum unionEnum; public enum UnionEnum { diff --git a/multiapi-engine/src/test/resources/openapigenerator/testComplexAnyOf/assets/ApiEnumFieldDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testComplexAnyOf/assets/ApiEnumFieldDTO.java index 9e233bb2..7bbf3ad8 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testComplexAnyOf/assets/ApiEnumFieldDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testComplexAnyOf/assets/ApiEnumFieldDTO.java @@ -13,11 +13,13 @@ public class ApiEnumFieldDTO { @JsonProperty(value ="enumValues") - private List enumValues = new ArrayList(); + @Singular("enumValue") + private List enumValues; @JsonProperty(value ="type") private String type; @JsonProperty(value ="defaultValues") - private List defaultValues = new ArrayList(); + @Singular("defaultValue") + private List defaultValues; @JsonProperty(value ="name") private String name; @JsonProperty(value ="defaultValue") diff --git a/multiapi-engine/src/test/resources/openapigenerator/testComplexAnyOf/assets/ApiMapFieldDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testComplexAnyOf/assets/ApiMapFieldDTO.java index 3938168c..95504464 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testComplexAnyOf/assets/ApiMapFieldDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testComplexAnyOf/assets/ApiMapFieldDTO.java @@ -17,13 +17,15 @@ public class ApiMapFieldDTO { @JsonProperty(value ="type") private String type; @JsonProperty(value ="defaultValues") - private List defaultValues = new ArrayList(); + @Singular("defaultValue") + private List defaultValues; @JsonProperty(value ="name") private String name; @JsonProperty(value ="mapSize") private Integer mapSize; @JsonProperty(value ="mapTypes") - private List mapTypes = new ArrayList(); + @Singular("mapType") + private List mapTypes; private ApiMapFieldDTO(String keyType, String type, List defaultValues, String name, Integer mapSize, List mapTypes) { this.keyType = keyType; diff --git a/multiapi-engine/src/test/resources/openapigenerator/testComplexAnyOf/assets/ApiNumberFieldDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testComplexAnyOf/assets/ApiNumberFieldDTO.java index 87a037e1..7c0dbf74 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testComplexAnyOf/assets/ApiNumberFieldDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testComplexAnyOf/assets/ApiNumberFieldDTO.java @@ -20,7 +20,8 @@ public class ApiNumberFieldDTO { @JsonProperty(value ="type") private String type; @JsonProperty(value ="defaultValues") - private List defaultValues = new ArrayList(); + @Singular("defaultValue") + private List defaultValues; @JsonProperty(value ="name") private String name; @JsonProperty(value ="multipleOf") diff --git a/multiapi-engine/src/test/resources/openapigenerator/testComplexAnyOf/assets/ApiObjectFieldDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testComplexAnyOf/assets/ApiObjectFieldDTO.java index da0632d9..065a2c77 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testComplexAnyOf/assets/ApiObjectFieldDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testComplexAnyOf/assets/ApiObjectFieldDTO.java @@ -13,13 +13,13 @@ public class ApiObjectFieldDTO { @JsonProperty(value ="requiredValues") - private List requiredValues = new ArrayList(); + private List requiredValues; @JsonProperty(value ="type") private String type; @JsonProperty(value ="properties") - private List properties = new ArrayList(); + private List properties; @JsonProperty(value ="defaultValues") - private List defaultValues = new ArrayList(); + private List defaultValues; @JsonProperty(value ="name") private String name; diff --git a/multiapi-engine/src/test/resources/openapigenerator/testComplexAnyOf/assets/ApiSchemaDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testComplexAnyOf/assets/ApiSchemaDTO.java index 97604c7d..ab0cbb64 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testComplexAnyOf/assets/ApiSchemaDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testComplexAnyOf/assets/ApiSchemaDTO.java @@ -31,7 +31,7 @@ public class ApiSchemaDTO { @NotNull private final String subjectName; @JsonProperty(value ="requiredFields") - private List requiredFields = new ArrayList(); + private List requiredFields; private ApiSchemaDTO(String type, List properties, String name, String id, String subjectName, List requiredFields) { this.type = type; diff --git a/multiapi-engine/src/test/resources/openapigenerator/testComplexAnyOf/assets/ApiSequenceFieldDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testComplexAnyOf/assets/ApiSequenceFieldDTO.java index 09173de9..161cb776 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testComplexAnyOf/assets/ApiSequenceFieldDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testComplexAnyOf/assets/ApiSequenceFieldDTO.java @@ -18,9 +18,9 @@ public class ApiSequenceFieldDTO { @JsonProperty(value ="type") private String type; @JsonProperty(value ="properties") - private List properties = new ArrayList(); + private List properties; @JsonProperty(value ="defaultValues") - private List defaultValues = new ArrayList(); + private List defaultValues; @JsonProperty(value ="seqEnum") private SeqEnum seqEnum; public enum SeqEnum { diff --git a/multiapi-engine/src/test/resources/openapigenerator/testComplexAnyOf/assets/ApiStringFieldDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testComplexAnyOf/assets/ApiStringFieldDTO.java index c38cb79f..c5547b57 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testComplexAnyOf/assets/ApiStringFieldDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testComplexAnyOf/assets/ApiStringFieldDTO.java @@ -17,9 +17,9 @@ public class ApiStringFieldDTO { @JsonProperty(value ="type") private String type; @JsonProperty(value ="properties") - private List properties = new ArrayList(); + private List properties; @JsonProperty(value ="defaultValues") - private List defaultValues = new ArrayList(); + private List defaultValues; @JsonProperty(value ="name") private String name; @JsonProperty(value ="regex") diff --git a/multiapi-engine/src/test/resources/openapigenerator/testComplexAnyOf/assets/ApiTypeArrayDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testComplexAnyOf/assets/ApiTypeArrayDTO.java index 0868564e..288ff72d 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testComplexAnyOf/assets/ApiTypeArrayDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testComplexAnyOf/assets/ApiTypeArrayDTO.java @@ -31,7 +31,7 @@ public class ApiTypeArrayDTO { @JsonProperty(value ="keyType") private String keyType; @JsonProperty(value ="requiredValues") - private List requiredValues = new ArrayList(); + private List requiredValues; @JsonProperty(value ="optionalUnion") private Boolean optionalUnion; @JsonProperty(value ="initialValue") @@ -43,11 +43,11 @@ public class ApiTypeArrayDTO { @JsonProperty(value ="defaultValue") private Boolean defaultValue; @JsonProperty(value ="enumValues") - private List enumValues = new ArrayList(); + private List enumValues; @JsonProperty(value ="properties") - private List properties = new ArrayList(); + private List properties; @JsonProperty(value ="defaultValues") - private List defaultValues = new ArrayList(); + private List defaultValues; @JsonProperty(value ="unionEnum") private UnionEnum unionEnum; public enum UnionEnum { @@ -104,7 +104,7 @@ public String toString() { @JsonProperty(value ="mapSize") private Integer mapSize; @JsonProperty(value ="mapTypes") - private List mapTypes = new ArrayList(); + private List mapTypes; @JsonProperty(value ="format") private Integer format; @JsonProperty(value ="generatedFlag") @@ -122,7 +122,7 @@ public String toString() { @JsonProperty(value ="minItems") private Integer minItems; @JsonProperty(value ="values") - private List values = new ArrayList(); + private List values; @JsonProperty(value ="minimum") private Integer minimum; @JsonProperty(value ="numberEnum") diff --git a/multiapi-engine/src/test/resources/openapigenerator/testCreateBasicDTO/assets/model/AddressDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testCreateBasicDTO/assets/model/AddressDTO.java index 2cdb6a65..e11417bf 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testCreateBasicDTO/assets/model/AddressDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testCreateBasicDTO/assets/model/AddressDTO.java @@ -2,11 +2,11 @@ import com.fasterxml.jackson.annotation.JsonProperty; import lombok.Builder; -import lombok.Data; +import lombok.Value; import lombok.NonNull; import lombok.extern.jackson.Jacksonized; -@Data +@Value public class AddressDTO { @JsonProperty(value ="country") diff --git a/multiapi-engine/src/test/resources/openapigenerator/testCreateBasicDTO/assets/model/TestDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testCreateBasicDTO/assets/model/TestDTO.java index 75f508b0..6f0c0a6b 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testCreateBasicDTO/assets/model/TestDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testCreateBasicDTO/assets/model/TestDTO.java @@ -3,11 +3,11 @@ import com.fasterxml.jackson.annotation.JsonProperty; import java.math.BigDecimal; import lombok.Builder; -import lombok.Data; +import lombok.Value; import lombok.NonNull; import lombok.extern.jackson.Jacksonized; -@Data +@Value public class TestDTO { @JsonProperty(value ="properties") diff --git a/multiapi-engine/src/test/resources/openapigenerator/testCreateDTO/assets/model/AddressDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testCreateDTO/assets/model/AddressDTO.java index 81038463..61db9b9f 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testCreateDTO/assets/model/AddressDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testCreateDTO/assets/model/AddressDTO.java @@ -2,11 +2,11 @@ import com.fasterxml.jackson.annotation.JsonProperty; import lombok.Builder; -import lombok.Data; +import lombok.Value; import lombok.NonNull; import lombok.extern.jackson.Jacksonized; -@Data +@Value public class AddressDTO { @JsonProperty(value ="country") diff --git a/multiapi-engine/src/test/resources/openapigenerator/testCreateDTO/assets/model/PropertiesDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testCreateDTO/assets/model/PropertiesDTO.java index 504691ef..24beca28 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testCreateDTO/assets/model/PropertiesDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testCreateDTO/assets/model/PropertiesDTO.java @@ -2,10 +2,10 @@ import com.fasterxml.jackson.annotation.JsonProperty; import lombok.Builder; -import lombok.Data; +import lombok.Value; import lombok.extern.jackson.Jacksonized; -@Data +@Value public class PropertiesDTO { @JsonProperty(value ="value") diff --git a/multiapi-engine/src/test/resources/openapigenerator/testCreateDTO/assets/model/TestDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testCreateDTO/assets/model/TestDTO.java index 7d2ba93a..2c9c9174 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testCreateDTO/assets/model/TestDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testCreateDTO/assets/model/TestDTO.java @@ -5,15 +5,16 @@ import java.util.ArrayList; import java.math.BigDecimal; import lombok.Builder; -import lombok.Data; +import lombok.Value; import lombok.NonNull; import lombok.extern.jackson.Jacksonized; -@Data +@Value public class TestDTO { @JsonProperty(value ="properties") - private List properties = new ArrayList(); + @Singular("property") + private List properties; @JsonProperty(value ="id") @NonNull diff --git a/multiapi-engine/src/test/resources/openapigenerator/testDateTime/assets/model/TestDateDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testDateTime/assets/model/TestDateDTO.java index b244caec..6f13bb5a 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testDateTime/assets/model/TestDateDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testDateTime/assets/model/TestDateDTO.java @@ -4,10 +4,10 @@ import java.time.LocalDate; import java.time.LocalDateTime; import lombok.Builder; -import lombok.Data; +import lombok.Value; import lombok.extern.jackson.Jacksonized; -@Data +@Value public class TestDateDTO { @JsonProperty(value ="someDate") diff --git a/multiapi-engine/src/test/resources/openapigenerator/testDateTimeOffset/assets/model/TestDateDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testDateTimeOffset/assets/model/TestDateDTO.java index d2e84706..c9b0234c 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testDateTimeOffset/assets/model/TestDateDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testDateTimeOffset/assets/model/TestDateDTO.java @@ -3,10 +3,10 @@ import com.fasterxml.jackson.annotation.JsonProperty; import java.time.OffsetDateTime; import lombok.Builder; -import lombok.Data; +import lombok.Value; import lombok.extern.jackson.Jacksonized; -@Data +@Value public class TestDateDTO { @JsonProperty(value ="someDate") diff --git a/multiapi-engine/src/test/resources/openapigenerator/testDateTimeZoned/assets/model/TestDateDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testDateTimeZoned/assets/model/TestDateDTO.java index 0794f9c4..69208701 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testDateTimeZoned/assets/model/TestDateDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testDateTimeZoned/assets/model/TestDateDTO.java @@ -3,10 +3,10 @@ import com.fasterxml.jackson.annotation.JsonProperty; import java.time.ZonedDateTime; import lombok.Builder; -import lombok.Data; +import lombok.Value; import lombok.extern.jackson.Jacksonized; -@Data +@Value public class TestDateDTO { @JsonProperty(value ="someDate") diff --git a/multiapi-engine/src/test/resources/openapigenerator/testInlineSchemaCreation/assets/ApiTestDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testInlineSchemaCreation/assets/ApiTestDTO.java index 32a0c1a4..d362246b 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testInlineSchemaCreation/assets/ApiTestDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testInlineSchemaCreation/assets/ApiTestDTO.java @@ -17,27 +17,16 @@ public class ApiTestDTO { @JsonProperty(value ="description") private String description; @JsonProperty(value ="tags") - private List tags = new ArrayList(); + private List tags; @JsonProperty(value ="name") private String name; @JsonProperty(value ="testTypeList") - private List testTypeList = new ArrayList(); + private List testTypeList; @JsonProperty(value ="id") private Integer id; @JsonProperty(value ="priority") private Integer priority; - private ApiTestDTO(ApiTestProcessorDTO testProcessor, String description, List tags, String name, List testTypeList, Integer id, Integer priority) { - this.testProcessor = testProcessor; - this.description = description; - this.tags = tags; - this.name = name; - this.testTypeList = testTypeList; - this.id = id; - this.priority = priority; - - } - private ApiTestDTO(ApiTestDTOBuilder builder) { this.testProcessor = builder.testProcessor; this.description = builder.description; @@ -58,9 +47,9 @@ public static class ApiTestDTOBuilder { private ApiTestProcessorDTO testProcessor; private String description; - private List tags = new ArrayList(); + private List tags; private String name; - private List testTypeList = new ArrayList(); + private List testTypeList; private Integer id; private Integer priority; public ApiTestDTO.ApiTestDTOBuilder testProcessor(ApiTestProcessorDTO testProcessor) { diff --git a/multiapi-engine/src/test/resources/openapigenerator/testIssueFaker/assets/model/ConfigurationDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testIssueFaker/assets/model/ConfigurationDTO.java index efebaf9d..66a453bf 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testIssueFaker/assets/model/ConfigurationDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testIssueFaker/assets/model/ConfigurationDTO.java @@ -5,14 +5,16 @@ import java.util.Map; import java.util.HashMap; import lombok.Builder; -import lombok.Data; +import lombok.Value; +import lombok.Singular; import lombok.extern.jackson.Jacksonized; -@Data +@Value public class ConfigurationDTO { @JsonProperty(value ="configuration") - private Map configuration = new HashMap(); + @Singular("_configuration") + private Map configuration; @JsonProperty(value ="numberToGenerate") private Integer numberToGenerate; diff --git a/multiapi-engine/src/test/resources/openapigenerator/testIssueFaker/assets/model/FakerFieldDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testIssueFaker/assets/model/FakerFieldDTO.java index cb5f2bb7..5cbfc2aa 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testIssueFaker/assets/model/FakerFieldDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testIssueFaker/assets/model/FakerFieldDTO.java @@ -2,11 +2,12 @@ import com.fasterxml.jackson.annotation.JsonProperty; import lombok.Builder; -import lombok.Data; +import lombok.Value; +import lombok.Singular; import lombok.NonNull; import lombok.extern.jackson.Jacksonized; -@Data +@Value public class FakerFieldDTO { @JsonProperty(value ="value") diff --git a/multiapi-engine/src/test/resources/openapigenerator/testIssueFaker/assets/model/FakerSchemaDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testIssueFaker/assets/model/FakerSchemaDTO.java index 01bd938a..fef942ad 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testIssueFaker/assets/model/FakerSchemaDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testIssueFaker/assets/model/FakerSchemaDTO.java @@ -4,18 +4,20 @@ import java.util.List; import java.util.ArrayList; import lombok.Builder; -import lombok.Data; +import lombok.Value; +import lombok.Singular; import lombok.NonNull; import lombok.extern.jackson.Jacksonized; -@Data +@Value public class FakerSchemaDTO { @JsonProperty(value ="type") private String type; @JsonProperty(value ="properties") - private List properties = new ArrayList(); + @Singular("property") + private List properties; @JsonProperty(value ="name") @NonNull @@ -25,14 +27,16 @@ public class FakerSchemaDTO { private String id; @JsonProperty(value ="definitions") - private List definitions = new ArrayList(); + @Singular("definition") + private List definitions; @JsonProperty(value ="subjectName") @NonNull private String subjectName; @JsonProperty(value ="requiredFields") - private List requiredFields = new ArrayList(); + @Singular("requiredField") + private List requiredFields; @JsonProperty(value ="original") private Boolean original; diff --git a/multiapi-engine/src/test/resources/openapigenerator/testIssueFaker/assets/model/FieldDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testIssueFaker/assets/model/FieldDTO.java index da30d8d8..78ae82b1 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testIssueFaker/assets/model/FieldDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testIssueFaker/assets/model/FieldDTO.java @@ -2,11 +2,12 @@ import com.fasterxml.jackson.annotation.JsonProperty; import lombok.Builder; -import lombok.Data; +import lombok.Value; +import lombok.Singular; import lombok.NonNull; import lombok.extern.jackson.Jacksonized; -@Data +@Value public class FieldDTO { @JsonProperty(value ="type") diff --git a/multiapi-engine/src/test/resources/openapigenerator/testIssueFaker/assets/model/SchemaDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testIssueFaker/assets/model/SchemaDTO.java index 60a22eed..8cad9671 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testIssueFaker/assets/model/SchemaDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testIssueFaker/assets/model/SchemaDTO.java @@ -4,18 +4,20 @@ import java.util.List; import java.util.ArrayList; import lombok.Builder; -import lombok.Data; +import lombok.Value; +import lombok.Singular; import lombok.NonNull; import lombok.extern.jackson.Jacksonized; -@Data +@Value public class SchemaDTO { @JsonProperty(value ="type") private String type; @JsonProperty(value ="properties") - private List properties = new ArrayList(); + @Singular("property") + private List properties; @JsonProperty(value ="name") @NonNull @@ -25,14 +27,16 @@ public class SchemaDTO { private String id; @JsonProperty(value ="definitions") - private List definitions = new ArrayList(); + @Singular("definition") + private List definitions; @JsonProperty(value ="subjectName") @NonNull private String subjectName; @JsonProperty(value ="requiredFields") - private List requiredFields = new ArrayList(); + @Singular("requiredField") + private List requiredFields; @JsonProperty(value ="original") private Boolean original; diff --git a/multiapi-engine/src/test/resources/openapigenerator/testOneOfInResponse/assets/GameDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testOneOfInResponse/assets/GameDTO.java index 6073b507..8d537c9e 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testOneOfInResponse/assets/GameDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testOneOfInResponse/assets/GameDTO.java @@ -2,11 +2,11 @@ import com.fasterxml.jackson.annotation.JsonProperty; import lombok.Builder; -import lombok.Data; +import lombok.Value; import lombok.NonNull; import lombok.extern.jackson.Jacksonized; -@Data +@Value public class GameDTO { @JsonProperty(value ="name") diff --git a/multiapi-engine/src/test/resources/openapigenerator/testOneOfInResponse/assets/GameInfoDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testOneOfInResponse/assets/GameInfoDTO.java index 4c118970..3214039b 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testOneOfInResponse/assets/GameInfoDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testOneOfInResponse/assets/GameInfoDTO.java @@ -4,11 +4,11 @@ import java.util.List; import java.util.ArrayList; import lombok.Builder; -import lombok.Data; +import lombok.Value; import lombok.NonNull; import lombok.extern.jackson.Jacksonized; -@Data +@Value public class GameInfoDTO { @JsonProperty(value ="gameName") diff --git a/multiapi-engine/src/test/resources/openapigenerator/testOneOfInResponse/assets/InlineResponse200ListGamesOneOfDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testOneOfInResponse/assets/InlineResponse200ListGamesOneOfDTO.java index 04051571..27592392 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testOneOfInResponse/assets/InlineResponse200ListGamesOneOfDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testOneOfInResponse/assets/InlineResponse200ListGamesOneOfDTO.java @@ -5,12 +5,12 @@ import java.util.List; import java.util.ArrayList; import lombok.Builder; -import lombok.Data; +import lombok.Value; import lombok.NonNull; import lombok.extern.jackson.Jacksonized; import com.sngular.multifileplugin.testoneofinresponse.model.exception.ModelClassException; -@Data +@Value public class InlineResponse200ListGamesOneOfDTO { @JsonProperty(value ="gameName") diff --git a/multiapi-engine/src/test/resources/openapigenerator/testOverWriteModelTrue/assets/ApiTestInfoDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testOverWriteModelTrue/assets/ApiTestInfoDTO.java index d5257e83..f6182fff 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testOverWriteModelTrue/assets/ApiTestInfoDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testOverWriteModelTrue/assets/ApiTestInfoDTO.java @@ -36,6 +36,7 @@ public static class ApiTestInfoDTOBuilder { private List testers = new ArrayList(); private String testName; + public ApiTestInfoDTO.ApiTestInfoDTOBuilder testers(List testers) { if (!testers.isEmpty()) { this.testers.addAll(testers); diff --git a/multiapi-engine/src/test/resources/openapigenerator/testReferenceFile/assets/TestDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testReferenceFile/assets/TestDTO.java index 4e285af7..b70b4a63 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testReferenceFile/assets/TestDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testReferenceFile/assets/TestDTO.java @@ -2,10 +2,10 @@ import com.fasterxml.jackson.annotation.JsonProperty; import lombok.Builder; -import lombok.Data; +import lombok.Value; import lombok.extern.jackson.Jacksonized; -@Data +@Value public class TestDTO { @JsonProperty(value ="something") diff --git a/multiapi-engine/src/test/resources/openapigenerator/testRestClientApiGeneration/assets/ApiTestInfoDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testRestClientApiGeneration/assets/ApiTestInfoDTO.java index c2f14d4d..aabce1ec 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testRestClientApiGeneration/assets/ApiTestInfoDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testRestClientApiGeneration/assets/ApiTestInfoDTO.java @@ -37,6 +37,7 @@ public static class ApiTestInfoDTOBuilder { private List testers = new ArrayList(); private String testName; + public ApiTestInfoDTO.ApiTestInfoDTOBuilder testers(List testers) { if (!testers.isEmpty()) { this.testers.addAll(testers); diff --git a/multiapi-engine/src/test/resources/openapigenerator/testRestrictionsSchema/assets/model/ArrayFieldDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testRestrictionsSchema/assets/model/ArrayFieldDTO.java index 87dd58a7..be71bcf2 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testRestrictionsSchema/assets/model/ArrayFieldDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testRestrictionsSchema/assets/model/ArrayFieldDTO.java @@ -4,10 +4,10 @@ import java.util.List; import java.util.ArrayList; import lombok.Builder; -import lombok.Data; +import lombok.Value; import lombok.extern.jackson.Jacksonized; -@Data +@Value public class ArrayFieldDTO { @JsonProperty(value ="mandatory") diff --git a/multiapi-engine/src/test/resources/openapigenerator/testRestrictionsSchema/assets/model/BooleanFieldDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testRestrictionsSchema/assets/model/BooleanFieldDTO.java index b90e0d6a..466604f1 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testRestrictionsSchema/assets/model/BooleanFieldDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testRestrictionsSchema/assets/model/BooleanFieldDTO.java @@ -2,10 +2,10 @@ import com.fasterxml.jackson.annotation.JsonProperty; import lombok.Builder; -import lombok.Data; +import lombok.Value; import lombok.extern.jackson.Jacksonized; -@Data +@Value public class BooleanFieldDTO { @JsonProperty(value ="mandatory") diff --git a/multiapi-engine/src/test/resources/openapigenerator/testRestrictionsSchema/assets/model/DateFieldDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testRestrictionsSchema/assets/model/DateFieldDTO.java index feae2e9a..0f5797a8 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testRestrictionsSchema/assets/model/DateFieldDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testRestrictionsSchema/assets/model/DateFieldDTO.java @@ -2,10 +2,10 @@ import com.fasterxml.jackson.annotation.JsonProperty; import lombok.Builder; -import lombok.Data; +import lombok.Value; import lombok.extern.jackson.Jacksonized; -@Data +@Value public class DateFieldDTO { @JsonProperty(value ="mandatory") diff --git a/multiapi-engine/src/test/resources/openapigenerator/testRestrictionsSchema/assets/model/EnumFieldDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testRestrictionsSchema/assets/model/EnumFieldDTO.java index 677520e4..c68f5bf6 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testRestrictionsSchema/assets/model/EnumFieldDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testRestrictionsSchema/assets/model/EnumFieldDTO.java @@ -4,10 +4,10 @@ import java.util.List; import java.util.ArrayList; import lombok.Builder; -import lombok.Data; +import lombok.Value; import lombok.extern.jackson.Jacksonized; -@Data +@Value public class EnumFieldDTO { @JsonProperty(value ="mandatory") diff --git a/multiapi-engine/src/test/resources/openapigenerator/testRestrictionsSchema/assets/model/FieldDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testRestrictionsSchema/assets/model/FieldDTO.java index 42117e85..31137467 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testRestrictionsSchema/assets/model/FieldDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testRestrictionsSchema/assets/model/FieldDTO.java @@ -3,10 +3,10 @@ import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonValue; import lombok.Builder; -import lombok.Data; +import lombok.Value; import lombok.extern.jackson.Jacksonized; -@Data +@Value public class FieldDTO { @JsonProperty(value ="typeField") diff --git a/multiapi-engine/src/test/resources/openapigenerator/testRestrictionsSchema/assets/model/FieldValueDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testRestrictionsSchema/assets/model/FieldValueDTO.java index b8ace51c..391ae8ee 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testRestrictionsSchema/assets/model/FieldValueDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testRestrictionsSchema/assets/model/FieldValueDTO.java @@ -6,11 +6,11 @@ import java.util.List; import java.util.ArrayList; import lombok.Builder; -import lombok.Data; +import lombok.Value; import lombok.extern.jackson.Jacksonized; import com.sngular.multifileplugin.testRestrictionsSchema.model.exception.ModelClassException; -@Data +@Value public class FieldValueDTO { @JsonProperty(value ="mandatory") diff --git a/multiapi-engine/src/test/resources/openapigenerator/testRestrictionsSchema/assets/model/MapFieldDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testRestrictionsSchema/assets/model/MapFieldDTO.java index 6f73023c..8d76cd6c 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testRestrictionsSchema/assets/model/MapFieldDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testRestrictionsSchema/assets/model/MapFieldDTO.java @@ -4,10 +4,10 @@ import java.util.List; import java.util.ArrayList; import lombok.Builder; -import lombok.Data; +import lombok.Value; import lombok.extern.jackson.Jacksonized; -@Data +@Value public class MapFieldDTO { @JsonProperty(value ="mandatory") diff --git a/multiapi-engine/src/test/resources/openapigenerator/testRestrictionsSchema/assets/model/NumberFieldDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testRestrictionsSchema/assets/model/NumberFieldDTO.java index 586cbaca..f394b8cb 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testRestrictionsSchema/assets/model/NumberFieldDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testRestrictionsSchema/assets/model/NumberFieldDTO.java @@ -3,10 +3,10 @@ import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonValue; import lombok.Builder; -import lombok.Data; +import lombok.Value; import lombok.extern.jackson.Jacksonized; -@Data +@Value public class NumberFieldDTO { @JsonProperty(value ="mandatory") diff --git a/multiapi-engine/src/test/resources/openapigenerator/testRestrictionsSchema/assets/model/ObjectFieldDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testRestrictionsSchema/assets/model/ObjectFieldDTO.java index 790cb2d9..8e1c3193 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testRestrictionsSchema/assets/model/ObjectFieldDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testRestrictionsSchema/assets/model/ObjectFieldDTO.java @@ -4,10 +4,10 @@ import java.util.List; import java.util.ArrayList; import lombok.Builder; -import lombok.Data; +import lombok.Value; import lombok.extern.jackson.Jacksonized; -@Data +@Value public class ObjectFieldDTO { @JsonProperty(value ="mandatory") diff --git a/multiapi-engine/src/test/resources/openapigenerator/testRestrictionsSchema/assets/model/SchemaDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testRestrictionsSchema/assets/model/SchemaDTO.java index f2dbcc7a..253b0bc0 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testRestrictionsSchema/assets/model/SchemaDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testRestrictionsSchema/assets/model/SchemaDTO.java @@ -4,11 +4,11 @@ import java.util.List; import java.util.ArrayList; import lombok.Builder; -import lombok.Data; +import lombok.Value; import lombok.NonNull; import lombok.extern.jackson.Jacksonized; -@Data +@Value public class SchemaDTO { @JsonProperty(value ="properties") diff --git a/multiapi-engine/src/test/resources/openapigenerator/testRestrictionsSchema/assets/model/SequenceFieldDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testRestrictionsSchema/assets/model/SequenceFieldDTO.java index 3deff992..21d6f614 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testRestrictionsSchema/assets/model/SequenceFieldDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testRestrictionsSchema/assets/model/SequenceFieldDTO.java @@ -3,10 +3,10 @@ import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonValue; import lombok.Builder; -import lombok.Data; +import lombok.Value; import lombok.extern.jackson.Jacksonized; -@Data +@Value public class SequenceFieldDTO { @JsonProperty(value ="mandatory") diff --git a/multiapi-engine/src/test/resources/openapigenerator/testRestrictionsSchema/assets/model/StringFieldDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testRestrictionsSchema/assets/model/StringFieldDTO.java index d7cfc435..488eb241 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testRestrictionsSchema/assets/model/StringFieldDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testRestrictionsSchema/assets/model/StringFieldDTO.java @@ -4,10 +4,10 @@ import java.util.List; import java.util.ArrayList; import lombok.Builder; -import lombok.Data; +import lombok.Value; import lombok.extern.jackson.Jacksonized; -@Data +@Value public class StringFieldDTO { @JsonProperty(value ="mandatory") diff --git a/multiapi-engine/src/test/resources/openapigenerator/testRestrictionsSchema/assets/model/UUIDFieldDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testRestrictionsSchema/assets/model/UUIDFieldDTO.java index 64273dfa..81620534 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testRestrictionsSchema/assets/model/UUIDFieldDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testRestrictionsSchema/assets/model/UUIDFieldDTO.java @@ -2,10 +2,10 @@ import com.fasterxml.jackson.annotation.JsonProperty; import lombok.Builder; -import lombok.Data; +import lombok.Value; import lombok.extern.jackson.Jacksonized; -@Data +@Value public class UUIDFieldDTO { @JsonProperty(value ="mandatory") diff --git a/multiapi-engine/src/test/resources/openapigenerator/testRestrictionsSchema/assets/model/UnionFieldDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testRestrictionsSchema/assets/model/UnionFieldDTO.java index b127d733..f6dc1427 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testRestrictionsSchema/assets/model/UnionFieldDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testRestrictionsSchema/assets/model/UnionFieldDTO.java @@ -5,10 +5,10 @@ import java.util.List; import java.util.ArrayList; import lombok.Builder; -import lombok.Data; +import lombok.Value; import lombok.extern.jackson.Jacksonized; -@Data +@Value public class UnionFieldDTO { @JsonProperty(value ="mandatory") diff --git a/multiapi-engine/src/test/resources/openapigenerator/testSimpleBuild/assets/model/ActivatePolicyDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testSimpleBuild/assets/model/ActivatePolicyDTO.java index 87ac7eec..0b4c7760 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testSimpleBuild/assets/model/ActivatePolicyDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testSimpleBuild/assets/model/ActivatePolicyDTO.java @@ -2,10 +2,10 @@ import com.fasterxml.jackson.annotation.JsonProperty; import lombok.Builder; -import lombok.Data; +import lombok.Value; import lombok.extern.jackson.Jacksonized; -@Data +@Value public class ActivatePolicyDTO { @JsonProperty(value ="provider") diff --git a/multiapi-engine/src/test/resources/openapigenerator/testSimpleBuild/assets/model/AddressDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testSimpleBuild/assets/model/AddressDTO.java index b6b4473c..ed660509 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testSimpleBuild/assets/model/AddressDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testSimpleBuild/assets/model/AddressDTO.java @@ -2,10 +2,10 @@ import com.fasterxml.jackson.annotation.JsonProperty; import lombok.Builder; -import lombok.Data; +import lombok.Value; import lombok.extern.jackson.Jacksonized; -@Data +@Value public class AddressDTO { @JsonProperty(value ="country") diff --git a/multiapi-engine/src/test/resources/openapigenerator/testSimpleBuild/assets/model/CompanyDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testSimpleBuild/assets/model/CompanyDTO.java index 3df90876..76fc31bf 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testSimpleBuild/assets/model/CompanyDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testSimpleBuild/assets/model/CompanyDTO.java @@ -2,10 +2,10 @@ import com.fasterxml.jackson.annotation.JsonProperty; import lombok.Builder; -import lombok.Data; +import lombok.Value; import lombok.extern.jackson.Jacksonized; -@Data +@Value public class CompanyDTO { @JsonProperty(value ="fiscalAddress") diff --git a/multiapi-engine/src/test/resources/openapigenerator/testSimpleBuild/assets/model/ContactDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testSimpleBuild/assets/model/ContactDTO.java index babcdd36..ee570819 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testSimpleBuild/assets/model/ContactDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testSimpleBuild/assets/model/ContactDTO.java @@ -2,11 +2,11 @@ import com.fasterxml.jackson.annotation.JsonProperty; import lombok.Builder; -import lombok.Data; +import lombok.Value; import lombok.NonNull; import lombok.extern.jackson.Jacksonized; -@Data +@Value public class ContactDTO { @JsonProperty(value ="email") diff --git a/multiapi-engine/src/test/resources/openapigenerator/testSimpleBuild/assets/model/CreditLimitDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testSimpleBuild/assets/model/CreditLimitDTO.java index 3bb0204b..e027d4ff 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testSimpleBuild/assets/model/CreditLimitDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testSimpleBuild/assets/model/CreditLimitDTO.java @@ -2,10 +2,10 @@ import com.fasterxml.jackson.annotation.JsonProperty; import lombok.Builder; -import lombok.Data; +import lombok.Value; import lombok.extern.jackson.Jacksonized; -@Data +@Value public class CreditLimitDTO { @JsonProperty(value ="insuredCreditLimit") diff --git a/multiapi-engine/src/test/resources/openapigenerator/testSimpleBuild/assets/model/DocumentDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testSimpleBuild/assets/model/DocumentDTO.java index f90ed4bd..60a3b0d8 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testSimpleBuild/assets/model/DocumentDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testSimpleBuild/assets/model/DocumentDTO.java @@ -2,10 +2,10 @@ import com.fasterxml.jackson.annotation.JsonProperty; import lombok.Builder; -import lombok.Data; +import lombok.Value; import lombok.extern.jackson.Jacksonized; -@Data +@Value public class DocumentDTO { @JsonProperty(value ="description") diff --git a/multiapi-engine/src/test/resources/openapigenerator/testSimpleBuild/assets/model/ErrorResponseDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testSimpleBuild/assets/model/ErrorResponseDTO.java index a10d1e45..8e7980be 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testSimpleBuild/assets/model/ErrorResponseDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testSimpleBuild/assets/model/ErrorResponseDTO.java @@ -2,10 +2,10 @@ import com.fasterxml.jackson.annotation.JsonProperty; import lombok.Builder; -import lombok.Data; +import lombok.Value; import lombok.extern.jackson.Jacksonized; -@Data +@Value public class ErrorResponseDTO { @JsonProperty(value ="status") diff --git a/multiapi-engine/src/test/resources/openapigenerator/testSimpleBuild/assets/model/InsuredCreditObjectDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testSimpleBuild/assets/model/InsuredCreditObjectDTO.java index 846edb36..06c9084b 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testSimpleBuild/assets/model/InsuredCreditObjectDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testSimpleBuild/assets/model/InsuredCreditObjectDTO.java @@ -2,10 +2,10 @@ import com.fasterxml.jackson.annotation.JsonProperty; import lombok.Builder; -import lombok.Data; +import lombok.Value; import lombok.extern.jackson.Jacksonized; -@Data +@Value public class InsuredCreditObjectDTO { @JsonProperty(value ="creditLimitInCents") diff --git a/multiapi-engine/src/test/resources/openapigenerator/testSimpleBuild/assets/model/PolicyActivationDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testSimpleBuild/assets/model/PolicyActivationDTO.java index 0b990552..d85cf040 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testSimpleBuild/assets/model/PolicyActivationDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testSimpleBuild/assets/model/PolicyActivationDTO.java @@ -2,10 +2,10 @@ import com.fasterxml.jackson.annotation.JsonProperty; import lombok.Builder; -import lombok.Data; +import lombok.Value; import lombok.extern.jackson.Jacksonized; -@Data +@Value public class PolicyActivationDTO { @JsonProperty(value ="policyId") diff --git a/multiapi-engine/src/test/resources/openapigenerator/testSimpleBuild/assets/model/PolicyClaimDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testSimpleBuild/assets/model/PolicyClaimDTO.java index 0f41c680..6cc5a3bc 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testSimpleBuild/assets/model/PolicyClaimDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testSimpleBuild/assets/model/PolicyClaimDTO.java @@ -2,10 +2,10 @@ import com.fasterxml.jackson.annotation.JsonProperty; import lombok.Builder; -import lombok.Data; +import lombok.Value; import lombok.extern.jackson.Jacksonized; -@Data +@Value public class PolicyClaimDTO { @JsonProperty(value ="proofOfDeliveryDocument") diff --git a/multiapi-engine/src/test/resources/openapigenerator/testSimpleBuild/assets/model/PolicySettlementDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testSimpleBuild/assets/model/PolicySettlementDTO.java index c2db1325..9ae0d843 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testSimpleBuild/assets/model/PolicySettlementDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testSimpleBuild/assets/model/PolicySettlementDTO.java @@ -2,10 +2,10 @@ import com.fasterxml.jackson.annotation.JsonProperty; import lombok.Builder; -import lombok.Data; +import lombok.Value; import lombok.extern.jackson.Jacksonized; -@Data +@Value public class PolicySettlementDTO { @JsonProperty(value ="provider") diff --git a/multiapi-engine/src/test/resources/openapigenerator/testSimpleBuild/assets/model/QuoteRequestDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testSimpleBuild/assets/model/QuoteRequestDTO.java index ef4452fe..9080ce27 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testSimpleBuild/assets/model/QuoteRequestDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testSimpleBuild/assets/model/QuoteRequestDTO.java @@ -2,10 +2,10 @@ import com.fasterxml.jackson.annotation.JsonProperty; import lombok.Builder; -import lombok.Data; +import lombok.Value; import lombok.extern.jackson.Jacksonized; -@Data +@Value public class QuoteRequestDTO { @JsonProperty(value ="debtorId") diff --git a/multiapi-engine/src/test/resources/openapigenerator/testSimpleBuild/assets/model/QuoteResponseDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testSimpleBuild/assets/model/QuoteResponseDTO.java index bebe901a..712104ec 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testSimpleBuild/assets/model/QuoteResponseDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testSimpleBuild/assets/model/QuoteResponseDTO.java @@ -2,10 +2,10 @@ import com.fasterxml.jackson.annotation.JsonProperty; import lombok.Builder; -import lombok.Data; +import lombok.Value; import lombok.extern.jackson.Jacksonized; -@Data +@Value public class QuoteResponseDTO { @JsonProperty(value ="activateBeforeDate") diff --git a/multiapi-engine/src/test/resources/openapigenerator/testSimpleBuild/assets/model/QuoteUpdateResponseDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testSimpleBuild/assets/model/QuoteUpdateResponseDTO.java index 5a804fa0..fbcb7c53 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testSimpleBuild/assets/model/QuoteUpdateResponseDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testSimpleBuild/assets/model/QuoteUpdateResponseDTO.java @@ -2,10 +2,10 @@ import com.fasterxml.jackson.annotation.JsonProperty; import lombok.Builder; -import lombok.Data; +import lombok.Value; import lombok.extern.jackson.Jacksonized; -@Data +@Value public class QuoteUpdateResponseDTO { @JsonProperty(value ="activateBeforeDate") diff --git a/multiapi-engine/src/test/resources/openapigenerator/testSimpleBuild/assets/model/UpdateQuoteDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testSimpleBuild/assets/model/UpdateQuoteDTO.java index dad05559..c52889b9 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testSimpleBuild/assets/model/UpdateQuoteDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testSimpleBuild/assets/model/UpdateQuoteDTO.java @@ -2,11 +2,11 @@ import com.fasterxml.jackson.annotation.JsonProperty; import lombok.Builder; -import lombok.Data; +import lombok.Value; import lombok.NonNull; import lombok.extern.jackson.Jacksonized; -@Data +@Value public class UpdateQuoteDTO { @JsonProperty(value ="invoiceDate") diff --git a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/assets/lombok/ApiErrorDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/assets/lombok/ApiErrorDTO.java index f77a3441..dab900cb 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/assets/lombok/ApiErrorDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/assets/lombok/ApiErrorDTO.java @@ -12,11 +12,11 @@ import com.sngular.multifileplugin.lombok.testapi.model.customvalidator.MinItems; import com.sngular.multifileplugin.lombok.testapi.model.customvalidator.UniqueItems; import lombok.Builder; -import lombok.Data; +import lombok.Value; import lombok.NonNull; import lombok.extern.jackson.Jacksonized; -@Data +@Value public class ApiErrorDTO { @JsonProperty(value ="intCode") diff --git a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/assets/lombok/ApiTestAllOfDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/assets/lombok/ApiTestAllOfDTO.java index 44fae21e..a44d32a4 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/assets/lombok/ApiTestAllOfDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/assets/lombok/ApiTestAllOfDTO.java @@ -4,10 +4,10 @@ import java.util.List; import java.util.ArrayList; import lombok.Builder; -import lombok.Data; +import lombok.Value; import lombok.extern.jackson.Jacksonized; -@Data +@Value public class ApiTestAllOfDTO { @JsonProperty(value ="testers") diff --git a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/assets/lombok/ApiTestDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/assets/lombok/ApiTestDTO.java index 9d9e9e27..be2c50e1 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/assets/lombok/ApiTestDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/assets/lombok/ApiTestDTO.java @@ -4,11 +4,11 @@ import java.util.List; import java.util.ArrayList; import lombok.Builder; -import lombok.Data; +import lombok.Value; import lombok.NonNull; import lombok.extern.jackson.Jacksonized; -@Data +@Value public class ApiTestDTO { @JsonProperty(value ="testers") diff --git a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/assets/lombok/ApiTestInfoDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/assets/lombok/ApiTestInfoDTO.java index 740549d2..edbe49b6 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/assets/lombok/ApiTestInfoDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/assets/lombok/ApiTestInfoDTO.java @@ -4,11 +4,11 @@ import java.util.List; import java.util.ArrayList; import lombok.Builder; -import lombok.Data; +import lombok.Value; import lombok.NonNull; import lombok.extern.jackson.Jacksonized; -@Data +@Value public class ApiTestInfoDTO { @JsonProperty(value ="testers") diff --git a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/assets/lombok/ApiTestsDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/assets/lombok/ApiTestsDTO.java index cfefde1c..9775510a 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/assets/lombok/ApiTestsDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/assets/lombok/ApiTestsDTO.java @@ -2,9 +2,9 @@ import com.fasterxml.jackson.annotation.JsonProperty; import lombok.Builder; -import lombok.Data; +import lombok.Value; -@Data +@Value public class ApiTestsDTO { @JsonProperty(value ="apiTestDTO") diff --git a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/assets/testApi/ApiTestInfoDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/assets/testApi/ApiTestInfoDTO.java index 921badfd..d1bba8fa 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/assets/testApi/ApiTestInfoDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/assets/testApi/ApiTestInfoDTO.java @@ -36,6 +36,7 @@ public static class ApiTestInfoDTOBuilder { private List testers = new ArrayList(); private String testName; + public ApiTestInfoDTO.ApiTestInfoDTOBuilder testers(List testers) { if (!testers.isEmpty()) { this.testers.addAll(testers); diff --git a/multiapi-engine/src/test/resources/openapigenerator/testWebClientApiGeneration/assets/ApiTestInfoDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testWebClientApiGeneration/assets/ApiTestInfoDTO.java index 127fae2a..0194c31d 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testWebClientApiGeneration/assets/ApiTestInfoDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testWebClientApiGeneration/assets/ApiTestInfoDTO.java @@ -36,6 +36,7 @@ public static class ApiTestInfoDTOBuilder { private List testers = new ArrayList(); private String testName; + public ApiTestInfoDTO.ApiTestInfoDTOBuilder testers(List testers) { if (!testers.isEmpty()) { this.testers.addAll(testers); From 2c7315fc3bdae41e1b51447e128f94c6d0e5c1b8 Mon Sep 17 00:00:00 2001 From: "joseenrique.garcia" Date: Wed, 4 Sep 2024 22:33:57 +0200 Subject: [PATCH 09/26] Fix OpenApi generator --- .../templates/model/templateSchema.ftlh | 22 ++++---- .../model/templateSchemaWithLombok.ftlh | 51 ++++++++++++++----- .../assets/TestDTO.java | 6 ++- .../assets/SubtestDTO.java | 2 +- .../assets/TestDTO.java | 6 ++- .../assets/SecondTestDTO.java | 2 +- .../assets/TestDTO.java | 2 +- .../assets/TestValueDTO.java | 2 +- .../assets/TestValueValueDTO.java | 2 +- .../assets/ThirdTestDTO.java | 2 +- .../testAllOf/assets/lombok/ApiErrorDTO.java | 3 +- .../assets/lombok/ApiTestAllOfDTO.java | 2 +- .../testAllOf/assets/lombok/ApiTestDTO.java | 4 +- .../assets/lombok/ApiTestInfoDTO.java | 4 +- .../testAnyOfInResponse/assets/GameDTO.java | 2 +- .../assets/GameInfoDTO.java | 2 +- .../InlineResponse200ListGamesAnyOfDTO.java | 2 +- .../assets/ApiErrorDTO.java | 2 +- .../assets/ApiTestDTO.java | 2 +- .../assets/ApiTestInfoDTO.java | 4 +- .../assets/ApiTestDTO.java | 3 ++ .../assets/ApiTestInfoDTO.java | 1 + .../assets/ApiErrorDTO.java | 2 +- .../assets/ApiTestDTO.java | 2 +- .../assets/ApiTestInfoDTO.java | 4 +- .../assets/ErrorDTO.java | 7 --- .../testApiTagsGeneration/assets/TestDTO.java | 7 --- .../assets/TestInfoDTO.java | 1 + .../assets/ErrorDTO.java | 7 --- .../assets/TestDTO.java | 7 --- .../assets/model/ArrayFieldDTO.java | 1 + .../assets/model/EnumFieldDTO.java | 1 + .../assets/model/FieldDTO.java | 5 +- .../assets/model/MapFieldDTO.java | 1 + .../assets/model/NumberFieldDTO.java | 1 + .../assets/model/ObjectFieldDTO.java | 1 + .../assets/model/SequenceFieldDTO.java | 1 + .../assets/model/StringFieldDTO.java | 1 + .../assets/model/UnionFieldDTO.java | 1 + .../assets/ApiArrayFieldDTO.java | 2 - .../assets/ApiEnumFieldDTO.java | 2 - .../assets/ApiMapFieldDTO.java | 2 - .../assets/ApiNumberFieldDTO.java | 1 - .../assets/model/AddressDTO.java | 2 +- .../assets/model/TestDTO.java | 2 +- .../assets/model/AddressDTO.java | 2 +- .../testCreateDTO/assets/model/TestDTO.java | 3 +- .../assets/ApiTestDTO.java | 7 ++- .../assets/ApiTestProcessorDTO.java | 6 --- .../assets/ApiTestTypeDTO.java | 6 --- .../assets/model/ConfigurationDTO.java | 2 +- .../assets/model/FakerFieldDTO.java | 3 +- .../assets/model/FakerSchemaDTO.java | 4 +- .../testIssueFaker/assets/model/FieldDTO.java | 3 +- .../assets/model/SchemaDTO.java | 4 +- .../testOneOfInResponse/assets/GameDTO.java | 2 +- .../assets/GameInfoDTO.java | 6 ++- .../InlineResponse200ListGamesOneOfDTO.java | 6 ++- .../assets/ApiTestInfoDTO.java | 7 --- .../assets/model/SchemaDTO.java | 2 +- .../assets/model/ContactDTO.java | 2 +- .../assets/model/UpdateQuoteDTO.java | 2 +- .../assets/lombok/ApiErrorDTO.java | 12 ++--- .../assets/lombok/ApiTestDTO.java | 2 +- .../assets/lombok/ApiTestInfoDTO.java | 2 +- 65 files changed, 137 insertions(+), 135 deletions(-) diff --git a/multiapi-engine/src/main/resources/templates/model/templateSchema.ftlh b/multiapi-engine/src/main/resources/templates/model/templateSchema.ftlh index c4ff1c19..09c5ad0d 100644 --- a/multiapi-engine/src/main/resources/templates/model/templateSchema.ftlh +++ b/multiapi-engine/src/main/resources/templates/model/templateSchema.ftlh @@ -425,12 +425,14 @@ public class ${schema.className} { private void validatePartialCombinations() { boolean satisfiedCondition = false; - <#list schema.fieldObjectList as field> - <#if field == schema.fieldObjectList?first> - if (Objects.nonNull(this.${calculateSafeName (field.baseName, "")})) { - <#else> else if (Objects.nonNull(this.${calculateSafeName (field.baseName, "")})) { - satisfiedCondition = true; - } +<#list schema.fieldObjectList as field> +<#if field == schema.fieldObjectList?first> + if (Objects.nonNull(this.${calculateSafeName (field.baseName, "")})) { +<#else> + else if (Objects.nonNull(this.${calculateSafeName (field.baseName, "")})) { + + satisfiedCondition = true; + } if (!satisfiedCondition) { throw new ModelClassException("${schema.className}"); @@ -442,12 +444,12 @@ public class ${schema.className} { private void validateRequiredAttributes() { boolean satisfiedCondition = true; - <#list schema.fieldObjectList?filter(f -> f.required) as field> - <#if field?index == 0> +<#list schema.fieldObjectList?filter(f -> f.required) as field> +<#if field?index == 0> if (!Objects.nonNull(this.${calculateSafeName (field.baseName, "")})) { - <#else> +<#else> else if (!Objects.nonNull(this.${calculateSafeName (field.baseName, "")})) { - + satisfiedCondition = false; } diff --git a/multiapi-engine/src/main/resources/templates/model/templateSchemaWithLombok.ftlh b/multiapi-engine/src/main/resources/templates/model/templateSchemaWithLombok.ftlh index 4e4d779c..96fd517d 100644 --- a/multiapi-engine/src/main/resources/templates/model/templateSchemaWithLombok.ftlh +++ b/multiapi-engine/src/main/resources/templates/model/templateSchemaWithLombok.ftlh @@ -33,6 +33,28 @@ <#return "_"+propertyName/> +<#function calculateMaxAnnotation dataType> + <#if dataType.baseType?lower_case == "bigdecimal"> + <#return "@MaxBigDecimal" > + <#elseif dataType.baseType?lower_case == "integer"> + <#return "@MaxInteger" > + <#elseif dataType.baseType?lower_case == "float"> + <#return "@MaxFloat" > + <#elseif dataType.baseType?lower_case == "double"> + <#return "@MaxDouble" > + + +<#function calculateMinAnnotation dataType> + <#if dataType.baseType?lower_case == "bigdecimal"> + <#return "@MinBigDecimal" > + <#elseif dataType.baseType?lower_case == "integer"> + <#return "@MinInteger" > + <#elseif dataType.baseType?lower_case == "float"> + <#return "@MinFloat" > + <#elseif dataType.baseType?lower_case == "double"> + <#return "@MinDouble" > + + package ${packageModel}; <#if schema.schemaCombinator == "anyOf" || schema.schemaCombinator == "oneOf"> @@ -114,14 +136,19 @@ import ${packageModel}.customvalidator.UniqueItems; import lombok.Builder; -import lombok.Value; -import lombok.Singular; <#list schema.fieldObjectList as field> - <#if field.required> + <#if field.required> import lombok.NonNull; - <#break> + <#break> + + +<#list schema.fieldObjectList as field> +<#if field.dataType.baseType == "array" || field.dataType.baseType == "map"> +import lombok.Singular; + <#break> +import lombok.Value; import lombok.extern.jackson.Jacksonized; <#if schema.schemaCombinator == "anyOf" || schema.schemaCombinator == "oneOf"> import ${packageModel}.exception.ModelClassException; @@ -184,13 +211,13 @@ public class ${schema.className} { private ${field.baseName?cap_first} ${field.baseName?uncap_first}; public enum ${field.baseName?cap_first} { - <#list field.enumValues as key, value> - <#if key?matches("[0-9].*")> - ${"_"+key}(${value})<#sep>, - <#else> - ${key}(${value})<#sep>, - - ; +<#list field.enumValues as key, value> + <#if key?matches("[0-9].*")> + ${"_"+key}(${value})<#sep>, + <#else> + ${key}(${value})<#sep>, + +; private ${field.dataType.innerType?cap_first} value; @@ -205,7 +232,7 @@ public class ${schema.className} { @Override public String toString() { - return String.valueOf(value); + return String.valueOf(value); } } <#elseif field.dataType.innerType?has_content && field.dataType.baseType == "object"> diff --git a/multiapi-engine/src/test/resources/openapigenerator/testAdditionalProperties/assets/TestDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testAdditionalProperties/assets/TestDTO.java index 652036fb..1f7d3133 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testAdditionalProperties/assets/TestDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testAdditionalProperties/assets/TestDTO.java @@ -4,15 +4,17 @@ import java.util.Map; import java.util.HashMap; import lombok.Builder; -import lombok.Value; import lombok.NonNull; +import lombok.Singular; +import lombok.Value; import lombok.extern.jackson.Jacksonized; @Value public class TestDTO { @JsonProperty(value ="additionalProperties") - private Map additionalProperties = new HashMap(); + @Singular("additionalProperty") + private Map additionalProperties; @JsonProperty(value ="id") @NonNull diff --git a/multiapi-engine/src/test/resources/openapigenerator/testAdditionalPropertiesWithSchema/assets/SubtestDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testAdditionalPropertiesWithSchema/assets/SubtestDTO.java index 3ad59e6e..bf2839fe 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testAdditionalPropertiesWithSchema/assets/SubtestDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testAdditionalPropertiesWithSchema/assets/SubtestDTO.java @@ -2,8 +2,8 @@ import com.fasterxml.jackson.annotation.JsonProperty; import lombok.Builder; -import lombok.Value; import lombok.NonNull; +import lombok.Value; import lombok.extern.jackson.Jacksonized; @Value diff --git a/multiapi-engine/src/test/resources/openapigenerator/testAdditionalPropertiesWithSchema/assets/TestDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testAdditionalPropertiesWithSchema/assets/TestDTO.java index a9e023c5..0099be4e 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testAdditionalPropertiesWithSchema/assets/TestDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testAdditionalPropertiesWithSchema/assets/TestDTO.java @@ -4,15 +4,17 @@ import java.util.Map; import java.util.HashMap; import lombok.Builder; -import lombok.Value; import lombok.NonNull; +import lombok.Singular; +import lombok.Value; import lombok.extern.jackson.Jacksonized; @Value public class TestDTO { @JsonProperty(value ="additionalProperties") - private Map additionalProperties = new HashMap(); + @Singular("additionalProperty") + private Map additionalProperties; @JsonProperty(value ="id") @NonNull diff --git a/multiapi-engine/src/test/resources/openapigenerator/testAdditionalPropertiesWithUnnamedObject/assets/SecondTestDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testAdditionalPropertiesWithUnnamedObject/assets/SecondTestDTO.java index 9147c5e5..c3d4b396 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testAdditionalPropertiesWithUnnamedObject/assets/SecondTestDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testAdditionalPropertiesWithUnnamedObject/assets/SecondTestDTO.java @@ -4,8 +4,8 @@ import java.util.Map; import java.util.HashMap; import lombok.Builder; -import lombok.Value; import lombok.NonNull; +import lombok.Value; import lombok.extern.jackson.Jacksonized; @Value diff --git a/multiapi-engine/src/test/resources/openapigenerator/testAdditionalPropertiesWithUnnamedObject/assets/TestDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testAdditionalPropertiesWithUnnamedObject/assets/TestDTO.java index 4625de60..4e3e408b 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testAdditionalPropertiesWithUnnamedObject/assets/TestDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testAdditionalPropertiesWithUnnamedObject/assets/TestDTO.java @@ -4,8 +4,8 @@ import java.util.Map; import java.util.HashMap; import lombok.Builder; -import lombok.Value; import lombok.NonNull; +import lombok.Value; import lombok.extern.jackson.Jacksonized; @Value diff --git a/multiapi-engine/src/test/resources/openapigenerator/testAdditionalPropertiesWithUnnamedObject/assets/TestValueDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testAdditionalPropertiesWithUnnamedObject/assets/TestValueDTO.java index ee99a77b..2427c476 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testAdditionalPropertiesWithUnnamedObject/assets/TestValueDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testAdditionalPropertiesWithUnnamedObject/assets/TestValueDTO.java @@ -4,8 +4,8 @@ import java.util.Map; import java.util.HashMap; import lombok.Builder; -import lombok.Value; import lombok.NonNull; +import lombok.Value; import lombok.extern.jackson.Jacksonized; @Value diff --git a/multiapi-engine/src/test/resources/openapigenerator/testAdditionalPropertiesWithUnnamedObject/assets/TestValueValueDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testAdditionalPropertiesWithUnnamedObject/assets/TestValueValueDTO.java index 2864e7a0..414f6fc7 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testAdditionalPropertiesWithUnnamedObject/assets/TestValueValueDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testAdditionalPropertiesWithUnnamedObject/assets/TestValueValueDTO.java @@ -6,8 +6,8 @@ import java.util.Map; import java.util.HashMap; import lombok.Builder; -import lombok.Value; import lombok.NonNull; +import lombok.Value; import lombok.extern.jackson.Jacksonized; @Value diff --git a/multiapi-engine/src/test/resources/openapigenerator/testAdditionalPropertiesWithUnnamedObject/assets/ThirdTestDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testAdditionalPropertiesWithUnnamedObject/assets/ThirdTestDTO.java index 57a0884a..68d269b5 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testAdditionalPropertiesWithUnnamedObject/assets/ThirdTestDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testAdditionalPropertiesWithUnnamedObject/assets/ThirdTestDTO.java @@ -4,8 +4,8 @@ import java.util.Map; import java.util.HashMap; import lombok.Builder; -import lombok.Value; import lombok.NonNull; +import lombok.Value; import lombok.extern.jackson.Jacksonized; @Value diff --git a/multiapi-engine/src/test/resources/openapigenerator/testAllOf/assets/lombok/ApiErrorDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testAllOf/assets/lombok/ApiErrorDTO.java index e0958c6b..d2ca03e6 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testAllOf/assets/lombok/ApiErrorDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testAllOf/assets/lombok/ApiErrorDTO.java @@ -2,9 +2,8 @@ import com.fasterxml.jackson.annotation.JsonProperty; import lombok.Builder; -import lombok.Value; -import lombok.Singular; import lombok.NonNull; +import lombok.Value; import lombok.extern.jackson.Jacksonized; @Value diff --git a/multiapi-engine/src/test/resources/openapigenerator/testAllOf/assets/lombok/ApiTestAllOfDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testAllOf/assets/lombok/ApiTestAllOfDTO.java index 4d215b03..fc3abdeb 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testAllOf/assets/lombok/ApiTestAllOfDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testAllOf/assets/lombok/ApiTestAllOfDTO.java @@ -4,8 +4,8 @@ import java.util.List; import java.util.ArrayList; import lombok.Builder; -import lombok.Value; import lombok.Singular; +import lombok.Value; import lombok.extern.jackson.Jacksonized; @Value diff --git a/multiapi-engine/src/test/resources/openapigenerator/testAllOf/assets/lombok/ApiTestDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testAllOf/assets/lombok/ApiTestDTO.java index 4c220189..72e183ab 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testAllOf/assets/lombok/ApiTestDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testAllOf/assets/lombok/ApiTestDTO.java @@ -4,9 +4,9 @@ import java.util.List; import java.util.ArrayList; import lombok.Builder; -import lombok.Value; -import lombok.Singular; import lombok.NonNull; +import lombok.Singular; +import lombok.Value; import lombok.extern.jackson.Jacksonized; @Value diff --git a/multiapi-engine/src/test/resources/openapigenerator/testAllOf/assets/lombok/ApiTestInfoDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testAllOf/assets/lombok/ApiTestInfoDTO.java index 7d0330c9..b23d1429 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testAllOf/assets/lombok/ApiTestInfoDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testAllOf/assets/lombok/ApiTestInfoDTO.java @@ -4,9 +4,9 @@ import java.util.List; import java.util.ArrayList; import lombok.Builder; -import lombok.Value; -import lombok.Singular; import lombok.NonNull; +import lombok.Singular; +import lombok.Value; import lombok.extern.jackson.Jacksonized; @Value diff --git a/multiapi-engine/src/test/resources/openapigenerator/testAnyOfInResponse/assets/GameDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testAnyOfInResponse/assets/GameDTO.java index 93085c93..b33eb913 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testAnyOfInResponse/assets/GameDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testAnyOfInResponse/assets/GameDTO.java @@ -2,8 +2,8 @@ import com.fasterxml.jackson.annotation.JsonProperty; import lombok.Builder; -import lombok.Value; import lombok.NonNull; +import lombok.Value; import lombok.extern.jackson.Jacksonized; @Value diff --git a/multiapi-engine/src/test/resources/openapigenerator/testAnyOfInResponse/assets/GameInfoDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testAnyOfInResponse/assets/GameInfoDTO.java index 02d822c4..c5bfafac 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testAnyOfInResponse/assets/GameInfoDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testAnyOfInResponse/assets/GameInfoDTO.java @@ -4,9 +4,9 @@ import java.util.List; import java.util.ArrayList; import lombok.Builder; -import lombok.Value; import lombok.NonNull; import lombok.Singular; +import lombok.Value; import lombok.extern.jackson.Jacksonized; @Value diff --git a/multiapi-engine/src/test/resources/openapigenerator/testAnyOfInResponse/assets/InlineResponse200ListGamesAnyOfDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testAnyOfInResponse/assets/InlineResponse200ListGamesAnyOfDTO.java index 284bdacb..e75cc2e8 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testAnyOfInResponse/assets/InlineResponse200ListGamesAnyOfDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testAnyOfInResponse/assets/InlineResponse200ListGamesAnyOfDTO.java @@ -5,9 +5,9 @@ import java.util.List; import java.util.ArrayList; import lombok.Builder; -import lombok.Value; import lombok.NonNull; import lombok.Singular; +import lombok.Value; import lombok.extern.jackson.Jacksonized; import com.sngular.multifileplugin.testanyofinresponse.model.exception.ModelClassException; diff --git a/multiapi-engine/src/test/resources/openapigenerator/testApiClientGeneration/assets/ApiErrorDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testApiClientGeneration/assets/ApiErrorDTO.java index cfa4426d..88aa46db 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testApiClientGeneration/assets/ApiErrorDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testApiClientGeneration/assets/ApiErrorDTO.java @@ -2,8 +2,8 @@ import com.fasterxml.jackson.annotation.JsonProperty; import lombok.Builder; -import lombok.Value; import lombok.NonNull; +import lombok.Value; import lombok.extern.jackson.Jacksonized; @Value diff --git a/multiapi-engine/src/test/resources/openapigenerator/testApiClientGeneration/assets/ApiTestDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testApiClientGeneration/assets/ApiTestDTO.java index 4e5913d3..ce80d4ae 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testApiClientGeneration/assets/ApiTestDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testApiClientGeneration/assets/ApiTestDTO.java @@ -2,8 +2,8 @@ import com.fasterxml.jackson.annotation.JsonProperty; import lombok.Builder; -import lombok.Value; import lombok.NonNull; +import lombok.Value; import lombok.extern.jackson.Jacksonized; @Value diff --git a/multiapi-engine/src/test/resources/openapigenerator/testApiClientGeneration/assets/ApiTestInfoDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testApiClientGeneration/assets/ApiTestInfoDTO.java index 1776ca56..79d6958b 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testApiClientGeneration/assets/ApiTestInfoDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testApiClientGeneration/assets/ApiTestInfoDTO.java @@ -4,14 +4,16 @@ import java.util.List; import java.util.ArrayList; import lombok.Builder; -import lombok.Value; import lombok.NonNull; +import lombok.Singular; +import lombok.Value; import lombok.extern.jackson.Jacksonized; @Value public class ApiTestInfoDTO { @JsonProperty(value ="testers") + @Singular("tester") private List testers; @JsonProperty(value ="testName") diff --git a/multiapi-engine/src/test/resources/openapigenerator/testApiEnumsGeneration/assets/ApiTestDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testApiEnumsGeneration/assets/ApiTestDTO.java index bcd8e6f6..025d96dc 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testApiEnumsGeneration/assets/ApiTestDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testApiEnumsGeneration/assets/ApiTestDTO.java @@ -113,6 +113,7 @@ public static class ApiTestDTOBuilder { private Integer id; private UnionIntegerEnum unionIntegerEnum; private UnionNumberEnum unionNumberEnum; + public ApiTestDTO.ApiTestDTOBuilder unionEnum(UnionEnum unionEnum) { this.unionEnum = unionEnum; return this; @@ -127,10 +128,12 @@ public ApiTestDTO.ApiTestDTOBuilder id(Integer id) { this.id = id; return this; } + public ApiTestDTO.ApiTestDTOBuilder unionIntegerEnum(UnionIntegerEnum unionIntegerEnum) { this.unionIntegerEnum = unionIntegerEnum; return this; } + public ApiTestDTO.ApiTestDTOBuilder unionNumberEnum(UnionNumberEnum unionNumberEnum) { this.unionNumberEnum = unionNumberEnum; return this; diff --git a/multiapi-engine/src/test/resources/openapigenerator/testApiEnumsGeneration/assets/ApiTestInfoDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testApiEnumsGeneration/assets/ApiTestInfoDTO.java index a8b86a97..2ac1ac02 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testApiEnumsGeneration/assets/ApiTestInfoDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testApiEnumsGeneration/assets/ApiTestInfoDTO.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 io.swagger.v3.oas.annotations.media.Schema; import java.util.List; import java.util.ArrayList; diff --git a/multiapi-engine/src/test/resources/openapigenerator/testApiEnumsLombokGeneration/assets/ApiErrorDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testApiEnumsLombokGeneration/assets/ApiErrorDTO.java index fbcd779f..4e94840e 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testApiEnumsLombokGeneration/assets/ApiErrorDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testApiEnumsLombokGeneration/assets/ApiErrorDTO.java @@ -2,8 +2,8 @@ import com.fasterxml.jackson.annotation.JsonProperty; import lombok.Builder; -import lombok.Value; import lombok.NonNull; +import lombok.Value; import lombok.extern.jackson.Jacksonized; @Value diff --git a/multiapi-engine/src/test/resources/openapigenerator/testApiEnumsLombokGeneration/assets/ApiTestDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testApiEnumsLombokGeneration/assets/ApiTestDTO.java index 6fb67359..4c248912 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testApiEnumsLombokGeneration/assets/ApiTestDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testApiEnumsLombokGeneration/assets/ApiTestDTO.java @@ -4,8 +4,8 @@ import com.fasterxml.jackson.annotation.JsonValue; import java.math.BigDecimal; import lombok.Builder; -import lombok.Value; import lombok.NonNull; +import lombok.Value; import lombok.extern.jackson.Jacksonized; @Value diff --git a/multiapi-engine/src/test/resources/openapigenerator/testApiEnumsLombokGeneration/assets/ApiTestInfoDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testApiEnumsLombokGeneration/assets/ApiTestInfoDTO.java index eebef7ad..7cc071a2 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testApiEnumsLombokGeneration/assets/ApiTestInfoDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testApiEnumsLombokGeneration/assets/ApiTestInfoDTO.java @@ -4,14 +4,16 @@ import java.util.List; import java.util.ArrayList; import lombok.Builder; -import lombok.Value; import lombok.NonNull; +import lombok.Singular; +import lombok.Value; import lombok.extern.jackson.Jacksonized; @Value public class ApiTestInfoDTO { @JsonProperty(value ="testers") + @Singular("tester") private List testers; @JsonProperty(value ="testName") diff --git a/multiapi-engine/src/test/resources/openapigenerator/testApiTagsGeneration/assets/ErrorDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testApiTagsGeneration/assets/ErrorDTO.java index 0e9f8c9b..b2efa01c 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testApiTagsGeneration/assets/ErrorDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testApiTagsGeneration/assets/ErrorDTO.java @@ -19,13 +19,6 @@ public class ErrorDTO { @NotNull private final String message; - private ErrorDTO(Integer code, String message) { - this.code = code; - this.message = message; - - validateRequiredAttributes(); - } - private ErrorDTO(ErrorDTOBuilder builder) { this.code = builder.code; this.message = builder.message; diff --git a/multiapi-engine/src/test/resources/openapigenerator/testApiTagsGeneration/assets/TestDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testApiTagsGeneration/assets/TestDTO.java index 564092d8..4d774251 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testApiTagsGeneration/assets/TestDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testApiTagsGeneration/assets/TestDTO.java @@ -19,13 +19,6 @@ public class TestDTO { @NotNull private final Integer id; - private TestDTO(String name, Integer id) { - this.name = name; - this.id = id; - - validateRequiredAttributes(); - } - private TestDTO(TestDTOBuilder builder) { this.name = builder.name; this.id = builder.id; diff --git a/multiapi-engine/src/test/resources/openapigenerator/testApiTagsGeneration/assets/TestInfoDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testApiTagsGeneration/assets/TestInfoDTO.java index 3a87139d..20bd0e26 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testApiTagsGeneration/assets/TestInfoDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testApiTagsGeneration/assets/TestInfoDTO.java @@ -36,6 +36,7 @@ public static class TestInfoDTOBuilder { private List testers = new ArrayList(); private String testName; + public TestInfoDTO.TestInfoDTOBuilder testers(List testers) { if (!testers.isEmpty()) { this.testers.addAll(testers); diff --git a/multiapi-engine/src/test/resources/openapigenerator/testClientPackageWebClientApiGeneration/assets/ErrorDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testClientPackageWebClientApiGeneration/assets/ErrorDTO.java index 6a8d2c93..020a9ce6 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testClientPackageWebClientApiGeneration/assets/ErrorDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testClientPackageWebClientApiGeneration/assets/ErrorDTO.java @@ -13,13 +13,6 @@ public class ErrorDTO { @JsonProperty(value ="message") private final String message; - private ErrorDTO(Integer code, String message) { - this.code = code; - this.message = message; - - validateRequiredAttributes(); - } - private ErrorDTO(ErrorDTOBuilder builder) { this.code = builder.code; this.message = builder.message; diff --git a/multiapi-engine/src/test/resources/openapigenerator/testClientPackageWebClientApiGeneration/assets/TestDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testClientPackageWebClientApiGeneration/assets/TestDTO.java index ba259b47..1dd01f4f 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testClientPackageWebClientApiGeneration/assets/TestDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testClientPackageWebClientApiGeneration/assets/TestDTO.java @@ -13,13 +13,6 @@ public class TestDTO { @JsonProperty(value ="id") private final Integer id; - private TestDTO(String name, Integer id) { - this.name = name; - this.id = id; - - validateRequiredAttributes(); - } - private TestDTO(TestDTOBuilder builder) { this.name = builder.name; this.id = builder.id; diff --git a/multiapi-engine/src/test/resources/openapigenerator/testCoconutSchema/assets/model/ArrayFieldDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testCoconutSchema/assets/model/ArrayFieldDTO.java index b2f5b0f9..1218728f 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testCoconutSchema/assets/model/ArrayFieldDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testCoconutSchema/assets/model/ArrayFieldDTO.java @@ -4,6 +4,7 @@ import java.util.List; import java.util.ArrayList; import lombok.Builder; +import lombok.Singular; import lombok.Value; import lombok.extern.jackson.Jacksonized; diff --git a/multiapi-engine/src/test/resources/openapigenerator/testCoconutSchema/assets/model/EnumFieldDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testCoconutSchema/assets/model/EnumFieldDTO.java index d4e722a1..d8f090c7 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testCoconutSchema/assets/model/EnumFieldDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testCoconutSchema/assets/model/EnumFieldDTO.java @@ -4,6 +4,7 @@ import java.util.List; import java.util.ArrayList; import lombok.Builder; +import lombok.Singular; import lombok.Value; import lombok.extern.jackson.Jacksonized; diff --git a/multiapi-engine/src/test/resources/openapigenerator/testCoconutSchema/assets/model/FieldDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testCoconutSchema/assets/model/FieldDTO.java index 3ecac5d8..bf4ff502 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testCoconutSchema/assets/model/FieldDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testCoconutSchema/assets/model/FieldDTO.java @@ -6,6 +6,7 @@ import java.util.List; import java.util.ArrayList; import lombok.Builder; +import lombok.Singular; import lombok.Value; import lombok.extern.jackson.Jacksonized; import com.sngular.multifileplugin.testCoconutSchema.model.exception.ModelClassException; @@ -17,8 +18,8 @@ public class FieldDTO { private Integer precision; @JsonProperty(value ="defaultItem") - @Singular("defaultItem") - private List defaultItem); + @Singular("_defaultItem") + private List defaultItem; @JsonProperty(value ="maximum") private Integer maximum; diff --git a/multiapi-engine/src/test/resources/openapigenerator/testCoconutSchema/assets/model/MapFieldDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testCoconutSchema/assets/model/MapFieldDTO.java index 5f5303f1..f3d497e5 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testCoconutSchema/assets/model/MapFieldDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testCoconutSchema/assets/model/MapFieldDTO.java @@ -4,6 +4,7 @@ import java.util.List; import java.util.ArrayList; import lombok.Builder; +import lombok.Singular; import lombok.Value; import lombok.extern.jackson.Jacksonized; diff --git a/multiapi-engine/src/test/resources/openapigenerator/testCoconutSchema/assets/model/NumberFieldDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testCoconutSchema/assets/model/NumberFieldDTO.java index 1d33d3b3..38d7723b 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testCoconutSchema/assets/model/NumberFieldDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testCoconutSchema/assets/model/NumberFieldDTO.java @@ -5,6 +5,7 @@ import java.util.List; import java.util.ArrayList; import lombok.Builder; +import lombok.Singular; import lombok.Value; import lombok.extern.jackson.Jacksonized; diff --git a/multiapi-engine/src/test/resources/openapigenerator/testCoconutSchema/assets/model/ObjectFieldDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testCoconutSchema/assets/model/ObjectFieldDTO.java index 87bc2596..a7e063de 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testCoconutSchema/assets/model/ObjectFieldDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testCoconutSchema/assets/model/ObjectFieldDTO.java @@ -4,6 +4,7 @@ import java.util.List; import java.util.ArrayList; import lombok.Builder; +import lombok.Singular; import lombok.Value; import lombok.extern.jackson.Jacksonized; diff --git a/multiapi-engine/src/test/resources/openapigenerator/testCoconutSchema/assets/model/SequenceFieldDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testCoconutSchema/assets/model/SequenceFieldDTO.java index 6a21ab64..f352f78f 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testCoconutSchema/assets/model/SequenceFieldDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testCoconutSchema/assets/model/SequenceFieldDTO.java @@ -5,6 +5,7 @@ import java.util.List; import java.util.ArrayList; import lombok.Builder; +import lombok.Singular; import lombok.Value; import lombok.extern.jackson.Jacksonized; diff --git a/multiapi-engine/src/test/resources/openapigenerator/testCoconutSchema/assets/model/StringFieldDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testCoconutSchema/assets/model/StringFieldDTO.java index 14808885..a87ccf75 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testCoconutSchema/assets/model/StringFieldDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testCoconutSchema/assets/model/StringFieldDTO.java @@ -4,6 +4,7 @@ import java.util.List; import java.util.ArrayList; import lombok.Builder; +import lombok.Singular; import lombok.Value; import lombok.extern.jackson.Jacksonized; diff --git a/multiapi-engine/src/test/resources/openapigenerator/testCoconutSchema/assets/model/UnionFieldDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testCoconutSchema/assets/model/UnionFieldDTO.java index c4a0d0bf..64eeec2c 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testCoconutSchema/assets/model/UnionFieldDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testCoconutSchema/assets/model/UnionFieldDTO.java @@ -5,6 +5,7 @@ import java.util.List; import java.util.ArrayList; import lombok.Builder; +import lombok.Singular; import lombok.Value; import lombok.extern.jackson.Jacksonized; diff --git a/multiapi-engine/src/test/resources/openapigenerator/testComplexAnyOf/assets/ApiArrayFieldDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testComplexAnyOf/assets/ApiArrayFieldDTO.java index 84a90430..ddf753b0 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testComplexAnyOf/assets/ApiArrayFieldDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testComplexAnyOf/assets/ApiArrayFieldDTO.java @@ -17,7 +17,6 @@ public class ApiArrayFieldDTO { @JsonProperty(value ="type") private String type; @JsonProperty(value ="defaultValues") - @Singular("defaultValue") private List defaultValues; @JsonProperty(value ="name") private String name; @@ -28,7 +27,6 @@ public class ApiArrayFieldDTO { @JsonProperty(value ="minItems") private Integer minItems; @JsonProperty(value ="values") - @Singular("value") private List values; private ApiArrayFieldDTO(Boolean uniqueItems, String type, List defaultValues, String name, Integer arraySize, String regex, Integer minItems, List values) { diff --git a/multiapi-engine/src/test/resources/openapigenerator/testComplexAnyOf/assets/ApiEnumFieldDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testComplexAnyOf/assets/ApiEnumFieldDTO.java index 7bbf3ad8..0334c5d9 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testComplexAnyOf/assets/ApiEnumFieldDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testComplexAnyOf/assets/ApiEnumFieldDTO.java @@ -13,12 +13,10 @@ public class ApiEnumFieldDTO { @JsonProperty(value ="enumValues") - @Singular("enumValue") private List enumValues; @JsonProperty(value ="type") private String type; @JsonProperty(value ="defaultValues") - @Singular("defaultValue") private List defaultValues; @JsonProperty(value ="name") private String name; diff --git a/multiapi-engine/src/test/resources/openapigenerator/testComplexAnyOf/assets/ApiMapFieldDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testComplexAnyOf/assets/ApiMapFieldDTO.java index 95504464..b6d7aa53 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testComplexAnyOf/assets/ApiMapFieldDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testComplexAnyOf/assets/ApiMapFieldDTO.java @@ -17,14 +17,12 @@ public class ApiMapFieldDTO { @JsonProperty(value ="type") private String type; @JsonProperty(value ="defaultValues") - @Singular("defaultValue") private List defaultValues; @JsonProperty(value ="name") private String name; @JsonProperty(value ="mapSize") private Integer mapSize; @JsonProperty(value ="mapTypes") - @Singular("mapType") private List mapTypes; private ApiMapFieldDTO(String keyType, String type, List defaultValues, String name, Integer mapSize, List mapTypes) { diff --git a/multiapi-engine/src/test/resources/openapigenerator/testComplexAnyOf/assets/ApiNumberFieldDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testComplexAnyOf/assets/ApiNumberFieldDTO.java index 7c0dbf74..c32c2b61 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testComplexAnyOf/assets/ApiNumberFieldDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testComplexAnyOf/assets/ApiNumberFieldDTO.java @@ -20,7 +20,6 @@ public class ApiNumberFieldDTO { @JsonProperty(value ="type") private String type; @JsonProperty(value ="defaultValues") - @Singular("defaultValue") private List defaultValues; @JsonProperty(value ="name") private String name; diff --git a/multiapi-engine/src/test/resources/openapigenerator/testCreateBasicDTO/assets/model/AddressDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testCreateBasicDTO/assets/model/AddressDTO.java index e11417bf..46209e7a 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testCreateBasicDTO/assets/model/AddressDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testCreateBasicDTO/assets/model/AddressDTO.java @@ -2,8 +2,8 @@ import com.fasterxml.jackson.annotation.JsonProperty; import lombok.Builder; -import lombok.Value; import lombok.NonNull; +import lombok.Value; import lombok.extern.jackson.Jacksonized; @Value diff --git a/multiapi-engine/src/test/resources/openapigenerator/testCreateBasicDTO/assets/model/TestDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testCreateBasicDTO/assets/model/TestDTO.java index 6f0c0a6b..42cb441c 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testCreateBasicDTO/assets/model/TestDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testCreateBasicDTO/assets/model/TestDTO.java @@ -3,8 +3,8 @@ import com.fasterxml.jackson.annotation.JsonProperty; import java.math.BigDecimal; import lombok.Builder; -import lombok.Value; import lombok.NonNull; +import lombok.Value; import lombok.extern.jackson.Jacksonized; @Value diff --git a/multiapi-engine/src/test/resources/openapigenerator/testCreateDTO/assets/model/AddressDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testCreateDTO/assets/model/AddressDTO.java index 61db9b9f..3ab0ccfb 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testCreateDTO/assets/model/AddressDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testCreateDTO/assets/model/AddressDTO.java @@ -2,8 +2,8 @@ import com.fasterxml.jackson.annotation.JsonProperty; import lombok.Builder; -import lombok.Value; import lombok.NonNull; +import lombok.Value; import lombok.extern.jackson.Jacksonized; @Value diff --git a/multiapi-engine/src/test/resources/openapigenerator/testCreateDTO/assets/model/TestDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testCreateDTO/assets/model/TestDTO.java index 2c9c9174..fe85d9d5 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testCreateDTO/assets/model/TestDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testCreateDTO/assets/model/TestDTO.java @@ -5,8 +5,9 @@ import java.util.ArrayList; import java.math.BigDecimal; import lombok.Builder; -import lombok.Value; import lombok.NonNull; +import lombok.Singular; +import lombok.Value; import lombok.extern.jackson.Jacksonized; @Value diff --git a/multiapi-engine/src/test/resources/openapigenerator/testInlineSchemaCreation/assets/ApiTestDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testInlineSchemaCreation/assets/ApiTestDTO.java index d362246b..6cc6e79c 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testInlineSchemaCreation/assets/ApiTestDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testInlineSchemaCreation/assets/ApiTestDTO.java @@ -47,11 +47,12 @@ public static class ApiTestDTOBuilder { private ApiTestProcessorDTO testProcessor; private String description; - private List tags; + private List tags = new ArrayList(); private String name; - private List testTypeList; + private List testTypeList = new ArrayList(); private Integer id; private Integer priority; + public ApiTestDTO.ApiTestDTOBuilder testProcessor(ApiTestProcessorDTO testProcessor) { this.testProcessor = testProcessor; return this; @@ -61,6 +62,7 @@ public ApiTestDTO.ApiTestDTOBuilder description(String description) { this.description = description; return this; } + public ApiTestDTO.ApiTestDTOBuilder tags(List tags) { if (!tags.isEmpty()) { this.tags.addAll(tags); @@ -79,6 +81,7 @@ public ApiTestDTO.ApiTestDTOBuilder name(String name) { this.name = name; return this; } + public ApiTestDTO.ApiTestDTOBuilder testTypeList(List testTypeList) { if (!testTypeList.isEmpty()) { this.testTypeList.addAll(testTypeList); diff --git a/multiapi-engine/src/test/resources/openapigenerator/testInlineSchemaCreation/assets/ApiTestProcessorDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testInlineSchemaCreation/assets/ApiTestProcessorDTO.java index da11254e..75d13d71 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testInlineSchemaCreation/assets/ApiTestProcessorDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testInlineSchemaCreation/assets/ApiTestProcessorDTO.java @@ -15,12 +15,6 @@ public class ApiTestProcessorDTO { @JsonProperty(value ="id") private String id; - private ApiTestProcessorDTO(String name, String id) { - this.name = name; - this.id = id; - - } - private ApiTestProcessorDTO(ApiTestProcessorDTOBuilder builder) { this.name = builder.name; this.id = builder.id; diff --git a/multiapi-engine/src/test/resources/openapigenerator/testInlineSchemaCreation/assets/ApiTestTypeDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testInlineSchemaCreation/assets/ApiTestTypeDTO.java index 2c8416fa..63501a1d 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testInlineSchemaCreation/assets/ApiTestTypeDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testInlineSchemaCreation/assets/ApiTestTypeDTO.java @@ -15,12 +15,6 @@ public class ApiTestTypeDTO { @JsonProperty(value ="id") private String id; - private ApiTestTypeDTO(String name, String id) { - this.name = name; - this.id = id; - - } - private ApiTestTypeDTO(ApiTestTypeDTOBuilder builder) { this.name = builder.name; this.id = builder.id; diff --git a/multiapi-engine/src/test/resources/openapigenerator/testIssueFaker/assets/model/ConfigurationDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testIssueFaker/assets/model/ConfigurationDTO.java index 66a453bf..040b97f8 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testIssueFaker/assets/model/ConfigurationDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testIssueFaker/assets/model/ConfigurationDTO.java @@ -5,8 +5,8 @@ import java.util.Map; import java.util.HashMap; import lombok.Builder; -import lombok.Value; import lombok.Singular; +import lombok.Value; import lombok.extern.jackson.Jacksonized; @Value diff --git a/multiapi-engine/src/test/resources/openapigenerator/testIssueFaker/assets/model/FakerFieldDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testIssueFaker/assets/model/FakerFieldDTO.java index 5cbfc2aa..8e018676 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testIssueFaker/assets/model/FakerFieldDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testIssueFaker/assets/model/FakerFieldDTO.java @@ -2,9 +2,8 @@ import com.fasterxml.jackson.annotation.JsonProperty; import lombok.Builder; -import lombok.Value; -import lombok.Singular; import lombok.NonNull; +import lombok.Value; import lombok.extern.jackson.Jacksonized; @Value diff --git a/multiapi-engine/src/test/resources/openapigenerator/testIssueFaker/assets/model/FakerSchemaDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testIssueFaker/assets/model/FakerSchemaDTO.java index fef942ad..884316ab 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testIssueFaker/assets/model/FakerSchemaDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testIssueFaker/assets/model/FakerSchemaDTO.java @@ -4,9 +4,9 @@ import java.util.List; import java.util.ArrayList; import lombok.Builder; -import lombok.Value; -import lombok.Singular; import lombok.NonNull; +import lombok.Singular; +import lombok.Value; import lombok.extern.jackson.Jacksonized; @Value diff --git a/multiapi-engine/src/test/resources/openapigenerator/testIssueFaker/assets/model/FieldDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testIssueFaker/assets/model/FieldDTO.java index 78ae82b1..1a3179b3 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testIssueFaker/assets/model/FieldDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testIssueFaker/assets/model/FieldDTO.java @@ -2,9 +2,8 @@ import com.fasterxml.jackson.annotation.JsonProperty; import lombok.Builder; -import lombok.Value; -import lombok.Singular; import lombok.NonNull; +import lombok.Value; import lombok.extern.jackson.Jacksonized; @Value diff --git a/multiapi-engine/src/test/resources/openapigenerator/testIssueFaker/assets/model/SchemaDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testIssueFaker/assets/model/SchemaDTO.java index 8cad9671..a9a7ca00 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testIssueFaker/assets/model/SchemaDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testIssueFaker/assets/model/SchemaDTO.java @@ -4,9 +4,9 @@ import java.util.List; import java.util.ArrayList; import lombok.Builder; -import lombok.Value; -import lombok.Singular; import lombok.NonNull; +import lombok.Singular; +import lombok.Value; import lombok.extern.jackson.Jacksonized; @Value diff --git a/multiapi-engine/src/test/resources/openapigenerator/testOneOfInResponse/assets/GameDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testOneOfInResponse/assets/GameDTO.java index 8d537c9e..9d1ffd0c 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testOneOfInResponse/assets/GameDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testOneOfInResponse/assets/GameDTO.java @@ -2,8 +2,8 @@ import com.fasterxml.jackson.annotation.JsonProperty; import lombok.Builder; -import lombok.Value; import lombok.NonNull; +import lombok.Value; import lombok.extern.jackson.Jacksonized; @Value diff --git a/multiapi-engine/src/test/resources/openapigenerator/testOneOfInResponse/assets/GameInfoDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testOneOfInResponse/assets/GameInfoDTO.java index 3214039b..cffa0261 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testOneOfInResponse/assets/GameInfoDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testOneOfInResponse/assets/GameInfoDTO.java @@ -4,8 +4,9 @@ import java.util.List; import java.util.ArrayList; import lombok.Builder; -import lombok.Value; import lombok.NonNull; +import lombok.Singular; +import lombok.Value; import lombok.extern.jackson.Jacksonized; @Value @@ -20,7 +21,8 @@ public class GameInfoDTO { private Integer rooms; @JsonProperty(value ="players") - private List players = new ArrayList(); + @Singular("player") + private List players; @Builder diff --git a/multiapi-engine/src/test/resources/openapigenerator/testOneOfInResponse/assets/InlineResponse200ListGamesOneOfDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testOneOfInResponse/assets/InlineResponse200ListGamesOneOfDTO.java index 27592392..eb6b99af 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testOneOfInResponse/assets/InlineResponse200ListGamesOneOfDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testOneOfInResponse/assets/InlineResponse200ListGamesOneOfDTO.java @@ -5,8 +5,9 @@ import java.util.List; import java.util.ArrayList; import lombok.Builder; -import lombok.Value; import lombok.NonNull; +import lombok.Singular; +import lombok.Value; import lombok.extern.jackson.Jacksonized; import com.sngular.multifileplugin.testoneofinresponse.model.exception.ModelClassException; @@ -30,7 +31,8 @@ public class InlineResponse200ListGamesOneOfDTO { private Integer rooms; @JsonProperty(value ="players") - private List players = new ArrayList(); + @Singular("player") + private List players; @Builder diff --git a/multiapi-engine/src/test/resources/openapigenerator/testRestClientApiWithRequestObjectGeneration/assets/ApiTestInfoDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testRestClientApiWithRequestObjectGeneration/assets/ApiTestInfoDTO.java index c2f14d4d..1bc98b4e 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testRestClientApiWithRequestObjectGeneration/assets/ApiTestInfoDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testRestClientApiWithRequestObjectGeneration/assets/ApiTestInfoDTO.java @@ -15,13 +15,6 @@ public class ApiTestInfoDTO { @JsonProperty(value ="testName") private final String testName; - private ApiTestInfoDTO(List testers, String testName) { - this.testers = testers; - this.testName = testName; - - validateRequiredAttributes(); - } - private ApiTestInfoDTO(ApiTestInfoDTOBuilder builder) { this.testers = builder.testers; this.testName = builder.testName; diff --git a/multiapi-engine/src/test/resources/openapigenerator/testRestrictionsSchema/assets/model/SchemaDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testRestrictionsSchema/assets/model/SchemaDTO.java index 253b0bc0..749ca408 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testRestrictionsSchema/assets/model/SchemaDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testRestrictionsSchema/assets/model/SchemaDTO.java @@ -4,8 +4,8 @@ import java.util.List; import java.util.ArrayList; import lombok.Builder; -import lombok.Value; import lombok.NonNull; +import lombok.Value; import lombok.extern.jackson.Jacksonized; @Value diff --git a/multiapi-engine/src/test/resources/openapigenerator/testSimpleBuild/assets/model/ContactDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testSimpleBuild/assets/model/ContactDTO.java index ee570819..54c8d42a 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testSimpleBuild/assets/model/ContactDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testSimpleBuild/assets/model/ContactDTO.java @@ -2,8 +2,8 @@ import com.fasterxml.jackson.annotation.JsonProperty; import lombok.Builder; -import lombok.Value; import lombok.NonNull; +import lombok.Value; import lombok.extern.jackson.Jacksonized; @Value diff --git a/multiapi-engine/src/test/resources/openapigenerator/testSimpleBuild/assets/model/UpdateQuoteDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testSimpleBuild/assets/model/UpdateQuoteDTO.java index c52889b9..20c04bc6 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testSimpleBuild/assets/model/UpdateQuoteDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testSimpleBuild/assets/model/UpdateQuoteDTO.java @@ -2,8 +2,8 @@ import com.fasterxml.jackson.annotation.JsonProperty; import lombok.Builder; -import lombok.Value; import lombok.NonNull; +import lombok.Value; import lombok.extern.jackson.Jacksonized; @Value diff --git a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/assets/lombok/ApiErrorDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/assets/lombok/ApiErrorDTO.java index dab900cb..509d1f49 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/assets/lombok/ApiErrorDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/assets/lombok/ApiErrorDTO.java @@ -4,16 +4,16 @@ import java.util.List; import java.util.ArrayList; import com.sngular.multifileplugin.lombok.testapi.model.customvalidator.Size; -import com.sngular.multifileplugin.lombok.testapi.model.customvalidator.Max; -import com.sngular.multifileplugin.lombok.testapi.model.customvalidator.Min; +import com.sngular.multifileplugin.lombok.testapi.model.customvalidator.MaxInteger; +import com.sngular.multifileplugin.lombok.testapi.model.customvalidator.MinInteger; import com.sngular.multifileplugin.lombok.testapi.model.customvalidator.Pattern; import com.sngular.multifileplugin.lombok.testapi.model.customvalidator.MultipleOf; import com.sngular.multifileplugin.lombok.testapi.model.customvalidator.MaxItems; import com.sngular.multifileplugin.lombok.testapi.model.customvalidator.MinItems; import com.sngular.multifileplugin.lombok.testapi.model.customvalidator.UniqueItems; import lombok.Builder; -import lombok.Value; import lombok.NonNull; +import lombok.Value; import lombok.extern.jackson.Jacksonized; @Value @@ -23,8 +23,8 @@ public class ApiErrorDTO { private Integer intCode; @JsonProperty(value ="code") - @Min(minimum = "10", exclusive = false) - @Max(maximum = "200", exclusive = true) + @MinInteger(minimum = "10", exclusive = false) + @MaxInteger(maximum = "200", exclusive = true) @MultipleOf(multiple = "10.55") @NonNull private Integer code; @@ -39,7 +39,7 @@ public class ApiErrorDTO { @MaxItems(maximum = 10) @MinItems(minimum = 5) @UniqueItems - private List test = new ArrayList(); + private List test; @Builder diff --git a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/assets/lombok/ApiTestDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/assets/lombok/ApiTestDTO.java index be2c50e1..ff436632 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/assets/lombok/ApiTestDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/assets/lombok/ApiTestDTO.java @@ -4,8 +4,8 @@ import java.util.List; import java.util.ArrayList; import lombok.Builder; -import lombok.Value; import lombok.NonNull; +import lombok.Value; import lombok.extern.jackson.Jacksonized; @Value diff --git a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/assets/lombok/ApiTestInfoDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/assets/lombok/ApiTestInfoDTO.java index edbe49b6..12fbc638 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/assets/lombok/ApiTestInfoDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/assets/lombok/ApiTestInfoDTO.java @@ -4,8 +4,8 @@ import java.util.List; import java.util.ArrayList; import lombok.Builder; -import lombok.Value; import lombok.NonNull; +import lombok.Value; import lombok.extern.jackson.Jacksonized; @Value From 61f9325246bc53cb4e7078ccdf4bb74edb2374d5 Mon Sep 17 00:00:00 2001 From: "joseenrique.garcia" Date: Mon, 9 Sep 2024 13:58:31 +0200 Subject: [PATCH 10/26] Fix OpenApi generator --- .../plugin/asyncapi/AsyncApiGenerator.java | 87 +---- .../template/ClasspathTemplateLoader.java | 29 +- .../asyncapi/template/TemplateFactory.java | 288 ++++------------- .../template/TemplateIndexConstants.java | 66 +--- .../template/CommonTemplateFactory.java | 300 ++++++++++++++++++ .../CommonTemplateIndexConstants.java | 69 ++++ .../common/template/CommonTemplateLoader.java | 34 ++ .../plugin/openapi/OpenApiGenerator.java | 58 +--- .../template/ClasspathTemplateLoader.java | 23 +- .../openapi/template/TemplateFactory.java | 92 ++---- .../template/TemplateIndexConstants.java | 48 +-- .../templates/model/templateSchema.ftlh | 2 +- .../AsyncApiGeneratorJakartaTest.java | 2 +- .../asyncapi/AsyncApiGeneratorTest.java | 2 +- .../openapi/OpenApiGeneratorFixtures.java | 4 +- .../customvalidator/jakarta/MaxValidator.java | 24 -- .../customvalidator/jakarta/MinValidator.java | 24 -- .../assets/testApi/ApiErrorDTO.java | 34 +- .../assets/testApi/ApiTestAllOfDTO.java | 1 + .../assets/testApi/ApiTestDTO.java | 1 + .../jakarta/{Max.java => MaxInteger.java} | 7 +- ...alidator.java => MaxIntegerValidator.java} | 4 +- .../customvalidator/jakarta/MaxItems.java | 3 +- .../jakarta/{Min.java => MinInteger.java} | 7 +- ...alidator.java => MinIntegerValidator.java} | 4 +- .../customvalidator/jakarta/MinItems.java | 3 +- .../customvalidator/jakarta/MultipleOf.java | 3 +- .../customvalidator/jakarta/NotNull.java | 3 +- .../customvalidator/jakarta/Pattern.java | 3 +- .../customvalidator/jakarta/Size.java | 3 +- .../customvalidator/jakarta/UniqueItems.java | 3 +- .../javax/{Max.java => MaxInteger.java} | 7 +- ...alidator.java => MaxIntegerValidator.java} | 4 +- .../customvalidator/javax/MaxItems.java | 3 +- .../javax/{Min.java => MinInteger.java} | 7 +- ...alidator.java => MinIntegerValidator.java} | 4 +- .../customvalidator/javax/MinItems.java | 3 +- .../customvalidator/javax/MultipleOf.java | 3 +- .../customvalidator/javax/NotNull.java | 3 +- .../customvalidator/javax/Pattern.java | 3 +- .../customvalidator/javax/Size.java | 3 +- .../customvalidator/javax/UniqueItems.java | 3 +- .../api/generator/plugin/OpenAsyncMojo.java | 2 +- 43 files changed, 585 insertions(+), 691 deletions(-) create mode 100644 multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/template/CommonTemplateFactory.java create mode 100644 multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/template/CommonTemplateIndexConstants.java create mode 100644 multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/template/CommonTemplateLoader.java delete mode 100644 multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/jakarta/MaxValidator.java delete mode 100644 multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/jakarta/MinValidator.java rename multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/{Max.java => MaxInteger.java} (80%) rename multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/{MaxValidator.java => MaxIntegerValidator.java} (82%) rename multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/{Min.java => MinInteger.java} (80%) rename multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/{MinValidator.java => MinIntegerValidator.java} (82%) rename multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/javax/{Max.java => MaxInteger.java} (80%) rename multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/javax/{MaxValidator.java => MaxIntegerValidator.java} (82%) rename multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/javax/{Min.java => MinInteger.java} (80%) rename multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/javax/{MinValidator.java => MinIntegerValidator.java} (82%) 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 63ac6fc6..39181a7b 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 @@ -45,8 +45,12 @@ @Slf4j public class AsyncApiGenerator { + private static final String PACKAGE_SEPARATOR_STR = "."; + private static final String SLASH = "/"; + public static final Pattern PACKAGE_SEPARATOR = Pattern.compile(PACKAGE_SEPARATOR_STR); + private static final String DEFAULT_ASYNCAPI_API_PACKAGE = PluginConstants.DEFAULT_API_PACKAGE + ".asyncapi"; private static final String DEFAULT_ASYNCAPI_MODEL_PACKAGE = DEFAULT_ASYNCAPI_API_PACKAGE + ".model"; @@ -63,10 +67,6 @@ public class AsyncApiGenerator { private static final String OPERATION_ID = "operationId"; - private static final String PACKAGE_SEPARATOR_STR = "."; - - public static final Pattern PACKAGE_SEPARATOR = Pattern.compile(PACKAGE_SEPARATOR_STR); - private static final String AVSC = "avsc"; private static final String PAYLOAD = "payload"; @@ -95,29 +95,25 @@ public class AsyncApiGenerator { private final List processedApiPackages = new ArrayList<>(); - private final File targetFolder; - private final File baseDir; - private final FilenameFilter targetFileFilter; - private final TemplateFactory templateFactory; - private final String processedGeneratedSourcesFolder; - private final String groupId; private final Integer springBootVersion; private boolean generateExceptionTemplate; - public AsyncApiGenerator(final Integer springBootVersion, final File targetFolder, final String processedGeneratedSourcesFolder, final String groupId, final File baseDir) { + public AsyncApiGenerator(final Integer springBootVersion, + final File targetFolder, + final String processedGeneratedSourcesFolder, + final String groupId, + final File baseDir, + boolean overwriteModel) { this.groupId = groupId; - this.processedGeneratedSourcesFolder = processedGeneratedSourcesFolder; - this.targetFolder = targetFolder; this.baseDir = baseDir; - this.templateFactory = new TemplateFactory(); - this.targetFileFilter = (dir, name) -> name.toLowerCase().contains(targetFolder.toPath().getFileName().toString()); + this.templateFactory = new TemplateFactory(overwriteModel, targetFolder, processedGeneratedSourcesFolder, baseDir); this.springBootVersion = springBootVersion; } @@ -312,26 +308,13 @@ private String getOperationId(final JsonNode channel) { private void setUpTemplate(final SpecFile fileParameter, final Integer springBootVersion) { processPackage(fileParameter); - processFilePaths(fileParameter); + templateFactory.processFilePaths(fileParameter, DEFAULT_ASYNCAPI_API_PACKAGE); processClassNames(fileParameter); processEntitiesSuffix(fileParameter); processJavaEEPackage(springBootVersion); } - private void processFilePaths(final SpecFile fileParameter) { - var pathToCreate = convertPackageToTargetPath(fileParameter.getSupplier()); - if (Objects.nonNull(pathToCreate)) { - templateFactory.setSupplierFilePath(processPath(pathToCreate)); - } - pathToCreate = convertPackageToTargetPath(fileParameter.getStreamBridge()); - if (Objects.nonNull(pathToCreate)) { - templateFactory.setStreamBridgeFilePath(processPath(pathToCreate)); - } - pathToCreate = convertPackageToTargetPath(fileParameter.getConsumer()); - if (Objects.nonNull(pathToCreate)) { - templateFactory.setSubscribeFilePath(processPath(pathToCreate)); - } - } + private void processEntitiesSuffix(final SpecFile fileParameter) { templateFactory.setSupplierEntitiesSuffix(fileParameter.getSupplier() != null && fileParameter.getSupplier().getModelNameSuffix() != null @@ -364,40 +347,6 @@ private void processClassNames(final SpecFile fileParameter) { ? fileParameter.getConsumer().getClassNamePostfix() : CONSUMER_CLASS_NAME); } - private Path processPath(final String packagePath) { - Path path; - final File[] pathList = Objects.requireNonNull(baseDir.listFiles(targetFileFilter)); - if (pathList.length > 0) { - path = pathList[0].toPath().resolve(packagePath); - } else { - path = targetFolder.toPath(); - if (!path.toFile().exists() && !path.toFile().mkdirs()) { - throw new FileSystemException(path.toFile().getName()); - } - path = path.resolve(packagePath); - } - if (!path.toFile().isDirectory() && !path.toFile().mkdirs()) { - throw new FileSystemException(path.toFile().getName()); - } - return path; - } - - private String convertPackageToTargetPath(final OperationParameterObject operationParameter) { - String path = null; - if (Objects.nonNull(operationParameter)) { - if (Objects.nonNull(operationParameter.getApiPackage())) { - path = getPath(operationParameter.getApiPackage()); - } else { - path = getPath(DEFAULT_ASYNCAPI_API_PACKAGE); - } - } - return path; - } - - private String getPath(final String pathName) { - return processedGeneratedSourcesFolder + pathName.replace(PACKAGE_SEPARATOR_STR, SLASH); - } - private void processJavaEEPackage(final Integer springBootVersion) { templateFactory.calculateJavaEEPackage(springBootVersion); } @@ -465,11 +414,10 @@ private void fillTemplateFactory( MapperContentUtil.mapComponentToSchemaObject(totalSchemas, className, schemaToBuild, parentPackage, operationObject, this.baseDir.toPath()).iterator(); if (schemaObjectIt.hasNext()) { - final var filePath = writeSchemaObject(operationObject.isUseLombokModelAnnotation(), operationObject.getModelPackage(), keyClassName, schemaObjectIt.next()); + writeSchemaObject(operationObject.isUseLombokModelAnnotation(), operationObject.getModelPackage(), keyClassName, schemaObjectIt.next()); if (Objects.nonNull(keyClassName)) { templateFactory.setWrapperPackageName(operationObject.getApiPackage()); - templateFactory.fillTemplateWrapper(processPath(getPath(operationObject.getApiPackage())), - operationObject.getApiPackage(), classFullName, className, keyClassFullName, keyClassName); + templateFactory.fillTemplateWrapper(operationObject.getApiPackage(), classFullName, className, keyClassFullName, keyClassName); } schemaObjectIt.forEachRemaining(schemaObj -> writeSchemaObject(operationObject.isUseLombokModelAnnotation(), operationObject.getModelPackage(), null, schemaObj)); @@ -493,9 +441,8 @@ private boolean shouldBuild(final JsonNode schemaToBuild) { } private Path writeSchemaObject(final boolean usingLombok, final String modelPackageReceived, final String keyClassName, final SchemaObject schemaObject) { - final var filePath = processPath(getPath(StringUtils.defaultIfEmpty(modelPackageReceived, DEFAULT_ASYNCAPI_API_PACKAGE + SLASH + schemaObject.getParentPackage()))); - final var propertiesPath = processPath(getPath(modelPackageReceived)); - templateFactory.addSchemaObject(modelPackageReceived, keyClassName, schemaObject, filePath, propertiesPath); + final var destinationPackage = StringUtils.defaultIfEmpty(modelPackageReceived, DEFAULT_ASYNCAPI_API_PACKAGE + SLASH + schemaObject.getParentPackage()); + templateFactory.addSchemaObject(modelPackageReceived, keyClassName, schemaObject, destinationPackage); checkRequiredOrCombinatorExists(schemaObject, usingLombok); return filePath; } diff --git a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/asyncapi/template/ClasspathTemplateLoader.java b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/asyncapi/template/ClasspathTemplateLoader.java index 14019dec..5f905731 100644 --- a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/asyncapi/template/ClasspathTemplateLoader.java +++ b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/asyncapi/template/ClasspathTemplateLoader.java @@ -15,13 +15,10 @@ import java.util.Map; import java.util.Objects; +import com.sngular.api.generator.plugin.common.template.CommonTemplateLoader; import com.sngular.api.generator.plugin.exception.GeneratorTemplateException; -import freemarker.cache.TemplateLoader; -public class ClasspathTemplateLoader implements TemplateLoader { - - private static final List TEMPLATE_MODEL_FILES = List.of( "templateSchema.ftlh", - "templateSchemaWithLombok.ftlh", "templateModelClassException.ftlh"); +public class ClasspathTemplateLoader extends CommonTemplateLoader { private static final List TEMPLATE_FILES = List.of("templateSuppliers.ftlh", "interfaceConsumer.ftlh", "templateConsumers.ftlh", @@ -30,28 +27,6 @@ public class ClasspathTemplateLoader implements TemplateLoader { "interfaceConsumerWithKafkaBindings.ftlh", "templateConsumersWithKafkaBindings.ftlh", "templateStreamBridgeWithKafkaBindings.ftlh", "templateMessageWrapper.ftlh"); - private static final List TEMPLATE_ANNOTATION_FILES = List.of(TemplateIndexConstants.TEMPLATE_NOT_NULL_ANNOTATION, - TemplateIndexConstants.TEMPLATE_NOT_NULL_VALIDATOR_ANNOTATION, - TemplateIndexConstants.TEMPLATE_MAX_INTEGER_ANNOTATION, TemplateIndexConstants.TEMPLATE_MAX_INTEGER_VALIDATOR_ANNOTATION, - TemplateIndexConstants.TEMPLATE_MAX_BIG_DECIMAL_ANNOTATION, TemplateIndexConstants.TEMPLATE_MAX_BIG_DECIMAL_VALIDATOR_ANNOTATION, - TemplateIndexConstants.TEMPLATE_MAX_DOUBLE_ANNOTATION, TemplateIndexConstants.TEMPLATE_MAX_DOUBLE_VALIDATOR_ANNOTATION, - TemplateIndexConstants.TEMPLATE_MAX_FLOAT_ANNOTATION, TemplateIndexConstants.TEMPLATE_MAX_FLOAT_VALIDATOR_ANNOTATION, - TemplateIndexConstants.TEMPLATE_MIN_INTEGER_ANNOTATION, TemplateIndexConstants.TEMPLATE_MIN_INTEGER_VALIDATOR_ANNOTATION, - TemplateIndexConstants.TEMPLATE_MIN_DOUBLE_ANNOTATION, TemplateIndexConstants.TEMPLATE_MIN_DOUBLE_VALIDATOR_ANNOTATION, - TemplateIndexConstants.TEMPLATE_MIN_FLOAT_ANNOTATION, TemplateIndexConstants.TEMPLATE_MIN_FLOAT_VALIDATOR_ANNOTATION, - TemplateIndexConstants.TEMPLATE_MIN_BIG_DECIMAL_ANNOTATION, TemplateIndexConstants.TEMPLATE_MIN_BIG_DECIMAL_VALIDATOR_ANNOTATION, - TemplateIndexConstants.TEMPLATE_SIZE_ANNOTATION, TemplateIndexConstants.TEMPLATE_SIZE_VALIDATOR_ANNOTATION, - TemplateIndexConstants.TEMPLATE_PATTERN_ANNOTATION, - TemplateIndexConstants.TEMPLATE_PATTERN_VALIDATOR_ANNOTATION, - TemplateIndexConstants.TEMPLATE_MULTIPLEOF_ANNOTATION, - TemplateIndexConstants.TEMPLATE_MULTIPLEOF_VALIDATOR_ANNOTATION, - TemplateIndexConstants.TEMPLATE_MAX_ITEMS_ANNOTATION, - TemplateIndexConstants.TEMPLATE_MAX_ITEMS_VALIDATOR_ANNOTATION, - TemplateIndexConstants.TEMPLATE_MIN_ITEMS_ANNOTATION, - TemplateIndexConstants.TEMPLATE_MIN_ITEMS_VALIDATOR_ANNOTATION, - TemplateIndexConstants.TEMPLATE_UNIQUE_ITEMS_ANNOTATION, - TemplateIndexConstants.TEMPLATE_UNIQUE_ITEMS_VALIDATOR_ANNOTATION); - private static final ClassLoader LOADER = ClasspathTemplateLoader.class.getClassLoader(); private final Map templatesMap = new HashMap<>(); 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 63facba8..a39f3ef0 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 @@ -7,7 +7,7 @@ package com.sngular.api.generator.plugin.asyncapi.template; import java.io.File; -import java.io.FileWriter; +import java.io.FilenameFilter; import java.io.IOException; import java.nio.file.Path; import java.nio.file.Paths; @@ -19,20 +19,23 @@ import java.util.Map; import java.util.Objects; import java.util.Set; +import java.util.regex.Pattern; 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; +import com.sngular.api.generator.plugin.asyncapi.parameter.OperationParameterObject; +import com.sngular.api.generator.plugin.asyncapi.parameter.SpecFile; import com.sngular.api.generator.plugin.asyncapi.util.BindingTypeEnum; import com.sngular.api.generator.plugin.common.model.SchemaFieldObject; import com.sngular.api.generator.plugin.common.model.SchemaObject; +import com.sngular.api.generator.plugin.common.template.CommonTemplateFactory; import com.sngular.api.generator.plugin.common.tools.MapperUtil; import freemarker.template.Configuration; -import freemarker.template.Template; import freemarker.template.TemplateException; import freemarker.template.TemplateExceptionHandler; -public class TemplateFactory { +public class TemplateFactory extends CommonTemplateFactory { private static final String SUBSCRIBE_PACKAGE = "subscribePackage"; @@ -48,22 +51,12 @@ public class TemplateFactory { private static final String SUBSCRIBE_ENTITIES_SUFFIX = "subscribeEntitiesSuffix"; - private static final String FILE_TYPE_JAVA = ".java"; - - private static final String EXCEPTION_PACKAGE = "exceptionPackage"; - - private final Configuration cfg = new Configuration(Configuration.VERSION_2_3_32); - - private final Map root = new HashMap<>(); - private final List publishMethods = new ArrayList<>(); private final List subscribeMethods = new ArrayList<>(); private final List streamBridgeMethods = new ArrayList<>(); - private final List schemaObjectMap = new LinkedList<>(); - private String subscribeFilePath = null; private String supplierFilePath = null; @@ -76,212 +69,63 @@ public class TemplateFactory { private String subscribeClassName = null; - public TemplateFactory() { - cfg.setTemplateLoader(new ClasspathTemplateLoader()); - cfg.setDefaultEncoding("UTF-8"); - cfg.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER); - cfg.setLogTemplateExceptions(true); - cfg.setAPIBuiltinEnabled(true); - + public TemplateFactory(boolean enableOverwrite, + final File targetFolder, + final String processedGeneratedSourcesFolder, + final File baseDir) { + super(enableOverwrite, targetFolder, processedGeneratedSourcesFolder, baseDir); } - private void fillTemplate(final String filePathToSave, final String className, final String templateName, final Map root) throws IOException, TemplateException { - final File fileToSave = Paths.get(filePathToSave).normalize().toFile(); - fileToSave.mkdirs(); - final String pathToSaveMainClass = fileToSave.toPath().resolve(className + FILE_TYPE_JAVA).toString(); - fillTemplate(pathToSaveMainClass, templateName, root); - } - - private void fillTemplate(final String pathToSaveMainClass, final String templateName, final Map root) throws IOException, TemplateException { - writeTemplateToFile(templateName, root, pathToSaveMainClass); - } - - public final void fillTemplates(final boolean generateExceptionTemplate) throws IOException, TemplateException { - root.put("publishMethods", publishMethods); - root.put("subscribeMethods", subscribeMethods); - root.put("streamBridgeMethods", streamBridgeMethods); + public final void fillTemplates(boolean generateExceptionTemplate) throws IOException, TemplateException { + addToRoot("publishMethods", publishMethods); + addToRoot("subscribeMethods", subscribeMethods); + addToRoot("streamBridgeMethods", streamBridgeMethods); for (final var method : publishMethods) { - fillTemplate(supplierFilePath, supplierClassName, checkTemplate(method.getBindingType(), TemplateIndexConstants.TEMPLATE_API_SUPPLIERS), root); + fillTemplate(supplierFilePath, supplierClassName, checkTemplate(method.getBindingType(), TemplateIndexConstants.TEMPLATE_API_SUPPLIERS)); } for (final var method : subscribeMethods) { - fillTemplate(subscribeFilePath, subscribeClassName, checkTemplate(method.getBindingType(), TemplateIndexConstants.TEMPLATE_API_CONSUMERS), root); + fillTemplate(subscribeFilePath, subscribeClassName, checkTemplate(method.getBindingType(), TemplateIndexConstants.TEMPLATE_API_CONSUMERS)); } for (final var method : streamBridgeMethods) { - fillTemplate(streamBridgeFilePath, streamBridgeClassName, checkTemplate(method.getBindingType(), TemplateIndexConstants.TEMPLATE_API_STREAM_BRIDGE), root); + fillTemplate(streamBridgeFilePath, streamBridgeClassName, checkTemplate(method.getBindingType(), TemplateIndexConstants.TEMPLATE_API_STREAM_BRIDGE)); } - final String exceptionPackage; - if (Boolean.TRUE.equals(generateExceptionTemplate)) { - exceptionPackage = getClassTemplate().getModelPackage(); - } else { - exceptionPackage = null; - } - - schemaObjectMap.forEach(classTemplate -> { - try { - fillTemplates(classTemplate.getPropertiesPath(), classTemplate.getModelPackage(), - fillTemplateSchema(classTemplate, false, exceptionPackage)); - } catch (final IOException | TemplateException exception) { - throw new FileSystemException(exception); - } - }); + generateTemplates(generateExceptionTemplate); this.generateInterfaces(); } - @SuppressWarnings("checkstyle:CyclomaticComplexity") - private void fillTemplates(final Path filePathToSave, final String modelPackage, final Set fieldProperties) throws TemplateException, IOException { - for (final String current : fieldProperties) { - switch (current) { - case "Size": - fillTemplateCustom(filePathToSave, modelPackage, "Size.java", TemplateIndexConstants.TEMPLATE_SIZE_ANNOTATION, "SizeValidator.java", - TemplateIndexConstants.TEMPLATE_SIZE_VALIDATOR_ANNOTATION); - break; - case "Pattern": - fillTemplateCustom(filePathToSave, modelPackage, "Pattern.java", TemplateIndexConstants.TEMPLATE_PATTERN_ANNOTATION, - "PatternValidator.java", TemplateIndexConstants.TEMPLATE_PATTERN_VALIDATOR_ANNOTATION); - break; - case "MultipleOf": - fillTemplateCustom(filePathToSave, modelPackage, "MultipleOf.java", TemplateIndexConstants.TEMPLATE_MULTIPLEOF_ANNOTATION, - "MultipleOfValidator.java", TemplateIndexConstants.TEMPLATE_MULTIPLEOF_VALIDATOR_ANNOTATION); - break; - case "Maximum": - fillTemplateCustom(filePathToSave, modelPackage, "MaxInteger.java", TemplateIndexConstants.TEMPLATE_MAX_INTEGER_ANNOTATION, - "MaxIntegerValidator.java", TemplateIndexConstants.TEMPLATE_MAX_INTEGER_VALIDATOR_ANNOTATION); - fillTemplateCustom(filePathToSave, modelPackage, "MaxBigDecimal.java", TemplateIndexConstants.TEMPLATE_MAX_BIG_DECIMAL_ANNOTATION, - "MaxBigDecimalValidator.java", TemplateIndexConstants.TEMPLATE_MAX_BIG_DECIMAL_VALIDATOR_ANNOTATION); - fillTemplateCustom(filePathToSave, modelPackage, "MaxDouble.java", TemplateIndexConstants.TEMPLATE_MAX_DOUBLE_ANNOTATION, - "MaxDoubleValidator.java", TemplateIndexConstants.TEMPLATE_MAX_DOUBLE_VALIDATOR_ANNOTATION); - fillTemplateCustom(filePathToSave, modelPackage, "MaxFloat.java", TemplateIndexConstants.TEMPLATE_MAX_FLOAT_ANNOTATION, - "MaxFloatValidator.java", TemplateIndexConstants.TEMPLATE_MAX_FLOAT_VALIDATOR_ANNOTATION); - break; - case "Minimum": - fillTemplateCustom(filePathToSave, modelPackage, "MinInteger.java", TemplateIndexConstants.TEMPLATE_MIN_INTEGER_ANNOTATION, - "MinIntegerValidator.java", TemplateIndexConstants.TEMPLATE_MIN_INTEGER_VALIDATOR_ANNOTATION); - fillTemplateCustom(filePathToSave, modelPackage, "MinDouble.java", TemplateIndexConstants.TEMPLATE_MIN_DOUBLE_ANNOTATION, - "MinDoubleValidator.java", TemplateIndexConstants.TEMPLATE_MIN_DOUBLE_VALIDATOR_ANNOTATION); - fillTemplateCustom(filePathToSave, modelPackage, "MinFloat.java", TemplateIndexConstants.TEMPLATE_MIN_FLOAT_ANNOTATION, - "MinFloatValidator.java", TemplateIndexConstants.TEMPLATE_MIN_FLOAT_VALIDATOR_ANNOTATION); - fillTemplateCustom(filePathToSave, modelPackage, "MinBigDecimal.java", TemplateIndexConstants.TEMPLATE_MIN_BIG_DECIMAL_ANNOTATION, - "MinBigDecimalValidator.java", TemplateIndexConstants.TEMPLATE_MIN_BIG_DECIMAL_VALIDATOR_ANNOTATION); - break; - case "MaxItems": - fillTemplateCustom(filePathToSave, modelPackage, "MaxItems.java", TemplateIndexConstants.TEMPLATE_MAX_ITEMS_ANNOTATION, - "MaxItemsValidator.java", TemplateIndexConstants.TEMPLATE_MAX_ITEMS_VALIDATOR_ANNOTATION); - break; - case "MinItems": - fillTemplateCustom(filePathToSave, modelPackage, "MinItems.java", TemplateIndexConstants.TEMPLATE_MIN_ITEMS_ANNOTATION, - "MinItemsValidator.java", TemplateIndexConstants.TEMPLATE_MIN_ITEMS_VALIDATOR_ANNOTATION); - break; - case "NotNull": - fillTemplateCustom(filePathToSave, modelPackage, "NotNull.java", TemplateIndexConstants.TEMPLATE_NOT_NULL_ANNOTATION, - "NotNullValidator.java", TemplateIndexConstants.TEMPLATE_NOT_NULL_VALIDATOR_ANNOTATION); - break; - case "UniqueItems": - fillTemplateCustom(filePathToSave, modelPackage, "UniqueItems.java", TemplateIndexConstants.TEMPLATE_UNIQUE_ITEMS_ANNOTATION, - "UniqueItemsValidator.java", TemplateIndexConstants.TEMPLATE_UNIQUE_ITEMS_VALIDATOR_ANNOTATION); - break; - default: - break; - } - } - } - - private ClassTemplate getClassTemplate() { - ClassTemplate ourClassTemplate = null; - for (ClassTemplate classTemplate : schemaObjectMap) { - if (classTemplate.getFilePath().endsWith("schemas")) { - ourClassTemplate = classTemplate; - break; - } - } - if (ourClassTemplate == null) { - ourClassTemplate = schemaObjectMap.get(0); - } - - return ourClassTemplate; - } - - public final void fillTemplateModelClassException(final Path filePathToSave, final String modelPackage) throws IOException, TemplateException { - final Path pathToExceptionPackage = filePathToSave.resolve("exception"); - pathToExceptionPackage.toFile().mkdirs(); - root.put(EXCEPTION_PACKAGE, modelPackage); - final String pathToSaveMainClass = pathToExceptionPackage.resolve("ModelClassException.java").toString(); - writeTemplateToFile(TemplateIndexConstants.TEMPLATE_MODEL_EXCEPTION, root, pathToSaveMainClass); - } - - public final void fillTemplateCustom( - final Path filePathToSave, final String modelPackage, final String fileNameAnnotation, final String templateAnnotation, - final String fileNameValidator, final String templateValidator) throws TemplateException, IOException { - final Path pathToCustomValidatorPackage = filePathToSave.resolve("customvalidator"); - pathToCustomValidatorPackage.toFile().mkdirs(); - root.put("packageModel", modelPackage); - final String pathToSaveAnnotationClass = pathToCustomValidatorPackage.resolve(fileNameAnnotation).toString(); - writeTemplateToFile(templateAnnotation, root, pathToSaveAnnotationClass); - final String pathToSaveValidatorClass = pathToCustomValidatorPackage.resolve(fileNameValidator).toString(); - writeTemplateToFile(templateValidator, root, pathToSaveValidatorClass); - } - - @SuppressWarnings("checkstyle:CyclomaticComplexity") - private Set fillTemplateSchema(final ClassTemplate classTemplate, final Boolean useLombok, final String exceptionPackage) - throws IOException, TemplateException { - final var propertiesSet = new HashSet(); - final var schemaObject = classTemplate.getClassSchema(); - final var filePath = classTemplate.getFilePath(); - if (Objects.nonNull(schemaObject) && Objects.nonNull(schemaObject.getFieldObjectList()) && !schemaObject.getFieldObjectList().isEmpty()) { - final Map rootSchema = new HashMap<>(); - rootSchema.put("schema", schemaObject); - root.put("schema", schemaObject); - final String templateName = null != useLombok && useLombok ? TemplateIndexConstants.TEMPLATE_CONTENT_SCHEMA_LOMBOK : TemplateIndexConstants.TEMPLATE_CONTENT_SCHEMA; - if (Objects.nonNull(classTemplate.getModelPackage())) { - rootSchema.put("packageModel", classTemplate.getModelPackage()); - } - if (Objects.nonNull(exceptionPackage)) { - rootSchema.put(EXCEPTION_PACKAGE, exceptionPackage); - root.put(EXCEPTION_PACKAGE, exceptionPackage); - } - fillTemplate(filePath.toString(), schemaObject.getClassName(), templateName, rootSchema); - for (SchemaFieldObject fieldObject : schemaObject.getFieldObjectList()) { - propertiesSet.addAll(fieldObject.getRestrictions().getProperties()); - if (fieldObject.isRequired() && Boolean.FALSE.equals(useLombok)) { - propertiesSet.add("NotNull"); - } - } - } - return propertiesSet; - } - public final void setSubscribePackageName(final String packageName) { - root.put(SUBSCRIBE_PACKAGE, packageName); + addToRoot(SUBSCRIBE_PACKAGE, packageName); } public final void setWrapperPackageName(final String packageName) { - root.put(WRAPPER_PACKAGE, packageName); + addToRoot(WRAPPER_PACKAGE, packageName); } public final void setSupplierPackageName(final String packageName) { - root.put(SUPPLIER_PACKAGE, packageName); + addToRoot(SUPPLIER_PACKAGE, packageName); } public final void setStreamBridgePackageName(final String packageName) { - root.put(STREAM_BRIDGE_PACKAGE, packageName); + addToRoot(STREAM_BRIDGE_PACKAGE, packageName); } public final void setSubscribeClassName(final String className) { - root.put("subscribeClassName", className); + addToRoot("subscribeClassName", className); this.subscribeClassName = className; } public final void setSupplierClassName(final String className) { - root.put("supplierClassName", className); + addToRoot("supplierClassName", className); this.supplierClassName = className; } public final void setStreamBridgeClassName(final String className) { - root.put("streamBridgeClassName", className); + addToRoot("streamBridgeClassName", className); this.streamBridgeClassName = className; } @@ -331,40 +175,30 @@ public final void addSubscribeMethod(final String operationId, final String clas .build()); } - public final void addSchemaObject(final String modelPackage, final String keyClassName, final SchemaObject schemaObject, final Path filePath, final Path propertiesPath) { - final var builder = ClassTemplate.builder().filePath(filePath).modelPackage(modelPackage).className(schemaObject.getClassName()).classSchema(schemaObject) - .propertiesPath(propertiesPath); - if (Objects.nonNull(keyClassName)) { - builder.keyClassName(keyClassName); - } - schemaObjectMap.add(builder.build()); - } - public final void setSupplierEntitiesSuffix(final String suffix) { - root.put(SUPPLIER_ENTITIES_SUFFIX, suffix); + addToRoot(SUPPLIER_ENTITIES_SUFFIX, suffix); } public final void setStreamBridgeEntitiesSuffix(final String suffix) { - root.put(STREAM_BRIDGE_ENTITIES_SUFFIX, suffix); + addToRoot(STREAM_BRIDGE_ENTITIES_SUFFIX, suffix); } public final void setSubscribeEntitiesSuffix(final String suffix) { - root.put(SUBSCRIBE_ENTITIES_SUFFIX, suffix); + addToRoot(SUBSCRIBE_ENTITIES_SUFFIX, suffix); } public final void calculateJavaEEPackage(final Integer springBootVersion) { if (3 <= springBootVersion) { - root.put("javaEEPackage", "jakarta"); + addToRoot("javaEEPackage", "jakarta"); } else { - root.put("javaEEPackage", "javax"); + addToRoot("javaEEPackage", "javax"); } } public final void clearData() { - root.clear(); + cleanData(); publishMethods.clear(); subscribeMethods.clear(); - schemaObjectMap.clear(); streamBridgeMethods.clear(); subscribeFilePath = null; supplierFilePath = null; @@ -375,52 +209,58 @@ public final void clearData() { } public final void fillTemplateWrapper( - final Path filePath, final String modelPackage, final String classFullName, final String className, final String keyClassFullName, final String keyClassName - ) throws TemplateException, IOException { - final Map context = Map.of(WRAPPER_PACKAGE, modelPackage, - "classNamespace", classFullName, - "className", className, - "keyNamespace", keyClassFullName, - "keyClassName", keyClassName); - - writeTemplateToFile(TemplateIndexConstants.TEMPLATE_MESSAGE_WRAPPER, context, filePath.resolve("MessageWrapper.java").toAbsolutePath().toString()); + ) throws IOException { + final var filePath = processPath(getPath(modelPackage)); + addToRoot(Map.of(WRAPPER_PACKAGE, modelPackage, + "classNamespace", classFullName, + "className", className, + "keyNamespace", keyClassFullName, + "keyClassName", keyClassName)); + writeTemplateToFile(TemplateIndexConstants.TEMPLATE_MESSAGE_WRAPPER, filePath.resolve("MessageWrapper.java").toAbsolutePath().toString()); + clearData(); + } + + public void processFilePaths(final SpecFile fileParameter, final String defaultApiPackage) { + var pathToCreate = convertPackageToTargetPath(fileParameter.getSupplier(), defaultApiPackage); + if (Objects.nonNull(pathToCreate)) { + setSupplierFilePath(processPath(pathToCreate)); + } + pathToCreate = convertPackageToTargetPath(fileParameter.getStreamBridge(), defaultApiPackage); + if (Objects.nonNull(pathToCreate)) { + setStreamBridgeFilePath(processPath(pathToCreate)); + } + pathToCreate = convertPackageToTargetPath(fileParameter.getConsumer(), defaultApiPackage); + if (Objects.nonNull(pathToCreate)) { + setSubscribeFilePath(processPath(pathToCreate)); + } } - private void generateInterfaces() throws IOException, TemplateException { final ArrayList allMethods = new ArrayList<>(subscribeMethods); allMethods.addAll(publishMethods); - final Map interfaceRoot = new HashMap<>(); - interfaceRoot.put(SUBSCRIBE_PACKAGE, root.get(SUBSCRIBE_PACKAGE)); - interfaceRoot.put(SUPPLIER_PACKAGE, root.get(SUPPLIER_PACKAGE)); + addToRoot(SUBSCRIBE_PACKAGE, getFromRoot(SUBSCRIBE_PACKAGE)); + addToRoot(SUPPLIER_PACKAGE, getFromRoot(SUPPLIER_PACKAGE)); - interfaceRoot.put(SUPPLIER_ENTITIES_SUFFIX, root.get(SUPPLIER_ENTITIES_SUFFIX)); - interfaceRoot.put(SUBSCRIBE_ENTITIES_SUFFIX, root.get(SUBSCRIBE_ENTITIES_SUFFIX)); + addToRoot(SUPPLIER_ENTITIES_SUFFIX, getFromRoot(SUPPLIER_ENTITIES_SUFFIX)); + addToRoot(SUBSCRIBE_ENTITIES_SUFFIX, getFromRoot(SUBSCRIBE_ENTITIES_SUFFIX)); for (MethodObject method : allMethods) { - interfaceRoot.put("method", method); + addToRoot("method", method); if (Objects.equals(method.getType(), "publish")) { fillTemplate(supplierFilePath, "I" + method.getOperationId().substring(0, 1).toUpperCase() + method.getOperationId().substring(1), - checkTemplate(method.getBindingType(), TemplateIndexConstants.TEMPLATE_INTERFACE_SUPPLIERS), interfaceRoot); + checkTemplate(method.getBindingType(), TemplateIndexConstants.TEMPLATE_INTERFACE_SUPPLIERS)); } else if (Objects.equals(method.getType(), "subscribe")) { fillTemplate(subscribeFilePath, "I" + method.getOperationId().substring(0, 1).toUpperCase() + method.getOperationId().substring(1), - checkTemplate(method.getBindingType(), TemplateIndexConstants.TEMPLATE_INTERFACE_CONSUMERS), interfaceRoot); + checkTemplate(method.getBindingType(), TemplateIndexConstants.TEMPLATE_INTERFACE_CONSUMERS)); } } - } - - private void writeTemplateToFile(final String templateName, final Map root, final String path) throws IOException, TemplateException { - final Template template = cfg.getTemplate(templateName); - - final FileWriter writer = new FileWriter(path); - template.process(root, writer); - writer.close(); + cleanData(); } private String checkTemplate(final String bindingType, final String defaultTemplate) { diff --git a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/asyncapi/template/TemplateIndexConstants.java b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/asyncapi/template/TemplateIndexConstants.java index 0212f10c..71f0dbec 100644 --- a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/asyncapi/template/TemplateIndexConstants.java +++ b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/asyncapi/template/TemplateIndexConstants.java @@ -6,13 +6,9 @@ package com.sngular.api.generator.plugin.asyncapi.template; -public class TemplateIndexConstants { +import com.sngular.api.generator.plugin.common.template.CommonTemplateIndexConstants; - public static final String TEMPLATE_CONTENT_SCHEMA = "templateSchema.ftlh"; - - public static final String TEMPLATE_CONTENT_SCHEMA_LOMBOK = "templateSchemaWithLombok.ftlh"; - - public static final String TEMPLATE_MODEL_EXCEPTION = "templateModelClassException.ftlh"; +public class TemplateIndexConstants extends CommonTemplateIndexConstants { public static final String TEMPLATE_API_SUPPLIERS = "templateSuppliers.ftlh"; @@ -26,64 +22,6 @@ public class TemplateIndexConstants { public static final String TEMPLATE_NOT_NULL_ANNOTATION = "templateNotNull.ftlh"; - public static final String TEMPLATE_NOT_NULL_VALIDATOR_ANNOTATION = "templateNotNullValidator.ftlh"; - - public static final String TEMPLATE_MIN_INTEGER_ANNOTATION = "templateMinInteger.ftlh"; - - public static final String TEMPLATE_MIN_INTEGER_VALIDATOR_ANNOTATION = "templateMinIntegerValidator.ftlh"; - - public static final String TEMPLATE_MIN_BIG_DECIMAL_ANNOTATION = "templateMinBigDecimal.ftlh"; - - public static final String TEMPLATE_MIN_BIG_DECIMAL_VALIDATOR_ANNOTATION = "templateMinBigDecimalValidator.ftlh"; - - public static final String TEMPLATE_MIN_DOUBLE_ANNOTATION = "templateMinDouble.ftlh"; - - public static final String TEMPLATE_MIN_DOUBLE_VALIDATOR_ANNOTATION = "templateMinDoubleValidator.ftlh"; - - public static final String TEMPLATE_MIN_FLOAT_ANNOTATION = "templateMinFloat.ftlh"; - - public static final String TEMPLATE_MIN_FLOAT_VALIDATOR_ANNOTATION = "templateMinFloatValidator.ftlh"; - - public static final String TEMPLATE_MAX_INTEGER_ANNOTATION = "templateMaxInteger.ftlh"; - - public static final String TEMPLATE_MAX_INTEGER_VALIDATOR_ANNOTATION = "templateMaxIntegerValidator.ftlh"; - - public static final String TEMPLATE_MAX_BIG_DECIMAL_ANNOTATION = "templateMaxBigDecimal.ftlh"; - - public static final String TEMPLATE_MAX_BIG_DECIMAL_VALIDATOR_ANNOTATION = "templateMaxBigDecimalValidator.ftlh"; - - public static final String TEMPLATE_MAX_DOUBLE_ANNOTATION = "templateMaxDouble.ftlh"; - - public static final String TEMPLATE_MAX_DOUBLE_VALIDATOR_ANNOTATION = "templateMaxDoubleValidator.ftlh"; - - public static final String TEMPLATE_MAX_FLOAT_ANNOTATION = "templateMaxFloat.ftlh"; - - public static final String TEMPLATE_MAX_FLOAT_VALIDATOR_ANNOTATION = "templateMaxFloatValidator.ftlh"; - - public static final String TEMPLATE_SIZE_ANNOTATION = "templateSize.ftlh"; - - public static final String TEMPLATE_SIZE_VALIDATOR_ANNOTATION = "templateSizeValidator.ftlh"; - - public static final String TEMPLATE_PATTERN_ANNOTATION = "templatePattern.ftlh"; - - public static final String TEMPLATE_PATTERN_VALIDATOR_ANNOTATION = "templatePatternValidator.ftlh"; - - public static final String TEMPLATE_MULTIPLEOF_ANNOTATION = "templateMultipleOf.ftlh"; - - public static final String TEMPLATE_MULTIPLEOF_VALIDATOR_ANNOTATION = "templateMultipleOfValidator.ftlh"; - - public static final String TEMPLATE_MAX_ITEMS_ANNOTATION = "templateMaxItems.ftlh"; - - public static final String TEMPLATE_MAX_ITEMS_VALIDATOR_ANNOTATION = "templateMaxItemsValidator.ftlh"; - - public static final String TEMPLATE_MIN_ITEMS_ANNOTATION = "templateMinItems.ftlh"; - - public static final String TEMPLATE_MIN_ITEMS_VALIDATOR_ANNOTATION = "templateMinItemsValidator.ftlh"; - - public static final String TEMPLATE_UNIQUE_ITEMS_ANNOTATION = "templateUniqueItems.ftlh"; - - public static final String TEMPLATE_UNIQUE_ITEMS_VALIDATOR_ANNOTATION = "templateUniqueItemsValidator.ftlh"; - public static final String TEMPLATE_MESSAGE_WRAPPER = "templateMessageWrapper.ftlh"; public static final String KAFKA_BINDINGS_FTLH = "WithKafkaBindings.ftlh"; diff --git a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/template/CommonTemplateFactory.java b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/template/CommonTemplateFactory.java new file mode 100644 index 00000000..259e9d6b --- /dev/null +++ b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/template/CommonTemplateFactory.java @@ -0,0 +1,300 @@ +package com.sngular.api.generator.plugin.common.template; + +import com.sngular.api.generator.plugin.asyncapi.exception.FileSystemException; +import com.sngular.api.generator.plugin.asyncapi.parameter.OperationParameterObject; +import com.sngular.api.generator.plugin.asyncapi.template.ClassTemplate; +import com.sngular.api.generator.plugin.asyncapi.template.ClasspathTemplateLoader; +import com.sngular.api.generator.plugin.asyncapi.template.TemplateIndexConstants; +import com.sngular.api.generator.plugin.common.model.SchemaFieldObject; +import com.sngular.api.generator.plugin.common.model.SchemaObject; +import com.sngular.api.generator.plugin.exception.GeneratorTemplateException; +import com.sngular.api.generator.plugin.openapi.exception.OverwritingApiFilesException; +import freemarker.template.Configuration; +import freemarker.template.Template; +import freemarker.template.TemplateException; +import freemarker.template.TemplateExceptionHandler; +import org.apache.commons.lang3.StringUtils; + +import java.io.File; +import java.io.FileWriter; +import java.io.FilenameFilter; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.*; + +public abstract class CommonTemplateFactory { + + private final static List BASIC_DATA_TYPES = List.of("Integer", "Long", "Float", "Double", "Boolean", "String", "Char", "Byte", "Short"); + + private static final String EXCEPTION_PACKAGE = "exceptionPackage"; + + private static final String SLASH = "/"; + + private static final String PACKAGE_SEPARATOR_STR = "."; + + private static final String FILE_TYPE_JAVA = ".java"; + + private final Configuration cfg = new Configuration(Configuration.VERSION_2_3_32); + + private final Map root = new HashMap<>(); + + private final List classTemplateList = new LinkedList<>(); + + private final boolean checkOverwrite; + + private File targetFolder; + + private String processedGeneratedSourcesFolder; + + private final FilenameFilter targetFileFilter; + + private final File baseDir; + + public CommonTemplateFactory(boolean checkOverwrite, + final File targetFolder, + final String processedGeneratedSourcesFolder, + final File baseDir) { + this.checkOverwrite = checkOverwrite; + cfg.setTemplateLoader(new ClasspathTemplateLoader()); + cfg.setDefaultEncoding("UTF-8"); + cfg.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER); + cfg.setLogTemplateExceptions(true); + cfg.setAPIBuiltinEnabled(true); + addToRoot("checkBasicTypes", BASIC_DATA_TYPES); + this.targetFolder = targetFolder; + this.targetFileFilter = (dir, name) -> name.toLowerCase().contains(targetFolder.toPath().getFileName().toString()); + this.processedGeneratedSourcesFolder = processedGeneratedSourcesFolder; + this.baseDir = baseDir; + } + + protected void generateTemplates(boolean generateExceptionTemplate) { + + final String exceptionPackage; + if (Boolean.TRUE.equals(generateExceptionTemplate)) { + exceptionPackage = getClassTemplate().getModelPackage(); + } else { + exceptionPackage = null; + } + + classTemplateList.forEach(classTemplate -> { + try { + fillTemplates(classTemplate.getPropertiesPath(), classTemplate.getModelPackage(), + fillTemplateSchema(classTemplate, false, exceptionPackage)); + } catch (final IOException | TemplateException exception) { + throw new FileSystemException(exception); + } + }); + } + + private ClassTemplate getClassTemplate() { + ClassTemplate ourClassTemplate = null; + for (ClassTemplate classTemplate : classTemplateList) { + if (classTemplate.getFilePath().endsWith("schemas")) { + ourClassTemplate = classTemplate; + break; + } + } + if (ourClassTemplate == null) { + ourClassTemplate = classTemplateList.get(0); + } + + return ourClassTemplate; + } + + protected void fillTemplate(final String filePathToSave, final String className, final String templateName) throws IOException, TemplateException { + final File fileToSave = Paths.get(filePathToSave).normalize().toFile(); + fileToSave.mkdirs(); + final String pathToSaveMainClass = fileToSave.toPath().resolve(className + FILE_TYPE_JAVA).toString(); + fillTemplate(pathToSaveMainClass, templateName); + } + + private void fillTemplate(final String pathToSaveMainClass, final String templateName) throws IOException, TemplateException { + writeTemplateToFile(templateName, pathToSaveMainClass); + } + + @SuppressWarnings("checkstyle:CyclomaticComplexity") + protected void fillTemplates(final Path filePathToSave, final String modelPackage, final Set fieldProperties) throws TemplateException, IOException { + for (final String current : fieldProperties) { + switch (current) { + case "Size": + fillTemplateCustom(filePathToSave, modelPackage, "Size.java", TemplateIndexConstants.TEMPLATE_SIZE_ANNOTATION, "SizeValidator.java", + TemplateIndexConstants.TEMPLATE_SIZE_VALIDATOR_ANNOTATION); + break; + case "Pattern": + fillTemplateCustom(filePathToSave, modelPackage, "Pattern.java", TemplateIndexConstants.TEMPLATE_PATTERN_ANNOTATION, + "PatternValidator.java", TemplateIndexConstants.TEMPLATE_PATTERN_VALIDATOR_ANNOTATION); + break; + case "MultipleOf": + fillTemplateCustom(filePathToSave, modelPackage, "MultipleOf.java", TemplateIndexConstants.TEMPLATE_MULTIPLEOF_ANNOTATION, + "MultipleOfValidator.java", TemplateIndexConstants.TEMPLATE_MULTIPLEOF_VALIDATOR_ANNOTATION); + break; + case "Maximum": + fillTemplateCustom(filePathToSave, modelPackage, "MaxInteger.java", TemplateIndexConstants.TEMPLATE_MAX_INTEGER_ANNOTATION, + "MaxIntegerValidator.java", TemplateIndexConstants.TEMPLATE_MAX_INTEGER_VALIDATOR_ANNOTATION); + fillTemplateCustom(filePathToSave, modelPackage, "MaxBigDecimal.java", TemplateIndexConstants.TEMPLATE_MAX_BIG_DECIMAL_ANNOTATION, + "MaxBigDecimalValidator.java", TemplateIndexConstants.TEMPLATE_MAX_BIG_DECIMAL_VALIDATOR_ANNOTATION); + fillTemplateCustom(filePathToSave, modelPackage, "MaxDouble.java", TemplateIndexConstants.TEMPLATE_MAX_DOUBLE_ANNOTATION, + "MaxDoubleValidator.java", TemplateIndexConstants.TEMPLATE_MAX_DOUBLE_VALIDATOR_ANNOTATION); + fillTemplateCustom(filePathToSave, modelPackage, "MaxFloat.java", TemplateIndexConstants.TEMPLATE_MAX_FLOAT_ANNOTATION, + "MaxFloatValidator.java", TemplateIndexConstants.TEMPLATE_MAX_FLOAT_VALIDATOR_ANNOTATION); + break; + case "Minimum": + fillTemplateCustom(filePathToSave, modelPackage, "MinInteger.java", TemplateIndexConstants.TEMPLATE_MIN_INTEGER_ANNOTATION, + "MinIntegerValidator.java", TemplateIndexConstants.TEMPLATE_MIN_INTEGER_VALIDATOR_ANNOTATION); + fillTemplateCustom(filePathToSave, modelPackage, "MinDouble.java", TemplateIndexConstants.TEMPLATE_MIN_DOUBLE_ANNOTATION, + "MinDoubleValidator.java", TemplateIndexConstants.TEMPLATE_MIN_DOUBLE_VALIDATOR_ANNOTATION); + fillTemplateCustom(filePathToSave, modelPackage, "MinFloat.java", TemplateIndexConstants.TEMPLATE_MIN_FLOAT_ANNOTATION, + "MinFloatValidator.java", TemplateIndexConstants.TEMPLATE_MIN_FLOAT_VALIDATOR_ANNOTATION); + fillTemplateCustom(filePathToSave, modelPackage, "MinBigDecimal.java", TemplateIndexConstants.TEMPLATE_MIN_BIG_DECIMAL_ANNOTATION, + "MinBigDecimalValidator.java", TemplateIndexConstants.TEMPLATE_MIN_BIG_DECIMAL_VALIDATOR_ANNOTATION); + break; + case "MaxItems": + fillTemplateCustom(filePathToSave, modelPackage, "MaxItems.java", TemplateIndexConstants.TEMPLATE_MAX_ITEMS_ANNOTATION, + "MaxItemsValidator.java", TemplateIndexConstants.TEMPLATE_MAX_ITEMS_VALIDATOR_ANNOTATION); + break; + case "MinItems": + fillTemplateCustom(filePathToSave, modelPackage, "MinItems.java", TemplateIndexConstants.TEMPLATE_MIN_ITEMS_ANNOTATION, + "MinItemsValidator.java", TemplateIndexConstants.TEMPLATE_MIN_ITEMS_VALIDATOR_ANNOTATION); + break; + case "NotNull": + fillTemplateCustom(filePathToSave, modelPackage, "NotNull.java", TemplateIndexConstants.TEMPLATE_NOT_NULL_ANNOTATION, + "NotNullValidator.java", TemplateIndexConstants.TEMPLATE_NOT_NULL_VALIDATOR_ANNOTATION); + break; + case "UniqueItems": + fillTemplateCustom(filePathToSave, modelPackage, "UniqueItems.java", TemplateIndexConstants.TEMPLATE_UNIQUE_ITEMS_ANNOTATION, + "UniqueItemsValidator.java", TemplateIndexConstants.TEMPLATE_UNIQUE_ITEMS_VALIDATOR_ANNOTATION); + break; + default: + break; + } + } + } + + @SuppressWarnings("checkstyle:CyclomaticComplexity") + private Set fillTemplateSchema(final ClassTemplate classTemplate, final Boolean useLombok, final String exceptionPackage) + throws IOException, TemplateException { + final var propertiesSet = new HashSet(); + final var schemaObject = classTemplate.getClassSchema(); + final var filePath = classTemplate.getFilePath(); + if (Objects.nonNull(schemaObject) && Objects.nonNull(schemaObject.getFieldObjectList()) && !schemaObject.getFieldObjectList().isEmpty()) { + addToRoot("schema", schemaObject); + final String templateName = null != useLombok && useLombok ? TemplateIndexConstants.TEMPLATE_CONTENT_SCHEMA_LOMBOK : TemplateIndexConstants.TEMPLATE_CONTENT_SCHEMA; + if (Objects.nonNull(classTemplate.getModelPackage())) { + addToRoot("packageModel", classTemplate.getModelPackage()); + } + if (Objects.nonNull(exceptionPackage)) { + addToRoot(EXCEPTION_PACKAGE, exceptionPackage); + } + fillTemplate(filePath.toString(), schemaObject.getClassName(), templateName); + for (SchemaFieldObject fieldObject : schemaObject.getFieldObjectList()) { + propertiesSet.addAll(fieldObject.getRestrictions().getProperties()); + if (fieldObject.isRequired() && Boolean.FALSE.equals(useLombok)) { + propertiesSet.add("NotNull"); + } + } + } + return propertiesSet; + } + + public final void fillTemplateModelClassException(final Path filePathToSave, final String modelPackage) throws IOException { + final Path pathToExceptionPackage = filePathToSave.resolve("exception"); + pathToExceptionPackage.toFile().mkdirs(); + addToRoot(EXCEPTION_PACKAGE, modelPackage); + final String pathToSaveMainClass = pathToExceptionPackage.resolve("ModelClassException.java").toString(); + writeTemplateToFile(TemplateIndexConstants.TEMPLATE_MODEL_EXCEPTION, pathToSaveMainClass); + } + + private void fillTemplateCustom( + final Path filePathToSave, final String modelPackage, final String fileNameAnnotation, final String templateAnnotation, + final String fileNameValidator, final String templateValidator) throws TemplateException, IOException { + final Path pathToCustomValidatorPackage = filePathToSave.resolve("customvalidator"); + pathToCustomValidatorPackage.toFile().mkdirs(); + root.put("packageModel", modelPackage); + final String pathToSaveAnnotationClass = pathToCustomValidatorPackage.resolve(fileNameAnnotation).toString(); + writeTemplateToFile(templateAnnotation, pathToSaveAnnotationClass); + final String pathToSaveValidatorClass = pathToCustomValidatorPackage.resolve(fileNameValidator).toString(); + writeTemplateToFile(templateValidator, pathToSaveValidatorClass); + } + + protected void addToRoot(final String key, final Object value) { + root.put(key, value); + } + + protected void addToRoot(final Map propertiesSet) { + root.putAll(propertiesSet); + } + + protected Object getFromRoot(final String key) { + return root.get(key); + } + + protected void cleanData() { + root.clear(); + classTemplateList.clear(); + } + + public final void addSchemaObject(final String modelPackage, + final String keyClassName, + final SchemaObject schemaObject, + final String destinationPackage) { + final var filePath = processPath(getPath(StringUtils.defaultIfEmpty(destinationPackage, DEFAULT_ASYNCAPI_API_PACKAGE + SLASH + schemaObject.getParentPackage()))); + final var propertiesPath = processPath(getPath(modelPackage)); + final var builder = ClassTemplate.builder().filePath(filePath).modelPackage(modelPackage).className(schemaObject.getClassName()).classSchema(schemaObject) + .propertiesPath(propertiesPath); + if (Objects.nonNull(keyClassName)) { + builder.keyClassName(keyClassName); + } + classTemplateList.add(builder.build()); + } + + protected void writeTemplateToFile(final String templateName, final String path) throws IOException { + final Template template = cfg.getTemplate(templateName); + + if (!Files.exists(Path.of(path)) || checkOverwrite) { + try (FileWriter writer = new FileWriter(path)) { + template.process(root, writer); + } catch (IOException | TemplateException exception) { + final var schema = root.get("schema"); + throw new GeneratorTemplateException(String.format(" Error processing template %s with object %s", templateName, ((SchemaObject) schema).getClassName()), exception); + } + } else { + throw new OverwritingApiFilesException(); + } + } + + public Path processPath(final String packagePath) { + Path path; + final File[] pathList = Objects.requireNonNull(baseDir.listFiles(targetFileFilter)); + if (pathList.length > 0) { + path = pathList[0].toPath().resolve(packagePath); + } else { + path = targetFolder.toPath(); + if (!path.toFile().exists() && !path.toFile().mkdirs()) { + throw new FileSystemException(path.toFile().getName()); + } + path = path.resolve(packagePath); + } + if (!path.toFile().isDirectory() && !path.toFile().mkdirs()) { + throw new FileSystemException(path.toFile().getName()); + } + return path; + } + + protected String convertPackageToTargetPath(final OperationParameterObject operationParameter, final String defaultApiPackage) { + String path = null; + if (Objects.nonNull(operationParameter)) { + if (Objects.nonNull(operationParameter.getApiPackage())) { + path = getPath(operationParameter.getApiPackage()); + } else { + path = getPath(defaultApiPackage); + } + } + return path; + } + + protected String getPath(final String pathName) { + return processedGeneratedSourcesFolder + pathName.replace(PACKAGE_SEPARATOR_STR, SLASH); + } +} diff --git a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/template/CommonTemplateIndexConstants.java b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/template/CommonTemplateIndexConstants.java new file mode 100644 index 00000000..a955ecfb --- /dev/null +++ b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/template/CommonTemplateIndexConstants.java @@ -0,0 +1,69 @@ +package com.sngular.api.generator.plugin.common.template; + +public abstract class CommonTemplateIndexConstants { + + public static final String TEMPLATE_CONTENT_SCHEMA = "templateSchema.ftlh"; + + public static final String TEMPLATE_CONTENT_SCHEMA_LOMBOK = "templateSchemaWithLombok.ftlh"; + + public static final String TEMPLATE_MODEL_EXCEPTION = "templateModelClassException.ftlh"; + + public static final String TEMPLATE_NOT_NULL_VALIDATOR_ANNOTATION = "templateNotNullValidator.ftlh"; + + public static final String TEMPLATE_MIN_INTEGER_ANNOTATION = "templateMinInteger.ftlh"; + + public static final String TEMPLATE_MIN_INTEGER_VALIDATOR_ANNOTATION = "templateMinIntegerValidator.ftlh"; + + public static final String TEMPLATE_MIN_BIG_DECIMAL_ANNOTATION = "templateMinBigDecimal.ftlh"; + + public static final String TEMPLATE_MIN_BIG_DECIMAL_VALIDATOR_ANNOTATION = "templateMinBigDecimalValidator.ftlh"; + + public static final String TEMPLATE_MIN_DOUBLE_ANNOTATION = "templateMinDouble.ftlh"; + + public static final String TEMPLATE_MIN_DOUBLE_VALIDATOR_ANNOTATION = "templateMinDoubleValidator.ftlh"; + + public static final String TEMPLATE_MIN_FLOAT_ANNOTATION = "templateMinFloat.ftlh"; + + public static final String TEMPLATE_MIN_FLOAT_VALIDATOR_ANNOTATION = "templateMinFloatValidator.ftlh"; + + public static final String TEMPLATE_MAX_INTEGER_ANNOTATION = "templateMaxInteger.ftlh"; + + public static final String TEMPLATE_MAX_INTEGER_VALIDATOR_ANNOTATION = "templateMaxIntegerValidator.ftlh"; + + public static final String TEMPLATE_MAX_BIG_DECIMAL_ANNOTATION = "templateMaxBigDecimal.ftlh"; + + public static final String TEMPLATE_MAX_BIG_DECIMAL_VALIDATOR_ANNOTATION = "templateMaxBigDecimalValidator.ftlh"; + + public static final String TEMPLATE_MAX_DOUBLE_ANNOTATION = "templateMaxDouble.ftlh"; + + public static final String TEMPLATE_MAX_DOUBLE_VALIDATOR_ANNOTATION = "templateMaxDoubleValidator.ftlh"; + + public static final String TEMPLATE_MAX_FLOAT_ANNOTATION = "templateMaxFloat.ftlh"; + + public static final String TEMPLATE_MAX_FLOAT_VALIDATOR_ANNOTATION = "templateMaxFloatValidator.ftlh"; + + public static final String TEMPLATE_SIZE_ANNOTATION = "templateSize.ftlh"; + + public static final String TEMPLATE_SIZE_VALIDATOR_ANNOTATION = "templateSizeValidator.ftlh"; + + public static final String TEMPLATE_PATTERN_ANNOTATION = "templatePattern.ftlh"; + + public static final String TEMPLATE_PATTERN_VALIDATOR_ANNOTATION = "templatePatternValidator.ftlh"; + + public static final String TEMPLATE_MULTIPLEOF_ANNOTATION = "templateMultipleOf.ftlh"; + + public static final String TEMPLATE_MULTIPLEOF_VALIDATOR_ANNOTATION = "templateMultipleOfValidator.ftlh"; + + public static final String TEMPLATE_MAX_ITEMS_ANNOTATION = "templateMaxItems.ftlh"; + + public static final String TEMPLATE_MAX_ITEMS_VALIDATOR_ANNOTATION = "templateMaxItemsValidator.ftlh"; + + public static final String TEMPLATE_MIN_ITEMS_ANNOTATION = "templateMinItems.ftlh"; + + public static final String TEMPLATE_MIN_ITEMS_VALIDATOR_ANNOTATION = "templateMinItemsValidator.ftlh"; + + public static final String TEMPLATE_UNIQUE_ITEMS_ANNOTATION = "templateUniqueItems.ftlh"; + + public static final String TEMPLATE_UNIQUE_ITEMS_VALIDATOR_ANNOTATION = "templateUniqueItemsValidator.ftlh"; + +} diff --git a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/template/CommonTemplateLoader.java b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/template/CommonTemplateLoader.java new file mode 100644 index 00000000..6f6d04db --- /dev/null +++ b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/template/CommonTemplateLoader.java @@ -0,0 +1,34 @@ +package com.sngular.api.generator.plugin.common.template; + +import com.sngular.api.generator.plugin.asyncapi.template.TemplateIndexConstants; +import freemarker.cache.TemplateLoader; + +import java.util.List; + +public abstract class CommonTemplateLoader implements TemplateLoader { + + protected static final List TEMPLATE_MODEL_FILES = List.of( "templateSchema.ftlh", + "templateSchemaWithLombok.ftlh", "templateModelClassException.ftlh"); + + protected static final List TEMPLATE_ANNOTATION_FILES = List.of(TemplateIndexConstants.TEMPLATE_NOT_NULL_ANNOTATION, + TemplateIndexConstants.TEMPLATE_NOT_NULL_VALIDATOR_ANNOTATION, + TemplateIndexConstants.TEMPLATE_MAX_INTEGER_ANNOTATION, TemplateIndexConstants.TEMPLATE_MAX_INTEGER_VALIDATOR_ANNOTATION, + TemplateIndexConstants.TEMPLATE_MAX_BIG_DECIMAL_ANNOTATION, TemplateIndexConstants.TEMPLATE_MAX_BIG_DECIMAL_VALIDATOR_ANNOTATION, + TemplateIndexConstants.TEMPLATE_MAX_DOUBLE_ANNOTATION, TemplateIndexConstants.TEMPLATE_MAX_DOUBLE_VALIDATOR_ANNOTATION, + TemplateIndexConstants.TEMPLATE_MAX_FLOAT_ANNOTATION, TemplateIndexConstants.TEMPLATE_MAX_FLOAT_VALIDATOR_ANNOTATION, + TemplateIndexConstants.TEMPLATE_MIN_INTEGER_ANNOTATION, TemplateIndexConstants.TEMPLATE_MIN_INTEGER_VALIDATOR_ANNOTATION, + TemplateIndexConstants.TEMPLATE_MIN_DOUBLE_ANNOTATION, TemplateIndexConstants.TEMPLATE_MIN_DOUBLE_VALIDATOR_ANNOTATION, + TemplateIndexConstants.TEMPLATE_MIN_FLOAT_ANNOTATION, TemplateIndexConstants.TEMPLATE_MIN_FLOAT_VALIDATOR_ANNOTATION, + TemplateIndexConstants.TEMPLATE_MIN_BIG_DECIMAL_ANNOTATION, TemplateIndexConstants.TEMPLATE_MIN_BIG_DECIMAL_VALIDATOR_ANNOTATION, + TemplateIndexConstants.TEMPLATE_SIZE_ANNOTATION, TemplateIndexConstants.TEMPLATE_SIZE_VALIDATOR_ANNOTATION, + TemplateIndexConstants.TEMPLATE_PATTERN_ANNOTATION, + TemplateIndexConstants.TEMPLATE_PATTERN_VALIDATOR_ANNOTATION, + TemplateIndexConstants.TEMPLATE_MULTIPLEOF_ANNOTATION, + TemplateIndexConstants.TEMPLATE_MULTIPLEOF_VALIDATOR_ANNOTATION, + TemplateIndexConstants.TEMPLATE_MAX_ITEMS_ANNOTATION, + TemplateIndexConstants.TEMPLATE_MAX_ITEMS_VALIDATOR_ANNOTATION, + TemplateIndexConstants.TEMPLATE_MIN_ITEMS_ANNOTATION, + TemplateIndexConstants.TEMPLATE_MIN_ITEMS_VALIDATOR_ANNOTATION, + TemplateIndexConstants.TEMPLATE_UNIQUE_ITEMS_ANNOTATION, + TemplateIndexConstants.TEMPLATE_UNIQUE_ITEMS_VALIDATOR_ANNOTATION); +} 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 17027ead..aa970249 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 @@ -33,7 +33,6 @@ import com.sngular.api.generator.plugin.common.model.TypeConstants; import com.sngular.api.generator.plugin.openapi.parameter.SpecFile; import com.sngular.api.generator.plugin.openapi.template.TemplateFactory; -import com.sngular.api.generator.plugin.openapi.template.TemplateIndexConstants; import com.sngular.api.generator.plugin.openapi.utils.MapperAuthUtil; import com.sngular.api.generator.plugin.openapi.utils.MapperContentUtil; import com.sngular.api.generator.plugin.openapi.utils.MapperPathUtil; @@ -104,6 +103,7 @@ public final void processFileSpec(final List specsListFile) { final String filePathToSave = processPath(specFile.getApiPackage(), false); processFile(specFile, filePathToSave); createClients(specFile); + templateFactory.clearData(); } catch (final IOException e) { throw new CodeGenerationException("Code generation failed. See above for the full exception.", e); } @@ -203,7 +203,7 @@ private void createModelTemplate(final SpecFile specFile, final JsonNode openAPI final var modelPackage = processModelPackage(specFile.getModelPackage()); final var totalSchemas = OpenApiUtil.processPaths(openAPI, globalObject.getSchemaMap()); templateFactory.setModelPackageName(modelPackage); - processModels(specFile, fileModelToSave, modelPackage, totalSchemas, Boolean.TRUE.equals(overwriteModel)); + processModels(specFile, fileModelToSave, modelPackage, totalSchemas, overwriteModel); } private void processPackage(final String apiPackage) { @@ -278,13 +278,13 @@ private void processModel( if (ApiTool.hasRef(basicSchema)) { final var refSchema = MapperUtil.getRefSchemaName(basicSchema); - builtSchemasMap.putAll(fillTemplateFactory(specFile, fileModelToSave, refSchema, basicSchemaMap.get(refSchema), basicSchemaMap, builtSchemasMap, modelPackage)); + builtSchemasMap.putAll(writeSchemaObject(specFile, fileModelToSave, refSchema, basicSchemaMap.get(refSchema), basicSchemaMap, builtSchemasMap, modelPackage)); } else if (!ApiTool.isArray(basicSchema) && !TypeConstants.STRING.equalsIgnoreCase(ApiTool.getType(basicSchema))) { - builtSchemasMap.putAll(fillTemplateFactory(specFile, fileModelToSave, schemaName, basicSchema, basicSchemaMap, builtSchemasMap, modelPackage)); + builtSchemasMap.putAll(writeSchemaObject(specFile, fileModelToSave, schemaName, basicSchema, basicSchemaMap, builtSchemasMap, modelPackage)); } } - private Map fillTemplateFactory( + private Map writeSchemaObject( final SpecFile specFile, final String fileModelToSave, final String schemaName, final JsonNode basicSchema, final Map basicSchemaMap, final Map builtSchemasMap, String modelPackage) { final var schemaObjectMap = MapperContentUtil @@ -295,7 +295,7 @@ private Map fillTemplateFactory( try { final Set propertiesSet = new HashSet<>(); templateFactory.fillTemplateSchema(fileModelToSave, specFile.isUseLombokModelAnnotation(), schemaObject, propertiesSet); - fillTemplates(fileModelToSave, propertiesSet); + fillTemplates(fileModelToSave, propertiesSet); } catch (IOException | TemplateException e) { throw new GeneratedSourcesException(schemaObject.getClassName(), e); } @@ -311,52 +311,6 @@ private Map fillTemplateFactory( return schemaObjectMap; } - @SuppressWarnings("checkstyle:CyclomaticComplexity") - private void fillTemplates(final String filePathToSave, final Set fieldProperties) throws TemplateException, IOException { - for (final String current : fieldProperties) { - switch (current) { - case "Size": - templateFactory.fillTemplateCustom(filePathToSave, "Size.java", "SizeValidator.java", TemplateIndexConstants.TEMPLATE_SIZE_ANNOTATION, - TemplateIndexConstants.TEMPLATE_SIZE_VALIDATOR_ANNOTATION); - break; - case "Pattern": - templateFactory.fillTemplateCustom(filePathToSave, "Pattern.java", "PatternValidator.java", TemplateIndexConstants.TEMPLATE_PATTERN_ANNOTATION, - TemplateIndexConstants.TEMPLATE_PATTERN_VALIDATOR_ANNOTATION); - break; - case "MultipleOf": - templateFactory.fillTemplateCustom(filePathToSave, "MultipleOf.java", "MultipleOfValidator.java", TemplateIndexConstants.TEMPLATE_MULTIPLEOF_ANNOTATION, - TemplateIndexConstants.TEMPLATE_MULTIPLEOF_VALIDATOR_ANNOTATION); - break; - case "Maximum": - templateFactory.fillTemplateCustom(filePathToSave, "Max.java", "MaxValidator.java", TemplateIndexConstants.TEMPLATE_MAX_ANNOTATION, - TemplateIndexConstants.TEMPLATE_MAX_VALIDATOR_ANNOTATION); - break; - case "Minimum": - templateFactory.fillTemplateCustom(filePathToSave, "Min.java", "MinValidator.java", TemplateIndexConstants.TEMPLATE_MIN_ANNOTATION, - TemplateIndexConstants.TEMPLATE_MIN_VALIDATOR_ANNOTATION); - break; - case "MaxItems": - templateFactory.fillTemplateCustom(filePathToSave, "MaxItems.java", "MaxItemsValidator.java", TemplateIndexConstants.TEMPLATE_MAX_ITEMS_ANNOTATION, - TemplateIndexConstants.TEMPLATE_MAX_ITEMS_VALIDATOR_ANNOTATION); - break; - case "MinItems": - templateFactory.fillTemplateCustom(filePathToSave, "MinItems.java", "MinItemsValidator.java", TemplateIndexConstants.TEMPLATE_MIN_ITEMS_ANNOTATION, - TemplateIndexConstants.TEMPLATE_MIN_ITEMS_VALIDATOR_ANNOTATION); - break; - case "NotNull": - templateFactory.fillTemplateCustom(filePathToSave, "NotNull.java", "NotNullValidator.java", TemplateIndexConstants.TEMPLATE_NOT_NULL_ANNOTATION, - TemplateIndexConstants.TEMPLATE_NOT_NULL_VALIDATOR_ANNOTATION); - break; - case "UniqueItems": - templateFactory.fillTemplateCustom(filePathToSave, "UniqueItems.java", "UniqueItemsValidator.java", TemplateIndexConstants.TEMPLATE_UNIQUE_ITEMS_ANNOTATION, - TemplateIndexConstants.TEMPLATE_UNIQUE_ITEMS_VALIDATOR_ANNOTATION); - break; - default: - break; - } - } - } - private void checkRequiredOrCombinatorExists(final Map schemaList) { boolean shouldGenerateException = false; final var schemaListIt = schemaList.values().iterator(); diff --git a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/openapi/template/ClasspathTemplateLoader.java b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/openapi/template/ClasspathTemplateLoader.java index 8c72d322..67b5894c 100644 --- a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/openapi/template/ClasspathTemplateLoader.java +++ b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/openapi/template/ClasspathTemplateLoader.java @@ -15,13 +15,10 @@ import java.util.Map; import java.util.Objects; +import com.sngular.api.generator.plugin.common.template.CommonTemplateLoader; import freemarker.cache.TemplateLoader; -public class ClasspathTemplateLoader implements TemplateLoader { - - private static final List TEMPLATE_MODEL_FILES = List.of( TemplateIndexConstants.TEMPLATE_CONTENT_SCHEMA, - TemplateIndexConstants.TEMPLATE_CONTENT_SCHEMA_LOMBOK, - TemplateIndexConstants.TEMPLATE_MODEL_EXCEPTION); +public class ClasspathTemplateLoader extends CommonTemplateLoader { private static final List TEMPLATE_FILES = List.of(TemplateIndexConstants.TEMPLATE_INTERFACE_API, TemplateIndexConstants.TEMPLATE_CALL_WEB_API, TemplateIndexConstants.TEMPLATE_WEB_CLIENT, TemplateIndexConstants.TEMPLATE_CALL_REST_API, @@ -31,22 +28,6 @@ public class ClasspathTemplateLoader implements TemplateLoader { TemplateIndexConstants.TEMPLATE_HTTP_BASIC, TemplateIndexConstants.TEMPLATE_HTTP_BEARER, TemplateIndexConstants.TEMPLATE_OAUTH, TemplateIndexConstants.TEMPLATE_OAUTH_FLOW); - private static final List TEMPLATE_ANNOTATION_FILES = List.of(TemplateIndexConstants.TEMPLATE_NOT_NULL_ANNOTATION, - TemplateIndexConstants.TEMPLATE_NOT_NULL_VALIDATOR_ANNOTATION, - TemplateIndexConstants.TEMPLATE_MAX_ANNOTATION, TemplateIndexConstants.TEMPLATE_MAX_VALIDATOR_ANNOTATION, - TemplateIndexConstants.TEMPLATE_MIN_ANNOTATION, TemplateIndexConstants.TEMPLATE_MIN_VALIDATOR_ANNOTATION, - TemplateIndexConstants.TEMPLATE_SIZE_ANNOTATION, TemplateIndexConstants.TEMPLATE_SIZE_VALIDATOR_ANNOTATION, - TemplateIndexConstants.TEMPLATE_PATTERN_ANNOTATION, - TemplateIndexConstants.TEMPLATE_PATTERN_VALIDATOR_ANNOTATION, - TemplateIndexConstants.TEMPLATE_MULTIPLEOF_ANNOTATION, - TemplateIndexConstants.TEMPLATE_MULTIPLEOF_VALIDATOR_ANNOTATION, - TemplateIndexConstants.TEMPLATE_MAX_ITEMS_ANNOTATION, - TemplateIndexConstants.TEMPLATE_MAX_ITEMS_VALIDATOR_ANNOTATION, - TemplateIndexConstants.TEMPLATE_MIN_ITEMS_ANNOTATION, - TemplateIndexConstants.TEMPLATE_MIN_ITEMS_VALIDATOR_ANNOTATION, - TemplateIndexConstants.TEMPLATE_UNIQUE_ITEMS_ANNOTATION, - TemplateIndexConstants.TEMPLATE_UNIQUE_ITEMS_VALIDATOR_ANNOTATION); - private static final ClassLoader LOADER = ClasspathTemplateLoader.class.getClassLoader(); private final Map templatesMap = new HashMap<>(); 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 6aae677a..dd1e98a7 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 @@ -11,7 +11,6 @@ import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; -import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Objects; @@ -19,6 +18,7 @@ import com.sngular.api.generator.plugin.common.model.SchemaFieldObject; import com.sngular.api.generator.plugin.common.model.SchemaObject; +import com.sngular.api.generator.plugin.common.template.CommonTemplateFactory; import com.sngular.api.generator.plugin.exception.GeneratorTemplateException; import com.sngular.api.generator.plugin.openapi.exception.OverwritingApiFilesException; import com.sngular.api.generator.plugin.openapi.model.AuthObject; @@ -28,27 +28,11 @@ import freemarker.template.Template; import freemarker.template.TemplateException; import freemarker.template.TemplateExceptionHandler; -import org.apache.commons.lang3.StringUtils; -public class TemplateFactory { - - private static final String JAVA_EXTENSION = ".java"; - - private static final String EXCEPTION_PACKAGE = "exceptionPackage"; - - private final Configuration cfg = new Configuration(Configuration.VERSION_2_3_32); - - private final Map root = new HashMap<>(); - - public TemplateFactory() { - cfg.setTemplateLoader(new ClasspathTemplateLoader()); - cfg.setDefaultEncoding("UTF-8"); - cfg.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER); - cfg.setLogTemplateExceptions(true); - cfg.setAPIBuiltinEnabled(true); - final List basicDataTypes = List.of("Integer", "Long", "Float", "Double", "Boolean", "String", "Char", "Byte", "Short"); - root.put("checkBasicTypes", basicDataTypes); +public class TemplateFactory extends CommonTemplateFactory { + public TemplateFactory(boolean enableOverwrite) { + super(enableOverwrite); } public final void fillTemplateSchema( @@ -57,9 +41,9 @@ public final void fillTemplateSchema( TemplateException { final File fileToSave = new File(filePathToSave); if (Objects.nonNull(schemaObject.getFieldObjectList()) && !schemaObject.getFieldObjectList().isEmpty()) { - root.put("schema", schemaObject); + addToRoot("schema", schemaObject); final String pathToSaveMainClass = fileToSave.toPath().resolve(schemaObject.getClassName() + JAVA_EXTENSION).toString(); - writeTemplateToFile(templateSelector(useLombok, schemaObject), root, pathToSaveMainClass); + writeTemplateToFile(templateSelector(useLombok, schemaObject), pathToSaveMainClass); for (SchemaFieldObject fieldObject : schemaObject.getFieldObjectList()) { propertiesSet.addAll(fieldObject.getRestrictions().getProperties()); if (fieldObject.isRequired() && Boolean.FALSE.equals(useLombok)) { @@ -69,14 +53,15 @@ public final void fillTemplateSchema( } } + public final void clearData() { + cleanData(); + } + private static String templateSelector(final Boolean useLombok, final SchemaObject schemaObject) { final var shouldUseLombok = Objects.requireNonNullElse(useLombok, false); - final var shouldUseEnum = schemaObject.isEnum(); final String template; - if (shouldUseEnum) { - template = TemplateIndexConstants.TEMPLATE_CONTENT_ENUM_SCHEMA; - } else if (Boolean.TRUE.equals(shouldUseLombok)) { + if (Boolean.TRUE.equals(shouldUseLombok)) { template = TemplateIndexConstants.TEMPLATE_CONTENT_SCHEMA_LOMBOK; } else { template = TemplateIndexConstants.TEMPLATE_CONTENT_SCHEMA; @@ -98,7 +83,7 @@ public final void fillTemplateWebClient(final String filePathToSave) throws IOEx final File fileToSave = new File(filePathToSave); final String pathToSaveMainClass = fileToSave.toPath().resolve("ApiWebClient.java").toString(); - writeTemplateToFile(TemplateIndexConstants.TEMPLATE_WEB_CLIENT, root, pathToSaveMainClass); + writeTemplateToFile(TemplateIndexConstants.TEMPLATE_WEB_CLIENT, pathToSaveMainClass); } @@ -106,7 +91,7 @@ public final void fillTemplateRestClient(final String filePathToSave) throws IOE final File fileToSave = new File(filePathToSave); final String pathToSaveMainClass = fileToSave.toPath().resolve("ApiRestClient.java").toString(); - writeTemplateToFile(TemplateIndexConstants.TEMPLATE_REST_CLIENT, root, pathToSaveMainClass); + writeTemplateToFile(TemplateIndexConstants.TEMPLATE_REST_CLIENT, pathToSaveMainClass); } @@ -114,7 +99,7 @@ public final void fillTemplateAuth(final String filePathToSave, final String aut final File fileToSave = new File(filePathToSave); final var nameAuthClass = authName + JAVA_EXTENSION; final String pathToSaveMainClass = fileToSave.toPath().resolve(nameAuthClass).toString(); - writeTemplateToFile(createNameTemplate(authName), root, pathToSaveMainClass); + writeTemplateToFile(createNameTemplate(authName), pathToSaveMainClass); } @@ -125,77 +110,62 @@ public final void fillTemplateCustom( final Path pathToValidatorPackage = fileToSave.toPath().resolve("customvalidator"); pathToValidatorPackage.toFile().mkdirs(); final String pathToSaveMainClass = pathToValidatorPackage.resolve(annotationFileName).toString(); - writeTemplateToFile(annotationTemplate, root, pathToSaveMainClass); + writeTemplateToFile(annotationTemplate, pathToSaveMainClass); final String pathToSaveMainClassValidator = pathToValidatorPackage.resolve(validatorFileName).toString(); - writeTemplateToFile(validatorTemplate, root, pathToSaveMainClassValidator); + writeTemplateToFile(validatorTemplate, pathToSaveMainClassValidator); } public final void fillTemplate( final String filePathToSave, final SpecFile specFile, final String className, final List pathObjects, final AuthObject authObject) throws IOException, TemplateException { - root.put("className", className); - root.put("pathObjects", pathObjects); + addToRoot("className", className); + addToRoot("pathObjects", pathObjects); if (Objects.nonNull(specFile.getApiPackage())) { - root.put("packageApi", specFile.getApiPackage()); + addToRoot("packageApi", specFile.getApiPackage()); } if (Objects.nonNull(specFile.getModelPackage())) { - root.put("packageModel", specFile.getModelPackage()); - root.put("exceptionPackage", specFile.getModelPackage()); + addToRoot("packageModel", specFile.getModelPackage()); + addToRoot("exceptionPackage", specFile.getModelPackage()); } final File fileToSave = new File(filePathToSave); if (specFile.isCallMode()) { - root.put("authObject", authObject); + addToRoot("authObject", authObject); } final String pathToSaveMainClass = fileToSave.toPath().resolve(className + "Api" + JAVA_EXTENSION).toString(); - writeTemplateToFile(specFile.isCallMode() ? getTemplateClientApi(specFile) : getTemplateApi(specFile), root, pathToSaveMainClass); + writeTemplateToFile(specFile.isCallMode() ? getTemplateClientApi(specFile) : getTemplateApi(specFile), pathToSaveMainClass); } public final void calculateJavaEEPackage(final Integer springBootVersion) { if (3 <= springBootVersion) { - root.put("javaEEPackage", "jakarta"); + addToRoot("javaEEPackage", "jakarta"); } else { - root.put("javaEEPackage", "javax"); + addToRoot("javaEEPackage", "javax"); } } - private void writeTemplateToFile(final String templateName, final Map root, final String path) throws IOException { - writeTemplateToFile(templateName, root, path, true); - } - - private void writeTemplateToFile(final String templateName, final Map root, final String path, final boolean checkOverwrite) throws IOException { - final Template template = cfg.getTemplate(templateName); - - if (!Files.exists(Path.of(path)) || checkOverwrite) { - try (FileWriter writer = new FileWriter(path)) { - template.process(root, writer); - } catch (IOException | TemplateException exception) { - final var schema = root.get("schema"); - throw new GeneratorTemplateException(String.format(" Error processing template %s with object %s", templateName, ((SchemaObject) schema).getClassName()), exception); - } - } else { - throw new OverwritingApiFilesException(); - } + void writeTemplateToFile(final String templateName, final String path) throws IOException { + writeTemplateToFile(templateName, path, true); } public final void setPackageName(final String packageName) { - root.put("package", packageName); + addToRoot("package", packageName); } public final void setModelPackageName(final String packageName) { - root.put("packageModel", packageName); + addToRoot("packageModel", packageName); } public final void setWebClientPackageName(final String packageName) { - root.put("packageClient", packageName); + addToRoot("packageClient", packageName); } public final void setAuthPackageName(final String packageName) { - root.put("packageAuth", packageName); + addToRoot("packageAuth", packageName); } private String createNameTemplate(final String classNameAuth) { diff --git a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/openapi/template/TemplateIndexConstants.java b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/openapi/template/TemplateIndexConstants.java index 01ec3343..c998266b 100644 --- a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/openapi/template/TemplateIndexConstants.java +++ b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/openapi/template/TemplateIndexConstants.java @@ -6,16 +6,14 @@ package com.sngular.api.generator.plugin.openapi.template; -public class TemplateIndexConstants { +import com.sngular.api.generator.plugin.common.template.CommonTemplateIndexConstants; + +public class TemplateIndexConstants extends CommonTemplateIndexConstants { public static final String TEMPLATE_INTERFACE_API = "template.ftlh"; public static final String TEMPLATE_REACTIVE_API = "templateReactive.ftlh"; - public static final String TEMPLATE_CONTENT_SCHEMA = "templateSchema.ftlh"; - - public static final String TEMPLATE_CONTENT_SCHEMA_LOMBOK = "templateSchemaWithLombok.ftlh"; - public static final String TEMPLATE_CALL_WEB_API = "templateCallWebClient.ftlh"; public static final String TEMPLATE_CALL_REST_API = "templateCallRestClient.ftlh"; @@ -36,46 +34,6 @@ public class TemplateIndexConstants { public static final String TEMPLATE_OAUTH_FLOW = "templateOAuthFlow.ftlh"; - public static final String TEMPLATE_MODEL_EXCEPTION = "templateModelClassException.ftlh"; - - public static final String TEMPLATE_NOT_NULL_ANNOTATION = "templateNotNull.ftlh"; - - public static final String TEMPLATE_NOT_NULL_VALIDATOR_ANNOTATION = "templateNotNullValidator.ftlh"; - - public static final String TEMPLATE_MIN_ANNOTATION = "templateMinInteger.ftlh"; - - public static final String TEMPLATE_MIN_VALIDATOR_ANNOTATION = "templateMinIntegerValidator.ftlh"; - - public static final String TEMPLATE_MAX_ANNOTATION = "templateMaxInteger.ftlh"; - - public static final String TEMPLATE_MAX_VALIDATOR_ANNOTATION = "templateMaxDoubleValidator.ftlh"; - - public static final String TEMPLATE_SIZE_ANNOTATION = "templateSize.ftlh"; - - public static final String TEMPLATE_SIZE_VALIDATOR_ANNOTATION = "templateSizeValidator.ftlh"; - - public static final String TEMPLATE_PATTERN_ANNOTATION = "templatePattern.ftlh"; - - public static final String TEMPLATE_PATTERN_VALIDATOR_ANNOTATION = "templatePatternValidator.ftlh"; - - public static final String TEMPLATE_MULTIPLEOF_ANNOTATION = "templateMultipleOf.ftlh"; - - public static final String TEMPLATE_MULTIPLEOF_VALIDATOR_ANNOTATION = "templateMultipleOfValidator.ftlh"; - - public static final String TEMPLATE_MAX_ITEMS_ANNOTATION = "templateMaxItems.ftlh"; - - public static final String TEMPLATE_MAX_ITEMS_VALIDATOR_ANNOTATION = "templateMaxItemsValidator.ftlh"; - - public static final String TEMPLATE_MIN_ITEMS_ANNOTATION = "templateMinItems.ftlh"; - - public static final String TEMPLATE_MIN_ITEMS_VALIDATOR_ANNOTATION = "templateMinItemsValidator.ftlh"; - - public static final String TEMPLATE_UNIQUE_ITEMS_ANNOTATION = "templateUniqueItems.ftlh"; - - public static final String TEMPLATE_UNIQUE_ITEMS_VALIDATOR_ANNOTATION = "templateUniqueItemsValidator.ftlh"; - - public static final String TEMPLATE_CONTENT_ENUM_SCHEMA = "templateEnumSchema.ftlh"; - private TemplateIndexConstants() {} } diff --git a/multiapi-engine/src/main/resources/templates/model/templateSchema.ftlh b/multiapi-engine/src/main/resources/templates/model/templateSchema.ftlh index 09c5ad0d..35f5ebde 100644 --- a/multiapi-engine/src/main/resources/templates/model/templateSchema.ftlh +++ b/multiapi-engine/src/main/resources/templates/model/templateSchema.ftlh @@ -22,7 +22,7 @@ <#elseif propertyName?matches(".*List")> <#return propertyName?remove_ending("List")/> <#else > - <#return propertyName/> + <#return "_"+propertyName/> <#function hasConstValue field> diff --git a/multiapi-engine/src/test/java/com/sngular/api/generator/plugin/asyncapi/AsyncApiGeneratorJakartaTest.java b/multiapi-engine/src/test/java/com/sngular/api/generator/plugin/asyncapi/AsyncApiGeneratorJakartaTest.java index cd4f0d5a..8ed76dd1 100644 --- a/multiapi-engine/src/test/java/com/sngular/api/generator/plugin/asyncapi/AsyncApiGeneratorJakartaTest.java +++ b/multiapi-engine/src/test/java/com/sngular/api/generator/plugin/asyncapi/AsyncApiGeneratorJakartaTest.java @@ -34,7 +34,7 @@ static void setup() { asyncApiGenerator = new AsyncApiGenerator(SPRING_BOOT_VERSION, new File(baseDir.toAbsolutePath() + File.separator + AsyncApiGeneratorFixtures.TARGET), AsyncApiGeneratorFixtures.GENERATED, "groupId", - baseDir.toFile()); + baseDir.toFile(), overwriteModel); } static Stream fileSpecToProcess() { 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 ef75a7d3..e82e3948 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 @@ -40,7 +40,7 @@ static void setup() { asyncApiGenerator = new AsyncApiGenerator(SPRING_BOOT_VERSION, new File(baseDir.toAbsolutePath() + File.separator + AsyncApiGeneratorFixtures.TARGET), AsyncApiGeneratorFixtures.GENERATED, "groupId", - baseDir.toFile()); + baseDir.toFile(), overwriteModel); } static Stream fileSpecToProcess() { diff --git a/multiapi-engine/src/test/java/com/sngular/api/generator/plugin/openapi/OpenApiGeneratorFixtures.java b/multiapi-engine/src/test/java/com/sngular/api/generator/plugin/openapi/OpenApiGeneratorFixtures.java index 5d36afa3..9dd1cff0 100644 --- a/multiapi-engine/src/test/java/com/sngular/api/generator/plugin/openapi/OpenApiGeneratorFixtures.java +++ b/multiapi-engine/src/test/java/com/sngular/api/generator/plugin/openapi/OpenApiGeneratorFixtures.java @@ -1269,11 +1269,11 @@ static Function validateValidationAnnotations(int springBootVersi CUSTOM_VALIDATOR_PATH + "MaxInteger.java", CUSTOM_VALIDATOR_PATH + "MaxItems.java", CUSTOM_VALIDATOR_PATH + "MaxItemsValidator.java", - CUSTOM_VALIDATOR_PATH + "MaxValidator.java", + CUSTOM_VALIDATOR_PATH + "MaxIntegerValidator.java", CUSTOM_VALIDATOR_PATH + "MinInteger.java", CUSTOM_VALIDATOR_PATH + "MinItems.java", CUSTOM_VALIDATOR_PATH + "MinItemsValidator.java", - CUSTOM_VALIDATOR_PATH + "MinValidator.java", + CUSTOM_VALIDATOR_PATH + "MinIntegerValidator.java", CUSTOM_VALIDATOR_PATH + "MultipleOf.java", CUSTOM_VALIDATOR_PATH + "MultipleOfValidator.java", CUSTOM_VALIDATOR_PATH + "NotNull.java", diff --git a/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/jakarta/MaxValidator.java b/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/jakarta/MaxValidator.java deleted file mode 100644 index 1d50b128..00000000 --- a/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/jakarta/MaxValidator.java +++ /dev/null @@ -1,24 +0,0 @@ -package com.sngular.scsplugin.customvalidator.model.event.customvalidator; - -import java.util.Objects; - -import jakarta.validation.ConstraintValidator; -import jakarta.validation.ConstraintValidatorContext; - -public class MaxValidator implements ConstraintValidator { - - private int maximum; - private boolean exclusive; - - @Override - public void initialize(Max constraintAnnotation) { - ConstraintValidator.super.initialize(constraintAnnotation); - this.maximum = Integer.parseInt(constraintAnnotation.maximum()); - this.exclusive = constraintAnnotation.exclusive(); - } - - @Override - public boolean isValid(Integer value, ConstraintValidatorContext context) { - return Objects.isNull(value) || (value.intValue() < this.maximum || (!exclusive && value.intValue() == this.maximum)); - } -} \ No newline at end of file diff --git a/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/jakarta/MinValidator.java b/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/jakarta/MinValidator.java deleted file mode 100644 index 3f1f7215..00000000 --- a/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/customvalidator/jakarta/MinValidator.java +++ /dev/null @@ -1,24 +0,0 @@ -package com.sngular.scsplugin.customvalidator.model.event.customvalidator; - -import java.util.Objects; - -import jakarta.validation.ConstraintValidator; -import jakarta.validation.ConstraintValidatorContext; - -public class MinValidator implements ConstraintValidator { - - private int minimum; - private boolean exclusive; - - @Override - public void initialize(Min constraintAnnotation) { - ConstraintValidator.super.initialize(constraintAnnotation); - this.minimum = Integer.parseInt(constraintAnnotation.minimum()); - this.exclusive = constraintAnnotation.exclusive(); - } - - @Override - public boolean isValid(Integer value, ConstraintValidatorContext context) { - return Objects.isNull(value) || (value.intValue() > this.minimum || (!exclusive && value.intValue() == this.minimum)); - } -} \ No newline at end of file diff --git a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/assets/testApi/ApiErrorDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/assets/testApi/ApiErrorDTO.java index 3f412e0d..4b79eeb5 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/assets/testApi/ApiErrorDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/assets/testApi/ApiErrorDTO.java @@ -8,15 +8,15 @@ import io.swagger.v3.oas.annotations.media.Schema; import java.util.List; import java.util.ArrayList; -import com.sngular.multifileplugin.testapi.model.customvalidator.Size; -import com.sngular.multifileplugin.testapi.model.customvalidator.Max; -import com.sngular.multifileplugin.testapi.model.customvalidator.Min; -import com.sngular.multifileplugin.testapi.model.customvalidator.MaxItems; -import com.sngular.multifileplugin.testapi.model.customvalidator.MinItems; +import com.sngular.multifileplugin.testapi.model.customvalidator.MaxInteger; +import com.sngular.multifileplugin.testapi.model.customvalidator.MinInteger; import com.sngular.multifileplugin.testapi.model.exception.ModelClassException; -import com.sngular.multifileplugin.testapi.model.customvalidator.Pattern; import com.sngular.multifileplugin.testapi.model.customvalidator.MultipleOf; import com.sngular.multifileplugin.testapi.model.customvalidator.NotNull; +import com.sngular.multifileplugin.testapi.model.customvalidator.Size; +import com.sngular.multifileplugin.testapi.model.customvalidator.Pattern; +import com.sngular.multifileplugin.testapi.model.customvalidator.MaxItems; +import com.sngular.multifileplugin.testapi.model.customvalidator.MinItems; import com.sngular.multifileplugin.testapi.model.customvalidator.UniqueItems; @JsonDeserialize(builder = ApiErrorDTO.ApiErrorDTOBuilder.class) @@ -25,8 +25,8 @@ public class ApiErrorDTO { @JsonProperty(value ="intCode") private Integer intCode; @JsonProperty(value ="code") - @Min(minimum = "10", exclusive = false) - @Max(maximum = "200", exclusive = true) + @MinInteger(minimum = "10", exclusive = false) + @MaxInteger(maximum = "200", exclusive = true) @MultipleOf(multiple = "10.55") @NotNull private final Integer code; @@ -39,16 +39,7 @@ public class ApiErrorDTO { @MaxItems(maximum = 10) @MinItems(minimum = 5) @UniqueItems - private List test = new ArrayList(); - - private ApiErrorDTO(Integer intCode, Integer code, String message, List test) { - this.intCode = intCode; - this.code = code; - this.message = message; - this.test = test; - - validateRequiredAttributes(); - } + private List test; private ApiErrorDTO(ApiErrorDTOBuilder builder) { this.intCode = builder.intCode; @@ -85,6 +76,7 @@ public ApiErrorDTO.ApiErrorDTOBuilder message(String message) { this.message = message; return this; } + public ApiErrorDTO.ApiErrorDTOBuilder test(List test) { if (!test.isEmpty()) { this.test.addAll(test); @@ -92,9 +84,9 @@ public ApiErrorDTO.ApiErrorDTOBuilder test(List test) { return this; } - public ApiErrorDTO.ApiErrorDTOBuilder test(Integer test) { - if (test != null) { - this.test.add(test); + public ApiErrorDTO.ApiErrorDTOBuilder _test(Integer _test) { + if (_test != null) { + this.test.add(_test); } return this; } diff --git a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/assets/testApi/ApiTestAllOfDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/assets/testApi/ApiTestAllOfDTO.java index 6519b3a0..eaee11fe 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/assets/testApi/ApiTestAllOfDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/assets/testApi/ApiTestAllOfDTO.java @@ -32,6 +32,7 @@ public static class ApiTestAllOfDTOBuilder { private List testers = new ArrayList(); private String testName; + public ApiTestAllOfDTO.ApiTestAllOfDTOBuilder testers(List testers) { if (!testers.isEmpty()) { this.testers.addAll(testers); diff --git a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/assets/testApi/ApiTestDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/assets/testApi/ApiTestDTO.java index cb7c0571..af64704d 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/assets/testApi/ApiTestDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/assets/testApi/ApiTestDTO.java @@ -37,6 +37,7 @@ public static class ApiTestDTOBuilder { private List testers = new ArrayList(); private String testName; + public ApiTestDTO.ApiTestDTOBuilder testers(List testers) { if (!testers.isEmpty()) { this.testers.addAll(testers); diff --git a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/Max.java b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/MaxInteger.java similarity index 80% rename from multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/Max.java rename to multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/MaxInteger.java index 99c47a48..253dfde6 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/Max.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/MaxInteger.java @@ -4,12 +4,11 @@ import jakarta.validation.Payload; import java.lang.annotation.*; -@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, -ElementType.ANNOTATION_TYPE}) +@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, ElementType.ANNOTATION_TYPE}) @Retention(RetentionPolicy.RUNTIME) -@Constraint(validatedBy = MaxValidator.class) +@Constraint(validatedBy = MaxIntegerValidator.class) @Documented -public @interface Max { +public @interface MaxInteger { String maximum(); boolean exclusive(); String message() default "Value is bigger than the maximum."; diff --git a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/MaxValidator.java b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/MaxIntegerValidator.java similarity index 82% rename from multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/MaxValidator.java rename to multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/MaxIntegerValidator.java index 7c14c642..806cc0ae 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/MaxValidator.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/MaxIntegerValidator.java @@ -5,13 +5,13 @@ import jakarta.validation.ConstraintValidator; import jakarta.validation.ConstraintValidatorContext; -public class MaxValidator implements ConstraintValidator { +public class MaxIntegerValidator implements ConstraintValidator { private int maximum; private boolean exclusive; @Override - public void initialize(Max constraintAnnotation) { + public void initialize(MaxInteger constraintAnnotation) { ConstraintValidator.super.initialize(constraintAnnotation); this.maximum = Integer.parseInt(constraintAnnotation.maximum()); this.exclusive = constraintAnnotation.exclusive(); diff --git a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/MaxItems.java b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/MaxItems.java index a9d0ecaf..948eb094 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/MaxItems.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/MaxItems.java @@ -4,8 +4,7 @@ import jakarta.validation.Payload; import java.lang.annotation.*; -@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, - ElementType.ANNOTATION_TYPE}) +@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, ElementType.ANNOTATION_TYPE}) @Retention(RetentionPolicy.RUNTIME) @Constraint(validatedBy = MaxItemsValidator.class) @Documented diff --git a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/Min.java b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/MinInteger.java similarity index 80% rename from multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/Min.java rename to multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/MinInteger.java index 4a14c217..b58a31b6 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/Min.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/MinInteger.java @@ -4,12 +4,11 @@ import jakarta.validation.Payload; import java.lang.annotation.*; -@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, - ElementType.ANNOTATION_TYPE}) +@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, ElementType.ANNOTATION_TYPE}) @Retention(RetentionPolicy.RUNTIME) -@Constraint(validatedBy = MinValidator.class) +@Constraint(validatedBy = MinIntegerValidator.class) @Documented -public @interface Min { +public @interface MinInteger { String minimum(); boolean exclusive(); String message() default "Value is smaller than the minimum."; diff --git a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/MinValidator.java b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/MinIntegerValidator.java similarity index 82% rename from multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/MinValidator.java rename to multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/MinIntegerValidator.java index e23a6da0..978d73e7 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/MinValidator.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/MinIntegerValidator.java @@ -5,13 +5,13 @@ import jakarta.validation.ConstraintValidator; import jakarta.validation.ConstraintValidatorContext; -public class MinValidator implements ConstraintValidator { +public class MinIntegerValidator implements ConstraintValidator { private int minimum; private boolean exclusive; @Override - public void initialize(Min constraintAnnotation) { + public void initialize(MinInteger constraintAnnotation) { ConstraintValidator.super.initialize(constraintAnnotation); this.minimum = Integer.parseInt(constraintAnnotation.minimum()); this.exclusive = constraintAnnotation.exclusive(); diff --git a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/MinItems.java b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/MinItems.java index fb2ace85..6c234dcb 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/MinItems.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/MinItems.java @@ -4,8 +4,7 @@ import jakarta.validation.Payload; import java.lang.annotation.*; -@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, - ElementType.ANNOTATION_TYPE}) +@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, ElementType.ANNOTATION_TYPE}) @Retention(RetentionPolicy.RUNTIME) @Constraint(validatedBy = MinItemsValidator.class) @Documented diff --git a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/MultipleOf.java b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/MultipleOf.java index 7289e413..3b5987b9 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/MultipleOf.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/MultipleOf.java @@ -4,8 +4,7 @@ import jakarta.validation.Payload; import java.lang.annotation.*; -@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, - ElementType.ANNOTATION_TYPE}) +@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, ElementType.ANNOTATION_TYPE}) @Retention(RetentionPolicy.RUNTIME) @Constraint(validatedBy = MultipleOfValidator.class) @Documented diff --git a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/NotNull.java b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/NotNull.java index 39a4e52d..5f8dd237 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/NotNull.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/NotNull.java @@ -4,8 +4,7 @@ import jakarta.validation.Payload; import java.lang.annotation.*; -@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, - ElementType.ANNOTATION_TYPE}) +@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, ElementType.ANNOTATION_TYPE}) @Retention(RetentionPolicy.RUNTIME) @Constraint(validatedBy = NotNullValidator.class) @Documented diff --git a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/Pattern.java b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/Pattern.java index ea8ad72c..3dcecd5c 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/Pattern.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/Pattern.java @@ -5,8 +5,7 @@ import java.lang.annotation.*; -@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, - ElementType.ANNOTATION_TYPE}) +@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, ElementType.ANNOTATION_TYPE}) @Retention(RetentionPolicy.RUNTIME) @Constraint(validatedBy = PatternValidator.class) @Documented diff --git a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/Size.java b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/Size.java index 187fac8d..4476390a 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/Size.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/Size.java @@ -4,8 +4,7 @@ import jakarta.validation.Payload; import java.lang.annotation.*; -@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, - ElementType.ANNOTATION_TYPE}) +@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, ElementType.ANNOTATION_TYPE}) @Retention(RetentionPolicy.RUNTIME) @Constraint(validatedBy = SizeValidator.class) @Documented diff --git a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/UniqueItems.java b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/UniqueItems.java index cc954e9b..c0ab9f15 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/UniqueItems.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/UniqueItems.java @@ -4,8 +4,7 @@ import jakarta.validation.Payload; import java.lang.annotation.*; -@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, - ElementType.ANNOTATION_TYPE}) +@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, ElementType.ANNOTATION_TYPE}) @Retention(RetentionPolicy.RUNTIME) @Constraint(validatedBy = UniqueItemsValidator.class) @Documented diff --git a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/javax/Max.java b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/javax/MaxInteger.java similarity index 80% rename from multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/javax/Max.java rename to multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/javax/MaxInteger.java index e37b0654..98db09d4 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/javax/Max.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/javax/MaxInteger.java @@ -4,12 +4,11 @@ import javax.validation.Payload; import java.lang.annotation.*; -@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, -ElementType.ANNOTATION_TYPE}) +@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, ElementType.ANNOTATION_TYPE}) @Retention(RetentionPolicy.RUNTIME) -@Constraint(validatedBy = MaxValidator.class) +@Constraint(validatedBy = MaxIntegerValidator.class) @Documented -public @interface Max { +public @interface MaxInteger { String maximum(); boolean exclusive(); String message() default "Value is bigger than the maximum."; diff --git a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/javax/MaxValidator.java b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/javax/MaxIntegerValidator.java similarity index 82% rename from multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/javax/MaxValidator.java rename to multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/javax/MaxIntegerValidator.java index 67e44625..3071e7e7 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/javax/MaxValidator.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/javax/MaxIntegerValidator.java @@ -5,13 +5,13 @@ import javax.validation.ConstraintValidator; import javax.validation.ConstraintValidatorContext; -public class MaxValidator implements ConstraintValidator { +public class MaxIntegerValidator implements ConstraintValidator { private int maximum; private boolean exclusive; @Override - public void initialize(Max constraintAnnotation) { + public void initialize(MaxInteger constraintAnnotation) { ConstraintValidator.super.initialize(constraintAnnotation); this.maximum = Integer.parseInt(constraintAnnotation.maximum()); this.exclusive = constraintAnnotation.exclusive(); diff --git a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/javax/MaxItems.java b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/javax/MaxItems.java index ae2d6b9d..7e828803 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/javax/MaxItems.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/javax/MaxItems.java @@ -4,8 +4,7 @@ import javax.validation.Payload; import java.lang.annotation.*; -@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, - ElementType.ANNOTATION_TYPE}) +@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, ElementType.ANNOTATION_TYPE}) @Retention(RetentionPolicy.RUNTIME) @Constraint(validatedBy = MaxItemsValidator.class) @Documented diff --git a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/javax/Min.java b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/javax/MinInteger.java similarity index 80% rename from multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/javax/Min.java rename to multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/javax/MinInteger.java index 553738ad..535c63c0 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/javax/Min.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/javax/MinInteger.java @@ -4,12 +4,11 @@ import javax.validation.Payload; import java.lang.annotation.*; -@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, - ElementType.ANNOTATION_TYPE}) +@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, ElementType.ANNOTATION_TYPE}) @Retention(RetentionPolicy.RUNTIME) -@Constraint(validatedBy = MinValidator.class) +@Constraint(validatedBy = MinIntegerValidator.class) @Documented -public @interface Min { +public @interface MinInteger { String minimum(); boolean exclusive(); String message() default "Value is smaller than the minimum."; diff --git a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/javax/MinValidator.java b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/javax/MinIntegerValidator.java similarity index 82% rename from multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/javax/MinValidator.java rename to multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/javax/MinIntegerValidator.java index 496982b4..6a377bff 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/javax/MinValidator.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/javax/MinIntegerValidator.java @@ -5,13 +5,13 @@ import javax.validation.ConstraintValidator; import javax.validation.ConstraintValidatorContext; -public class MinValidator implements ConstraintValidator { +public class MinIntegerValidator implements ConstraintValidator { private int minimum; private boolean exclusive; @Override - public void initialize(Min constraintAnnotation) { + public void initialize(MinInteger constraintAnnotation) { ConstraintValidator.super.initialize(constraintAnnotation); this.minimum = Integer.parseInt(constraintAnnotation.minimum()); this.exclusive = constraintAnnotation.exclusive(); diff --git a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/javax/MinItems.java b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/javax/MinItems.java index 5639c329..d70d4a83 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/javax/MinItems.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/javax/MinItems.java @@ -4,8 +4,7 @@ import javax.validation.Payload; import java.lang.annotation.*; -@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, - ElementType.ANNOTATION_TYPE}) +@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, ElementType.ANNOTATION_TYPE}) @Retention(RetentionPolicy.RUNTIME) @Constraint(validatedBy = MinItemsValidator.class) @Documented diff --git a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/javax/MultipleOf.java b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/javax/MultipleOf.java index 1698d0b8..64f01632 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/javax/MultipleOf.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/javax/MultipleOf.java @@ -4,8 +4,7 @@ import javax.validation.Payload; import java.lang.annotation.*; -@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, - ElementType.ANNOTATION_TYPE}) +@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, ElementType.ANNOTATION_TYPE}) @Retention(RetentionPolicy.RUNTIME) @Constraint(validatedBy = MultipleOfValidator.class) @Documented diff --git a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/javax/NotNull.java b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/javax/NotNull.java index 5a7a05e1..467b2857 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/javax/NotNull.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/javax/NotNull.java @@ -4,8 +4,7 @@ import javax.validation.Payload; import java.lang.annotation.*; -@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, - ElementType.ANNOTATION_TYPE}) +@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, ElementType.ANNOTATION_TYPE}) @Retention(RetentionPolicy.RUNTIME) @Constraint(validatedBy = NotNullValidator.class) @Documented diff --git a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/javax/Pattern.java b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/javax/Pattern.java index 96efffca..849464f0 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/javax/Pattern.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/javax/Pattern.java @@ -5,8 +5,7 @@ import java.lang.annotation.*; -@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, - ElementType.ANNOTATION_TYPE}) +@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, ElementType.ANNOTATION_TYPE}) @Retention(RetentionPolicy.RUNTIME) @Constraint(validatedBy = PatternValidator.class) @Documented diff --git a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/javax/Size.java b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/javax/Size.java index beceb0bd..4665c3b0 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/javax/Size.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/javax/Size.java @@ -4,8 +4,7 @@ import javax.validation.Payload; import java.lang.annotation.*; -@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, - ElementType.ANNOTATION_TYPE}) +@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, ElementType.ANNOTATION_TYPE}) @Retention(RetentionPolicy.RUNTIME) @Constraint(validatedBy = SizeValidator.class) @Documented diff --git a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/javax/UniqueItems.java b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/javax/UniqueItems.java index c376189a..a61e12b7 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/javax/UniqueItems.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/javax/UniqueItems.java @@ -4,8 +4,7 @@ import javax.validation.Payload; import java.lang.annotation.*; -@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, - ElementType.ANNOTATION_TYPE}) +@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, ElementType.ANNOTATION_TYPE}) @Retention(RetentionPolicy.RUNTIME) @Constraint(validatedBy = UniqueItemsValidator.class) @Documented diff --git a/scs-multiapi-maven-plugin/src/main/java/com/sngular/api/generator/plugin/OpenAsyncMojo.java b/scs-multiapi-maven-plugin/src/main/java/com/sngular/api/generator/plugin/OpenAsyncMojo.java index 1f71a2b0..11693d17 100644 --- a/scs-multiapi-maven-plugin/src/main/java/com/sngular/api/generator/plugin/OpenAsyncMojo.java +++ b/scs-multiapi-maven-plugin/src/main/java/com/sngular/api/generator/plugin/OpenAsyncMojo.java @@ -44,7 +44,7 @@ public void execute() { final var processedGeneratedSourcesFolder = processGeneratedSourcesFolderName(); addGeneratedSourcesToProject(processedGeneratedSourcesFolder); - final var asyncApiGenerator = new AsyncApiGenerator(springBootVersion, targetFolder, processedGeneratedSourcesFolder, project.getModel().getGroupId(), project.getBasedir()); + final var asyncApiGenerator = new AsyncApiGenerator(springBootVersion, targetFolder, processedGeneratedSourcesFolder, project.getModel().getGroupId(), project.getBasedir(), overwriteModel); asyncApiGenerator.processFileSpec(specFiles); From 3c0eed9fe5929ea5f5b4a8fc873fe04052a07d34 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?jose=20enrique=20garcia=20maci=C3=B1eiras?= Date: Mon, 9 Sep 2024 21:41:34 +0200 Subject: [PATCH 11/26] Rework staff --- .../template/CommonTemplateFactory.java | 97 +++++++++---------- .../openapi/template/TemplateFactory.java | 30 ++---- .../model/templateSchemaWithLombok.ftlh | 18 ++-- 3 files changed, 66 insertions(+), 79 deletions(-) diff --git a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/template/CommonTemplateFactory.java b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/template/CommonTemplateFactory.java index 259e9d6b..68187523 100644 --- a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/template/CommonTemplateFactory.java +++ b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/template/CommonTemplateFactory.java @@ -26,7 +26,7 @@ public abstract class CommonTemplateFactory { - private final static List BASIC_DATA_TYPES = List.of("Integer", "Long", "Float", "Double", "Boolean", "String", "Char", "Byte", "Short"); + private static final List BASIC_DATA_TYPES = List.of("Integer", "Long", "Float", "Double", "Boolean", "String", "Char", "Byte", "Short"); private static final String EXCEPTION_PACKAGE = "exceptionPackage"; @@ -44,15 +44,15 @@ public abstract class CommonTemplateFactory { private final boolean checkOverwrite; - private File targetFolder; + private final File targetFolder; - private String processedGeneratedSourcesFolder; + private final String processedGeneratedSourcesFolder; private final FilenameFilter targetFileFilter; private final File baseDir; - public CommonTemplateFactory(boolean checkOverwrite, + protected CommonTemplateFactory(boolean checkOverwrite, final File targetFolder, final String processedGeneratedSourcesFolder, final File baseDir) { @@ -104,14 +104,9 @@ private ClassTemplate getClassTemplate() { } protected void fillTemplate(final String filePathToSave, final String className, final String templateName) throws IOException, TemplateException { - final File fileToSave = Paths.get(filePathToSave).normalize().toFile(); - fileToSave.mkdirs(); - final String pathToSaveMainClass = fileToSave.toPath().resolve(className + FILE_TYPE_JAVA).toString(); - fillTemplate(pathToSaveMainClass, templateName); - } - - private void fillTemplate(final String pathToSaveMainClass, final String templateName) throws IOException, TemplateException { - writeTemplateToFile(templateName, pathToSaveMainClass); + final var fileToSave = Paths.get(filePathToSave); + fileToSave.toFile().mkdirs(); + writeTemplateToFile(templateName, fileToSave, className); } @SuppressWarnings("checkstyle:CyclomaticComplexity") @@ -119,52 +114,52 @@ protected void fillTemplates(final Path filePathToSave, final String modelPackag for (final String current : fieldProperties) { switch (current) { case "Size": - fillTemplateCustom(filePathToSave, modelPackage, "Size.java", TemplateIndexConstants.TEMPLATE_SIZE_ANNOTATION, "SizeValidator.java", + fillTemplateCustom(filePathToSave, modelPackage, "Size", TemplateIndexConstants.TEMPLATE_SIZE_ANNOTATION, "SizeValidator", TemplateIndexConstants.TEMPLATE_SIZE_VALIDATOR_ANNOTATION); break; case "Pattern": - fillTemplateCustom(filePathToSave, modelPackage, "Pattern.java", TemplateIndexConstants.TEMPLATE_PATTERN_ANNOTATION, - "PatternValidator.java", TemplateIndexConstants.TEMPLATE_PATTERN_VALIDATOR_ANNOTATION); + fillTemplateCustom(filePathToSave, modelPackage, "Pattern", TemplateIndexConstants.TEMPLATE_PATTERN_ANNOTATION, + "PatternValidator", TemplateIndexConstants.TEMPLATE_PATTERN_VALIDATOR_ANNOTATION); break; case "MultipleOf": - fillTemplateCustom(filePathToSave, modelPackage, "MultipleOf.java", TemplateIndexConstants.TEMPLATE_MULTIPLEOF_ANNOTATION, - "MultipleOfValidator.java", TemplateIndexConstants.TEMPLATE_MULTIPLEOF_VALIDATOR_ANNOTATION); + fillTemplateCustom(filePathToSave, modelPackage, "MultipleOf", TemplateIndexConstants.TEMPLATE_MULTIPLEOF_ANNOTATION, + "MultipleOfValidator", TemplateIndexConstants.TEMPLATE_MULTIPLEOF_VALIDATOR_ANNOTATION); break; case "Maximum": - fillTemplateCustom(filePathToSave, modelPackage, "MaxInteger.java", TemplateIndexConstants.TEMPLATE_MAX_INTEGER_ANNOTATION, - "MaxIntegerValidator.java", TemplateIndexConstants.TEMPLATE_MAX_INTEGER_VALIDATOR_ANNOTATION); - fillTemplateCustom(filePathToSave, modelPackage, "MaxBigDecimal.java", TemplateIndexConstants.TEMPLATE_MAX_BIG_DECIMAL_ANNOTATION, - "MaxBigDecimalValidator.java", TemplateIndexConstants.TEMPLATE_MAX_BIG_DECIMAL_VALIDATOR_ANNOTATION); - fillTemplateCustom(filePathToSave, modelPackage, "MaxDouble.java", TemplateIndexConstants.TEMPLATE_MAX_DOUBLE_ANNOTATION, - "MaxDoubleValidator.java", TemplateIndexConstants.TEMPLATE_MAX_DOUBLE_VALIDATOR_ANNOTATION); - fillTemplateCustom(filePathToSave, modelPackage, "MaxFloat.java", TemplateIndexConstants.TEMPLATE_MAX_FLOAT_ANNOTATION, - "MaxFloatValidator.java", TemplateIndexConstants.TEMPLATE_MAX_FLOAT_VALIDATOR_ANNOTATION); + fillTemplateCustom(filePathToSave, modelPackage, "MaxInteger", TemplateIndexConstants.TEMPLATE_MAX_INTEGER_ANNOTATION, + "MaxIntegerValidator", TemplateIndexConstants.TEMPLATE_MAX_INTEGER_VALIDATOR_ANNOTATION); + fillTemplateCustom(filePathToSave, modelPackage, "MaxBigDecimal", TemplateIndexConstants.TEMPLATE_MAX_BIG_DECIMAL_ANNOTATION, + "MaxBigDecimalValidator", TemplateIndexConstants.TEMPLATE_MAX_BIG_DECIMAL_VALIDATOR_ANNOTATION); + fillTemplateCustom(filePathToSave, modelPackage, "MaxDouble", TemplateIndexConstants.TEMPLATE_MAX_DOUBLE_ANNOTATION, + "MaxDoubleValidator", TemplateIndexConstants.TEMPLATE_MAX_DOUBLE_VALIDATOR_ANNOTATION); + fillTemplateCustom(filePathToSave, modelPackage, "MaxFloat", TemplateIndexConstants.TEMPLATE_MAX_FLOAT_ANNOTATION, + "MaxFloatValidator", TemplateIndexConstants.TEMPLATE_MAX_FLOAT_VALIDATOR_ANNOTATION); break; case "Minimum": - fillTemplateCustom(filePathToSave, modelPackage, "MinInteger.java", TemplateIndexConstants.TEMPLATE_MIN_INTEGER_ANNOTATION, - "MinIntegerValidator.java", TemplateIndexConstants.TEMPLATE_MIN_INTEGER_VALIDATOR_ANNOTATION); - fillTemplateCustom(filePathToSave, modelPackage, "MinDouble.java", TemplateIndexConstants.TEMPLATE_MIN_DOUBLE_ANNOTATION, - "MinDoubleValidator.java", TemplateIndexConstants.TEMPLATE_MIN_DOUBLE_VALIDATOR_ANNOTATION); - fillTemplateCustom(filePathToSave, modelPackage, "MinFloat.java", TemplateIndexConstants.TEMPLATE_MIN_FLOAT_ANNOTATION, - "MinFloatValidator.java", TemplateIndexConstants.TEMPLATE_MIN_FLOAT_VALIDATOR_ANNOTATION); - fillTemplateCustom(filePathToSave, modelPackage, "MinBigDecimal.java", TemplateIndexConstants.TEMPLATE_MIN_BIG_DECIMAL_ANNOTATION, - "MinBigDecimalValidator.java", TemplateIndexConstants.TEMPLATE_MIN_BIG_DECIMAL_VALIDATOR_ANNOTATION); + fillTemplateCustom(filePathToSave, modelPackage, "MinInteger", TemplateIndexConstants.TEMPLATE_MIN_INTEGER_ANNOTATION, + "MinIntegerValidator", TemplateIndexConstants.TEMPLATE_MIN_INTEGER_VALIDATOR_ANNOTATION); + fillTemplateCustom(filePathToSave, modelPackage, "MinDouble", TemplateIndexConstants.TEMPLATE_MIN_DOUBLE_ANNOTATION, + "MinDoubleValidator", TemplateIndexConstants.TEMPLATE_MIN_DOUBLE_VALIDATOR_ANNOTATION); + fillTemplateCustom(filePathToSave, modelPackage, "MinFloat", TemplateIndexConstants.TEMPLATE_MIN_FLOAT_ANNOTATION, + "MinFloatValidator", TemplateIndexConstants.TEMPLATE_MIN_FLOAT_VALIDATOR_ANNOTATION); + fillTemplateCustom(filePathToSave, modelPackage, "MinBigDecimal", TemplateIndexConstants.TEMPLATE_MIN_BIG_DECIMAL_ANNOTATION, + "MinBigDecimalValidator", TemplateIndexConstants.TEMPLATE_MIN_BIG_DECIMAL_VALIDATOR_ANNOTATION); break; case "MaxItems": - fillTemplateCustom(filePathToSave, modelPackage, "MaxItems.java", TemplateIndexConstants.TEMPLATE_MAX_ITEMS_ANNOTATION, - "MaxItemsValidator.java", TemplateIndexConstants.TEMPLATE_MAX_ITEMS_VALIDATOR_ANNOTATION); + fillTemplateCustom(filePathToSave, modelPackage, "MaxItems", TemplateIndexConstants.TEMPLATE_MAX_ITEMS_ANNOTATION, + "MaxItemsValidator", TemplateIndexConstants.TEMPLATE_MAX_ITEMS_VALIDATOR_ANNOTATION); break; case "MinItems": - fillTemplateCustom(filePathToSave, modelPackage, "MinItems.java", TemplateIndexConstants.TEMPLATE_MIN_ITEMS_ANNOTATION, - "MinItemsValidator.java", TemplateIndexConstants.TEMPLATE_MIN_ITEMS_VALIDATOR_ANNOTATION); + fillTemplateCustom(filePathToSave, modelPackage, "MinItems", TemplateIndexConstants.TEMPLATE_MIN_ITEMS_ANNOTATION, + "MinItemsValidator", TemplateIndexConstants.TEMPLATE_MIN_ITEMS_VALIDATOR_ANNOTATION); break; case "NotNull": - fillTemplateCustom(filePathToSave, modelPackage, "NotNull.java", TemplateIndexConstants.TEMPLATE_NOT_NULL_ANNOTATION, - "NotNullValidator.java", TemplateIndexConstants.TEMPLATE_NOT_NULL_VALIDATOR_ANNOTATION); + fillTemplateCustom(filePathToSave, modelPackage, "NotNull", TemplateIndexConstants.TEMPLATE_NOT_NULL_ANNOTATION, + "NotNullValidator", TemplateIndexConstants.TEMPLATE_NOT_NULL_VALIDATOR_ANNOTATION); break; case "UniqueItems": - fillTemplateCustom(filePathToSave, modelPackage, "UniqueItems.java", TemplateIndexConstants.TEMPLATE_UNIQUE_ITEMS_ANNOTATION, - "UniqueItemsValidator.java", TemplateIndexConstants.TEMPLATE_UNIQUE_ITEMS_VALIDATOR_ANNOTATION); + fillTemplateCustom(filePathToSave, modelPackage, "UniqueItems", TemplateIndexConstants.TEMPLATE_UNIQUE_ITEMS_ANNOTATION, + "UniqueItemsValidator", TemplateIndexConstants.TEMPLATE_UNIQUE_ITEMS_VALIDATOR_ANNOTATION); break; default: break; @@ -202,20 +197,17 @@ public final void fillTemplateModelClassException(final Path filePathToSave, fin final Path pathToExceptionPackage = filePathToSave.resolve("exception"); pathToExceptionPackage.toFile().mkdirs(); addToRoot(EXCEPTION_PACKAGE, modelPackage); - final String pathToSaveMainClass = pathToExceptionPackage.resolve("ModelClassException.java").toString(); - writeTemplateToFile(TemplateIndexConstants.TEMPLATE_MODEL_EXCEPTION, pathToSaveMainClass); + writeTemplateToFile(TemplateIndexConstants.TEMPLATE_MODEL_EXCEPTION, filePathToSave, "ModelClassException"); } private void fillTemplateCustom( final Path filePathToSave, final String modelPackage, final String fileNameAnnotation, final String templateAnnotation, - final String fileNameValidator, final String templateValidator) throws TemplateException, IOException { + final String fileNameValidator, final String templateValidator) throws IOException { final Path pathToCustomValidatorPackage = filePathToSave.resolve("customvalidator"); pathToCustomValidatorPackage.toFile().mkdirs(); root.put("packageModel", modelPackage); - final String pathToSaveAnnotationClass = pathToCustomValidatorPackage.resolve(fileNameAnnotation).toString(); - writeTemplateToFile(templateAnnotation, pathToSaveAnnotationClass); - final String pathToSaveValidatorClass = pathToCustomValidatorPackage.resolve(fileNameValidator).toString(); - writeTemplateToFile(templateValidator, pathToSaveValidatorClass); + writeTemplateToFile(templateAnnotation, filePathToSave, fileNameAnnotation); + writeTemplateToFile(templateValidator, filePathToSave, fileNameValidator); } protected void addToRoot(final String key, final Object value) { @@ -239,7 +231,7 @@ public final void addSchemaObject(final String modelPackage, final String keyClassName, final SchemaObject schemaObject, final String destinationPackage) { - final var filePath = processPath(getPath(StringUtils.defaultIfEmpty(destinationPackage, DEFAULT_ASYNCAPI_API_PACKAGE + SLASH + schemaObject.getParentPackage()))); + final var filePath = processPath(getPath(destinationPackage)); final var propertiesPath = processPath(getPath(modelPackage)); final var builder = ClassTemplate.builder().filePath(filePath).modelPackage(modelPackage).className(schemaObject.getClassName()).classSchema(schemaObject) .propertiesPath(propertiesPath); @@ -249,7 +241,12 @@ public final void addSchemaObject(final String modelPackage, classTemplateList.add(builder.build()); } - protected void writeTemplateToFile(final String templateName, final String path) throws IOException { + protected void writeTemplateToFile(final String templateName, final String filePathToSave, final String partialPath) throws IOException { + writeTemplateToFile(templateName, Paths.get(filePathToSave), partialPath); + } + + protected void writeTemplateToFile(final String templateName, final Path filePathToSave, final String partialPath) throws IOException { + final String path = filePathToSave.resolve(partialPath + FILE_TYPE_JAVA).toString(); final Template template = cfg.getTemplate(templateName); if (!Files.exists(Path.of(path)) || checkOverwrite) { 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 dd1e98a7..57cb96e1 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 @@ -31,19 +31,20 @@ public class TemplateFactory extends CommonTemplateFactory { - public TemplateFactory(boolean enableOverwrite) { - super(enableOverwrite); + public TemplateFactory(boolean enableOverwrite, + final File targetFolder, + final String processedGeneratedSourcesFolder, + final File baseDir) { + super(enableOverwrite, targetFolder, processedGeneratedSourcesFolder, baseDir); } public final void fillTemplateSchema( final String filePathToSave, final Boolean useLombok, final SchemaObject schemaObject, final Set propertiesSet) throws IOException, TemplateException { - final File fileToSave = new File(filePathToSave); if (Objects.nonNull(schemaObject.getFieldObjectList()) && !schemaObject.getFieldObjectList().isEmpty()) { addToRoot("schema", schemaObject); - final String pathToSaveMainClass = fileToSave.toPath().resolve(schemaObject.getClassName() + JAVA_EXTENSION).toString(); - writeTemplateToFile(templateSelector(useLombok, schemaObject), pathToSaveMainClass); + writeTemplateToFile(templateSelector(useLombok, schemaObject), filePathToSave, schemaObject.getClassName()); for (SchemaFieldObject fieldObject : schemaObject.getFieldObjectList()) { propertiesSet.addAll(fieldObject.getRestrictions().getProperties()); if (fieldObject.isRequired() && Boolean.FALSE.equals(useLombok)) { @@ -70,21 +71,16 @@ private static String templateSelector(final Boolean useLombok, final SchemaObje return template; } - public final void fillTemplateModelClassException(final String filePathToSave, final boolean overwriteEnabled, String modelPackage) throws IOException, TemplateException { + public final void fillTemplateModelClassException(final String filePathToSave) throws IOException, TemplateException { final File fileToSave = new File(filePathToSave); final Path pathToExceptionPackage = fileToSave.toPath().resolve("exception"); pathToExceptionPackage.toFile().mkdirs(); - final String pathToSaveMainClass = pathToExceptionPackage.resolve("ModelClassException.java").toString(); - writeTemplateToFile(TemplateIndexConstants.TEMPLATE_MODEL_EXCEPTION, root, pathToSaveMainClass, overwriteEnabled); + writeTemplateToFile(TemplateIndexConstants.TEMPLATE_MODEL_EXCEPTION, pathToExceptionPackage, "ModelClassException"); } public final void fillTemplateWebClient(final String filePathToSave) throws IOException, TemplateException { - final File fileToSave = new File(filePathToSave); - - final String pathToSaveMainClass = fileToSave.toPath().resolve("ApiWebClient.java").toString(); - writeTemplateToFile(TemplateIndexConstants.TEMPLATE_WEB_CLIENT, pathToSaveMainClass); - + writeTemplateToFile(TemplateIndexConstants.TEMPLATE_WEB_CLIENT, pathToSaveMainClass, "ApiWebClient"); } public final void fillTemplateRestClient(final String filePathToSave) throws IOException, TemplateException { @@ -129,14 +125,12 @@ public final void fillTemplate( addToRoot("packageModel", specFile.getModelPackage()); addToRoot("exceptionPackage", specFile.getModelPackage()); } - final File fileToSave = new File(filePathToSave); if (specFile.isCallMode()) { addToRoot("authObject", authObject); } - final String pathToSaveMainClass = fileToSave.toPath().resolve(className + "Api" + JAVA_EXTENSION).toString(); - writeTemplateToFile(specFile.isCallMode() ? getTemplateClientApi(specFile) : getTemplateApi(specFile), pathToSaveMainClass); + writeTemplateToFile(specFile.isCallMode() ? getTemplateClientApi(specFile) : getTemplateApi(specFile), filePathToSave, className + "Api"); } @@ -148,10 +142,6 @@ public final void calculateJavaEEPackage(final Integer springBootVersion) { } } - void writeTemplateToFile(final String templateName, final String path) throws IOException { - writeTemplateToFile(templateName, path, true); - } - public final void setPackageName(final String packageName) { addToRoot("package", packageName); } diff --git a/multiapi-engine/src/main/resources/templates/model/templateSchemaWithLombok.ftlh b/multiapi-engine/src/main/resources/templates/model/templateSchemaWithLombok.ftlh index 96fd517d..ad6baa93 100644 --- a/multiapi-engine/src/main/resources/templates/model/templateSchemaWithLombok.ftlh +++ b/multiapi-engine/src/main/resources/templates/model/templateSchemaWithLombok.ftlh @@ -1,5 +1,6 @@ <#ftl output_format="plainText"> -<#assign words = ["abstract", "assert", "boolean", "break", "byte", "case", "catch", "char", "class", "const", "continue", "default", "double", "do", "else", "enum", "extends", "false", "final", "finally", "float", "for", "goto", "if", "implements", "import", "instanceof", "int", "interface", "long", "native", "new", "null", "package", "private", "protected", "public", "return", "short", "static", "strictfp", "super", "switch", "synchronized", "this", "throw", "throws", "transient", "true", "try", "void", "volatile", "while"]> +<#assign words = ["abstract", "assert", "boolean", "break", "byte", "case", "catch", "char", "class", "const", "continue", "default", "double", "do", "else", "enum", "extends", "false", "final", "finally", "float", "for", "goto", "if", "implements", "import", "instanceof", "int", "interface", "long", "native", "new", "null", "package", "private", "protected", "public", "return", "short", "static", "strictfp", "super", "switch", "synchronized", "this", "throw", "throws", "transient", "true", "try", "void", "volatile", "while"]/> +<#assign collection = ["array","map"]/> <#function calculateSafeName propertyName ender const=""> <#if words?seq_contains(propertyName?uncap_first) || propertyName?matches("[0-9].*")> <#if const?has_content> @@ -137,15 +138,14 @@ import ${packageModel}.customvalidator.UniqueItems; import lombok.Builder; <#list schema.fieldObjectList as field> - <#if field.required> -import lombok.NonNull; - <#break> - - -<#list schema.fieldObjectList as field> -<#if field.dataType.baseType == "array" || field.dataType.baseType == "map"> + <#if collection?seq_contains(field.dataType.baseType)> import lombok.Singular; - <#break> + <#break> + +<#list schema.fieldObjectList as field> + <#if field.required> +import lombok.NonNull; + <#break> import lombok.Value; From 61c7012e4cd1cf4cc4861e6fa1e27d47be9fe527 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?jose=20enrique=20garcia=20maci=C3=B1eiras?= Date: Sat, 21 Sep 2024 09:47:10 +0200 Subject: [PATCH 12/26] Rework things --- .../plugin/asyncapi/AsyncApiGenerator.java | 2 +- .../asyncapi/template/TemplateFactory.java | 2 +- .../template/CommonTemplateFactory.java | 6 +-- .../CommonTemplateIndexConstants.java | 2 + .../plugin/openapi/OpenApiGenerator.java | 6 +-- .../openapi/template/TemplateFactory.java | 39 ++++--------------- 6 files changed, 17 insertions(+), 40 deletions(-) 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 39181a7b..b94a8d30 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 @@ -422,7 +422,7 @@ private void fillTemplateFactory( schemaObjectIt.forEachRemaining(schemaObj -> writeSchemaObject(operationObject.isUseLombokModelAnnotation(), operationObject.getModelPackage(), null, schemaObj)); if (Boolean.TRUE.equals(generateExceptionTemplate)) { - templateFactory.fillTemplateModelClassException(filePath, modelPackage); + templateFactory.fillTemplateModelClassException(operationObject.getApiPackage(), modelPackage); } } } 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 a39f3ef0..c67c0935 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 @@ -221,7 +221,7 @@ public final void fillTemplateWrapper( "className", className, "keyNamespace", keyClassFullName, "keyClassName", keyClassName)); - writeTemplateToFile(TemplateIndexConstants.TEMPLATE_MESSAGE_WRAPPER, filePath.resolve("MessageWrapper.java").toAbsolutePath().toString()); + writeTemplateToFile(TemplateIndexConstants.TEMPLATE_MESSAGE_WRAPPER, filePath, "MessageWrapper"); clearData(); } diff --git a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/template/CommonTemplateFactory.java b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/template/CommonTemplateFactory.java index 68187523..2734273b 100644 --- a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/template/CommonTemplateFactory.java +++ b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/template/CommonTemplateFactory.java @@ -193,11 +193,11 @@ private Set fillTemplateSchema(final ClassTemplate classTemplate, final return propertiesSet; } - public final void fillTemplateModelClassException(final Path filePathToSave, final String modelPackage) throws IOException { - final Path pathToExceptionPackage = filePathToSave.resolve("exception"); + public final void fillTemplateModelClassException(final String filePathToSave, final String modelPackage) throws IOException { + final Path pathToExceptionPackage = Paths.get(filePathToSave).resolve("exception"); pathToExceptionPackage.toFile().mkdirs(); addToRoot(EXCEPTION_PACKAGE, modelPackage); - writeTemplateToFile(TemplateIndexConstants.TEMPLATE_MODEL_EXCEPTION, filePathToSave, "ModelClassException"); + writeTemplateToFile(CommonTemplateIndexConstants.TEMPLATE_MODEL_EXCEPTION, filePathToSave, "ModelClassException"); } private void fillTemplateCustom( diff --git a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/template/CommonTemplateIndexConstants.java b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/template/CommonTemplateIndexConstants.java index a955ecfb..224ac430 100644 --- a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/template/CommonTemplateIndexConstants.java +++ b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/template/CommonTemplateIndexConstants.java @@ -66,4 +66,6 @@ public abstract class CommonTemplateIndexConstants { public static final String TEMPLATE_UNIQUE_ITEMS_VALIDATOR_ANNOTATION = "templateUniqueItemsValidator.ftlh"; + private CommonTemplateIndexConstants() { + } } 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 aa970249..935bba10 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 @@ -295,7 +295,7 @@ private Map writeSchemaObject( try { final Set propertiesSet = new HashSet<>(); templateFactory.fillTemplateSchema(fileModelToSave, specFile.isUseLombokModelAnnotation(), schemaObject, propertiesSet); - fillTemplates(fileModelToSave, propertiesSet); + fillTempla(fileModelToSave, propertiesSet); } catch (IOException | TemplateException e) { throw new GeneratedSourcesException(schemaObject.getClassName(), e); } @@ -303,8 +303,8 @@ private Map writeSchemaObject( if (Boolean.TRUE.equals(generateExceptionTemplate)) { try { - templateFactory.fillTemplateModelClassException(fileModelToSave, true, modelPackage); - } catch (IOException | TemplateException e) { + templateFactory.fillTemplateModelClassException(fileModelToSave, modelPackage); + } catch (IOException e) { throw new GeneratedSourcesException(fileModelToSave, e); } } 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 57cb96e1..336987da 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 @@ -11,6 +11,7 @@ import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; +import java.nio.file.Paths; import java.util.List; import java.util.Map; import java.util.Objects; @@ -44,7 +45,7 @@ public final void fillTemplateSchema( TemplateException { if (Objects.nonNull(schemaObject.getFieldObjectList()) && !schemaObject.getFieldObjectList().isEmpty()) { addToRoot("schema", schemaObject); - writeTemplateToFile(templateSelector(useLombok, schemaObject), filePathToSave, schemaObject.getClassName()); + writeTemplateToFile(templateSelector(useLombok), filePathToSave, schemaObject.getClassName()); for (SchemaFieldObject fieldObject : schemaObject.getFieldObjectList()) { propertiesSet.addAll(fieldObject.getRestrictions().getProperties()); if (fieldObject.isRequired() && Boolean.FALSE.equals(useLombok)) { @@ -58,7 +59,7 @@ public final void clearData() { cleanData(); } - private static String templateSelector(final Boolean useLombok, final SchemaObject schemaObject) { + private static String templateSelector(final Boolean useLombok) { final var shouldUseLombok = Objects.requireNonNullElse(useLombok, false); final String template; @@ -71,44 +72,18 @@ private static String templateSelector(final Boolean useLombok, final SchemaObje return template; } - public final void fillTemplateModelClassException(final String filePathToSave) throws IOException, TemplateException { - final File fileToSave = new File(filePathToSave); - final Path pathToExceptionPackage = fileToSave.toPath().resolve("exception"); - pathToExceptionPackage.toFile().mkdirs(); - writeTemplateToFile(TemplateIndexConstants.TEMPLATE_MODEL_EXCEPTION, pathToExceptionPackage, "ModelClassException"); - - } - public final void fillTemplateWebClient(final String filePathToSave) throws IOException, TemplateException { - writeTemplateToFile(TemplateIndexConstants.TEMPLATE_WEB_CLIENT, pathToSaveMainClass, "ApiWebClient"); + writeTemplateToFile(TemplateIndexConstants.TEMPLATE_WEB_CLIENT, filePathToSave, "ApiWebClient"); } public final void fillTemplateRestClient(final String filePathToSave) throws IOException, TemplateException { - final File fileToSave = new File(filePathToSave); - - final String pathToSaveMainClass = fileToSave.toPath().resolve("ApiRestClient.java").toString(); - writeTemplateToFile(TemplateIndexConstants.TEMPLATE_REST_CLIENT, pathToSaveMainClass); + writeTemplateToFile(TemplateIndexConstants.TEMPLATE_REST_CLIENT, Paths.get(filePathToSave), "ApiRestClient"); } public final void fillTemplateAuth(final String filePathToSave, final String authName) throws IOException { - final File fileToSave = new File(filePathToSave); - final var nameAuthClass = authName + JAVA_EXTENSION; - final String pathToSaveMainClass = fileToSave.toPath().resolve(nameAuthClass).toString(); - writeTemplateToFile(createNameTemplate(authName), pathToSaveMainClass); - - } - - public final void fillTemplateCustom( - final String filePathToSave, final String annotationFileName, final String validatorFileName, final String annotationTemplate, - final String validatorTemplate) throws IOException { - final File fileToSave = new File(filePathToSave); - final Path pathToValidatorPackage = fileToSave.toPath().resolve("customvalidator"); - pathToValidatorPackage.toFile().mkdirs(); - final String pathToSaveMainClass = pathToValidatorPackage.resolve(annotationFileName).toString(); - writeTemplateToFile(annotationTemplate, pathToSaveMainClass); - final String pathToSaveMainClassValidator = pathToValidatorPackage.resolve(validatorFileName).toString(); - writeTemplateToFile(validatorTemplate, pathToSaveMainClassValidator); + writeTemplateToFile(createNameTemplate(authName), Paths.get(filePathToSave), authName); + } public final void fillTemplate( From 11082b23f48658992224880fe34cdce9bb033a7c Mon Sep 17 00:00:00 2001 From: "joseenrique.garcia" Date: Sat, 21 Sep 2024 12:48:07 +0200 Subject: [PATCH 13/26] Fix OpenApi generator --- .../plugin/asyncapi/AsyncApiGenerator.java | 19 ++++---- .../asyncapi/template/TemplateFactory.java | 43 ++++--------------- .../template/CommonTemplateFactory.java | 6 ++- .../CommonTemplateIndexConstants.java | 2 +- .../plugin/openapi/OpenApiGenerator.java | 21 ++++----- .../openapi/template/TemplateFactory.java | 12 ++++-- .../template/TemplateIndexConstants.java | 4 +- .../model/templateSchemaWithLombok.ftlh | 8 ++-- .../AsyncApiGeneratorJakartaTest.java | 4 +- .../asyncapi/AsyncApiGeneratorTest.java | 10 +++-- .../openapi/OpenApiGeneratorJakartaTest.java | 5 +-- .../plugin/openapi/OpenApiGeneratorTest.java | 9 ++-- .../api/generator/plugin/AsyncApiTask.groovy | 2 +- .../api/generator/plugin/OpenAsyncMojo.java | 5 ++- .../plugin/OpenapiMultiFileMojo.java | 4 +- 15 files changed, 73 insertions(+), 81 deletions(-) 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 b94a8d30..e97462d5 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 @@ -95,7 +95,7 @@ public class AsyncApiGenerator { private final List processedApiPackages = new ArrayList<>(); - private final File baseDir; + private final Path baseDir; private final TemplateFactory templateFactory; @@ -106,13 +106,13 @@ public class AsyncApiGenerator { private boolean generateExceptionTemplate; public AsyncApiGenerator(final Integer springBootVersion, + boolean overwriteModel, final File targetFolder, final String processedGeneratedSourcesFolder, final String groupId, - final File baseDir, - boolean overwriteModel) { + final File baseDir) { this.groupId = groupId; - this.baseDir = baseDir; + this.baseDir = baseDir.toPath().toAbsolutePath(); this.templateFactory = new TemplateFactory(overwriteModel, targetFolder, processedGeneratedSourcesFolder, baseDir); this.springBootVersion = springBootVersion; } @@ -411,7 +411,7 @@ private void fillTemplateFactory( final JsonNode schemaToBuild = processedMethod.getPayload(); if (shouldBuild(schemaToBuild)) { final var schemaObjectIt = - MapperContentUtil.mapComponentToSchemaObject(totalSchemas, className, schemaToBuild, parentPackage, operationObject, this.baseDir.toPath()).iterator(); + MapperContentUtil.mapComponentToSchemaObject(totalSchemas, className, schemaToBuild, parentPackage, operationObject, this.baseDir).iterator(); if (schemaObjectIt.hasNext()) { writeSchemaObject(operationObject.isUseLombokModelAnnotation(), operationObject.getModelPackage(), keyClassName, schemaObjectIt.next()); @@ -440,11 +440,10 @@ private boolean shouldBuild(final JsonNode schemaToBuild) { return result; } - private Path writeSchemaObject(final boolean usingLombok, final String modelPackageReceived, final String keyClassName, final SchemaObject schemaObject) { + private void writeSchemaObject(final boolean usingLombok, final String modelPackageReceived, final String keyClassName, final SchemaObject schemaObject) { final var destinationPackage = StringUtils.defaultIfEmpty(modelPackageReceived, DEFAULT_ASYNCAPI_API_PACKAGE + SLASH + schemaObject.getParentPackage()); templateFactory.addSchemaObject(modelPackageReceived, keyClassName, schemaObject, destinationPackage); checkRequiredOrCombinatorExists(schemaObject, usingLombok); - return filePath; } private ProcessMethodResult processMethod( @@ -506,18 +505,18 @@ private String processMessageRef(final JsonNode messageBody, final String modelP } else if (messageContent.contains("#")) { namespace = processExternalRef(modelPackage, ymlParent, messageBody); } else { - namespace = processExternalAvro(modelPackage, ymlParent, messageContent); + namespace = processExternalAvro(ymlParent, messageContent); } return namespace; } - private String processExternalAvro(final String modelPackage, final FileLocation ymlParent, final String messageContent) { + private String processExternalAvro(final FileLocation ymlParent, final String messageContent) { String avroFilePath = messageContent; final String namespace; if (messageContent.startsWith(SLASH)) { avroFilePath = avroFilePath.replaceFirst(SLASH, ""); } else if (messageContent.startsWith(".")) { - avroFilePath = baseDir.getAbsolutePath() + avroFilePath.replaceFirst("\\.", ""); + avroFilePath = baseDir.toAbsolutePath() + avroFilePath.replaceFirst("\\.", ""); } final InputStream avroFile = ymlParent.getFileAtLocation(avroFilePath); final ObjectMapper mapper = new ObjectMapper(); 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 c67c0935..82c75974 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 @@ -6,34 +6,21 @@ package com.sngular.api.generator.plugin.asyncapi.template; -import java.io.File; -import java.io.FilenameFilter; -import java.io.IOException; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.HashSet; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; -import java.util.Objects; -import java.util.Set; -import java.util.regex.Pattern; - -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; -import com.sngular.api.generator.plugin.asyncapi.parameter.OperationParameterObject; import com.sngular.api.generator.plugin.asyncapi.parameter.SpecFile; import com.sngular.api.generator.plugin.asyncapi.util.BindingTypeEnum; -import com.sngular.api.generator.plugin.common.model.SchemaFieldObject; -import com.sngular.api.generator.plugin.common.model.SchemaObject; import com.sngular.api.generator.plugin.common.template.CommonTemplateFactory; import com.sngular.api.generator.plugin.common.tools.MapperUtil; -import freemarker.template.Configuration; import freemarker.template.TemplateException; -import freemarker.template.TemplateExceptionHandler; + +import java.io.File; +import java.io.IOException; +import java.nio.file.Path; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.Objects; public class TemplateFactory extends CommonTemplateFactory { @@ -73,7 +60,7 @@ public TemplateFactory(boolean enableOverwrite, final File targetFolder, final String processedGeneratedSourcesFolder, final File baseDir) { - super(enableOverwrite, targetFolder, processedGeneratedSourcesFolder, baseDir); + super(enableOverwrite, targetFolder, processedGeneratedSourcesFolder, baseDir, new ClasspathTemplateLoader()); } public final void fillTemplates(boolean generateExceptionTemplate) throws IOException, TemplateException { @@ -200,12 +187,6 @@ public final void clearData() { publishMethods.clear(); subscribeMethods.clear(); streamBridgeMethods.clear(); - subscribeFilePath = null; - supplierFilePath = null; - streamBridgeFilePath = null; - supplierClassName = null; - subscribeClassName = null; - streamBridgeClassName = null; } public final void fillTemplateWrapper( @@ -243,12 +224,6 @@ private void generateInterfaces() throws IOException, TemplateException { final ArrayList allMethods = new ArrayList<>(subscribeMethods); allMethods.addAll(publishMethods); - addToRoot(SUBSCRIBE_PACKAGE, getFromRoot(SUBSCRIBE_PACKAGE)); - addToRoot(SUPPLIER_PACKAGE, getFromRoot(SUPPLIER_PACKAGE)); - - addToRoot(SUPPLIER_ENTITIES_SUFFIX, getFromRoot(SUPPLIER_ENTITIES_SUFFIX)); - addToRoot(SUBSCRIBE_ENTITIES_SUFFIX, getFromRoot(SUBSCRIBE_ENTITIES_SUFFIX)); - for (MethodObject method : allMethods) { addToRoot("method", method); diff --git a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/template/CommonTemplateFactory.java b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/template/CommonTemplateFactory.java index 2734273b..76a55674 100644 --- a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/template/CommonTemplateFactory.java +++ b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/template/CommonTemplateFactory.java @@ -55,9 +55,10 @@ public abstract class CommonTemplateFactory { protected CommonTemplateFactory(boolean checkOverwrite, final File targetFolder, final String processedGeneratedSourcesFolder, - final File baseDir) { + final File baseDir, + final CommonTemplateLoader classpathTemplateLoader) { this.checkOverwrite = checkOverwrite; - cfg.setTemplateLoader(new ClasspathTemplateLoader()); + cfg.setTemplateLoader(classpathTemplateLoader); cfg.setDefaultEncoding("UTF-8"); cfg.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER); cfg.setLogTemplateExceptions(true); @@ -224,6 +225,7 @@ protected Object getFromRoot(final String key) { protected void cleanData() { root.clear(); + addToRoot("checkBasicTypes", BASIC_DATA_TYPES); classTemplateList.clear(); } diff --git a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/template/CommonTemplateIndexConstants.java b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/template/CommonTemplateIndexConstants.java index 224ac430..c8fbf291 100644 --- a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/template/CommonTemplateIndexConstants.java +++ b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/template/CommonTemplateIndexConstants.java @@ -66,6 +66,6 @@ public abstract class CommonTemplateIndexConstants { public static final String TEMPLATE_UNIQUE_ITEMS_VALIDATOR_ANNOTATION = "templateUniqueItemsValidator.ftlh"; - private CommonTemplateIndexConstants() { + protected CommonTemplateIndexConstants() { } } 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 935bba10..f2abba38 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 @@ -82,14 +82,18 @@ public class OpenApiGenerator { private final Integer springBootVersion; public OpenApiGenerator( - final Integer springBootVersion, final Boolean overwriteModel, final String processedGeneratedSourcesFolder, final String groupId, - final File targetFolder, final File basedir) { - templateFactory = new TemplateFactory(); + final Integer springBootVersion, + final Boolean overwriteModel, + final File targetFolder, + final String processedGeneratedSourcesFolder, + final String groupId, + final File basedir) { this.overwriteModel = overwriteModel; this.processedGeneratedSourcesFolder = processedGeneratedSourcesFolder; this.groupId = groupId; this.targetFolder = targetFolder; this.baseDir = basedir.toPath().toAbsolutePath(); + this.templateFactory = new TemplateFactory(overwriteModel, targetFolder, processedGeneratedSourcesFolder, basedir); this.targetFileFilter = (dir, name) -> name.toLowerCase().contains(targetFolder.toPath().getFileName().toString()); this.springBootVersion = springBootVersion; } @@ -295,18 +299,15 @@ private Map writeSchemaObject( try { final Set propertiesSet = new HashSet<>(); templateFactory.fillTemplateSchema(fileModelToSave, specFile.isUseLombokModelAnnotation(), schemaObject, propertiesSet); - fillTempla(fileModelToSave, propertiesSet); } catch (IOException | TemplateException e) { throw new GeneratedSourcesException(schemaObject.getClassName(), e); } }); - if (Boolean.TRUE.equals(generateExceptionTemplate)) { - try { - templateFactory.fillTemplateModelClassException(fileModelToSave, modelPackage); - } catch (IOException e) { - throw new GeneratedSourcesException(fileModelToSave, e); - } + try { + templateFactory.fillTemplates(generateExceptionTemplate); + } catch (IOException | TemplateException e) { + throw new GeneratedSourcesException("Exception Class", e); } return schemaObjectMap; } 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 336987da..09b19d10 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 @@ -36,7 +36,7 @@ public TemplateFactory(boolean enableOverwrite, final File targetFolder, final String processedGeneratedSourcesFolder, final File baseDir) { - super(enableOverwrite, targetFolder, processedGeneratedSourcesFolder, baseDir); + super(enableOverwrite, targetFolder, processedGeneratedSourcesFolder, baseDir, new ClasspathTemplateLoader()); } public final void fillTemplateSchema( @@ -77,13 +77,12 @@ public final void fillTemplateWebClient(final String filePathToSave) throws IOEx } public final void fillTemplateRestClient(final String filePathToSave) throws IOException, TemplateException { - writeTemplateToFile(TemplateIndexConstants.TEMPLATE_REST_CLIENT, Paths.get(filePathToSave), "ApiRestClient"); + writeTemplateToFile(TemplateIndexConstants.TEMPLATE_REST_CLIENT, filePathToSave, "ApiRestClient"); } public final void fillTemplateAuth(final String filePathToSave, final String authName) throws IOException { - writeTemplateToFile(createNameTemplate(authName), Paths.get(filePathToSave), authName); - + writeTemplateToFile(createNameTemplate(authName),filePathToSave, authName); } public final void fillTemplate( @@ -109,6 +108,11 @@ public final void fillTemplate( } + public final void fillTemplates(boolean generateExceptionTemplate) throws IOException, TemplateException { + generateTemplates(generateExceptionTemplate); + + } + public final void calculateJavaEEPackage(final Integer springBootVersion) { if (3 <= springBootVersion) { addToRoot("javaEEPackage", "jakarta"); diff --git a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/openapi/template/TemplateIndexConstants.java b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/openapi/template/TemplateIndexConstants.java index c998266b..662dfc06 100644 --- a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/openapi/template/TemplateIndexConstants.java +++ b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/openapi/template/TemplateIndexConstants.java @@ -34,6 +34,8 @@ public class TemplateIndexConstants extends CommonTemplateIndexConstants { public static final String TEMPLATE_OAUTH_FLOW = "templateOAuthFlow.ftlh"; - private TemplateIndexConstants() {} + private TemplateIndexConstants() { + super(); + } } diff --git a/multiapi-engine/src/main/resources/templates/model/templateSchemaWithLombok.ftlh b/multiapi-engine/src/main/resources/templates/model/templateSchemaWithLombok.ftlh index ad6baa93..5ef641b9 100644 --- a/multiapi-engine/src/main/resources/templates/model/templateSchemaWithLombok.ftlh +++ b/multiapi-engine/src/main/resources/templates/model/templateSchemaWithLombok.ftlh @@ -142,6 +142,7 @@ import lombok.Builder; import lombok.Singular; <#break> + <#list schema.fieldObjectList as field> <#if field.required> import lombok.NonNull; @@ -235,12 +236,11 @@ public class ${schema.className} { return String.valueOf(value); } } - <#elseif field.dataType.innerType?has_content && field.dataType.baseType == "object"> +<#elseif field.dataType.innerType?has_content && field.dataType.baseType == "object"> private ${field.dataType.innerType?cap_first} ${field.baseName?uncap_first}; - <#else> +<#else> private ${field.dataType} ${createSimpleType (field)} - - + @Builder diff --git a/multiapi-engine/src/test/java/com/sngular/api/generator/plugin/asyncapi/AsyncApiGeneratorJakartaTest.java b/multiapi-engine/src/test/java/com/sngular/api/generator/plugin/asyncapi/AsyncApiGeneratorJakartaTest.java index 8ed76dd1..cfdbbe3c 100644 --- a/multiapi-engine/src/test/java/com/sngular/api/generator/plugin/asyncapi/AsyncApiGeneratorJakartaTest.java +++ b/multiapi-engine/src/test/java/com/sngular/api/generator/plugin/asyncapi/AsyncApiGeneratorJakartaTest.java @@ -32,9 +32,9 @@ class AsyncApiGeneratorJakartaTest { @BeforeAll static void setup() { asyncApiGenerator = - new AsyncApiGenerator(SPRING_BOOT_VERSION, new File(baseDir.toAbsolutePath() + File.separator + AsyncApiGeneratorFixtures.TARGET), AsyncApiGeneratorFixtures.GENERATED, + new AsyncApiGenerator(SPRING_BOOT_VERSION, true, new File(baseDir.toAbsolutePath() + File.separator + AsyncApiGeneratorFixtures.TARGET), AsyncApiGeneratorFixtures.GENERATED, "groupId", - baseDir.toFile(), overwriteModel); + baseDir.toFile()); } static Stream fileSpecToProcess() { 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 e82e3948..2ad8a406 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 @@ -38,9 +38,13 @@ class AsyncApiGeneratorTest { @BeforeAll static void setup() { asyncApiGenerator = - new AsyncApiGenerator(SPRING_BOOT_VERSION, new File(baseDir.toAbsolutePath() + File.separator + AsyncApiGeneratorFixtures.TARGET), AsyncApiGeneratorFixtures.GENERATED, - "groupId", - baseDir.toFile(), overwriteModel); + new AsyncApiGenerator(SPRING_BOOT_VERSION, + true, + new File(baseDir.toAbsolutePath() + File.separator + AsyncApiGeneratorFixtures.TARGET), + AsyncApiGeneratorFixtures.GENERATED, + "groupId", + Path.of("src","test","resources").toFile() + ); } static Stream fileSpecToProcess() { diff --git a/multiapi-engine/src/test/java/com/sngular/api/generator/plugin/openapi/OpenApiGeneratorJakartaTest.java b/multiapi-engine/src/test/java/com/sngular/api/generator/plugin/openapi/OpenApiGeneratorJakartaTest.java index 174575a2..470bb9ec 100644 --- a/multiapi-engine/src/test/java/com/sngular/api/generator/plugin/openapi/OpenApiGeneratorJakartaTest.java +++ b/multiapi-engine/src/test/java/com/sngular/api/generator/plugin/openapi/OpenApiGeneratorJakartaTest.java @@ -33,9 +33,8 @@ class OpenApiGeneratorJakartaTest { @BeforeAll static void setup() { openApiGenerator = - new OpenApiGenerator(SPRING_BOOT_VERSION, Boolean.TRUE, OpenApiGeneratorFixtures.GENERATED, "groupId", - new File(baseDir.toAbsolutePath() + File.separator + OpenApiGeneratorFixtures.TARGET), - baseDir.toFile()); + new OpenApiGenerator(SPRING_BOOT_VERSION, Boolean.TRUE, new File(baseDir.toAbsolutePath() + File.separator + OpenApiGeneratorFixtures.TARGET), OpenApiGeneratorFixtures.GENERATED, "groupId", + baseDir.toFile()); } static Stream fileSpecToProcess() { diff --git a/multiapi-engine/src/test/java/com/sngular/api/generator/plugin/openapi/OpenApiGeneratorTest.java b/multiapi-engine/src/test/java/com/sngular/api/generator/plugin/openapi/OpenApiGeneratorTest.java index f5ded4be..f05e91df 100644 --- a/multiapi-engine/src/test/java/com/sngular/api/generator/plugin/openapi/OpenApiGeneratorTest.java +++ b/multiapi-engine/src/test/java/com/sngular/api/generator/plugin/openapi/OpenApiGeneratorTest.java @@ -37,9 +37,12 @@ class OpenApiGeneratorTest { @BeforeAll static void setup() { openApiGenerator = - new OpenApiGenerator(SPRING_BOOT_VERSION, Boolean.TRUE, OpenApiGeneratorFixtures.GENERATED, "groupId", - new File(baseDir.toAbsolutePath() + File.separator + OpenApiGeneratorFixtures.TARGET), - Path.of("src","test","resources").toFile()); + new OpenApiGenerator(SPRING_BOOT_VERSION, + Boolean.TRUE, + new File(baseDir.toAbsolutePath() + File.separator + OpenApiGeneratorFixtures.TARGET), + OpenApiGeneratorFixtures.GENERATED, + "groupId", + Path.of("src","test","resources").toFile()); } static Stream fileSpecToProcess() { diff --git a/scs-multiapi-gradle-plugin/src/main/groovy/com/sngular/api/generator/plugin/AsyncApiTask.groovy b/scs-multiapi-gradle-plugin/src/main/groovy/com/sngular/api/generator/plugin/AsyncApiTask.groovy index 02d3eea5..74c39b13 100644 --- a/scs-multiapi-gradle-plugin/src/main/groovy/com/sngular/api/generator/plugin/AsyncApiTask.groovy +++ b/scs-multiapi-gradle-plugin/src/main/groovy/com/sngular/api/generator/plugin/AsyncApiTask.groovy @@ -30,7 +30,7 @@ abstract class AsyncApiTask extends DefaultTask { def generatedDir = getOrCreateGenerated(getOutputDir()) AsyncApiModelExtension asyncApiModelExtension = getProject().getExtensions().getByType(AsyncApiModelExtension.class) if (null != asyncApiModelExtension && !asyncApiModelExtension.getSpecFiles().isEmpty()) { - def asyncApiGen = new AsyncApiGenerator(asyncApiModelExtension.getSpringBootVersion(), targetFolder, generatedDir, project.getGroup() as String, project.getProjectDir()) + def asyncApiGen = new AsyncApiGenerator(asyncApiModelExtension.getSpringBootVersion(), asyncApiModelExtension.getOverWriteModel(), targetFolder, generatedDir, project.getGroup() as String, project.getProjectDir()) List asyncApiSpecFiles = [] asyncApiModelExtension.getSpecFiles().forEach(apiSpec -> { asyncApiSpecFiles.add(toFileSpec(apiSpec)) diff --git a/scs-multiapi-maven-plugin/src/main/java/com/sngular/api/generator/plugin/OpenAsyncMojo.java b/scs-multiapi-maven-plugin/src/main/java/com/sngular/api/generator/plugin/OpenAsyncMojo.java index 11693d17..df5a4b22 100644 --- a/scs-multiapi-maven-plugin/src/main/java/com/sngular/api/generator/plugin/OpenAsyncMojo.java +++ b/scs-multiapi-maven-plugin/src/main/java/com/sngular/api/generator/plugin/OpenAsyncMojo.java @@ -39,12 +39,15 @@ public final class OpenAsyncMojo extends AbstractMojo { @Parameter(name = "springBootVersion", property = "spring-boot-version", defaultValue = "2") private Integer springBootVersion; + @Parameter(name = "overwriteModel", property = "overwriteModel", defaultValue = "true") + private Boolean overwriteModel; + @Override public void execute() { final var processedGeneratedSourcesFolder = processGeneratedSourcesFolderName(); addGeneratedSourcesToProject(processedGeneratedSourcesFolder); - final var asyncApiGenerator = new AsyncApiGenerator(springBootVersion, targetFolder, processedGeneratedSourcesFolder, project.getModel().getGroupId(), project.getBasedir(), overwriteModel); + final var asyncApiGenerator = new AsyncApiGenerator(springBootVersion, overwriteModel, targetFolder, processedGeneratedSourcesFolder, project.getModel().getGroupId(), project.getBasedir()); asyncApiGenerator.processFileSpec(specFiles); diff --git a/scs-multiapi-maven-plugin/src/main/java/com/sngular/api/generator/plugin/OpenapiMultiFileMojo.java b/scs-multiapi-maven-plugin/src/main/java/com/sngular/api/generator/plugin/OpenapiMultiFileMojo.java index c0b62539..bdd310f9 100644 --- a/scs-multiapi-maven-plugin/src/main/java/com/sngular/api/generator/plugin/OpenapiMultiFileMojo.java +++ b/scs-multiapi-maven-plugin/src/main/java/com/sngular/api/generator/plugin/OpenapiMultiFileMojo.java @@ -50,8 +50,8 @@ public final class OpenapiMultiFileMojo extends AbstractMojo { public void execute() throws MojoExecutionException { processGeneratedSourcesFolderName(); addGeneratedSourcesToProject(); - final OpenApiGenerator openApiGenerator = new OpenApiGenerator(springBootVersion, overwriteModel, processedGeneratedSourcesFolder, project.getModel().getGroupId(), - targetFolder, project.getBasedir()); + final OpenApiGenerator openApiGenerator = new OpenApiGenerator(springBootVersion, overwriteModel, targetFolder, processedGeneratedSourcesFolder, project.getModel().getGroupId(), + project.getBasedir()); if (null != specFiles && !specFiles.isEmpty()) { openApiGenerator.processFileSpec(specFiles); } else { From e047fd23bdfb35ec1724cb4ad73bdab3f4941467 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Enrique=20Garc=C3=ADa=20Maci=C3=B1eiras?= Date: Sat, 21 Sep 2024 20:12:12 +0200 Subject: [PATCH 14/26] Fix things --- .../template/CommonTemplateFactory.java | 35 +++++---- .../plugin/common/tools/MapperUtil.java | 4 ++ .../templates/model/templateSchema.ftlh | 2 +- .../asyncapi/AsyncApiGeneratorFixtures.java | 72 ++++++++++--------- .../asyncapi/AsyncApiGeneratorTest.java | 2 +- .../testCustomValidators/assets/DataDTO.java | 6 +- .../testFileGeneration/assets/OrderDTO.java | 2 +- .../assets/OrderLineDTO.java | 2 +- .../assets/OrderLineMapper.java | 2 +- .../assets/OrderMapper.java | 2 +- .../assets/ObjectArrayDTO.java | 2 +- .../assets/CustomerOrderDTO.java | 4 +- .../assets/OrderDTO.java | 2 +- .../assets/OrderLineDTO.java | 2 +- .../assets/OrderLineMapper.java | 2 +- .../assets/OrderMapper.java | 2 +- .../assets/MailRequestDTO.java | 2 +- .../assets/MailRequestInfiniteDTO.java | 2 +- .../assets/schemas/MailRequestDTO.java | 2 +- .../assets/OrderDTO.java | 2 +- .../assets/OrderLineDTO.java | 2 +- .../assets/OrderDTO.java | 6 +- .../assets/OrderLineDTO.java | 6 +- .../testReservedWordsGeneration/event-api.yml | 4 +- 24 files changed, 93 insertions(+), 76 deletions(-) diff --git a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/template/CommonTemplateFactory.java b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/template/CommonTemplateFactory.java index 76a55674..57569975 100644 --- a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/template/CommonTemplateFactory.java +++ b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/template/CommonTemplateFactory.java @@ -7,6 +7,7 @@ import com.sngular.api.generator.plugin.asyncapi.template.TemplateIndexConstants; import com.sngular.api.generator.plugin.common.model.SchemaFieldObject; import com.sngular.api.generator.plugin.common.model.SchemaObject; +import com.sngular.api.generator.plugin.common.tools.MapperUtil; import com.sngular.api.generator.plugin.exception.GeneratorTemplateException; import com.sngular.api.generator.plugin.openapi.exception.OverwritingApiFilesException; import freemarker.template.Configuration; @@ -195,20 +196,22 @@ private Set fillTemplateSchema(final ClassTemplate classTemplate, final } public final void fillTemplateModelClassException(final String filePathToSave, final String modelPackage) throws IOException { - final Path pathToExceptionPackage = Paths.get(filePathToSave).resolve("exception"); - pathToExceptionPackage.toFile().mkdirs(); addToRoot(EXCEPTION_PACKAGE, modelPackage); - writeTemplateToFile(CommonTemplateIndexConstants.TEMPLATE_MODEL_EXCEPTION, filePathToSave, "ModelClassException"); + writeTemplateToFile(CommonTemplateIndexConstants.TEMPLATE_MODEL_EXCEPTION, MapperUtil.packageToFolder(filePathToSave) + SLASH + "exception", "ModelClassException"); } private void fillTemplateCustom( final Path filePathToSave, final String modelPackage, final String fileNameAnnotation, final String templateAnnotation, final String fileNameValidator, final String templateValidator) throws IOException { final Path pathToCustomValidatorPackage = filePathToSave.resolve("customvalidator"); - pathToCustomValidatorPackage.toFile().mkdirs(); + if (!pathToCustomValidatorPackage.toFile().exists()) { + if (!pathToCustomValidatorPackage.toFile().mkdirs()) { + throw new RuntimeException("Can't create custom validator directory"); + } + } root.put("packageModel", modelPackage); - writeTemplateToFile(templateAnnotation, filePathToSave, fileNameAnnotation); - writeTemplateToFile(templateValidator, filePathToSave, fileNameValidator); + writeTemplateToFile(templateAnnotation, pathToCustomValidatorPackage, fileNameAnnotation); + writeTemplateToFile(templateValidator, pathToCustomValidatorPackage, fileNameValidator); } protected void addToRoot(final String key, final Object value) { @@ -219,10 +222,6 @@ protected void addToRoot(final Map propertiesSet) { root.putAll(propertiesSet); } - protected Object getFromRoot(final String key) { - return root.get(key); - } - protected void cleanData() { root.clear(); addToRoot("checkBasicTypes", BASIC_DATA_TYPES); @@ -235,8 +234,13 @@ public final void addSchemaObject(final String modelPackage, final String destinationPackage) { final var filePath = processPath(getPath(destinationPackage)); final var propertiesPath = processPath(getPath(modelPackage)); - final var builder = ClassTemplate.builder().filePath(filePath).modelPackage(modelPackage).className(schemaObject.getClassName()).classSchema(schemaObject) - .propertiesPath(propertiesPath); + final var builder = ClassTemplate + .builder() + .filePath(filePath) + .modelPackage(modelPackage) + .className(schemaObject.getClassName()) + .classSchema(schemaObject) + .propertiesPath(propertiesPath); if (Objects.nonNull(keyClassName)) { builder.keyClassName(keyClassName); } @@ -244,10 +248,15 @@ public final void addSchemaObject(final String modelPackage, } protected void writeTemplateToFile(final String templateName, final String filePathToSave, final String partialPath) throws IOException { - writeTemplateToFile(templateName, Paths.get(filePathToSave), partialPath); + writeTemplateToFile(templateName, processPath(getPath(filePathToSave)), partialPath); } protected void writeTemplateToFile(final String templateName, final Path filePathToSave, final String partialPath) throws IOException { + if (!filePathToSave.toFile().exists()) { + if (!filePathToSave.toFile().mkdirs()) { + throw new IOException("Could not create directory: " + filePathToSave.toFile().getAbsolutePath()); + } + } final String path = filePathToSave.resolve(partialPath + FILE_TYPE_JAVA).toString(); final Template template = cfg.getTemplate(templateName); diff --git a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/tools/MapperUtil.java b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/tools/MapperUtil.java index 50659064..67a8cd51 100644 --- a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/tools/MapperUtil.java +++ b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/tools/MapperUtil.java @@ -67,6 +67,10 @@ public static String[] splitName(final String name) { return ArrayUtils.removeAllOccurrences(name.split(DIVISOR), ""); } + public static String packageToFolder(final String packageName) { + return StringUtils.replace(packageName, ".", SLASH); + } + public static String buildKey(final String[] pathList) { final var arrayLength = pathList.length; return (arrayLength > 2 ? pathList[arrayLength - 2] + SLASH + pathList[arrayLength - 1] : pathList[0]).toUpperCase(); diff --git a/multiapi-engine/src/main/resources/templates/model/templateSchema.ftlh b/multiapi-engine/src/main/resources/templates/model/templateSchema.ftlh index 35f5ebde..1cc1b1e4 100644 --- a/multiapi-engine/src/main/resources/templates/model/templateSchema.ftlh +++ b/multiapi-engine/src/main/resources/templates/model/templateSchema.ftlh @@ -295,7 +295,7 @@ public class ${schema.className} { <#assign singName>${singularizeName (calculateSafeName (field.baseName, ""))} public ${schema.className}.${schema.className}Builder ${singName}(${field.dataType.innerType} ${singName}) { - if (${singName} != null) { + if (Objects.nonNull(${singName})) { this.${propName}.add(${singName}); } return this; 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 7b5e038e..1c6735af 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 @@ -420,7 +420,9 @@ static Function validateTestFileGeneration() { final String CUSTOM_VALIDATOR_PATH = COMMON_PATH + "customvalidator/"; - final String DEFAULT_EXCEPTION_API = "generated/com/sngular/scsplugin/filegeneration/model/event/exception"; + final String DEFAULT_CONSUMER_EXCEPTION_API = DEFAULT_CONSUMER_FOLDER + "/exception"; + + final String DEFAULT_PRODUCER_EXCEPTION_API = DEFAULT_PRODUCER_FOLDER + "/exception"; final List expectedConsumerFiles = List.of( ASSETS_PATH + "IPublishOperationFileGeneration.java", @@ -450,14 +452,14 @@ static Function validateTestFileGeneration() { ASSETS_PATH + "ModelClassException.java"); return (path) -> commonTest(path, expectedConsumerFiles, expectedProducerFiles, DEFAULT_CONSUMER_FOLDER, DEFAULT_PRODUCER_FOLDER, - expectedExceptionFiles, DEFAULT_EXCEPTION_API) && + expectedExceptionFiles, List.of(DEFAULT_CONSUMER_EXCEPTION_API, DEFAULT_PRODUCER_EXCEPTION_API)) && modelTest(path, expectedModelSchemaFiles, DEFAULT_COMMON_FOLDER) && customValidatorTest(path, expectedValidatorFiles, DEFAULT_CUSTOM_VALIDATOR_FOLDER); } private static Boolean commonTest( final Path resultPath, final List expectedFile, final List expectedModelFiles, final String targetConsumer, - final String targetProducer, final List expectedExceptionFiles, final String targetException) { + final String targetProducer, final List expectedExceptionFiles, final List targetExceptionList) { Boolean result = Boolean.TRUE; try { final Path pathToTarget = Path.of(resultPath.toString(), "target"); @@ -475,10 +477,12 @@ private static Boolean commonTest( } if (CollectionUtils.isNotEmpty(expectedExceptionFiles)) { - final Path pathToTargetException = pathToTarget.resolve(targetException); - final File targetModelException = pathToTargetException.toFile(); - Assertions.assertThat(targetModelException).isNotEmptyDirectory(); - TestUtils.validateFiles(expectedExceptionFiles, targetModelException); + for (final var targetException: targetExceptionList) { + final Path pathToTargetException = pathToTarget.resolve(targetException); + final File targetModelException = pathToTargetException.toFile(); + Assertions.assertThat(targetModelException).isNotEmptyDirectory(); + TestUtils.validateFiles(expectedExceptionFiles, targetModelException); + } } } catch (final IOException e) { result = Boolean.FALSE; @@ -544,10 +548,8 @@ static Function validateTestIssueGeneration() { ASSETS_PATH + "StatusMsgDTO.java" ); - final List expectedExceptionFiles = List.of(); - return (path) -> commonTest(path, expectedConsumerFiles, expectedProducerFiles, DEFAULT_CONSUMER_FOLDER, DEFAULT_PRODUCER_FOLDER, - expectedExceptionFiles, null) && + Collections.emptyList(), Collections.emptyList()) && modelTest(path, expectedModelSchemaFiles, DEFAULT_MODEL_SCHEMA_FOLDER); } @@ -575,10 +577,8 @@ static Function validateTestIssueSimpleTypeGeneration() { ASSETS_PATH + "StatusMsgDTO.java" ); - final List expectedExceptionFiles = List.of(); - return (path) -> commonTest(path, expectedConsumerFiles, expectedProducerFiles, DEFAULT_CONSUMER_FOLDER, DEFAULT_PRODUCER_FOLDER, - expectedExceptionFiles, null) && + Collections.emptyList(), Collections.emptyList()) && modelTest(path, expectedModelSchemaFiles, DEFAULT_MODEL_SCHEMA_FOLDER); } @@ -608,9 +608,7 @@ static Function validateTestReservedWordsGeneration() { ASSETS_PATH + "WaiterDTO.java" ); - final List expectedExceptionFiles = List.of(); - - return (path) -> commonTest(path, expectedConsumerFiles, expectedProducerFiles, DEFAULT_CONSUMER_FOLDER, DEFAULT_PRODUCER_FOLDER, expectedExceptionFiles, null) && + return (path) -> commonTest(path, expectedConsumerFiles, expectedProducerFiles, DEFAULT_CONSUMER_FOLDER, DEFAULT_PRODUCER_FOLDER, Collections.emptyList(), Collections.emptyList()) && modelTest(path, expectedModelSchemaFiles, DEFAULT_MODEL_SCHEMA_FOLDER); } @@ -639,9 +637,7 @@ static Function validateTestRareCharsGeneration() { ASSETS_PATH + "WaiterDTO.java" ); - final List expectedExceptionFiles = List.of(); - - return (path) -> commonTest(path, expectedConsumerFiles, expectedProducerFiles, DEFAULT_CONSUMER_FOLDER, DEFAULT_PRODUCER_FOLDER, expectedExceptionFiles, null) && + return (path) -> commonTest(path, expectedConsumerFiles, expectedProducerFiles, DEFAULT_CONSUMER_FOLDER, DEFAULT_PRODUCER_FOLDER, Collections.emptyList(), Collections.emptyList()) && modelTest(path, expectedModelSchemaFiles, DEFAULT_MODEL_SCHEMA_FOLDER); } @@ -660,7 +656,9 @@ static Function validateCustomValidators(final int springBootVers final String CUSTOM_VALIDATOR_PATH = COMMON_PATH + "customvalidator/" + calculateJavaEEPackage(springBootVersion); - final String DEFAULT_EXCEPTION_API = "generated/com/sngular/scsplugin/customvalidator/model/event/exception"; + final String DEFAULT_CONSUMER_EXCEPTION_API = DEFAULT_CONSUMER_FOLDER + "/exception"; + + final String DEFAULT_PRODUCER_EXCEPTION_API = DEFAULT_PRODUCER_FOLDER + "/exception"; final List expectedConsumerFiles = List.of( ASSETS_PATH + "ICustomValidatorResponse.java", @@ -712,7 +710,7 @@ static Function validateCustomValidators(final int springBootVers ASSETS_PATH + "ModelClassException.java"); return (path) -> commonTest(path, expectedConsumerFiles, expectedProducerFiles, DEFAULT_CONSUMER_FOLDER, DEFAULT_PRODUCER_FOLDER, - expectedExceptionFiles, DEFAULT_EXCEPTION_API) && + expectedExceptionFiles, List.of(DEFAULT_CONSUMER_EXCEPTION_API, DEFAULT_PRODUCER_EXCEPTION_API)) && modelTest(path, expectedModelSchemaFiles, DEFAULT_MODEL_SCHEMA_FOLDER) && customValidatorTest(path, expectedValidatorFiles, DEFAULT_CUSTOM_VALIDATOR_FOLDER); } @@ -741,7 +739,9 @@ static Function validateTestFileGenerationIssue() { final String CUSTOM_VALIDATOR_PATH = COMMON_PATH + "customvalidator/"; - final String DEFAULT_EXCEPTION_API = "generated/com/sngular/scsplugin/filegenerationissue/model/event/exception"; + final String DEFAULT_CONSUMER_EXCEPTION_API = DEFAULT_CONSUMER_FOLDER + "/exception"; + + final String DEFAULT_PRODUCER_EXCEPTION_API = DEFAULT_PRODUCER_FOLDER + "/exception"; final List expectedConsumerFiles = List.of( ASSETS_PATH + "IOnCustomerEvent.java", @@ -772,7 +772,7 @@ static Function validateTestFileGenerationIssue() { ASSETS_PATH + "ModelClassException.java"); return (path) -> commonTest(path, expectedConsumerFiles, expectedProducerFiles, DEFAULT_CONSUMER_FOLDER, DEFAULT_PRODUCER_FOLDER, - expectedExceptionFiles, DEFAULT_EXCEPTION_API) && + expectedExceptionFiles, List.of(DEFAULT_CONSUMER_EXCEPTION_API, DEFAULT_PRODUCER_EXCEPTION_API)) && modelTest(path, expectedModelSchemaFiles, DEFAULT_COMMON_FOLDER) && customValidatorTest(path, expectedValidatorFiles, DEFAULT_CUSTOM_VALIDATOR_FOLDER); } @@ -786,8 +786,6 @@ static Function validateTestFileGenerationExternalAvro() { final String ASSETS_PATH = COMMON_PATH + "assets/"; - final String DEFAULT_EXCEPTION_API = "generated/com/sngular/scsplugin/externalavro/model/event/exception"; - final List expectedConsumerFiles = List.of( ASSETS_PATH + "ISubscribeOperationExternalAvro.java", ASSETS_PATH + "ISubscribeReceiptExternalAvro.java", @@ -800,7 +798,7 @@ static Function validateTestFileGenerationExternalAvro() { ); return (path) -> commonTest(path, expectedConsumerFiles, expectedProducerFiles, DEFAULT_CONSUMER_FOLDER, DEFAULT_PRODUCER_FOLDER, - Collections.emptyList(), DEFAULT_EXCEPTION_API); + Collections.emptyList(), Collections.emptyList()); } static Function validateTestFileGenerationStreamBridge() { @@ -812,7 +810,9 @@ static Function validateTestFileGenerationStreamBridge() { final String ASSETS_PATH = COMMON_PATH + "assets/"; - final String DEFAULT_EXCEPTION_API = "generated/com/sngular/scsplugin/streambridge/model/event/exception"; + final String DEFAULT_CONSUMER_EXCEPTION_API = DEFAULT_CONSUMER_FOLDER + "/exception"; + + final String DEFAULT_PRODUCER_EXCEPTION_API = DEFAULT_PRODUCER_FOLDER + "/exception"; final List expectedConsumerFiles = List.of( ASSETS_PATH + "ISubscribeOperationStreamBridge.java", @@ -827,7 +827,7 @@ static Function validateTestFileGenerationStreamBridge() { ASSETS_PATH + "ModelClassException.java"); return (path) -> commonTest(path, expectedConsumerFiles, expectedProducerFiles, DEFAULT_CONSUMER_FOLDER, DEFAULT_PRODUCER_FOLDER, - expectedExceptionFiles, DEFAULT_EXCEPTION_API); + expectedExceptionFiles, List.of(DEFAULT_CONSUMER_EXCEPTION_API, DEFAULT_PRODUCER_EXCEPTION_API)); } static Function validateTestFileGenerationWithoutIds() { @@ -839,7 +839,9 @@ static Function validateTestFileGenerationWithoutIds() { final String ASSETS_PATH = COMMON_PATH + "assets/"; - final String DEFAULT_EXCEPTION_API = "generated/com/sngular/scsplugin/withoutids/model/event/exception"; + final String DEFAULT_CONSUMER_EXCEPTION_API = DEFAULT_CONSUMER_FOLDER + "/exception"; + + final String DEFAULT_PRODUCER_EXCEPTION_API = DEFAULT_PRODUCER_FOLDER + "/exception"; final List expectedConsumerFiles = List.of( ASSETS_PATH + "ISubscribeOperation.java", @@ -854,7 +856,7 @@ static Function validateTestFileGenerationWithoutIds() { ASSETS_PATH + "ModelClassException.java"); return (path) -> commonTest(path, expectedConsumerFiles, expectedProducerFiles, DEFAULT_CONSUMER_FOLDER, DEFAULT_PRODUCER_FOLDER, - expectedExceptionFiles, DEFAULT_EXCEPTION_API); + expectedExceptionFiles, List.of(DEFAULT_CONSUMER_EXCEPTION_API, DEFAULT_PRODUCER_EXCEPTION_API)); } static Function validateTestFileGenerationArrayString() { @@ -909,7 +911,9 @@ static Function validateTestModelClassExceptionGeneration() { final String CUSTOM_VALIDATOR_PATH = COMMON_PATH + "customvalidator/"; - final String DEFAULT_EXCEPTION_API = DEFAULT_COMMON_FOLDER + "/exception"; + final String DEFAULT_CONSUMER_EXCEPTION_API = DEFAULT_CONSUMER_FOLDER + "/exception"; + + final String DEFAULT_PRODUCER_EXCEPTION_API = DEFAULT_PRODUCER_FOLDER + "/exception"; final List expectedConsumerFiles = List.of( ASSETS_PATH + "ISubscribeOrder.java", @@ -936,7 +940,7 @@ static Function validateTestModelClassExceptionGeneration() { ASSETS_PATH + "ModelClassException.java"); return (path) -> commonTest(path, expectedConsumerFiles, expectedProducerFiles, DEFAULT_CONSUMER_FOLDER, DEFAULT_PRODUCER_FOLDER, - expectedExceptionFiles, DEFAULT_EXCEPTION_API) && + expectedExceptionFiles, List.of(DEFAULT_CONSUMER_EXCEPTION_API, DEFAULT_PRODUCER_EXCEPTION_API)) && modelTest(path, expectedModelSchemaFiles, DEFAULT_COMMON_FOLDER) && customValidatorTest(path, expectedValidatorFiles, DEFAULT_CUSTOM_VALIDATOR_FOLDER); } @@ -1051,7 +1055,7 @@ static Function validateTestFileGenerationWithKafkaBindings() { CUSTOM_VALIDATOR_PATH + "NotNullValidator.java" ); - return (path) -> commonTest(path, expectedConsumerFiles, expectedProducerFiles, DEFAULT_CONSUMER_FOLDER, DEFAULT_PRODUCER_FOLDER, Collections.emptyList(), null) && + return (path) -> commonTest(path, expectedConsumerFiles, expectedProducerFiles, DEFAULT_CONSUMER_FOLDER, DEFAULT_PRODUCER_FOLDER, Collections.emptyList(), Collections.emptyList()) && modelTest(path, expectedModelSchemaFiles, DEFAULT_COMMON_FOLDER) && customValidatorTest(path, expectedValidatorFiles, DEFAULT_CUSTOM_VALIDATOR_FOLDER); } @@ -1095,7 +1099,7 @@ static Function validateTestSubObjectSameName() { DEFAULT_CONSUMER_FOLDER, DEFAULT_PRODUCER_FOLDER, Collections.emptyList(), - null) + Collections.emptyList()) && modelTest(path, expectedConsumerModelSchemaFiles, DEFAULT_CONSUMER_MODEL_FOLDER) && modelTest(path, expectedProducerModelSchemaFiles, DEFAULT_PRODUCER_MODEL_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 2ad8a406..49edd58d 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 @@ -28,7 +28,7 @@ @Slf4j class AsyncApiGeneratorTest { - @TempDir(cleanup = CleanupMode.ALWAYS) + @TempDir(cleanup = CleanupMode.NEVER) static Path baseDir; private static AsyncApiGenerator asyncApiGenerator; diff --git a/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/assets/DataDTO.java b/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/assets/DataDTO.java index 457ee5bc..aefeaad3 100644 --- a/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/assets/DataDTO.java +++ b/multiapi-engine/src/test/resources/asyncapigenerator/testCustomValidators/assets/DataDTO.java @@ -85,9 +85,9 @@ public DataDTO.DataDTOBuilder test(List test) { return this; } - public DataDTO.DataDTOBuilder test(Integer test) { - if (test != null) { - this.test.add(test); + public DataDTO.DataDTOBuilder _test(Integer _test) { + if (Objects.nonNull(_test)) { + this.test.add(_test); } return this; } diff --git a/multiapi-engine/src/test/resources/asyncapigenerator/testFileGeneration/assets/OrderDTO.java b/multiapi-engine/src/test/resources/asyncapigenerator/testFileGeneration/assets/OrderDTO.java index 9e3d144d..6b403fc1 100644 --- a/multiapi-engine/src/test/resources/asyncapigenerator/testFileGeneration/assets/OrderDTO.java +++ b/multiapi-engine/src/test/resources/asyncapigenerator/testFileGeneration/assets/OrderDTO.java @@ -60,7 +60,7 @@ public OrderDTO.OrderDTOBuilder lines(List lines) { } public OrderDTO.OrderDTOBuilder line(OrderLineDTO line) { - if (line != null) { + if (Objects.nonNull(line)) { this.lines.add(line); } return this; diff --git a/multiapi-engine/src/test/resources/asyncapigenerator/testFileGeneration/assets/OrderLineDTO.java b/multiapi-engine/src/test/resources/asyncapigenerator/testFileGeneration/assets/OrderLineDTO.java index 9bedb67d..c7a7b492 100644 --- a/multiapi-engine/src/test/resources/asyncapigenerator/testFileGeneration/assets/OrderLineDTO.java +++ b/multiapi-engine/src/test/resources/asyncapigenerator/testFileGeneration/assets/OrderLineDTO.java @@ -45,7 +45,7 @@ public OrderLineDTO.OrderLineDTOBuilder products(List products) } public OrderLineDTO.OrderLineDTOBuilder product(OrderProductDTO product) { - if (product != null) { + if (Objects.nonNull(product)) { this.products.add(product); } return this; diff --git a/multiapi-engine/src/test/resources/asyncapigenerator/testFileGeneration/assets/OrderLineMapper.java b/multiapi-engine/src/test/resources/asyncapigenerator/testFileGeneration/assets/OrderLineMapper.java index b104db2b..0e214061 100644 --- a/multiapi-engine/src/test/resources/asyncapigenerator/testFileGeneration/assets/OrderLineMapper.java +++ b/multiapi-engine/src/test/resources/asyncapigenerator/testFileGeneration/assets/OrderLineMapper.java @@ -45,7 +45,7 @@ public OrderLineMapper.OrderLineMapperBuilder products(List } public OrderLineMapper.OrderLineMapperBuilder product(OrderProductMapper product) { - if (product != null) { + if (Objects.nonNull(product)) { this.products.add(product); } return this; diff --git a/multiapi-engine/src/test/resources/asyncapigenerator/testFileGeneration/assets/OrderMapper.java b/multiapi-engine/src/test/resources/asyncapigenerator/testFileGeneration/assets/OrderMapper.java index 11f18510..c50493ff 100644 --- a/multiapi-engine/src/test/resources/asyncapigenerator/testFileGeneration/assets/OrderMapper.java +++ b/multiapi-engine/src/test/resources/asyncapigenerator/testFileGeneration/assets/OrderMapper.java @@ -60,7 +60,7 @@ public OrderMapper.OrderMapperBuilder lines(List lines) { } public OrderMapper.OrderMapperBuilder line(OrderLineMapper line) { - if (line != null) { + if (Objects.nonNull(line)) { this.lines.add(line); } return this; diff --git a/multiapi-engine/src/test/resources/asyncapigenerator/testFileGenerationArrayString/assets/ObjectArrayDTO.java b/multiapi-engine/src/test/resources/asyncapigenerator/testFileGenerationArrayString/assets/ObjectArrayDTO.java index c9f7a3b6..9fb8e1e9 100644 --- a/multiapi-engine/src/test/resources/asyncapigenerator/testFileGenerationArrayString/assets/ObjectArrayDTO.java +++ b/multiapi-engine/src/test/resources/asyncapigenerator/testFileGenerationArrayString/assets/ObjectArrayDTO.java @@ -55,7 +55,7 @@ public ObjectArrayDTO.ObjectArrayDTOBuilder players(List players) { } public ObjectArrayDTO.ObjectArrayDTOBuilder player(String player) { - if (player != null) { + if (Objects.nonNull(player)) { this.players.add(player); } return this; 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 fc1cd6b0..77f3b51d 100644 --- a/multiapi-engine/src/test/resources/asyncapigenerator/testFileGenerationIssue/assets/CustomerOrderDTO.java +++ b/multiapi-engine/src/test/resources/asyncapigenerator/testFileGenerationIssue/assets/CustomerOrderDTO.java @@ -99,7 +99,7 @@ public CustomerOrderDTO.CustomerOrderDTOBuilder orderedItems(List lines) { } public OrderDTO.OrderDTOBuilder line(OrderLineDTO line) { - if (line != null) { + if (Objects.nonNull(line)) { this.lines.add(line); } return this; diff --git a/multiapi-engine/src/test/resources/asyncapigenerator/testFileGenerationWithKafkaBindings/assets/OrderLineDTO.java b/multiapi-engine/src/test/resources/asyncapigenerator/testFileGenerationWithKafkaBindings/assets/OrderLineDTO.java index 8084a1ef..5ea687a7 100644 --- a/multiapi-engine/src/test/resources/asyncapigenerator/testFileGenerationWithKafkaBindings/assets/OrderLineDTO.java +++ b/multiapi-engine/src/test/resources/asyncapigenerator/testFileGenerationWithKafkaBindings/assets/OrderLineDTO.java @@ -45,7 +45,7 @@ public OrderLineDTO.OrderLineDTOBuilder products(List products) } public OrderLineDTO.OrderLineDTOBuilder product(OrderProductDTO product) { - if (product != null) { + if (Objects.nonNull(product)) { this.products.add(product); } return this; diff --git a/multiapi-engine/src/test/resources/asyncapigenerator/testFileGenerationWithKafkaBindings/assets/OrderLineMapper.java b/multiapi-engine/src/test/resources/asyncapigenerator/testFileGenerationWithKafkaBindings/assets/OrderLineMapper.java index 224c312b..d1811ecc 100644 --- a/multiapi-engine/src/test/resources/asyncapigenerator/testFileGenerationWithKafkaBindings/assets/OrderLineMapper.java +++ b/multiapi-engine/src/test/resources/asyncapigenerator/testFileGenerationWithKafkaBindings/assets/OrderLineMapper.java @@ -45,7 +45,7 @@ public OrderLineMapper.OrderLineMapperBuilder products(List } public OrderLineMapper.OrderLineMapperBuilder product(OrderProductMapper product) { - if (product != null) { + if (Objects.nonNull(product)) { this.products.add(product); } return this; diff --git a/multiapi-engine/src/test/resources/asyncapigenerator/testFileGenerationWithKafkaBindings/assets/OrderMapper.java b/multiapi-engine/src/test/resources/asyncapigenerator/testFileGenerationWithKafkaBindings/assets/OrderMapper.java index e4782054..1d933c32 100644 --- a/multiapi-engine/src/test/resources/asyncapigenerator/testFileGenerationWithKafkaBindings/assets/OrderMapper.java +++ b/multiapi-engine/src/test/resources/asyncapigenerator/testFileGenerationWithKafkaBindings/assets/OrderMapper.java @@ -60,7 +60,7 @@ public OrderMapper.OrderMapperBuilder lines(List lines) { } public OrderMapper.OrderMapperBuilder line(OrderLineMapper line) { - if (line != null) { + if (Objects.nonNull(line)) { this.lines.add(line); } return this; 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 b50398b1..923b667a 100644 --- a/multiapi-engine/src/test/resources/asyncapigenerator/testIssueGenerateSupplier/assets/MailRequestDTO.java +++ b/multiapi-engine/src/test/resources/asyncapigenerator/testIssueGenerateSupplier/assets/MailRequestDTO.java @@ -55,7 +55,7 @@ public MailRequestDTO.MailRequestDTOBuilder recipients(List recipients) } public MailRequestDTO.MailRequestDTOBuilder recipient(String recipient) { - if (recipient != null) { + if (Objects.nonNull(recipient)) { this.recipients.add(recipient); } return this; diff --git a/multiapi-engine/src/test/resources/asyncapigenerator/testIssueInfiniteLoop/assets/MailRequestInfiniteDTO.java b/multiapi-engine/src/test/resources/asyncapigenerator/testIssueInfiniteLoop/assets/MailRequestInfiniteDTO.java index 1aaa2f74..e8444604 100644 --- a/multiapi-engine/src/test/resources/asyncapigenerator/testIssueInfiniteLoop/assets/MailRequestInfiniteDTO.java +++ b/multiapi-engine/src/test/resources/asyncapigenerator/testIssueInfiniteLoop/assets/MailRequestInfiniteDTO.java @@ -55,7 +55,7 @@ public MailRequestInfiniteDTO.MailRequestInfiniteDTOBuilder recipients(List recipients) } public MailRequestDTO.MailRequestDTOBuilder recipient(String recipient) { - if (recipient != null) { + if (Objects.nonNull(recipient)) { this.recipients.add(recipient); } return this; diff --git a/multiapi-engine/src/test/resources/asyncapigenerator/testModelClassExceptionGeneration/assets/OrderDTO.java b/multiapi-engine/src/test/resources/asyncapigenerator/testModelClassExceptionGeneration/assets/OrderDTO.java index 1fe72eb0..7d95b8ac 100644 --- a/multiapi-engine/src/test/resources/asyncapigenerator/testModelClassExceptionGeneration/assets/OrderDTO.java +++ b/multiapi-engine/src/test/resources/asyncapigenerator/testModelClassExceptionGeneration/assets/OrderDTO.java @@ -59,7 +59,7 @@ public OrderDTO.OrderDTOBuilder lines(List lines) { } public OrderDTO.OrderDTOBuilder line(OrderLineDTO line) { - if (line != null) { + if (Objects.nonNull(line)) { this.lines.add(line); } return this; diff --git a/multiapi-engine/src/test/resources/asyncapigenerator/testModelClassExceptionGeneration/assets/OrderLineDTO.java b/multiapi-engine/src/test/resources/asyncapigenerator/testModelClassExceptionGeneration/assets/OrderLineDTO.java index 86698206..ae1599f0 100644 --- a/multiapi-engine/src/test/resources/asyncapigenerator/testModelClassExceptionGeneration/assets/OrderLineDTO.java +++ b/multiapi-engine/src/test/resources/asyncapigenerator/testModelClassExceptionGeneration/assets/OrderLineDTO.java @@ -45,7 +45,7 @@ public OrderLineDTO.OrderLineDTOBuilder products(List products) } public OrderLineDTO.OrderLineDTOBuilder product(OrderProductDTO product) { - if (product != null) { + if (Objects.nonNull(product)) { this.products.add(product); } return this; diff --git a/multiapi-engine/src/test/resources/asyncapigenerator/testReservedWordsGeneration/assets/OrderDTO.java b/multiapi-engine/src/test/resources/asyncapigenerator/testReservedWordsGeneration/assets/OrderDTO.java index 6f4a9b30..7ea36cd4 100644 --- a/multiapi-engine/src/test/resources/asyncapigenerator/testReservedWordsGeneration/assets/OrderDTO.java +++ b/multiapi-engine/src/test/resources/asyncapigenerator/testReservedWordsGeneration/assets/OrderDTO.java @@ -59,9 +59,9 @@ public OrderDTO.OrderDTOBuilder _new(List _new) { return this; } - public OrderDTO.OrderDTOBuilder _new(OrderLineDTO _new) { - if (_new != null) { - this._new.add(_new); + public OrderDTO.OrderDTOBuilder __new(OrderLineDTO __new) { + if (Objects.nonNull(__new)) { + this._new.add(__new); } return this; } diff --git a/multiapi-engine/src/test/resources/asyncapigenerator/testReservedWordsGeneration/assets/OrderLineDTO.java b/multiapi-engine/src/test/resources/asyncapigenerator/testReservedWordsGeneration/assets/OrderLineDTO.java index f5b80feb..91b31018 100644 --- a/multiapi-engine/src/test/resources/asyncapigenerator/testReservedWordsGeneration/assets/OrderLineDTO.java +++ b/multiapi-engine/src/test/resources/asyncapigenerator/testReservedWordsGeneration/assets/OrderLineDTO.java @@ -45,9 +45,9 @@ public OrderLineDTO.OrderLineDTOBuilder _continue(List _continue) { return this; } - public OrderLineDTO.OrderLineDTOBuilder _continue(String _continue) { - if (_continue != null) { - this._continue.add(_continue); + public OrderLineDTO.OrderLineDTOBuilder __continue(String __continue) { + if (Objects.nonNull(__continue)) { + this._continue.add(__continue); } return this; } diff --git a/multiapi-engine/src/test/resources/asyncapigenerator/testReservedWordsGeneration/event-api.yml b/multiapi-engine/src/test/resources/asyncapigenerator/testReservedWordsGeneration/event-api.yml index 13ead31f..c1559739 100644 --- a/multiapi-engine/src/test/resources/asyncapigenerator/testReservedWordsGeneration/event-api.yml +++ b/multiapi-engine/src/test/resources/asyncapigenerator/testReservedWordsGeneration/event-api.yml @@ -24,10 +24,10 @@ channels: publish: operationId: "publishOperationFileGeneration" message: - $ref: './assets/path.yml#/components/messages/OrderCreated' + $ref: 'assets/path.yml#/components/messages/OrderCreated' order.createCommand: subscribe: operationId: "subscribeOperationFileGeneration" message: payload: - $ref: './assets/path.yml#/components/schemas/CreateOrder' \ No newline at end of file + $ref: 'assets/path.yml#/components/schemas/CreateOrder' \ No newline at end of file From adbbcb6dbb2777268df66ca1c962de765bd1c7da Mon Sep 17 00:00:00 2001 From: "joseenrique.garcia" Date: Mon, 23 Sep 2024 00:25:21 +0200 Subject: [PATCH 15/26] Fix OpenApi generator --- .../plugin/asyncapi/AsyncApiGenerator.java | 36 +---- .../asyncapi/template/ClassTemplate.java | 2 + .../asyncapi/template/TemplateFactory.java | 4 +- .../template/CommonTemplateFactory.java | 56 ++++++-- .../tools}/MapperContentUtil.java | 17 +-- .../plugin/common/tools/MapperUtil.java | 38 ++---- .../plugin/openapi/OpenApiGenerator.java | 125 +++++------------- .../openapi/template/TemplateFactory.java | 41 +----- .../plugin/openapi/utils/MapperAuthUtil.java | 17 ++- .../openapi/utils/MapperContentUtil.java | 47 ------- .../plugin/openapi/utils/MapperPathUtil.java | 10 +- .../plugin/openapi/utils/OpenApiUtil.java | 11 +- .../model/templateSchemaWithLombok.ftlh | 9 +- .../asyncapi/AsyncApiGeneratorFixtures.java | 76 +++++------ .../assets/testApi/ApiTestAllOfDTO.java | 2 +- .../testAllOf/assets/testApi/ApiTestDTO.java | 2 +- .../assets/testApi/ApiTestInfoDTO.java | 2 +- .../testAllOf/assets/testApi/ApiTestsDTO.java | 2 +- .../assets/ApiTestInfoDTO.java | 2 +- .../assets/ApiInlineParameterTestIdDTO.java | 5 - .../assets/ApiTestInfoDTO.java | 9 +- .../assets/TestInfoDTO.java | 2 +- .../assets/ApiTestInfoDTO.java | 2 +- .../assets/TestInfoDTO.java | 2 +- .../assets/ApiTestInfoDTO.java | 2 +- .../assets/TestInfoDTO.java | 2 +- .../assets/TestInfoDTO.java | 2 +- .../assets/ApiNumberFieldDTO.java | 2 +- .../assets/ApiStringFieldDTO.java | 4 +- .../assets/ApiTestDTO.java | 4 +- .../assets/ApiTestInfoDTO.java | 2 +- .../assets/ApiTestInfoDTO.java | 2 +- .../assets/ApiTestInfoDTO.java | 2 +- .../assets/testApi/ApiTestAllOfDTO.java | 2 +- .../assets/testApi/ApiTestDTO.java | 2 +- .../assets/testApi/ApiTestInfoDTO.java | 2 +- .../testWebClientApiGeneration/api-test.yml | 4 - .../assets/ApiTestInfoDTO.java | 2 +- 38 files changed, 189 insertions(+), 364 deletions(-) rename multiapi-engine/src/main/java/com/sngular/api/generator/plugin/{asyncapi/util => common/tools}/MapperContentUtil.java (69%) delete mode 100644 multiapi-engine/src/main/java/com/sngular/api/generator/plugin/openapi/utils/MapperContentUtil.java 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 e97462d5..a1c0f69a 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 @@ -19,7 +19,7 @@ import com.sngular.api.generator.plugin.asyncapi.template.TemplateFactory; import com.sngular.api.generator.plugin.asyncapi.util.BindingTypeEnum; import com.sngular.api.generator.plugin.asyncapi.util.FactoryTypeEnum; -import com.sngular.api.generator.plugin.asyncapi.util.MapperContentUtil; +import com.sngular.api.generator.plugin.common.tools.MapperContentUtil; import com.sngular.api.generator.plugin.asyncapi.util.ReferenceProcessor; import com.sngular.api.generator.plugin.common.files.ClasspathFileLocation; import com.sngular.api.generator.plugin.common.files.DirectoryFileLocation; @@ -103,8 +103,6 @@ public class AsyncApiGenerator { private final Integer springBootVersion; - private boolean generateExceptionTemplate; - public AsyncApiGenerator(final Integer springBootVersion, boolean overwriteModel, final File targetFolder, @@ -137,8 +135,8 @@ private static Pair resolveYmlLocation(final String y public final void processFileSpec(final List specsListFile) { final ObjectMapper om = new ObjectMapper(new YAMLFactory()); processedOperationIds.clear(); - generateExceptionTemplate = false; - for (final SpecFile fileParameter : specsListFile) { + templateFactory.setNotGenerateTemplate(); + for (final SpecFile fileParameter : specsListFile) { final Pair ymlFileAndPath; try { ymlFileAndPath = resolveYmlLocation(fileParameter.getFilePath()); @@ -166,7 +164,7 @@ public final void processFileSpec(final List specsListFile) { processOperation(fileParameter, ymlParent, entry, channel, operationId, channelPayload, totalSchemas); } - templateFactory.fillTemplates(generateExceptionTemplate); + templateFactory.fillTemplates(); templateFactory.clearData(); } catch (final TemplateException | IOException e) { throw new FileSystemException(e); @@ -174,22 +172,6 @@ public final void processFileSpec(final List specsListFile) { } } - private void checkRequiredOrCombinatorExists(final SchemaObject schema, final boolean useLombok) { - if ("anyOf".equals(schema.getSchemaCombinator()) || "oneOf".equals(schema.getSchemaCombinator())) { - generateExceptionTemplate = true; - } else if (Objects.nonNull(schema.getFieldObjectList()) && !useLombok) { - final var fieldListIt = schema.getFieldObjectList().iterator(); - if (fieldListIt.hasNext()) { - do { - final var field = fieldListIt.next(); - if (field.isRequired()) { - generateExceptionTemplate = true; - } - } while (fieldListIt.hasNext() && !generateExceptionTemplate); - } - } - } - private Map getAllSchemas(final FileLocation ymlParent, final JsonNode node) { final Map totalSchemas = new HashMap<>(); final List referenceList = node.findValues(REF); @@ -401,7 +383,7 @@ private void processSubscribeMethod( private void fillTemplateFactory( final ProcessMethodResult processedMethod, final Map totalSchemas, final OperationParameterObject operationObject) - throws TemplateException, IOException { + throws IOException { final String classFullName = processedMethod.getNamespace(); final String keyClassFullName = processedMethod.getBindings(); final String modelPackage = classFullName.substring(0, classFullName.lastIndexOf(".")); @@ -420,10 +402,6 @@ private void fillTemplateFactory( templateFactory.fillTemplateWrapper(operationObject.getApiPackage(), classFullName, className, keyClassFullName, keyClassName); } schemaObjectIt.forEachRemaining(schemaObj -> writeSchemaObject(operationObject.isUseLombokModelAnnotation(), operationObject.getModelPackage(), null, schemaObj)); - - if (Boolean.TRUE.equals(generateExceptionTemplate)) { - templateFactory.fillTemplateModelClassException(operationObject.getApiPackage(), modelPackage); - } } } } @@ -442,8 +420,8 @@ private boolean shouldBuild(final JsonNode schemaToBuild) { private void writeSchemaObject(final boolean usingLombok, final String modelPackageReceived, final String keyClassName, final SchemaObject schemaObject) { final var destinationPackage = StringUtils.defaultIfEmpty(modelPackageReceived, DEFAULT_ASYNCAPI_API_PACKAGE + SLASH + schemaObject.getParentPackage()); - templateFactory.addSchemaObject(modelPackageReceived, keyClassName, schemaObject, destinationPackage); - checkRequiredOrCombinatorExists(schemaObject, usingLombok); + templateFactory.addSchemaObject(modelPackageReceived, keyClassName, schemaObject, destinationPackage, usingLombok); + templateFactory.checkRequiredOrCombinatorExists(schemaObject, usingLombok); } private ProcessMethodResult processMethod( diff --git a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/asyncapi/template/ClassTemplate.java b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/asyncapi/template/ClassTemplate.java index c84524d0..811b2de2 100644 --- a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/asyncapi/template/ClassTemplate.java +++ b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/asyncapi/template/ClassTemplate.java @@ -28,4 +28,6 @@ public class ClassTemplate { SchemaObject classSchema; + boolean useLombok; + } 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 82c75974..2a522c27 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 @@ -63,7 +63,7 @@ public TemplateFactory(boolean enableOverwrite, super(enableOverwrite, targetFolder, processedGeneratedSourcesFolder, baseDir, new ClasspathTemplateLoader()); } - public final void fillTemplates(boolean generateExceptionTemplate) throws IOException, TemplateException { + public final void fillTemplates() throws IOException, TemplateException { addToRoot("publishMethods", publishMethods); addToRoot("subscribeMethods", subscribeMethods); addToRoot("streamBridgeMethods", streamBridgeMethods); @@ -80,7 +80,7 @@ public final void fillTemplates(boolean generateExceptionTemplate) throws IOExce fillTemplate(streamBridgeFilePath, streamBridgeClassName, checkTemplate(method.getBindingType(), TemplateIndexConstants.TEMPLATE_API_STREAM_BRIDGE)); } - generateTemplates(generateExceptionTemplate); + generateTemplates(); this.generateInterfaces(); } diff --git a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/template/CommonTemplateFactory.java b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/template/CommonTemplateFactory.java index 57569975..ecd74be4 100644 --- a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/template/CommonTemplateFactory.java +++ b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/template/CommonTemplateFactory.java @@ -53,6 +53,8 @@ public abstract class CommonTemplateFactory { private final File baseDir; + protected boolean generateExceptionTemplate; + protected CommonTemplateFactory(boolean checkOverwrite, final File targetFolder, final String processedGeneratedSourcesFolder, @@ -71,7 +73,7 @@ protected CommonTemplateFactory(boolean checkOverwrite, this.baseDir = baseDir; } - protected void generateTemplates(boolean generateExceptionTemplate) { + protected void generateTemplates() { final String exceptionPackage; if (Boolean.TRUE.equals(generateExceptionTemplate)) { @@ -83,7 +85,10 @@ protected void generateTemplates(boolean generateExceptionTemplate) { classTemplateList.forEach(classTemplate -> { try { fillTemplates(classTemplate.getPropertiesPath(), classTemplate.getModelPackage(), - fillTemplateSchema(classTemplate, false, exceptionPackage)); + fillTemplateSchema(classTemplate, exceptionPackage)); + if (generateExceptionTemplate) { + fillTemplateModelClassException(classTemplate.getModelPackage()); + } } catch (final IOException | TemplateException exception) { throw new FileSystemException(exception); } @@ -92,10 +97,11 @@ protected void generateTemplates(boolean generateExceptionTemplate) { private ClassTemplate getClassTemplate() { ClassTemplate ourClassTemplate = null; - for (ClassTemplate classTemplate : classTemplateList) { + final var classTemplateListIt = classTemplateList.iterator(); + while (Objects.isNull(ourClassTemplate) && classTemplateListIt.hasNext()) { + final var classTemplate = classTemplateListIt.next(); if (classTemplate.getFilePath().endsWith("schemas")) { ourClassTemplate = classTemplate; - break; } } if (ourClassTemplate == null) { @@ -170,14 +176,14 @@ protected void fillTemplates(final Path filePathToSave, final String modelPackag } @SuppressWarnings("checkstyle:CyclomaticComplexity") - private Set fillTemplateSchema(final ClassTemplate classTemplate, final Boolean useLombok, final String exceptionPackage) + private Set fillTemplateSchema(final ClassTemplate classTemplate, final String exceptionPackage) throws IOException, TemplateException { final var propertiesSet = new HashSet(); final var schemaObject = classTemplate.getClassSchema(); final var filePath = classTemplate.getFilePath(); if (Objects.nonNull(schemaObject) && Objects.nonNull(schemaObject.getFieldObjectList()) && !schemaObject.getFieldObjectList().isEmpty()) { addToRoot("schema", schemaObject); - final String templateName = null != useLombok && useLombok ? TemplateIndexConstants.TEMPLATE_CONTENT_SCHEMA_LOMBOK : TemplateIndexConstants.TEMPLATE_CONTENT_SCHEMA; + final String templateName = classTemplate.isUseLombok() ? TemplateIndexConstants.TEMPLATE_CONTENT_SCHEMA_LOMBOK : TemplateIndexConstants.TEMPLATE_CONTENT_SCHEMA; if (Objects.nonNull(classTemplate.getModelPackage())) { addToRoot("packageModel", classTemplate.getModelPackage()); } @@ -187,7 +193,7 @@ private Set fillTemplateSchema(final ClassTemplate classTemplate, final fillTemplate(filePath.toString(), schemaObject.getClassName(), templateName); for (SchemaFieldObject fieldObject : schemaObject.getFieldObjectList()) { propertiesSet.addAll(fieldObject.getRestrictions().getProperties()); - if (fieldObject.isRequired() && Boolean.FALSE.equals(useLombok)) { + if (fieldObject.isRequired() && Boolean.FALSE.equals(classTemplate.isUseLombok())) { propertiesSet.add("NotNull"); } } @@ -195,9 +201,13 @@ private Set fillTemplateSchema(final ClassTemplate classTemplate, final return propertiesSet; } - public final void fillTemplateModelClassException(final String filePathToSave, final String modelPackage) throws IOException { + public final void fillTemplateModelClassException(final String modelPackage) throws IOException { addToRoot(EXCEPTION_PACKAGE, modelPackage); - writeTemplateToFile(CommonTemplateIndexConstants.TEMPLATE_MODEL_EXCEPTION, MapperUtil.packageToFolder(filePathToSave) + SLASH + "exception", "ModelClassException"); + writeTemplateToFile(CommonTemplateIndexConstants.TEMPLATE_MODEL_EXCEPTION, MapperUtil.packageToFolder(modelPackage) + SLASH + "exception", "ModelClassException"); + } + + public void setNotGenerateTemplate() { + this.generateExceptionTemplate = false; } private void fillTemplateCustom( @@ -231,7 +241,8 @@ protected void cleanData() { public final void addSchemaObject(final String modelPackage, final String keyClassName, final SchemaObject schemaObject, - final String destinationPackage) { + final String destinationPackage, + final boolean useLombok) { final var filePath = processPath(getPath(destinationPackage)); final var propertiesPath = processPath(getPath(modelPackage)); final var builder = ClassTemplate @@ -240,15 +251,16 @@ public final void addSchemaObject(final String modelPackage, .modelPackage(modelPackage) .className(schemaObject.getClassName()) .classSchema(schemaObject) - .propertiesPath(propertiesPath); + .propertiesPath(propertiesPath) + .useLombok(useLombok); if (Objects.nonNull(keyClassName)) { builder.keyClassName(keyClassName); } classTemplateList.add(builder.build()); } - protected void writeTemplateToFile(final String templateName, final String filePathToSave, final String partialPath) throws IOException { - writeTemplateToFile(templateName, processPath(getPath(filePathToSave)), partialPath); + protected void writeTemplateToFile(final String templateName, final String apiPackage, final String partialPath) throws IOException { + writeTemplateToFile(templateName, processPath(getPath(apiPackage)), partialPath); } protected void writeTemplateToFile(final String templateName, final Path filePathToSave, final String partialPath) throws IOException { @@ -303,6 +315,22 @@ protected String convertPackageToTargetPath(final OperationParameterObject opera } protected String getPath(final String pathName) { - return processedGeneratedSourcesFolder + pathName.replace(PACKAGE_SEPARATOR_STR, SLASH); + return processedGeneratedSourcesFolder + SLASH + pathName.replace(PACKAGE_SEPARATOR_STR, SLASH); + } + + public void checkRequiredOrCombinatorExists(final SchemaObject schema, final boolean useLombok) { + if ("anyOf".equals(schema.getSchemaCombinator()) || "oneOf".equals(schema.getSchemaCombinator())) { + generateExceptionTemplate = true; + } else if (Objects.nonNull(schema.getFieldObjectList()) && !useLombok) { + final var fieldListIt = schema.getFieldObjectList().iterator(); + if (fieldListIt.hasNext()) { + do { + final var field = fieldListIt.next(); + if (field.isRequired()) { + generateExceptionTemplate = true; + } + } while (fieldListIt.hasNext() && !generateExceptionTemplate); + } + } } } 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/common/tools/MapperContentUtil.java similarity index 69% rename from multiapi-engine/src/main/java/com/sngular/api/generator/plugin/asyncapi/util/MapperContentUtil.java rename to multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/tools/MapperContentUtil.java index 0a1d3642..744405f3 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/common/tools/MapperContentUtil.java @@ -4,30 +4,20 @@ * * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ -package com.sngular.api.generator.plugin.asyncapi.util; - +package com.sngular.api.generator.plugin.common.tools; import com.fasterxml.jackson.databind.JsonNode; import com.sngular.api.generator.plugin.common.model.CommonSpecFile; import com.sngular.api.generator.plugin.common.model.SchemaObject; -import com.sngular.api.generator.plugin.common.tools.ModelBuilder; import java.nio.file.Path; import java.util.*; public class MapperContentUtil { - private static final String ADDITIONAL_PROPERTY_NAME = "AdditionalProperty"; - - private static final String ADDITIONAL_PROPERTIES = "additionalProperties"; - - private static final String ANY_OF_COMBINATOR = "anyOf"; - - private static final String ONE_OF_COMBINATOR = "oneOf"; - private static final String ALL_OF_COMBINATOR = "allOf"; - - private MapperContentUtil() {} + private MapperContentUtil() { + } public static List mapComponentToSchemaObject( final Map totalSchemas, final String className, final JsonNode model, @@ -41,5 +31,4 @@ public static List mapComponentToSchemaObject( return schemasList; } - } diff --git a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/tools/MapperUtil.java b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/tools/MapperUtil.java index 67a8cd51..7f95402d 100644 --- a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/tools/MapperUtil.java +++ b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/tools/MapperUtil.java @@ -16,30 +16,6 @@ public class MapperUtil { - private static final String INTEGER = "integer"; - - private static final String DOUBLE = "double"; - - private static final String FLOAT = "float"; - - private static final String NUMBER = "number"; - - private static final String INT_64 = "int64"; - - private static final String LONG = "long"; - - private static final String DATE = "date"; - - private static final String DATE_TIME = "date-time"; - - private static final String BIG_DECIMAL = "BigDecimal"; - - private static final String LOCAL_DATE = "LocalDate"; - - private static final String LOCAL_DATE_TIME = "LocalDateTime"; - - private static final String ZONED_DATE_TIME = "ZonedDateTime"; - private static final String REF = "$ref"; private static final String DIVISOR = "([./])"; @@ -71,9 +47,9 @@ public static String packageToFolder(final String packageName) { return StringUtils.replace(packageName, ".", SLASH); } - public static String buildKey(final String[] pathList) { - final var arrayLength = pathList.length; - return (arrayLength > 2 ? pathList[arrayLength - 2] + SLASH + pathList[arrayLength - 1] : pathList[0]).toUpperCase(); + public static String buildKey(final JsonNode parameter) { + final String[] pathObjectRef = ApiTool.getRefValue(parameter).split("/"); + return StringUtils.upperCase(pathObjectRef[pathObjectRef.length - 2] + "/" + StringCaseUtils.titleToSnakeCase(pathObjectRef[pathObjectRef.length - 1])); } public static String getRefSchemaName(final JsonNode parameter) { @@ -87,8 +63,12 @@ public static String getRefSchemaKey(final JsonNode parameter) { } public static String getKeySchemaName(final String parameter) { - final String[] pathObjectRef = parameter.split("/"); - return StringCaseUtils.toCamelCase(pathObjectRef[pathObjectRef.length - 1]); + return StringCaseUtils.toCamelCase(getKey(parameter)); + } + + public static String getKey(final String keyString) { + final String[] pathObjectRef = keyString.split("/"); + return pathObjectRef[pathObjectRef.length - 1]; } public static String getRefSchemaKey(final String parameter) { 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 f2abba38..96cfcaa0 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 @@ -23,7 +23,6 @@ import com.sngular.api.generator.plugin.PluginConstants; import com.sngular.api.generator.plugin.common.model.SchemaObject; import com.sngular.api.generator.plugin.common.tools.ApiTool; -import com.sngular.api.generator.plugin.exception.GeneratedSourcesException; import com.sngular.api.generator.plugin.exception.GeneratorTemplateException; import com.sngular.api.generator.plugin.openapi.exception.CodeGenerationException; import com.sngular.api.generator.plugin.openapi.exception.DuplicateModelClassException; @@ -34,17 +33,18 @@ import com.sngular.api.generator.plugin.openapi.parameter.SpecFile; import com.sngular.api.generator.plugin.openapi.template.TemplateFactory; import com.sngular.api.generator.plugin.openapi.utils.MapperAuthUtil; -import com.sngular.api.generator.plugin.openapi.utils.MapperContentUtil; +import com.sngular.api.generator.plugin.common.tools.MapperContentUtil; import com.sngular.api.generator.plugin.openapi.utils.MapperPathUtil; import com.sngular.api.generator.plugin.common.tools.MapperUtil; import com.sngular.api.generator.plugin.openapi.utils.OpenApiUtil; import freemarker.template.TemplateException; import org.apache.commons.collections4.MultiValuedMap; -import org.apache.commons.io.FilenameUtils; import org.apache.commons.lang3.StringUtils; public class OpenApiGenerator { + private static final String SLASH = "/"; + private static final String DEFAULT_OPENAPI_API_PACKAGE = PluginConstants.DEFAULT_API_PACKAGE + ".openapi"; private static final String DEFAULT_OPENAPI_MODEL_PACKAGE = DEFAULT_OPENAPI_API_PACKAGE + ".model"; @@ -77,8 +77,6 @@ public class OpenApiGenerator { private final List authentications = new ArrayList<>(); - private boolean useLombok; - private final Integer springBootVersion; public OpenApiGenerator( @@ -101,11 +99,9 @@ public OpenApiGenerator( public final void processFileSpec(final List specsListFile) { for (SpecFile specFile : specsListFile) { generateExceptionTemplate = false; - useLombok = Boolean.TRUE.equals(specFile.isUseLombokModelAnnotation()); try { processPackage(specFile.getApiPackage()); - final String filePathToSave = processPath(specFile.getApiPackage(), false); - processFile(specFile, filePathToSave); + processFile(specFile); createClients(specFile); templateFactory.clearData(); } catch (final IOException e) { @@ -114,7 +110,7 @@ public final void processFileSpec(final List specsListFile) { } } - private void processFile(final SpecFile specFile, final String filePathToSave) throws IOException { + private void processFile(final SpecFile specFile) throws IOException { final JsonNode openAPI = OpenApiUtil.getPojoFromSpecFile(baseDir, specFile); final String clientPackage = specFile.getClientPackage(); @@ -127,10 +123,10 @@ private void processFile(final SpecFile specFile, final String filePathToSave) t } templateFactory.calculateJavaEEPackage(springBootVersion); - final var globalObject = createApiTemplate(specFile, filePathToSave, openAPI); + final var globalObject = createApiTemplate(specFile, specFile.getApiPackage(), openAPI); createModelTemplate(specFile, openAPI, globalObject); - + templateFactory.fillTemplates(); } private void createClients(final SpecFile specFile) { @@ -138,7 +134,7 @@ private void createClients(final SpecFile specFile) { if (isWebClient || isRestClient) { try { final String clientPackage = specFile.getClientPackage(); - final String clientPath = processPath(StringUtils.isNotBlank(clientPackage) ? clientPackage : DEFAULT_OPENAPI_CLIENT_PACKAGE, false); + final String clientPath = StringUtils.isNotBlank(clientPackage) ? clientPackage : DEFAULT_OPENAPI_CLIENT_PACKAGE; if (Boolean.TRUE.equals(isWebClient)) { templateFactory.fillTemplateWebClient(clientPath); } @@ -155,19 +151,18 @@ private void createClients(final SpecFile specFile) { private void createAuthTemplates(final SpecFile specFile) throws TemplateException, IOException { final String clientPackage = specFile.getClientPackage(); final var authFileRoot = (StringUtils.isNotBlank(clientPackage) ? clientPackage : DEFAULT_OPENAPI_CLIENT_PACKAGE) + ".auth"; - final String authFileToSave = processPath(authFileRoot, false); templateFactory.setAuthPackageName(authFileRoot); - templateFactory.fillTemplateAuth(authFileToSave, "Authentication"); + templateFactory.fillTemplateAuth(authFileRoot, "Authentication"); if (!authentications.isEmpty()) { for (String authentication : authentications) { - templateFactory.fillTemplateAuth(authFileToSave, authentication); + templateFactory.fillTemplateAuth(authFileRoot, authentication); } } } - private GlobalObject createApiTemplate(final SpecFile specFile, final String filePathToSave, final JsonNode openAPI) { + private GlobalObject createApiTemplate(final SpecFile specFile, final String apiPackage, final JsonNode openAPI) { final MultiValuedMap> apis = OpenApiUtil.mapApiGroups(openAPI, specFile.isUseTagsGroup()); final var authSchemaList = MapperAuthUtil.createAuthSchemaList(openAPI); final GlobalObject globalObject = MapperPathUtil.mapOpenApiObjectToOurModels(openAPI, authSchemaList); @@ -178,7 +173,7 @@ private GlobalObject createApiTemplate(final SpecFile specFile, final String fil final AuthObject authObject = MapperAuthUtil.getApiAuthObject(globalObject.getAuthSchemas(), pathObjects); try { - templateFactory.fillTemplate(filePathToSave, specFile, javaFileName, pathObjects, authObject); + templateFactory.fillTemplate(apiPackage, specFile, javaFileName, pathObjects, authObject); } catch (IOException | TemplateException e) { throw new GeneratorTemplateException("Error filling the template", specFile.getFilePath(), e); } @@ -203,11 +198,11 @@ private void addAuthentications(final AuthObject authObject) { } private void createModelTemplate(final SpecFile specFile, final JsonNode openAPI, final GlobalObject globalObject) throws IOException { - final String fileModelToSave = processPath(specFile.getModelPackage(), true); final var modelPackage = processModelPackage(specFile.getModelPackage()); + final var totalSchemas = OpenApiUtil.processPaths(openAPI, globalObject.getSchemaMap()); templateFactory.setModelPackageName(modelPackage); - processModels(specFile, fileModelToSave, modelPackage, totalSchemas, overwriteModel); + processModels(specFile, modelPackage, totalSchemas, overwriteModel); } private void processPackage(final String apiPackage) { @@ -230,41 +225,16 @@ private String processModelPackage(final String modelPackage) { return modelReturnPackage; } - private String processPath(final String fileSpecPackage, final boolean isModel) throws IOException { - Path path; - final File[] pathList = Objects.requireNonNull(baseDir.toFile().listFiles(targetFileFilter)); - if (pathList.length > 0) { - path = pathList[0].toPath().resolve(convertPackageToTargetPath(fileSpecPackage, isModel)); - } else { - path = targetFolder.toPath(); - if (path.toFile().exists() || path.toFile().mkdirs()) { - path = path.resolve(convertPackageToTargetPath(fileSpecPackage, isModel)); - } else { - throw new IOException("Problem creating folders: " + path.toFile()); - } - } - if (!path.toFile().isDirectory() && !path.toFile().mkdirs()) { - throw new IOException("Problem creating folders: " + path.toFile()); - } - return path.toString(); - } - - private String convertPackageToTargetPath(final String fileSpecPackage, final boolean isModel) { - final String toMatch = StringUtils.defaultIfBlank(fileSpecPackage, StringUtils.defaultIfBlank(groupId, isModel ? DEFAULT_OPENAPI_MODEL_PACKAGE : DEFAULT_OPENAPI_API_PACKAGE)); - return FilenameUtils.concat(processedGeneratedSourcesFolder, PACKAGE_SEPARATOR.matcher(toMatch).replaceAll("/")); - } - private void processModels( - final SpecFile specFile, final String fileModelToSave, final String modelPackage, final Map basicSchemaMap, + final SpecFile specFile, final String modelPackage, final Map basicSchemaMap, final boolean overwrite) { - final Map builtSchemasMap = new HashMap<>(); basicSchemaMap.forEach((schemaName, basicSchema) -> { if (ApiTool.hasType(basicSchema)) { if (validType(ApiTool.getType(basicSchema))) { - processModel(specFile, fileModelToSave, modelPackage, basicSchemaMap, overwrite, MapperUtil.getKeySchemaName(schemaName), basicSchema, builtSchemasMap); + processModel(specFile, modelPackage, basicSchemaMap, overwrite, MapperUtil.getKeySchemaName(schemaName), basicSchema); } } else { - processModel(specFile, fileModelToSave, modelPackage, basicSchemaMap, overwrite, MapperUtil.getKeySchemaName(schemaName), basicSchema, builtSchemasMap); + processModel(specFile, modelPackage, basicSchemaMap, overwrite, MapperUtil.getKeySchemaName(schemaName), basicSchema); } }); } @@ -274,61 +244,36 @@ private boolean validType(final String type) { } 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) { + final SpecFile specFile, final String modelPackage, final Map basicSchemaMap, final boolean overwrite, + final String schemaName, final JsonNode basicSchema) { if (!overwrite && !overwriteModelList.add(schemaName + modelPackage)) { throw new DuplicateModelClassException(schemaName, modelPackage); } if (ApiTool.hasRef(basicSchema)) { final var refSchema = MapperUtil.getRefSchemaName(basicSchema); - builtSchemasMap.putAll(writeSchemaObject(specFile, fileModelToSave, refSchema, basicSchemaMap.get(refSchema), basicSchemaMap, builtSchemasMap, modelPackage)); + writeSchemaObject(specFile, refSchema, basicSchemaMap.get(refSchema), basicSchemaMap, modelPackage); } else if (!ApiTool.isArray(basicSchema) && !TypeConstants.STRING.equalsIgnoreCase(ApiTool.getType(basicSchema))) { - builtSchemasMap.putAll(writeSchemaObject(specFile, fileModelToSave, schemaName, basicSchema, basicSchemaMap, builtSchemasMap, modelPackage)); + writeSchemaObject(specFile, schemaName, basicSchema, basicSchemaMap, modelPackage); } } - private Map writeSchemaObject( - final SpecFile specFile, final String fileModelToSave, final String schemaName, final JsonNode basicSchema, final Map basicSchemaMap, - final Map builtSchemasMap, String modelPackage) { - final var schemaObjectMap = MapperContentUtil - .mapComponentToSchemaObject(basicSchemaMap, builtSchemasMap, basicSchema, schemaName, specFile, baseDir); - checkRequiredOrCombinatorExists(schemaObjectMap); - //TODO: Create only required classes - schemaObjectMap.values().forEach(schemaObject -> { - try { - final Set propertiesSet = new HashSet<>(); - templateFactory.fillTemplateSchema(fileModelToSave, specFile.isUseLombokModelAnnotation(), schemaObject, propertiesSet); - } catch (IOException | TemplateException e) { - throw new GeneratedSourcesException(schemaObject.getClassName(), e); - } - }); - - try { - templateFactory.fillTemplates(generateExceptionTemplate); - } catch (IOException | TemplateException e) { - throw new GeneratedSourcesException("Exception Class", e); + private void writeSchemaObject( + final SpecFile specFile, final String schemaName, final JsonNode model, final Map basicSchemaMap, + final String modelPackage) { + final String parentPackage = modelPackage.substring(modelPackage.lastIndexOf(".") + 1); + final var schemaObjectIt = MapperContentUtil + .mapComponentToSchemaObject(basicSchemaMap, schemaName, model, parentPackage, specFile, this.baseDir).iterator(); + if (schemaObjectIt.hasNext()) { + writeSchemaObject(specFile.isUseLombokModelAnnotation(), specFile.getModelPackage(), schemaName, schemaObjectIt.next()); } - return schemaObjectMap; + schemaObjectIt.forEachRemaining(schemaObj -> writeSchemaObject(specFile.isUseLombokModelAnnotation(), specFile.getModelPackage(), null, schemaObj)); + } - private void checkRequiredOrCombinatorExists(final Map schemaList) { - boolean shouldGenerateException = false; - final var schemaListIt = schemaList.values().iterator(); - while (schemaListIt.hasNext() && !shouldGenerateException) { - final var schema = schemaListIt.next(); - if ("anyOf".equals(schema.getSchemaCombinator()) || "oneOf".equals(schema.getSchemaCombinator())) { - shouldGenerateException = true; - } else if (Objects.nonNull(schema.getFieldObjectList()) && !useLombok) { - final var fieldListIt = schema.getFieldObjectList().iterator(); - while (fieldListIt.hasNext() && !shouldGenerateException) { - final var field = fieldListIt.next(); - if (field.isRequired()) { - shouldGenerateException = true; - } - } - } - } - generateExceptionTemplate = shouldGenerateException; + private void writeSchemaObject(final boolean usingLombok, final String modelPackageReceived, final String keyClassName, final SchemaObject schemaObject) { + final var destinationPackage = StringUtils.defaultIfEmpty(modelPackageReceived, DEFAULT_OPENAPI_API_PACKAGE + SLASH + schemaObject.getParentPackage()); + templateFactory.addSchemaObject(modelPackageReceived, keyClassName, schemaObject, destinationPackage, usingLombok); + templateFactory.checkRequiredOrCombinatorExists(schemaObject, usingLombok); } } 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 09b19d10..da6ac9bd 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 @@ -39,37 +39,12 @@ public TemplateFactory(boolean enableOverwrite, super(enableOverwrite, targetFolder, processedGeneratedSourcesFolder, baseDir, new ClasspathTemplateLoader()); } - public final void fillTemplateSchema( - final String filePathToSave, final Boolean useLombok, final SchemaObject schemaObject, - final Set propertiesSet) throws IOException, - TemplateException { - if (Objects.nonNull(schemaObject.getFieldObjectList()) && !schemaObject.getFieldObjectList().isEmpty()) { - addToRoot("schema", schemaObject); - writeTemplateToFile(templateSelector(useLombok), filePathToSave, schemaObject.getClassName()); - for (SchemaFieldObject fieldObject : schemaObject.getFieldObjectList()) { - propertiesSet.addAll(fieldObject.getRestrictions().getProperties()); - if (fieldObject.isRequired() && Boolean.FALSE.equals(useLombok)) { - propertiesSet.add("NotNull"); - } - } - } - } - public final void clearData() { cleanData(); } - private static String templateSelector(final Boolean useLombok) { - final var shouldUseLombok = Objects.requireNonNullElse(useLombok, false); - final String template; - - if (Boolean.TRUE.equals(shouldUseLombok)) { - template = TemplateIndexConstants.TEMPLATE_CONTENT_SCHEMA_LOMBOK; - } else { - template = TemplateIndexConstants.TEMPLATE_CONTENT_SCHEMA; - } - - return template; + public final void fillTemplates() { + generateTemplates(); } public final void fillTemplateWebClient(final String filePathToSave) throws IOException, TemplateException { @@ -78,11 +53,10 @@ public final void fillTemplateWebClient(final String filePathToSave) throws IOEx public final void fillTemplateRestClient(final String filePathToSave) throws IOException, TemplateException { writeTemplateToFile(TemplateIndexConstants.TEMPLATE_REST_CLIENT, filePathToSave, "ApiRestClient"); - } - public final void fillTemplateAuth(final String filePathToSave, final String authName) throws IOException { - writeTemplateToFile(createNameTemplate(authName),filePathToSave, authName); + public final void fillTemplateAuth(final String apiPackage, final String authName) throws IOException { + writeTemplateToFile(createNameTemplate(authName), apiPackage, authName); } public final void fillTemplate( @@ -102,15 +76,10 @@ public final void fillTemplate( if (specFile.isCallMode()) { addToRoot("authObject", authObject); + addToRoot("clientPackage", specFile.getClientPackage()); } writeTemplateToFile(specFile.isCallMode() ? getTemplateClientApi(specFile) : getTemplateApi(specFile), filePathToSave, className + "Api"); - - } - - public final void fillTemplates(boolean generateExceptionTemplate) throws IOException, TemplateException { - generateTemplates(generateExceptionTemplate); - } public final void calculateJavaEEPackage(final Integer springBootVersion) { 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 b2d26eb7..0af9f1a5 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 @@ -13,6 +13,8 @@ import com.fasterxml.jackson.databind.JsonNode; import com.sngular.api.generator.plugin.common.tools.ApiTool; +import com.sngular.api.generator.plugin.common.tools.MapperUtil; +import com.sngular.api.generator.plugin.common.tools.StringCaseUtils; import com.sngular.api.generator.plugin.openapi.model.AuthObject; import com.sngular.api.generator.plugin.openapi.model.AuthSchemaObject; import com.sngular.api.generator.plugin.openapi.model.OperationObject; @@ -32,11 +34,14 @@ public static List createAuthSchemaList(final JsonNode openAPI final JsonNode value = entry.getValue(); final var typeStr = ApiTool.getType(value); final var isHttpBearer = "http".equalsIgnoreCase(typeStr) && "bearer".equalsIgnoreCase(ApiTool.getNodeAsString(value, "scheme")); - final var authSchema = AuthSchemaObject.builder() - .type(isHttpBearer ? "HttpBearerAuth" : getModelTypeAuth(value)).name(key) - .apiKeyParam(API_KEY.equalsIgnoreCase(typeStr) ? ApiTool.getName(value) : "") - .apiKeyPlace(API_KEY.equalsIgnoreCase(typeStr) ? ApiTool.getNodeAsString(value, "in") : "") - .bearerSchema(isHttpBearer ? ApiTool.getNodeAsString(value, "scheme") : "").build(); + final var authSchema = AuthSchemaObject + .builder() + .name(StringCaseUtils.toCamelCase(MapperUtil.getKey(key))) + .type(isHttpBearer ? "HttpBearerAuth" : getModelTypeAuth(value)) + .apiKeyParam(API_KEY.equalsIgnoreCase(typeStr) ? ApiTool.getName(value) : "") + .apiKeyPlace(API_KEY.equalsIgnoreCase(typeStr) ? ApiTool.getNodeAsString(value, "in") : "") + .bearerSchema(isHttpBearer ? ApiTool.getNodeAsString(value, "scheme") : "") + .build(); authList.add(authSchema); } return authList; @@ -58,7 +63,7 @@ private static String getModelTypeAuth(final JsonNode securityScheme) { public static AuthObject getApiAuthObject(final List authSchemas, final List pathObjects) { final var authList = getApiAuthNames(pathObjects); final var authApiList = new HashSet(); - if (null != authSchemas && !authSchemas.isEmpty() && !authList.isEmpty()) { + if (CollectionUtils.isNotEmpty(authSchemas) && !authList.isEmpty()) { authSchemas.forEach(authValue -> { if (authList.contains(authValue.getName())) { authApiList.add(authValue.getType()); 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 deleted file mode 100644 index 1e97483b..00000000 --- a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/openapi/utils/MapperContentUtil.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * This Source Code Form is subject to the terms of the Mozilla Public - * * License, v. 2.0. If a copy of the MPL was not distributed with this - * * file, You can obtain one at https://mozilla.org/MPL/2.0/. - */ - -package com.sngular.api.generator.plugin.openapi.utils; - -import com.fasterxml.jackson.databind.JsonNode; -import com.sngular.api.generator.plugin.common.model.CommonSpecFile; -import com.sngular.api.generator.plugin.common.model.SchemaObject; -import com.sngular.api.generator.plugin.common.tools.ApiTool; -import com.sngular.api.generator.plugin.common.tools.ModelBuilder; -import org.apache.commons.lang3.StringUtils; - -import java.nio.file.Path; -import java.util.HashSet; -import java.util.Map; -import java.util.Set; - -public class MapperContentUtil { - - - private MapperContentUtil() { - } - - public static Map mapComponentToSchemaObject( - final Map totalSchemas, final Map compositedSchemas, final JsonNode model, - final String schemaName, final CommonSpecFile specFile, final Path baseDir) { - - return mapComponentToSchemaObject(totalSchemas, compositedSchemas, new HashSet<>(), model, - StringUtils.defaultIfEmpty(ApiTool.getName(model), schemaName), specFile, baseDir); - } - - private static Map mapComponentToSchemaObject( - final Map totalSchemas, final Map compositedSchemas, - final Set antiLoopList, final JsonNode schema, final String schemaName, final CommonSpecFile specFile, - final Path baseDir) { - final var name = StringUtils.defaultIfBlank(ApiTool.getName(schema), schemaName); - if (!compositedSchemas.containsKey(name)) { - compositedSchemas - .put(name, ModelBuilder.buildSchemaObject(totalSchemas, schemaName, schema, antiLoopList, compositedSchemas,"", specFile, baseDir)); - } - return compositedSchemas; - } - -} 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 8b4ed802..2ce21042 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 @@ -10,9 +10,7 @@ import com.sngular.api.generator.plugin.common.model.SchemaFieldObjectType; import com.sngular.api.generator.plugin.common.model.SchemaObject; import com.sngular.api.generator.plugin.common.model.TypeConstants; -import com.sngular.api.generator.plugin.common.tools.ApiTool; -import com.sngular.api.generator.plugin.common.tools.MapperUtil; -import com.sngular.api.generator.plugin.common.tools.SchemaUtil; +import com.sngular.api.generator.plugin.common.tools.*; 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.*; @@ -282,7 +280,7 @@ private static List buildParameterContent( .dataType(SchemaFieldObjectType.fromTypeList(inlineParameterPojo)) .importName(inlineParameterPojo) .build()); - globalObject.getSchemaMap().put(inlineParameter, parameterSchema); + globalObject.getSchemaMap().put(StringCaseUtils.titleToSnakeCase(inlineParameter), parameterSchema); } else { parameterObjects.add(builder .name(parameterName) @@ -324,7 +322,7 @@ private static void buildResponse( final JsonNode response) { var realResponse = response; if (ApiTool.hasRef(response)) { - realResponse = globalObject.getResponseNode(MapperUtil.getRefSchemaName(response)).orElseThrow(); + realResponse = globalObject.getResponseNode(MapperUtil.buildKey(response)).orElseThrow(); } final String operationIdWithCap = operationId.substring(0, 1).toUpperCase() + operationId.substring(1); final var content = ApiTool.getNode(realResponse, CONTENT); @@ -349,7 +347,7 @@ private static List mapContentObject( final String importName = getImportFromType(dataType); SchemaObject schemaObject = null; if (mediaType.equals("application/x-www-form-urlencoded") || mediaType.equals("multipart/form-data")) { - schemaObject = MapperContentUtil.mapComponentToSchemaObject(globalObject.getSchemaMap(), new HashMap(), schema, dataType.getBaseType(), specFile, baseDir).get("object"); + schemaObject = MapperContentUtil.mapComponentToSchemaObject(globalObject.getSchemaMap(), pojoName, schema, dataType.getBaseType(), specFile, baseDir).get(0); } contentObjects.add(ContentObject.builder() .dataType(dataType) 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 beb62bdb..c08f23a5 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 @@ -28,6 +28,7 @@ import com.fasterxml.jackson.databind.node.ObjectNode; import com.fasterxml.jackson.dataformat.yaml.YAMLFactory; import com.sngular.api.generator.plugin.common.tools.ApiTool; +import com.sngular.api.generator.plugin.common.tools.StringCaseUtils; import com.sngular.api.generator.plugin.openapi.exception.FileParseException; import com.sngular.api.generator.plugin.openapi.parameter.SpecFile; import org.apache.commons.collections4.IteratorUtils; @@ -158,9 +159,9 @@ private static void processRequestBody(final HashMap basicJson final var content = operation.at("/requestBody/content"); final var schema = content.findValue("schema"); if (!ApiTool.hasRef(schema)) { - basicJsonNodeMap.put("InlineObject" + StringUtils.capitalize(getOperationId(operation)), schema); + basicJsonNodeMap.put(StringCaseUtils.titleToSnakeCase("InlineObject" + StringUtils.capitalize(getOperationId(operation))), schema); } else if (ApiTool.hasItems(schema)) { - basicJsonNodeMap.put("InlineObject" + StringUtils.capitalize(ApiTool.getNodeAsString(operation, "operationId")), ApiTool.getItems(schema)); + basicJsonNodeMap.put(StringCaseUtils.titleToSnakeCase("InlineObject" + StringUtils.capitalize(ApiTool.getNodeAsString(operation, "operationId"))), ApiTool.getItems(schema)); } } } @@ -174,9 +175,9 @@ private static void processResponses(final HashMap basicJsonNo final var schemaList = ApiTool.findContentSchemas(response.getValue()); for (var schema : schemaList) { if (!ApiTool.hasRef(schema) && ApiTool.isObject(schema)) { - basicJsonNodeMap.put("InlineResponse" + response.getKey() + StringUtils.capitalize(getOperationId(operation)), schema); + basicJsonNodeMap.put(StringCaseUtils.titleToSnakeCase("InlineResponse" + response.getKey() + StringUtils.capitalize(getOperationId(operation))), schema); } else if (ApiTool.isComposed(schema)) { - basicJsonNodeMap.put("InlineResponse" + response.getKey() + StringUtils.capitalize(getOperationId(operation)) + getComposedJsonNodeName(schema), schema); + basicJsonNodeMap.put(StringCaseUtils.titleToSnakeCase("InlineResponse" + response.getKey() + StringUtils.capitalize(getOperationId(operation)) + getComposedJsonNodeName(schema)), schema); } } } @@ -190,7 +191,7 @@ private static void processParameters(final HashMap basicJsonN final var parameter = it.next(); if (ApiTool.hasNode(parameter, "content")) { basicJsonNodeMap.putIfAbsent( - "InlineParameter" + StringUtils.capitalize(getOperationId(operation)) + StringUtils.capitalize(ApiTool.getName(parameter)), + StringCaseUtils.titleToSnakeCase("InlineParameter" + StringUtils.capitalize(getOperationId(operation)) + StringUtils.capitalize(ApiTool.getName(parameter))), ApiTool.getNode(parameter, "schema")); } } diff --git a/multiapi-engine/src/main/resources/templates/model/templateSchemaWithLombok.ftlh b/multiapi-engine/src/main/resources/templates/model/templateSchemaWithLombok.ftlh index 5ef641b9..3f88fddf 100644 --- a/multiapi-engine/src/main/resources/templates/model/templateSchemaWithLombok.ftlh +++ b/multiapi-engine/src/main/resources/templates/model/templateSchemaWithLombok.ftlh @@ -138,14 +138,14 @@ import ${packageModel}.customvalidator.UniqueItems; import lombok.Builder; <#list schema.fieldObjectList as field> - <#if collection?seq_contains(field.dataType.baseType)> -import lombok.Singular; + <#if field.required> +import lombok.NonNull; <#break> <#list schema.fieldObjectList as field> - <#if field.required> -import lombok.NonNull; + <#if collection?seq_contains(field.dataType.baseType)> +import lombok.Singular; <#break> @@ -241,6 +241,7 @@ public class ${schema.className} { <#else> private ${field.dataType} ${createSimpleType (field)} + @Builder 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 1c6735af..c83edec7 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 @@ -420,9 +420,7 @@ static Function validateTestFileGeneration() { final String CUSTOM_VALIDATOR_PATH = COMMON_PATH + "customvalidator/"; - final String DEFAULT_CONSUMER_EXCEPTION_API = DEFAULT_CONSUMER_FOLDER + "/exception"; - - final String DEFAULT_PRODUCER_EXCEPTION_API = DEFAULT_PRODUCER_FOLDER + "/exception"; + final String DEFAULT_EXCEPTION_API = DEFAULT_COMMON_FOLDER + "/exception"; final List expectedConsumerFiles = List.of( ASSETS_PATH + "IPublishOperationFileGeneration.java", @@ -452,14 +450,14 @@ static Function validateTestFileGeneration() { ASSETS_PATH + "ModelClassException.java"); return (path) -> commonTest(path, expectedConsumerFiles, expectedProducerFiles, DEFAULT_CONSUMER_FOLDER, DEFAULT_PRODUCER_FOLDER, - expectedExceptionFiles, List.of(DEFAULT_CONSUMER_EXCEPTION_API, DEFAULT_PRODUCER_EXCEPTION_API)) && + expectedExceptionFiles, DEFAULT_EXCEPTION_API) && modelTest(path, expectedModelSchemaFiles, DEFAULT_COMMON_FOLDER) && customValidatorTest(path, expectedValidatorFiles, DEFAULT_CUSTOM_VALIDATOR_FOLDER); } private static Boolean commonTest( final Path resultPath, final List expectedFile, final List expectedModelFiles, final String targetConsumer, - final String targetProducer, final List expectedExceptionFiles, final List targetExceptionList) { + final String targetProducer, final List expectedExceptionFiles, final String targetException) { Boolean result = Boolean.TRUE; try { final Path pathToTarget = Path.of(resultPath.toString(), "target"); @@ -477,12 +475,10 @@ private static Boolean commonTest( } if (CollectionUtils.isNotEmpty(expectedExceptionFiles)) { - for (final var targetException: targetExceptionList) { - final Path pathToTargetException = pathToTarget.resolve(targetException); - final File targetModelException = pathToTargetException.toFile(); - Assertions.assertThat(targetModelException).isNotEmptyDirectory(); - TestUtils.validateFiles(expectedExceptionFiles, targetModelException); - } + final Path pathToTargetException = pathToTarget.resolve(targetException); + final File targetModelException = pathToTargetException.toFile(); + Assertions.assertThat(targetModelException).isNotEmptyDirectory(); + TestUtils.validateFiles(expectedExceptionFiles, targetModelException); } } catch (final IOException e) { result = Boolean.FALSE; @@ -549,7 +545,7 @@ static Function validateTestIssueGeneration() { ); return (path) -> commonTest(path, expectedConsumerFiles, expectedProducerFiles, DEFAULT_CONSUMER_FOLDER, DEFAULT_PRODUCER_FOLDER, - Collections.emptyList(), Collections.emptyList()) && + Collections.emptyList(), null) && modelTest(path, expectedModelSchemaFiles, DEFAULT_MODEL_SCHEMA_FOLDER); } @@ -578,7 +574,7 @@ static Function validateTestIssueSimpleTypeGeneration() { ); return (path) -> commonTest(path, expectedConsumerFiles, expectedProducerFiles, DEFAULT_CONSUMER_FOLDER, DEFAULT_PRODUCER_FOLDER, - Collections.emptyList(), Collections.emptyList()) && + Collections.emptyList(), null) && modelTest(path, expectedModelSchemaFiles, DEFAULT_MODEL_SCHEMA_FOLDER); } @@ -608,7 +604,7 @@ static Function validateTestReservedWordsGeneration() { ASSETS_PATH + "WaiterDTO.java" ); - return (path) -> commonTest(path, expectedConsumerFiles, expectedProducerFiles, DEFAULT_CONSUMER_FOLDER, DEFAULT_PRODUCER_FOLDER, Collections.emptyList(), Collections.emptyList()) && + return (path) -> commonTest(path, expectedConsumerFiles, expectedProducerFiles, DEFAULT_CONSUMER_FOLDER, DEFAULT_PRODUCER_FOLDER, Collections.emptyList(), null) && modelTest(path, expectedModelSchemaFiles, DEFAULT_MODEL_SCHEMA_FOLDER); } @@ -637,7 +633,7 @@ static Function validateTestRareCharsGeneration() { ASSETS_PATH + "WaiterDTO.java" ); - return (path) -> commonTest(path, expectedConsumerFiles, expectedProducerFiles, DEFAULT_CONSUMER_FOLDER, DEFAULT_PRODUCER_FOLDER, Collections.emptyList(), Collections.emptyList()) && + return (path) -> commonTest(path, expectedConsumerFiles, expectedProducerFiles, DEFAULT_CONSUMER_FOLDER, DEFAULT_PRODUCER_FOLDER, Collections.emptyList(), null) && modelTest(path, expectedModelSchemaFiles, DEFAULT_MODEL_SCHEMA_FOLDER); } @@ -656,9 +652,7 @@ static Function validateCustomValidators(final int springBootVers final String CUSTOM_VALIDATOR_PATH = COMMON_PATH + "customvalidator/" + calculateJavaEEPackage(springBootVersion); - final String DEFAULT_CONSUMER_EXCEPTION_API = DEFAULT_CONSUMER_FOLDER + "/exception"; - - final String DEFAULT_PRODUCER_EXCEPTION_API = DEFAULT_PRODUCER_FOLDER + "/exception"; + final String DEFAULT_EXCEPTION_API = DEFAULT_MODEL_SCHEMA_FOLDER + "/exception"; final List expectedConsumerFiles = List.of( ASSETS_PATH + "ICustomValidatorResponse.java", @@ -710,7 +704,7 @@ static Function validateCustomValidators(final int springBootVers ASSETS_PATH + "ModelClassException.java"); return (path) -> commonTest(path, expectedConsumerFiles, expectedProducerFiles, DEFAULT_CONSUMER_FOLDER, DEFAULT_PRODUCER_FOLDER, - expectedExceptionFiles, List.of(DEFAULT_CONSUMER_EXCEPTION_API, DEFAULT_PRODUCER_EXCEPTION_API)) && + expectedExceptionFiles, DEFAULT_EXCEPTION_API) && modelTest(path, expectedModelSchemaFiles, DEFAULT_MODEL_SCHEMA_FOLDER) && customValidatorTest(path, expectedValidatorFiles, DEFAULT_CUSTOM_VALIDATOR_FOLDER); } @@ -739,9 +733,7 @@ static Function validateTestFileGenerationIssue() { final String CUSTOM_VALIDATOR_PATH = COMMON_PATH + "customvalidator/"; - final String DEFAULT_CONSUMER_EXCEPTION_API = DEFAULT_CONSUMER_FOLDER + "/exception"; - - final String DEFAULT_PRODUCER_EXCEPTION_API = DEFAULT_PRODUCER_FOLDER + "/exception"; + final String DEFAULT_EXCEPTION_API = DEFAULT_COMMON_FOLDER + "/exception"; final List expectedConsumerFiles = List.of( ASSETS_PATH + "IOnCustomerEvent.java", @@ -772,7 +764,7 @@ static Function validateTestFileGenerationIssue() { ASSETS_PATH + "ModelClassException.java"); return (path) -> commonTest(path, expectedConsumerFiles, expectedProducerFiles, DEFAULT_CONSUMER_FOLDER, DEFAULT_PRODUCER_FOLDER, - expectedExceptionFiles, List.of(DEFAULT_CONSUMER_EXCEPTION_API, DEFAULT_PRODUCER_EXCEPTION_API)) && + expectedExceptionFiles, DEFAULT_EXCEPTION_API) && modelTest(path, expectedModelSchemaFiles, DEFAULT_COMMON_FOLDER) && customValidatorTest(path, expectedValidatorFiles, DEFAULT_CUSTOM_VALIDATOR_FOLDER); } @@ -798,21 +790,22 @@ static Function validateTestFileGenerationExternalAvro() { ); return (path) -> commonTest(path, expectedConsumerFiles, expectedProducerFiles, DEFAULT_CONSUMER_FOLDER, DEFAULT_PRODUCER_FOLDER, - Collections.emptyList(), Collections.emptyList()); + Collections.emptyList(), null); } static Function validateTestFileGenerationStreamBridge() { - final String DEFAULT_CONSUMER_FOLDER = "generated/com/sngular/scsplugin/streambridge/model/event/consumer"; - final String DEFAULT_PRODUCER_FOLDER = "generated/com/sngular/scsplugin/streambridge/model/event/producer"; + final String DEFAULT_COMMON_FOLDER = "generated/com/sngular/scsplugin/streambridge/model/event"; + + final String DEFAULT_CONSUMER_FOLDER = DEFAULT_COMMON_FOLDER + "/consumer"; + + final String DEFAULT_PRODUCER_FOLDER = DEFAULT_COMMON_FOLDER + "/producer"; final String COMMON_PATH = "asyncapigenerator/testFileGenerationStreamBridge/"; final String ASSETS_PATH = COMMON_PATH + "assets/"; - final String DEFAULT_CONSUMER_EXCEPTION_API = DEFAULT_CONSUMER_FOLDER + "/exception"; - - final String DEFAULT_PRODUCER_EXCEPTION_API = DEFAULT_PRODUCER_FOLDER + "/exception"; + final String DEFAULT_EXCEPTION_API = DEFAULT_COMMON_FOLDER + "/exception"; final List expectedConsumerFiles = List.of( ASSETS_PATH + "ISubscribeOperationStreamBridge.java", @@ -827,21 +820,22 @@ static Function validateTestFileGenerationStreamBridge() { ASSETS_PATH + "ModelClassException.java"); return (path) -> commonTest(path, expectedConsumerFiles, expectedProducerFiles, DEFAULT_CONSUMER_FOLDER, DEFAULT_PRODUCER_FOLDER, - expectedExceptionFiles, List.of(DEFAULT_CONSUMER_EXCEPTION_API, DEFAULT_PRODUCER_EXCEPTION_API)); + expectedExceptionFiles, DEFAULT_EXCEPTION_API); } static Function validateTestFileGenerationWithoutIds() { - final String DEFAULT_CONSUMER_FOLDER = "generated/com/sngular/scsplugin/withoutids/model/event/consumer"; - final String DEFAULT_PRODUCER_FOLDER = "generated/com/sngular/scsplugin/withoutids/model/event/producer"; + final String DEFAULT_COMMON_FOLDER = "generated/com/sngular/scsplugin/withoutids/model/event"; + + final String DEFAULT_CONSUMER_FOLDER = DEFAULT_COMMON_FOLDER + "/consumer"; + + final String DEFAULT_PRODUCER_FOLDER = DEFAULT_COMMON_FOLDER + "/producer"; final String COMMON_PATH = "asyncapigenerator/testFileGenerationWithoutOperationIds/"; final String ASSETS_PATH = COMMON_PATH + "assets/"; - final String DEFAULT_CONSUMER_EXCEPTION_API = DEFAULT_CONSUMER_FOLDER + "/exception"; - - final String DEFAULT_PRODUCER_EXCEPTION_API = DEFAULT_PRODUCER_FOLDER + "/exception"; + final String DEFAULT_EXCEPTION_API = DEFAULT_COMMON_FOLDER + "/exception"; final List expectedConsumerFiles = List.of( ASSETS_PATH + "ISubscribeOperation.java", @@ -856,7 +850,7 @@ static Function validateTestFileGenerationWithoutIds() { ASSETS_PATH + "ModelClassException.java"); return (path) -> commonTest(path, expectedConsumerFiles, expectedProducerFiles, DEFAULT_CONSUMER_FOLDER, DEFAULT_PRODUCER_FOLDER, - expectedExceptionFiles, List.of(DEFAULT_CONSUMER_EXCEPTION_API, DEFAULT_PRODUCER_EXCEPTION_API)); + expectedExceptionFiles, DEFAULT_EXCEPTION_API); } static Function validateTestFileGenerationArrayString() { @@ -911,9 +905,7 @@ static Function validateTestModelClassExceptionGeneration() { final String CUSTOM_VALIDATOR_PATH = COMMON_PATH + "customvalidator/"; - final String DEFAULT_CONSUMER_EXCEPTION_API = DEFAULT_CONSUMER_FOLDER + "/exception"; - - final String DEFAULT_PRODUCER_EXCEPTION_API = DEFAULT_PRODUCER_FOLDER + "/exception"; + final String DEFAULT_EXCEPTION_API = DEFAULT_COMMON_FOLDER + "/exception"; final List expectedConsumerFiles = List.of( ASSETS_PATH + "ISubscribeOrder.java", @@ -940,7 +932,7 @@ static Function validateTestModelClassExceptionGeneration() { ASSETS_PATH + "ModelClassException.java"); return (path) -> commonTest(path, expectedConsumerFiles, expectedProducerFiles, DEFAULT_CONSUMER_FOLDER, DEFAULT_PRODUCER_FOLDER, - expectedExceptionFiles, List.of(DEFAULT_CONSUMER_EXCEPTION_API, DEFAULT_PRODUCER_EXCEPTION_API)) && + expectedExceptionFiles, DEFAULT_EXCEPTION_API) && modelTest(path, expectedModelSchemaFiles, DEFAULT_COMMON_FOLDER) && customValidatorTest(path, expectedValidatorFiles, DEFAULT_CUSTOM_VALIDATOR_FOLDER); } @@ -1055,7 +1047,7 @@ static Function validateTestFileGenerationWithKafkaBindings() { CUSTOM_VALIDATOR_PATH + "NotNullValidator.java" ); - return (path) -> commonTest(path, expectedConsumerFiles, expectedProducerFiles, DEFAULT_CONSUMER_FOLDER, DEFAULT_PRODUCER_FOLDER, Collections.emptyList(), Collections.emptyList()) && + return (path) -> commonTest(path, expectedConsumerFiles, expectedProducerFiles, DEFAULT_CONSUMER_FOLDER, DEFAULT_PRODUCER_FOLDER, Collections.emptyList(), null) && modelTest(path, expectedModelSchemaFiles, DEFAULT_COMMON_FOLDER) && customValidatorTest(path, expectedValidatorFiles, DEFAULT_CUSTOM_VALIDATOR_FOLDER); } @@ -1099,7 +1091,7 @@ static Function validateTestSubObjectSameName() { DEFAULT_CONSUMER_FOLDER, DEFAULT_PRODUCER_FOLDER, Collections.emptyList(), - Collections.emptyList()) + null) && modelTest(path, expectedConsumerModelSchemaFiles, DEFAULT_CONSUMER_MODEL_FOLDER) && modelTest(path, expectedProducerModelSchemaFiles, DEFAULT_PRODUCER_MODEL_FOLDER); } diff --git a/multiapi-engine/src/test/resources/openapigenerator/testAllOf/assets/testApi/ApiTestAllOfDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testAllOf/assets/testApi/ApiTestAllOfDTO.java index eaee11fe..48d0812d 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testAllOf/assets/testApi/ApiTestAllOfDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testAllOf/assets/testApi/ApiTestAllOfDTO.java @@ -41,7 +41,7 @@ public ApiTestAllOfDTO.ApiTestAllOfDTOBuilder testers(List testers) { } public ApiTestAllOfDTO.ApiTestAllOfDTOBuilder tester(String tester) { - if (tester != null) { + if (Objects.nonNull(tester)) { this.testers.add(tester); } return this; diff --git a/multiapi-engine/src/test/resources/openapigenerator/testAllOf/assets/testApi/ApiTestDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testAllOf/assets/testApi/ApiTestDTO.java index af64704d..ffeb43d3 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testAllOf/assets/testApi/ApiTestDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testAllOf/assets/testApi/ApiTestDTO.java @@ -46,7 +46,7 @@ public ApiTestDTO.ApiTestDTOBuilder testers(List testers) { } public ApiTestDTO.ApiTestDTOBuilder tester(String tester) { - if (tester != null) { + if (Objects.nonNull(tester)) { this.testers.add(tester); } return this; diff --git a/multiapi-engine/src/test/resources/openapigenerator/testAllOf/assets/testApi/ApiTestInfoDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testAllOf/assets/testApi/ApiTestInfoDTO.java index d1bba8fa..3db018d5 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testAllOf/assets/testApi/ApiTestInfoDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testAllOf/assets/testApi/ApiTestInfoDTO.java @@ -45,7 +45,7 @@ public ApiTestInfoDTO.ApiTestInfoDTOBuilder testers(List testers) { } public ApiTestInfoDTO.ApiTestInfoDTOBuilder tester(String tester) { - if (tester != null) { + if (Objects.nonNull(tester)) { this.testers.add(tester); } return this; diff --git a/multiapi-engine/src/test/resources/openapigenerator/testAllOf/assets/testApi/ApiTestsDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testAllOf/assets/testApi/ApiTestsDTO.java index af64704d..ffeb43d3 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testAllOf/assets/testApi/ApiTestsDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testAllOf/assets/testApi/ApiTestsDTO.java @@ -46,7 +46,7 @@ public ApiTestDTO.ApiTestDTOBuilder testers(List testers) { } public ApiTestDTO.ApiTestDTOBuilder tester(String tester) { - if (tester != null) { + if (Objects.nonNull(tester)) { this.testers.add(tester); } return this; diff --git a/multiapi-engine/src/test/resources/openapigenerator/testApiEnumsGeneration/assets/ApiTestInfoDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testApiEnumsGeneration/assets/ApiTestInfoDTO.java index 2ac1ac02..deca06c2 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testApiEnumsGeneration/assets/ApiTestInfoDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testApiEnumsGeneration/assets/ApiTestInfoDTO.java @@ -46,7 +46,7 @@ public ApiTestInfoDTO.ApiTestInfoDTOBuilder testers(List testers) { } public ApiTestInfoDTO.ApiTestInfoDTOBuilder tester(String tester) { - if (tester != null) { + if (Objects.nonNull(tester)) { this.testers.add(tester); } return this; diff --git a/multiapi-engine/src/test/resources/openapigenerator/testApiParametersWithContentGeneration/assets/ApiInlineParameterTestIdDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testApiParametersWithContentGeneration/assets/ApiInlineParameterTestIdDTO.java index c515f211..7b8d9e89 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testApiParametersWithContentGeneration/assets/ApiInlineParameterTestIdDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testApiParametersWithContentGeneration/assets/ApiInlineParameterTestIdDTO.java @@ -13,11 +13,6 @@ public class ApiInlineParameterTestIdDTO { @JsonProperty(value ="email") private String email; - private ApiInlineParameterTestIdDTO(String email) { - this.email = email; - - } - private ApiInlineParameterTestIdDTO(ApiInlineParameterTestIdDTOBuilder builder) { this.email = builder.email; diff --git a/multiapi-engine/src/test/resources/openapigenerator/testApiParametersWithContentGeneration/assets/ApiTestInfoDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testApiParametersWithContentGeneration/assets/ApiTestInfoDTO.java index 05edc58b..4a2a0597 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testApiParametersWithContentGeneration/assets/ApiTestInfoDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testApiParametersWithContentGeneration/assets/ApiTestInfoDTO.java @@ -20,13 +20,6 @@ public class ApiTestInfoDTO { @NotNull private final String testName; - private ApiTestInfoDTO(List testers, String testName) { - this.testers = testers; - this.testName = testName; - - validateRequiredAttributes(); - } - private ApiTestInfoDTO(ApiTestInfoDTOBuilder builder) { this.testers = builder.testers; this.testName = builder.testName; @@ -52,7 +45,7 @@ public ApiTestInfoDTO.ApiTestInfoDTOBuilder testers(List testers) { } public ApiTestInfoDTO.ApiTestInfoDTOBuilder tester(String tester) { - if (tester != null) { + if (Objects.nonNull(tester)) { this.testers.add(tester); } return this; diff --git a/multiapi-engine/src/test/resources/openapigenerator/testApiPathParameterGeneration/assets/TestInfoDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testApiPathParameterGeneration/assets/TestInfoDTO.java index a82dd168..d9054249 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testApiPathParameterGeneration/assets/TestInfoDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testApiPathParameterGeneration/assets/TestInfoDTO.java @@ -44,7 +44,7 @@ public TestInfoDTO.TestInfoDTOBuilder testers(List testers) { } public TestInfoDTO.TestInfoDTOBuilder tester(String tester) { - if (tester != null) { + if (Objects.nonNull(tester)) { this.testers.add(tester); } return this; diff --git a/multiapi-engine/src/test/resources/openapigenerator/testApiPathWithSpecialCharGeneration/assets/ApiTestInfoDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testApiPathWithSpecialCharGeneration/assets/ApiTestInfoDTO.java index 99e7093d..02bc2822 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testApiPathWithSpecialCharGeneration/assets/ApiTestInfoDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testApiPathWithSpecialCharGeneration/assets/ApiTestInfoDTO.java @@ -45,7 +45,7 @@ public ApiTestInfoDTO.ApiTestInfoDTOBuilder testers(List testers) { } public ApiTestInfoDTO.ApiTestInfoDTOBuilder tester(String tester) { - if (tester != null) { + if (Objects.nonNull(tester)) { this.testers.add(tester); } return this; diff --git a/multiapi-engine/src/test/resources/openapigenerator/testApiQueryParameterGeneration/assets/TestInfoDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testApiQueryParameterGeneration/assets/TestInfoDTO.java index 3f4fbae4..9faf34a1 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testApiQueryParameterGeneration/assets/TestInfoDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testApiQueryParameterGeneration/assets/TestInfoDTO.java @@ -44,7 +44,7 @@ public TestInfoDTO.TestInfoDTOBuilder testers(List testers) { } public TestInfoDTO.TestInfoDTOBuilder tester(String tester) { - if (tester != null) { + if (Objects.nonNull(tester)) { this.testers.add(tester); } return this; diff --git a/multiapi-engine/src/test/resources/openapigenerator/testApiReactiveGeneration/assets/ApiTestInfoDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testApiReactiveGeneration/assets/ApiTestInfoDTO.java index 60fd9aea..7bfc22d2 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testApiReactiveGeneration/assets/ApiTestInfoDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testApiReactiveGeneration/assets/ApiTestInfoDTO.java @@ -45,7 +45,7 @@ public ApiTestInfoDTO.ApiTestInfoDTOBuilder testers(List testers) { } public ApiTestInfoDTO.ApiTestInfoDTOBuilder tester(String tester) { - if (tester != null) { + if (Objects.nonNull(tester)) { this.testers.add(tester); } return this; diff --git a/multiapi-engine/src/test/resources/openapigenerator/testApiTagsGeneration/assets/TestInfoDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testApiTagsGeneration/assets/TestInfoDTO.java index 20bd0e26..21f599ff 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testApiTagsGeneration/assets/TestInfoDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testApiTagsGeneration/assets/TestInfoDTO.java @@ -45,7 +45,7 @@ public TestInfoDTO.TestInfoDTOBuilder testers(List testers) { } public TestInfoDTO.TestInfoDTOBuilder tester(String tester) { - if (tester != null) { + if (Objects.nonNull(tester)) { this.testers.add(tester); } return this; diff --git a/multiapi-engine/src/test/resources/openapigenerator/testClientPackageWebClientApiGeneration/assets/TestInfoDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testClientPackageWebClientApiGeneration/assets/TestInfoDTO.java index f003d1bf..8b856b50 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testClientPackageWebClientApiGeneration/assets/TestInfoDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testClientPackageWebClientApiGeneration/assets/TestInfoDTO.java @@ -38,7 +38,7 @@ public TestInfoDTO.TestInfoDTOBuilder testers(List testers) { } public TestInfoDTO.TestInfoDTOBuilder tester(String tester) { - if (tester != null) { + if (Objects.nonNull(tester)) { this.testers.add(tester); } return this; diff --git a/multiapi-engine/src/test/resources/openapigenerator/testComplexAnyOf/assets/ApiNumberFieldDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testComplexAnyOf/assets/ApiNumberFieldDTO.java index c32c2b61..78ed2a5c 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testComplexAnyOf/assets/ApiNumberFieldDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testComplexAnyOf/assets/ApiNumberFieldDTO.java @@ -132,7 +132,7 @@ public ApiNumberFieldDTO.ApiNumberFieldDTOBuilder defaultValues(List def } public ApiNumberFieldDTO.ApiNumberFieldDTOBuilder defaultValue(Object defaultValue) { - if (defaultValue != null) { + if (Objects.nonNull(defaultValue)) { this.defaultValues.add(defaultValue); } return this; diff --git a/multiapi-engine/src/test/resources/openapigenerator/testComplexAnyOf/assets/ApiStringFieldDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testComplexAnyOf/assets/ApiStringFieldDTO.java index c5547b57..19c98317 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testComplexAnyOf/assets/ApiStringFieldDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testComplexAnyOf/assets/ApiStringFieldDTO.java @@ -91,7 +91,7 @@ public ApiStringFieldDTO.ApiStringFieldDTOBuilder properties(List proper } public ApiStringFieldDTO.ApiStringFieldDTOBuilder propertie(String propertie) { - if (propertie != null) { + if (Objects.nonNull(propertie)) { this.properties.add(propertie); } return this; @@ -104,7 +104,7 @@ public ApiStringFieldDTO.ApiStringFieldDTOBuilder defaultValues(List def } public ApiStringFieldDTO.ApiStringFieldDTOBuilder defaultValue(String defaultValue) { - if (defaultValue != null) { + if (Objects.nonNull(defaultValue)) { this.defaultValues.add(defaultValue); } return this; diff --git a/multiapi-engine/src/test/resources/openapigenerator/testInlineSchemaCreation/assets/ApiTestDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testInlineSchemaCreation/assets/ApiTestDTO.java index 6cc6e79c..5d30a895 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testInlineSchemaCreation/assets/ApiTestDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testInlineSchemaCreation/assets/ApiTestDTO.java @@ -71,7 +71,7 @@ public ApiTestDTO.ApiTestDTOBuilder tags(List tags) { } public ApiTestDTO.ApiTestDTOBuilder tag(String tag) { - if (tag != null) { + if (Objects.nonNull(tag)) { this.tags.add(tag); } return this; @@ -90,7 +90,7 @@ public ApiTestDTO.ApiTestDTOBuilder testTypeList(List testTypeLi } public ApiTestDTO.ApiTestDTOBuilder testType(ApiTestTypeDTO testType) { - if (testType != null) { + if (Objects.nonNull(testType)) { this.testTypeList.add(testType); } return this; diff --git a/multiapi-engine/src/test/resources/openapigenerator/testOverWriteModelTrue/assets/ApiTestInfoDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testOverWriteModelTrue/assets/ApiTestInfoDTO.java index f6182fff..6875adaf 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testOverWriteModelTrue/assets/ApiTestInfoDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testOverWriteModelTrue/assets/ApiTestInfoDTO.java @@ -45,7 +45,7 @@ public ApiTestInfoDTO.ApiTestInfoDTOBuilder testers(List testers) { } public ApiTestInfoDTO.ApiTestInfoDTOBuilder tester(String tester) { - if (tester != null) { + if (Objects.nonNull(tester)) { this.testers.add(tester); } return this; diff --git a/multiapi-engine/src/test/resources/openapigenerator/testRestClientApiGeneration/assets/ApiTestInfoDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testRestClientApiGeneration/assets/ApiTestInfoDTO.java index aabce1ec..f1282020 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testRestClientApiGeneration/assets/ApiTestInfoDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testRestClientApiGeneration/assets/ApiTestInfoDTO.java @@ -46,7 +46,7 @@ public ApiTestInfoDTO.ApiTestInfoDTOBuilder testers(List testers) { } public ApiTestInfoDTO.ApiTestInfoDTOBuilder tester(String tester) { - if (tester != null) { + if (Objects.nonNull(tester)) { this.testers.add(tester); } return this; diff --git a/multiapi-engine/src/test/resources/openapigenerator/testRestClientApiWithRequestObjectGeneration/assets/ApiTestInfoDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testRestClientApiWithRequestObjectGeneration/assets/ApiTestInfoDTO.java index 1bc98b4e..0bf76344 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testRestClientApiWithRequestObjectGeneration/assets/ApiTestInfoDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testRestClientApiWithRequestObjectGeneration/assets/ApiTestInfoDTO.java @@ -38,7 +38,7 @@ public ApiTestInfoDTO.ApiTestInfoDTOBuilder testers(List testers) { } public ApiTestInfoDTO.ApiTestInfoDTOBuilder tester(String tester) { - if (tester != null) { + if (Objects.nonNull(tester)) { this.testers.add(tester); } return this; diff --git a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/assets/testApi/ApiTestAllOfDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/assets/testApi/ApiTestAllOfDTO.java index eaee11fe..48d0812d 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/assets/testApi/ApiTestAllOfDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/assets/testApi/ApiTestAllOfDTO.java @@ -41,7 +41,7 @@ public ApiTestAllOfDTO.ApiTestAllOfDTOBuilder testers(List testers) { } public ApiTestAllOfDTO.ApiTestAllOfDTOBuilder tester(String tester) { - if (tester != null) { + if (Objects.nonNull(tester)) { this.testers.add(tester); } return this; diff --git a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/assets/testApi/ApiTestDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/assets/testApi/ApiTestDTO.java index af64704d..ffeb43d3 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/assets/testApi/ApiTestDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/assets/testApi/ApiTestDTO.java @@ -46,7 +46,7 @@ public ApiTestDTO.ApiTestDTOBuilder testers(List testers) { } public ApiTestDTO.ApiTestDTOBuilder tester(String tester) { - if (tester != null) { + if (Objects.nonNull(tester)) { this.testers.add(tester); } return this; diff --git a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/assets/testApi/ApiTestInfoDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/assets/testApi/ApiTestInfoDTO.java index d1bba8fa..3db018d5 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/assets/testApi/ApiTestInfoDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/assets/testApi/ApiTestInfoDTO.java @@ -45,7 +45,7 @@ public ApiTestInfoDTO.ApiTestInfoDTOBuilder testers(List testers) { } public ApiTestInfoDTO.ApiTestInfoDTOBuilder tester(String tester) { - if (tester != null) { + if (Objects.nonNull(tester)) { this.testers.add(tester); } return this; diff --git a/multiapi-engine/src/test/resources/openapigenerator/testWebClientApiGeneration/api-test.yml b/multiapi-engine/src/test/resources/openapigenerator/testWebClientApiGeneration/api-test.yml index 4e0a7e4d..ac4ab75e 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testWebClientApiGeneration/api-test.yml +++ b/multiapi-engine/src/test/resources/openapigenerator/testWebClientApiGeneration/api-test.yml @@ -94,10 +94,6 @@ components: type: array items: type: string - Tests: - type: array - items: - $ref: "#/components/schemas/Test" Error: type: object required: diff --git a/multiapi-engine/src/test/resources/openapigenerator/testWebClientApiGeneration/assets/ApiTestInfoDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testWebClientApiGeneration/assets/ApiTestInfoDTO.java index 0194c31d..3e6be228 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testWebClientApiGeneration/assets/ApiTestInfoDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testWebClientApiGeneration/assets/ApiTestInfoDTO.java @@ -45,7 +45,7 @@ public ApiTestInfoDTO.ApiTestInfoDTOBuilder testers(List testers) { } public ApiTestInfoDTO.ApiTestInfoDTOBuilder tester(String tester) { - if (tester != null) { + if (Objects.nonNull(tester)) { this.testers.add(tester); } return this; From 2baa29d0743f4e3ee03687f65ce53c5ba9fe4ca9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?jose=20enrique=20garcia=20maci=C3=B1eiras?= Date: Mon, 23 Sep 2024 16:44:56 +0200 Subject: [PATCH 16/26] Fix Async Generator --- .../plugin/asyncapi/AsyncApiGenerator.java | 2 +- .../asyncapi/template/TemplateFactory.java | 11 +- .../template/CommonTemplateFactory.java | 9 +- .../plugin/common/tools/ModelBuilder.java | 2 +- .../openapi/template/TemplateFactory.java | 12 + .../model/templateSchemaWithLombok.ftlh | 26 +- .../asyncapi/AsyncApiGeneratorFixtures.java | 1140 ++++++++--------- .../assets/payload/SomeOtherObject.java | 76 +- .../assets/payload/UserSignedUpPayload.java | 137 +- .../assets/ObjectArrayDTO.java | 111 +- .../assets/ConfigurationDTO.java | 68 +- .../assets/MailRequestDTO.java | 111 +- .../assets/ConfigDTO.java | 68 +- .../assets/MailRequestInfiniteDTO.java | 111 +- .../assets/payload/SomeOtherObject.java | 84 +- .../assets/payload/UserSignedUpPayload.java | 132 +- .../testNoSchemas/assets/TestMsg.java | 68 +- .../testNoSchemas/assets/Thing.java | 68 +- .../assets/payload/UserDetails.java | 100 +- .../assets/payload/UserSignedUp.java | 84 +- .../assets/testApi/ApiErrorDTO.java | 2 +- 21 files changed, 751 insertions(+), 1671 deletions(-) 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 a1c0f69a..95bedcd9 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 @@ -165,10 +165,10 @@ public final void processFileSpec(final List specsListFile) { } templateFactory.fillTemplates(); - templateFactory.clearData(); } catch (final TemplateException | IOException e) { throw new FileSystemException(e); } + templateFactory.clearData(); } } 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 2a522c27..4ba588a4 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 @@ -189,6 +189,16 @@ public final void clearData() { streamBridgeMethods.clear(); } + @Override + protected void clearRoot() { + delFromRoot("classNamespace"); + delFromRoot("className"); + delFromRoot("keyNamespace"); + delFromRoot("publishMethods"); + delFromRoot("subscribeMethods"); + delFromRoot("streamBridgeMethods"); + } + public final void fillTemplateWrapper( final String modelPackage, final String classFullName, @@ -203,7 +213,6 @@ public final void fillTemplateWrapper( "keyNamespace", keyClassFullName, "keyClassName", keyClassName)); writeTemplateToFile(TemplateIndexConstants.TEMPLATE_MESSAGE_WRAPPER, filePath, "MessageWrapper"); - clearData(); } public void processFilePaths(final SpecFile fileParameter, final String defaultApiPackage) { diff --git a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/template/CommonTemplateFactory.java b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/template/CommonTemplateFactory.java index ecd74be4..5a091439 100644 --- a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/template/CommonTemplateFactory.java +++ b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/template/CommonTemplateFactory.java @@ -3,7 +3,6 @@ import com.sngular.api.generator.plugin.asyncapi.exception.FileSystemException; import com.sngular.api.generator.plugin.asyncapi.parameter.OperationParameterObject; import com.sngular.api.generator.plugin.asyncapi.template.ClassTemplate; -import com.sngular.api.generator.plugin.asyncapi.template.ClasspathTemplateLoader; import com.sngular.api.generator.plugin.asyncapi.template.TemplateIndexConstants; import com.sngular.api.generator.plugin.common.model.SchemaFieldObject; import com.sngular.api.generator.plugin.common.model.SchemaObject; @@ -228,16 +227,22 @@ protected void addToRoot(final String key, final Object value) { root.put(key, value); } + protected void delFromRoot(final String key) { + root.remove(key); + } + protected void addToRoot(final Map propertiesSet) { root.putAll(propertiesSet); } protected void cleanData() { - root.clear(); + clearRoot(); addToRoot("checkBasicTypes", BASIC_DATA_TYPES); classTemplateList.clear(); } + protected abstract void clearRoot(); + public final void addSchemaObject(final String modelPackage, final String keyClassName, final SchemaObject schemaObject, diff --git a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/tools/ModelBuilder.java b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/tools/ModelBuilder.java index 62d4c4c8..a3135c66 100644 --- a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/tools/ModelBuilder.java +++ b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/tools/ModelBuilder.java @@ -260,7 +260,7 @@ private static List processObjectProperty(final String buildi .baseName(fieldName) .required(isRequired || ApiTool.hasConst(fieldBody)) .dataType(new SchemaFieldObjectType(MapperUtil.getSimpleType(fieldBody, specFile))) - .constValue(getConst(fieldBody)) + .constValue(ApiTool.getConst(fieldBody)) .build(); addPropertiesToFieldObject(field, fieldBody); setFieldType(field, fieldBody, schema, specFile, fieldName); 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 da6ac9bd..a40b124e 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 @@ -43,6 +43,18 @@ public final void clearData() { cleanData(); } + @Override + protected void clearRoot() { + delFromRoot("className"); + delFromRoot("pathObjects"); + delFromRoot("packageApi"); + delFromRoot("packageModel"); + delFromRoot("exceptionPackage"); + delFromRoot("authObject"); + delFromRoot("clientPackage"); + delFromRoot("javaEEPackage"); + } + public final void fillTemplates() { generateTemplates(); } diff --git a/multiapi-engine/src/main/resources/templates/model/templateSchemaWithLombok.ftlh b/multiapi-engine/src/main/resources/templates/model/templateSchemaWithLombok.ftlh index 3f88fddf..eb404252 100644 --- a/multiapi-engine/src/main/resources/templates/model/templateSchemaWithLombok.ftlh +++ b/multiapi-engine/src/main/resources/templates/model/templateSchemaWithLombok.ftlh @@ -4,25 +4,41 @@ <#function calculateSafeName propertyName ender const=""> <#if words?seq_contains(propertyName?uncap_first) || propertyName?matches("[0-9].*")> <#if const?has_content> - <#return "_"+propertyName?uncap_first + " = " + const + ender/> + <#return getConstValue ("_"+propertyName?uncap_first, ender, const) /> <#else> - <#return "_"+propertyName?uncap_first + ender/> + <#return getConstValue ("_"+propertyName?uncap_first, ender) /> <#else > <#if const?has_content> - <#return propertyName?uncap_first + " = " + const + ender/> + <#return getConstValue( propertyName?uncap_first, ender, const) /> <#else> - <#return propertyName?uncap_first + ender/> + <#return getConstValue( propertyName?uncap_first, ender) /> <#function createSimpleType field> <#if (field.constValue?has_content)> - ${calculateSafeName (field.baseName, ";", field.const)} + ${calculateSafeName (field.baseName, ";", field.constValue)} <#else > ${calculateSafeName (field.baseName, ";", "")} +<#function getConstValue fieldName ender value=""> + <#if value?has_content> + <#return fieldName +" = " + renderValue (value) + ender/> + <#else > + <#return fieldName + ender/> + + +<#function renderValue value=""> + <#if value?is_boolean> + <#return value == true> + <#elseif value?is_number> + <#return value> + <#elseif value?is_string> + <#return '\"${value}\"'> + + <#function singularizeName propertyName> <#if propertyName?matches(".*ies")> <#return propertyName?remove_ending("ies")+"y"/> 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 c83edec7..1f33d5f3 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,6 +6,12 @@ package com.sngular.api.generator.plugin.asyncapi; +import com.sngular.api.generator.plugin.asyncapi.parameter.OperationParameterObject; +import com.sngular.api.generator.plugin.asyncapi.parameter.SpecFile; +import com.sngular.api.generator.test.utils.TestUtils; +import org.apache.commons.collections4.CollectionUtils; +import org.assertj.core.api.Assertions; + import java.io.File; import java.io.IOException; import java.nio.file.Path; @@ -13,396 +19,390 @@ import java.util.List; import java.util.function.Function; -import com.sngular.api.generator.plugin.asyncapi.parameter.OperationParameterObject; -import com.sngular.api.generator.plugin.asyncapi.parameter.SpecFile; -import com.sngular.api.generator.test.utils.TestUtils; -import org.apache.commons.collections4.CollectionUtils; -import org.assertj.core.api.Assertions; - public class AsyncApiGeneratorFixtures { - final static List TEST_FILE_GENERATION = List.of( - SpecFile - .builder() - .filePath("src/test/resources/asyncapigenerator/testFileGeneration/event-api.yml") - .consumer(OperationParameterObject.builder() - .ids("publishOperationFileGeneration") - .classNamePostfix("TestClassName") - .modelNameSuffix("DTO") - .apiPackage("com.sngular.scsplugin.filegeneration.model.event.consumer") - .modelPackage("com.sngular.scsplugin.filegeneration.model.event") - .build()) - .supplier(OperationParameterObject.builder() - .ids("subscribeOperationFileGeneration") - .modelNameSuffix("Mapper") - .apiPackage("com.sngular.scsplugin.filegeneration.model.event.producer") - .modelPackage("com.sngular.scsplugin.filegeneration.model.event") - .build()) - .build() + static final List TEST_FILE_GENERATION = List.of( + SpecFile + .builder() + .filePath("src/test/resources/asyncapigenerator/testFileGeneration/event-api.yml") + .consumer(OperationParameterObject.builder() + .ids("publishOperationFileGeneration") + .classNamePostfix("TestClassName") + .modelNameSuffix("DTO") + .apiPackage("com.sngular.scsplugin.filegeneration.model.event.consumer") + .modelPackage("com.sngular.scsplugin.filegeneration.model.event") + .build()) + .supplier(OperationParameterObject.builder() + .ids("subscribeOperationFileGeneration") + .modelNameSuffix("Mapper") + .apiPackage("com.sngular.scsplugin.filegeneration.model.event.producer") + .modelPackage("com.sngular.scsplugin.filegeneration.model.event") + .build()) + .build() ); - final static List TEST_FILE_GENERATION_NO_CONFIG = List.of( - SpecFile - .builder() - .filePath("src/test/resources/asyncapigenerator/testFileGenerationNoConfiguration/event-api.yml") - .build() + static final List TEST_FILE_GENERATION_NO_CONFIG = List.of( + SpecFile + .builder() + .filePath("src/test/resources/asyncapigenerator/testFileGenerationNoConfiguration/event-api.yml") + .build() ); - final static List TEST_ISSUE_GENERATION = List.of( - SpecFile - .builder() - .filePath("src/test/resources/asyncapigenerator/testIssueGeneration/event-api.yml") - .consumer(OperationParameterObject.builder() - .ids("response") - .modelNameSuffix("DTO") - .apiPackage("com.sngular.scsplugin.issuegeneration.model.event.consumer") - .modelPackage("com.sngular.scsplugin.issuegeneration.model.event") - .build()) - .supplier(OperationParameterObject.builder() - .ids("clients") - .modelNameSuffix("DTO") - .apiPackage("com.sngular.scsplugin.issuegeneration.model.event.producer") - .modelPackage("com.sngular.scsplugin.issuegeneration.model.event") - .build()) - .build() + static final List TEST_ISSUE_GENERATION = List.of( + SpecFile + .builder() + .filePath("src/test/resources/asyncapigenerator/testIssueGeneration/event-api.yml") + .consumer(OperationParameterObject.builder() + .ids("response") + .modelNameSuffix("DTO") + .apiPackage("com.sngular.scsplugin.issuegeneration.model.event.consumer") + .modelPackage("com.sngular.scsplugin.issuegeneration.model.event") + .build()) + .supplier(OperationParameterObject.builder() + .ids("clients") + .modelNameSuffix("DTO") + .apiPackage("com.sngular.scsplugin.issuegeneration.model.event.producer") + .modelPackage("com.sngular.scsplugin.issuegeneration.model.event") + .build()) + .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() + static final 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_RESERVED_WORDS_GENERATION = List.of( - SpecFile - .builder() - .filePath("src/test/resources/asyncapigenerator/testReservedWordsGeneration/event-api.yml") - .consumer(OperationParameterObject.builder() - .ids("subscribeOperationFileGeneration") - .modelNameSuffix("DTO") - .apiPackage("com.sngular.scsplugin.reservedwordsgeneration.model.event.consumer") - .modelPackage("com.sngular.scsplugin.reservedwordsgeneration.model.event") - .build()) - .supplier(OperationParameterObject.builder() - .ids("publishOperationFileGeneration") - .modelNameSuffix("DTO") - .apiPackage("com.sngular.scsplugin.reservedwordsgeneration.model.event.producer") - .modelPackage("com.sngular.scsplugin.reservedwordsgeneration.model.event") - .build()) - .build() + static final List TEST_RESERVED_WORDS_GENERATION = List.of( + SpecFile + .builder() + .filePath("src/test/resources/asyncapigenerator/testReservedWordsGeneration/event-api.yml") + .consumer(OperationParameterObject.builder() + .ids("subscribeOperationFileGeneration") + .modelNameSuffix("DTO") + .apiPackage("com.sngular.scsplugin.reservedwordsgeneration.model.event.consumer") + .modelPackage("com.sngular.scsplugin.reservedwordsgeneration.model.event") + .build()) + .supplier(OperationParameterObject.builder() + .ids("publishOperationFileGeneration") + .modelNameSuffix("DTO") + .apiPackage("com.sngular.scsplugin.reservedwordsgeneration.model.event.producer") + .modelPackage("com.sngular.scsplugin.reservedwordsgeneration.model.event") + .build()) + .build() ); - final static List TEST_RARE_CHARS_GENERATION = List.of( - SpecFile - .builder() - .filePath("src/test/resources/asyncapigenerator/testRareCharsGeneration/event-api.yml") - .consumer(OperationParameterObject.builder() - .ids("subscribeOperationFileGeneration") - .modelNameSuffix("DTO") - .apiPackage("com.sngular.scsplugin.rarecharsgeneration.model.event.consumer") - .modelPackage("com.sngular.scsplugin.rarecharsgeneration.model.event") - .build()) - .supplier(OperationParameterObject.builder() - .ids("publishOperationFileGeneration") - .modelNameSuffix("DTO") - .apiPackage("com.sngular.scsplugin.rarecharsgeneration.model.event.producer") - .modelPackage("com.sngular.scsplugin.rarecharsgeneration.model.event") - .build()) - .build() + static final List TEST_RARE_CHARS_GENERATION = List.of( + SpecFile + .builder() + .filePath("src/test/resources/asyncapigenerator/testRareCharsGeneration/event-api.yml") + .consumer(OperationParameterObject.builder() + .ids("subscribeOperationFileGeneration") + .modelNameSuffix("DTO") + .apiPackage("com.sngular.scsplugin.rarecharsgeneration.model.event.consumer") + .modelPackage("com.sngular.scsplugin.rarecharsgeneration.model.event") + .build()) + .supplier(OperationParameterObject.builder() + .ids("publishOperationFileGeneration") + .modelNameSuffix("DTO") + .apiPackage("com.sngular.scsplugin.rarecharsgeneration.model.event.producer") + .modelPackage("com.sngular.scsplugin.rarecharsgeneration.model.event") + .build()) + .build() ); - final static List TEST_CUSTOM_VALIDATORS = List.of( - SpecFile - .builder() - .filePath("src/test/resources/asyncapigenerator/testCustomValidators/event-api.yml") - .consumer(OperationParameterObject.builder() - .ids("customValidatorResponse") - .modelNameSuffix("DTO") - .apiPackage("com.sngular.scsplugin.customvalidator.model.event.consumer") - .modelPackage("com.sngular.scsplugin.customvalidator.model.event") - .build()) - .supplier(OperationParameterObject.builder() - .ids("customValidatorClients") - .modelNameSuffix("DTO") - .apiPackage("com.sngular.scsplugin.customvalidator.model.event.producer") - .modelPackage("com.sngular.scsplugin.customvalidator.model.event") - .build()) - .build() + static final List TEST_CUSTOM_VALIDATORS = List.of( + SpecFile + .builder() + .filePath("src/test/resources/asyncapigenerator/testCustomValidators/event-api.yml") + .consumer(OperationParameterObject.builder() + .ids("customValidatorResponse") + .modelNameSuffix("DTO") + .apiPackage("com.sngular.scsplugin.customvalidator.model.event.consumer") + .modelPackage("com.sngular.scsplugin.customvalidator.model.event") + .build()) + .supplier(OperationParameterObject.builder() + .ids("customValidatorClients") + .modelNameSuffix("DTO") + .apiPackage("com.sngular.scsplugin.customvalidator.model.event.producer") + .modelPackage("com.sngular.scsplugin.customvalidator.model.event") + .build()) + .build() ); - final static List TEST_FILE_GENERATION_ISSUE = List.of( - SpecFile - .builder() - .filePath("src/test/resources/asyncapigenerator/testFileGenerationIssue/event-api.yml") - .consumer(OperationParameterObject.builder() - .ids("onCustomerEvent") - .classNamePostfix("TestClassName") - .modelNameSuffix("DTO") - .apiPackage("com.sngular.scsplugin.filegenerationissue.model.event.consumer") - .modelPackage("com.sngular.scsplugin.filegenerationissue.model.event") - .build()) - .supplier(OperationParameterObject.builder() - .ids("onCustomerOrderEvent") - .modelNameSuffix("DTO") - .apiPackage("com.sngular.scsplugin.filegenerationissue.model.event.producer") - .modelPackage("com.sngular.scsplugin.filegenerationissue.model.event") - .build()) - .build() + static final List TEST_FILE_GENERATION_ISSUE = List.of( + SpecFile + .builder() + .filePath("src/test/resources/asyncapigenerator/testFileGenerationIssue/event-api.yml") + .consumer(OperationParameterObject.builder() + .ids("onCustomerEvent") + .classNamePostfix("TestClassName") + .modelNameSuffix("DTO") + .apiPackage("com.sngular.scsplugin.filegenerationissue.model.event.consumer") + .modelPackage("com.sngular.scsplugin.filegenerationissue.model.event") + .build()) + .supplier(OperationParameterObject.builder() + .ids("onCustomerOrderEvent") + .modelNameSuffix("DTO") + .apiPackage("com.sngular.scsplugin.filegenerationissue.model.event.producer") + .modelPackage("com.sngular.scsplugin.filegenerationissue.model.event") + .build()) + .build() ); - final static List TEST_FILE_GENERATION_EXTERNAL_AVRO = List.of( - SpecFile - .builder() - .filePath("src/test/resources/asyncapigenerator/testFileGenerationExternalAvro/event-api.yml") - .consumer(OperationParameterObject.builder() - .ids("subscribeOperationExternalAvro,subscribeReceiptExternalAvro") - .apiPackage("com.sngular.scsplugin.externalavro.model.event.consumer") - .modelPackage("com.sngular.scsplugin.externalavro.model.event") - .build()) - .supplier(OperationParameterObject.builder() - .ids("publishOperationExternalAvro") - .apiPackage("com.sngular.scsplugin.externalavro.model.event.producer") - .modelPackage("com.sngular.scsplugin.externalavro.model.event") - .build()) - .build() + static final List TEST_FILE_GENERATION_EXTERNAL_AVRO = List.of( + SpecFile + .builder() + .filePath("src/test/resources/asyncapigenerator/testFileGenerationExternalAvro/event-api.yml") + .consumer(OperationParameterObject.builder() + .ids("subscribeOperationExternalAvro,subscribeReceiptExternalAvro") + .apiPackage("com.sngular.scsplugin.externalavro.model.event.consumer") + .modelPackage("com.sngular.scsplugin.externalavro.model.event") + .build()) + .supplier(OperationParameterObject.builder() + .ids("publishOperationExternalAvro") + .apiPackage("com.sngular.scsplugin.externalavro.model.event.producer") + .modelPackage("com.sngular.scsplugin.externalavro.model.event") + .build()) + .build() ); - final static List TEST_ISSUE_INVALID_AVRO = List.of( - SpecFile - .builder() - .filePath("src/test/resources/asyncapigenerator/testIssueInvalidAvro/event-api.yml") - .consumer(OperationParameterObject.builder() - .ids("subscribeOperationExternalAvro") - .apiPackage("com.sngular.scsplugin.issueAvro.model.event.consumer") - .modelPackage("com.sngular.scsplugin.issueAvro.model.event") - .build()) - .supplier(OperationParameterObject.builder() - .ids("publishOperationExternalAvro") - .apiPackage("com.sngular.scsplugin.issueAvro.model.event.producer") - .modelPackage("com.sngular.scsplugin.issueAvro.model.event") - .build()) - .build() + static final List TEST_ISSUE_INVALID_AVRO = List.of( + SpecFile + .builder() + .filePath("src/test/resources/asyncapigenerator/testIssueInvalidAvro/event-api.yml") + .consumer(OperationParameterObject.builder() + .ids("subscribeOperationExternalAvro") + .apiPackage("com.sngular.scsplugin.issueAvro.model.event.consumer") + .modelPackage("com.sngular.scsplugin.issueAvro.model.event") + .build()) + .supplier(OperationParameterObject.builder() + .ids("publishOperationExternalAvro") + .apiPackage("com.sngular.scsplugin.issueAvro.model.event.producer") + .modelPackage("com.sngular.scsplugin.issueAvro.model.event") + .build()) + .build() ); - final static List TEST_FILE_GENERATION_STREAM_BRIDGE = List.of( - SpecFile - .builder() - .filePath("src/test/resources/asyncapigenerator/testFileGenerationStreamBridge/event-api.yml") - .consumer(OperationParameterObject.builder() - .ids("subscribeOperationStreamBridge") - .classNamePostfix("TestClassName") - .modelNameSuffix("DTO") - .apiPackage("com.sngular.scsplugin.streambridge.model.event.consumer") - .modelPackage("com.sngular.scsplugin.streambridge.model.event") - .build()) - .streamBridge(OperationParameterObject.builder() - .ids("publishOperationStreamBridge") - .apiPackage("com.sngular.scsplugin.streambridge.model.event.producer") - .modelPackage("com.sngular.scsplugin.streambridge.model.event") - .build()) - .build() + static final List TEST_FILE_GENERATION_STREAM_BRIDGE = List.of( + SpecFile + .builder() + .filePath("src/test/resources/asyncapigenerator/testFileGenerationStreamBridge/event-api.yml") + .consumer(OperationParameterObject.builder() + .ids("subscribeOperationStreamBridge") + .classNamePostfix("TestClassName") + .modelNameSuffix("DTO") + .apiPackage("com.sngular.scsplugin.streambridge.model.event.consumer") + .modelPackage("com.sngular.scsplugin.streambridge.model.event") + .build()) + .streamBridge(OperationParameterObject.builder() + .ids("publishOperationStreamBridge") + .apiPackage("com.sngular.scsplugin.streambridge.model.event.producer") + .modelPackage("com.sngular.scsplugin.streambridge.model.event") + .build()) + .build() ); - final static List TEST_FILE_GENERATION_WITHOUT_IDS = List.of( - SpecFile - .builder() - .filePath("src/test/resources/asyncapigenerator/testFileGenerationWithoutOperationIds/event-api.yml") - .consumer(OperationParameterObject.builder() - .classNamePostfix("TestClassName") - .modelNameSuffix("DTO") - .apiPackage("com.sngular.scsplugin.withoutids.model.event.consumer") - .modelPackage("com.sngular.scsplugin.withoutids.model.event") - .build()) - .streamBridge(OperationParameterObject.builder() - .apiPackage("com.sngular.scsplugin.withoutids.model.event.producer") - .modelPackage("com.sngular.scsplugin.withoutids.model.event") - .modelNameSuffix("DTO") - .build()) - .build() + static final List TEST_FILE_GENERATION_WITHOUT_IDS = List.of( + SpecFile + .builder() + .filePath("src/test/resources/asyncapigenerator/testFileGenerationWithoutOperationIds/event-api.yml") + .consumer(OperationParameterObject.builder() + .classNamePostfix("TestClassName") + .modelNameSuffix("DTO") + .apiPackage("com.sngular.scsplugin.withoutids.model.event.consumer") + .modelPackage("com.sngular.scsplugin.withoutids.model.event") + .build()) + .streamBridge(OperationParameterObject.builder() + .apiPackage("com.sngular.scsplugin.withoutids.model.event.producer") + .modelPackage("com.sngular.scsplugin.withoutids.model.event") + .modelNameSuffix("DTO") + .build()) + .build() ); - final static List TEST_FILE_GENERATION_WITH_ARRAY_STRING = List.of( - SpecFile - .builder() - .filePath("src/test/resources/asyncapigenerator/testFileGenerationArrayString/event-api.yml") - .supplier(OperationParameterObject.builder() - .modelNameSuffix("DTO") - .apiPackage("com.sngular.scsplugin.arraywithstring.model.event.producer") - .modelPackage("com.sngular.scsplugin.arraywithstring.model.event") - .useLombokModelAnnotation(true) - .build()) - .build()); - - final static List TEST_ISSUE_GENERATE_SUPPLIER = List.of( - SpecFile - .builder() - .filePath("src/test/resources/asyncapigenerator/testIssueGenerateSupplier/async-api.yml") - .supplier(OperationParameterObject.builder() - .modelNameSuffix("DTO") - .apiPackage("company.mail.messaging") - .modelPackage("company.mail.model") - .useLombokModelAnnotation(true) - .build()) - .build()); - - final static List TEST_ISSUE_INFINITE_LOOP = List.of( - SpecFile - .builder() - .filePath("src/test/resources/asyncapigenerator/testIssueInfiniteLoop/async-api.yml") - .supplier(OperationParameterObject.builder() - .modelNameSuffix("DTO") - .apiPackage("com.sngular.scsplugin.infiniteLoop.messaging") - .modelPackage("com.sngular.scsplugin.infiniteLoop.model") - .useLombokModelAnnotation(true) - .build()) - .build()); - - final static List TEST_MODEL_CLASS_EXCEPTION_GENERATION = List.of( - SpecFile - .builder() - .filePath("src/test/resources/asyncapigenerator/testModelClassExceptionGeneration/event-api.yml") - .consumer(OperationParameterObject.builder() - .ids("subscribeOrder") - .modelNameSuffix("DTO") - .apiPackage("com.sngular.scsplugin.modelclass.model.event.consumer") - .modelPackage("com.sngular.scsplugin.modelclass.model.event") - .build()) - .supplier(OperationParameterObject.builder() - .ids("publishOrder") - .modelNameSuffix("DTO") - .apiPackage("com.sngular.scsplugin.modelclass.model.event.producer") - .modelPackage("com.sngular.scsplugin.modelclass.model.event") - .build()) - .build() + static final List TEST_FILE_GENERATION_WITH_ARRAY_STRING = List.of( + SpecFile + .builder() + .filePath("src/test/resources/asyncapigenerator/testFileGenerationArrayString/event-api.yml") + .supplier(OperationParameterObject.builder() + .modelNameSuffix("DTO") + .apiPackage("com.sngular.scsplugin.arraywithstring.model.event.producer") + .modelPackage("com.sngular.scsplugin.arraywithstring.model.event") + .useLombokModelAnnotation(true) + .build()) + .build()); + + static final List TEST_ISSUE_GENERATE_SUPPLIER = List.of( + SpecFile + .builder() + .filePath("src/test/resources/asyncapigenerator/testIssueGenerateSupplier/async-api.yml") + .supplier(OperationParameterObject.builder() + .modelNameSuffix("DTO") + .apiPackage("company.mail.messaging") + .modelPackage("company.mail.model") + .useLombokModelAnnotation(true) + .build()) + .build()); + + static final List TEST_ISSUE_INFINITE_LOOP = List.of( + SpecFile + .builder() + .filePath("src/test/resources/asyncapigenerator/testIssueInfiniteLoop/async-api.yml") + .supplier(OperationParameterObject.builder() + .modelNameSuffix("DTO") + .apiPackage("com.sngular.scsplugin.infiniteLoop.messaging") + .modelPackage("com.sngular.scsplugin.infiniteLoop.model") + .useLombokModelAnnotation(true) + .build()) + .build()); + + static final List TEST_MODEL_CLASS_EXCEPTION_GENERATION = List.of( + SpecFile + .builder() + .filePath("src/test/resources/asyncapigenerator/testModelClassExceptionGeneration/event-api.yml") + .consumer(OperationParameterObject.builder() + .ids("subscribeOrder") + .modelNameSuffix("DTO") + .apiPackage("com.sngular.scsplugin.modelclass.model.event.consumer") + .modelPackage("com.sngular.scsplugin.modelclass.model.event") + .build()) + .supplier(OperationParameterObject.builder() + .ids("publishOrder") + .modelNameSuffix("DTO") + .apiPackage("com.sngular.scsplugin.modelclass.model.event.producer") + .modelPackage("com.sngular.scsplugin.modelclass.model.event") + .build()) + .build() ); - final static List TEST_GENERATION_WITH_NO_OPERATION_ID = List.of( - SpecFile - .builder() - .filePath("src/test/resources/asyncapigenerator/testGenerationWithNoOperationId/event-api.yml") - .consumer(OperationParameterObject.builder() - .modelNameSuffix("DTO") - .apiPackage("com.sngular.scsplugin.withoutoperationid.model.event.consumer") - .modelPackage("com.sngular.scsplugin.withoutoperationid.model.event") - .build()) - .build() + static final List TEST_GENERATION_WITH_NO_OPERATION_ID = List.of( + SpecFile + .builder() + .filePath("src/test/resources/asyncapigenerator/testGenerationWithNoOperationId/event-api.yml") + .consumer(OperationParameterObject.builder() + .modelNameSuffix("DTO") + .apiPackage("com.sngular.scsplugin.withoutoperationid.model.event.consumer") + .modelPackage("com.sngular.scsplugin.withoutoperationid.model.event") + .build()) + .build() ); - final static List TEST_NO_SCHEMAS = List.of( - SpecFile - .builder() - .filePath("src/test/resources/asyncapigenerator/testNoSchemas/event-api.yml") - .supplier(OperationParameterObject.builder() - .modelNameSuffix("") - .apiPackage("com.sngular.scsplugin.noschemas") - .modelPackage("com.sngular.scsplugin.noschemas.model") - .useLombokModelAnnotation(true) - .build()) - .build()); - - final static List TEST_NESTED_OBJECT = List.of( - SpecFile - .builder() - .filePath("src/test/resources/asyncapigenerator/testNestedObjectIssue/event-api.yml") - .consumer(OperationParameterObject.builder() - .modelNameSuffix("") - .apiPackage("com.sngular.scsplugin.nestedobject.consumer") - .modelPackage("com.sngular.scsplugin.nestedobject.model") - .useLombokModelAnnotation(true) - .build()) - .supplier(OperationParameterObject.builder() - .modelNameSuffix("") - .apiPackage("com.sngular.scsplugin.nestedobject.producer") - .modelPackage("com.sngular.scsplugin.nestedobject.model") - .useLombokModelAnnotation(true) - .build()) - .build()); - - final static List TEST_CONSTANT_GENERATION = List.of( - SpecFile - .builder() - .filePath("src/test/resources/asyncapigenerator/testConstantGeneration/event-api.yml") - .consumer(OperationParameterObject.builder() - .modelNameSuffix("") - .apiPackage("com.sngular.scsplugin.constantgeneration.consumer") - .modelPackage("com.sngular.scsplugin.constantgeneration.model") - .useLombokModelAnnotation(true) - .build()) - .supplier(OperationParameterObject.builder() - .modelNameSuffix("") - .apiPackage("com.sngular.scsplugin.constantgeneration.producer") - .modelPackage("com.sngular.scsplugin.constantgeneration.model") - .useLombokModelAnnotation(true) - .build()) - .build()); - - final static List PROPERTIES_NOT_GENERATED_ISSUE = List.of( - SpecFile - .builder() - .filePath("src/test/resources/asyncapigenerator/testPropertiesNotGeneratedIssue/event-api.yml") - .consumer(OperationParameterObject.builder() - .modelNameSuffix("") - .operationIds(List.of("emitUserSignUpEvent")) - .apiPackage("com.sngular.scsplugin.notgeneratedproperties.consumer") - .modelPackage("com.sngular.scsplugin.notgeneratedproperties.model") - .useLombokModelAnnotation(true) - .build()) - .build()); - - final static List TEST_FILE_GENERATION_WITH_KAFKA_BINDINGS = List.of( - SpecFile - .builder() - .filePath("src/test/resources/asyncapigenerator/testFileGenerationWithKafkaBindings/event-api.yml") - .consumer(OperationParameterObject.builder() - .ids("publishOperationFileGenerationWithKafkaBindings") - .classNamePostfix("TestClassName") - .modelNameSuffix("DTO") - .apiPackage("com.sngular.scsplugin.filegenerationwithkafkabindings.model.event.consumer") - .modelPackage("com.sngular.scsplugin.filegenerationwithkafkabindings.model.event") - .build()) - .supplier(OperationParameterObject.builder() - .ids("subscribeOperationFileGenerationWithKafkaBindings") - .modelNameSuffix("Mapper") - .apiPackage("com.sngular.scsplugin.filegenerationwithkafkabindings.model.event.producer") - .modelPackage("com.sngular.scsplugin.filegenerationwithkafkabindings.model.event") - .build()) - .build() + static final List TEST_NO_SCHEMAS = List.of( + SpecFile + .builder() + .filePath("src/test/resources/asyncapigenerator/testNoSchemas/event-api.yml") + .supplier(OperationParameterObject.builder() + .modelNameSuffix("") + .apiPackage("com.sngular.scsplugin.noschemas") + .modelPackage("com.sngular.scsplugin.noschemas.model") + .useLombokModelAnnotation(true) + .build()) + .build()); + + static final List TEST_NESTED_OBJECT = List.of( + SpecFile + .builder() + .filePath("src/test/resources/asyncapigenerator/testNestedObjectIssue/event-api.yml") + .consumer(OperationParameterObject.builder() + .modelNameSuffix("") + .apiPackage("com.sngular.scsplugin.nestedobject.consumer") + .modelPackage("com.sngular.scsplugin.nestedobject.model") + .useLombokModelAnnotation(true) + .build()) + .supplier(OperationParameterObject.builder() + .modelNameSuffix("") + .apiPackage("com.sngular.scsplugin.nestedobject.producer") + .modelPackage("com.sngular.scsplugin.nestedobject.model") + .useLombokModelAnnotation(true) + .build()) + .build()); + + static final List TEST_CONSTANT_GENERATION = List.of( + SpecFile + .builder() + .filePath("src/test/resources/asyncapigenerator/testConstantGeneration/event-api.yml") + .consumer(OperationParameterObject.builder() + .modelNameSuffix("") + .apiPackage("com.sngular.scsplugin.constantgeneration.consumer") + .modelPackage("com.sngular.scsplugin.constantgeneration.model") + .useLombokModelAnnotation(true) + .build()) + .supplier(OperationParameterObject.builder() + .modelNameSuffix("") + .apiPackage("com.sngular.scsplugin.constantgeneration.producer") + .modelPackage("com.sngular.scsplugin.constantgeneration.model") + .useLombokModelAnnotation(true) + .build()) + .build()); + + static final List PROPERTIES_NOT_GENERATED_ISSUE = List.of( + SpecFile + .builder() + .filePath("src/test/resources/asyncapigenerator/testPropertiesNotGeneratedIssue/event-api.yml") + .consumer(OperationParameterObject.builder() + .modelNameSuffix("") + .operationIds(List.of("emitUserSignUpEvent")) + .apiPackage("com.sngular.scsplugin.notgeneratedproperties.consumer") + .modelPackage("com.sngular.scsplugin.notgeneratedproperties.model") + .useLombokModelAnnotation(true) + .build()) + .build()); + + static final List TEST_FILE_GENERATION_WITH_KAFKA_BINDINGS = List.of( + SpecFile + .builder() + .filePath("src/test/resources/asyncapigenerator/testFileGenerationWithKafkaBindings/event-api.yml") + .consumer(OperationParameterObject.builder() + .ids("publishOperationFileGenerationWithKafkaBindings") + .classNamePostfix("TestClassName") + .modelNameSuffix("DTO") + .apiPackage("com.sngular.scsplugin.filegenerationwithkafkabindings.model.event.consumer") + .modelPackage("com.sngular.scsplugin.filegenerationwithkafkabindings.model.event") + .build()) + .supplier(OperationParameterObject.builder() + .ids("subscribeOperationFileGenerationWithKafkaBindings") + .modelNameSuffix("Mapper") + .apiPackage("com.sngular.scsplugin.filegenerationwithkafkabindings.model.event.producer") + .modelPackage("com.sngular.scsplugin.filegenerationwithkafkabindings.model.event") + .build()) + .build() ); static final List TEST_SUB_OBJECT_SAME_NAME = - List.of( - SpecFile.builder() - .filePath("src/test/resources/asyncapigenerator/testSubObjectSameName/event-api.yml") - .consumer( - OperationParameterObject.builder() - .ids("input") - .apiPackage("input.controller") - .modelPackage("input.model") - .build()) - .supplier( - OperationParameterObject.builder() - .ids("output") - .apiPackage("output.provider") - .modelPackage("output.model") - .build()) - .build()); - - final static String TARGET = "target"; - - final static String GENERATED = "generated/"; + List.of( + SpecFile.builder() + .filePath("src/test/resources/asyncapigenerator/testSubObjectSameName/event-api.yml") + .consumer( + OperationParameterObject.builder() + .ids("input") + .apiPackage("input.controller") + .modelPackage("input.model") + .build()) + .supplier( + OperationParameterObject.builder() + .ids("output") + .apiPackage("output.provider") + .modelPackage("output.model") + .build()) + .build()); + + static final String TARGET = "target"; + + static final String GENERATED = "generated/"; static Function validateTestFileGeneration() { @@ -423,41 +423,41 @@ static Function validateTestFileGeneration() { final String DEFAULT_EXCEPTION_API = DEFAULT_COMMON_FOLDER + "/exception"; final List expectedConsumerFiles = List.of( - ASSETS_PATH + "IPublishOperationFileGeneration.java", - ASSETS_PATH + "TestClassName.java"); + ASSETS_PATH + "IPublishOperationFileGeneration.java", + ASSETS_PATH + "TestClassName.java"); final List expectedProducerFiles = List.of( - ASSETS_PATH + "ISubscribeOperationFileGeneration.java", - ASSETS_PATH + "Producer.java"); + ASSETS_PATH + "ISubscribeOperationFileGeneration.java", + ASSETS_PATH + "Producer.java"); final List expectedModelSchemaFiles = List.of( - ASSETS_PATH + "CreateOrderMapper.java", - ASSETS_PATH + "OrderDTO.java", - ASSETS_PATH + "OrderLineDTO.java", - ASSETS_PATH + "OrderLineMapper.java", - ASSETS_PATH + "OrderMapper.java", - ASSETS_PATH + "OrderProductDTO.java", - ASSETS_PATH + "OrderProductMapper.java", - ASSETS_PATH + "WaiterMapper.java" + ASSETS_PATH + "CreateOrderMapper.java", + ASSETS_PATH + "OrderDTO.java", + ASSETS_PATH + "OrderLineDTO.java", + ASSETS_PATH + "OrderLineMapper.java", + ASSETS_PATH + "OrderMapper.java", + ASSETS_PATH + "OrderProductDTO.java", + ASSETS_PATH + "OrderProductMapper.java", + ASSETS_PATH + "WaiterMapper.java" ); final List expectedValidatorFiles = List.of( - CUSTOM_VALIDATOR_PATH + "NotNull.java", - CUSTOM_VALIDATOR_PATH + "NotNullValidator.java" + CUSTOM_VALIDATOR_PATH + "NotNull.java", + CUSTOM_VALIDATOR_PATH + "NotNullValidator.java" ); final List expectedExceptionFiles = List.of( - ASSETS_PATH + "ModelClassException.java"); + ASSETS_PATH + "ModelClassException.java"); - return (path) -> commonTest(path, expectedConsumerFiles, expectedProducerFiles, DEFAULT_CONSUMER_FOLDER, DEFAULT_PRODUCER_FOLDER, - expectedExceptionFiles, DEFAULT_EXCEPTION_API) && - modelTest(path, expectedModelSchemaFiles, DEFAULT_COMMON_FOLDER) && - customValidatorTest(path, expectedValidatorFiles, DEFAULT_CUSTOM_VALIDATOR_FOLDER); + return path -> commonTest(path, expectedConsumerFiles, expectedProducerFiles, DEFAULT_CONSUMER_FOLDER, DEFAULT_PRODUCER_FOLDER, + expectedExceptionFiles, DEFAULT_EXCEPTION_API) && + modelTest(path, expectedModelSchemaFiles, DEFAULT_COMMON_FOLDER) && + customValidatorTest(path, expectedValidatorFiles, DEFAULT_CUSTOM_VALIDATOR_FOLDER); } private static Boolean commonTest( - final Path resultPath, final List expectedFile, final List expectedModelFiles, final String targetConsumer, - final String targetProducer, final List expectedExceptionFiles, final String targetException) { + final Path resultPath, final List expectedFile, final List expectedModelFiles, final String targetConsumer, + final String targetProducer, final List expectedExceptionFiles, final String targetException) { Boolean result = Boolean.TRUE; try { final Path pathToTarget = Path.of(resultPath.toString(), "target"); @@ -532,21 +532,21 @@ static Function validateTestIssueGeneration() { final String ASSETS_PATH = COMMON_PATH + "assets/"; final List expectedConsumerFiles = List.of( - ASSETS_PATH + "IResponse.java", - ASSETS_PATH + "Subscriber.java"); + ASSETS_PATH + "IResponse.java", + ASSETS_PATH + "Subscriber.java"); final List expectedProducerFiles = List.of( - ASSETS_PATH + "IClients.java", - ASSETS_PATH + "Producer.java"); + ASSETS_PATH + "IClients.java", + ASSETS_PATH + "Producer.java"); final List expectedModelSchemaFiles = List.of( - ASSETS_PATH + "DataDTO.java", - ASSETS_PATH + "StatusMsgDTO.java" + ASSETS_PATH + "DataDTO.java", + ASSETS_PATH + "StatusMsgDTO.java" ); - return (path) -> commonTest(path, expectedConsumerFiles, expectedProducerFiles, DEFAULT_CONSUMER_FOLDER, DEFAULT_PRODUCER_FOLDER, - Collections.emptyList(), null) && - modelTest(path, expectedModelSchemaFiles, DEFAULT_MODEL_SCHEMA_FOLDER); + return path -> commonTest(path, expectedConsumerFiles, expectedProducerFiles, DEFAULT_CONSUMER_FOLDER, DEFAULT_PRODUCER_FOLDER, + Collections.emptyList(), null) && + modelTest(path, expectedModelSchemaFiles, DEFAULT_MODEL_SCHEMA_FOLDER); } static Function validateTestIssueSimpleTypeGeneration() { @@ -561,21 +561,21 @@ static Function validateTestIssueSimpleTypeGeneration() { final String ASSETS_PATH = COMMON_PATH + "assets/"; final List expectedConsumerFiles = List.of( - ASSETS_PATH + "IResponse.java", - ASSETS_PATH + "Subscriber.java"); + ASSETS_PATH + "IResponse.java", + ASSETS_PATH + "Subscriber.java"); final List expectedProducerFiles = List.of( - ASSETS_PATH + "IClients.java", - ASSETS_PATH + "Producer.java"); + ASSETS_PATH + "IClients.java", + ASSETS_PATH + "Producer.java"); final List expectedModelSchemaFiles = List.of( - ASSETS_PATH + "DataDTO.java", - ASSETS_PATH + "StatusMsgDTO.java" + ASSETS_PATH + "DataDTO.java", + ASSETS_PATH + "StatusMsgDTO.java" ); - return (path) -> commonTest(path, expectedConsumerFiles, expectedProducerFiles, DEFAULT_CONSUMER_FOLDER, DEFAULT_PRODUCER_FOLDER, - Collections.emptyList(), null) && - modelTest(path, expectedModelSchemaFiles, DEFAULT_MODEL_SCHEMA_FOLDER); + return path -> commonTest(path, expectedConsumerFiles, expectedProducerFiles, DEFAULT_CONSUMER_FOLDER, DEFAULT_PRODUCER_FOLDER, + Collections.emptyList(), null) && + modelTest(path, expectedModelSchemaFiles, DEFAULT_MODEL_SCHEMA_FOLDER); } static Function validateTestReservedWordsGeneration() { @@ -590,22 +590,22 @@ static Function validateTestReservedWordsGeneration() { final String ASSETS_PATH = COMMON_PATH + "assets/"; final List expectedConsumerFiles = List.of( - ASSETS_PATH + "ISubscribeOperationFileGeneration.java", - ASSETS_PATH + "Subscriber.java"); + ASSETS_PATH + "ISubscribeOperationFileGeneration.java", + ASSETS_PATH + "Subscriber.java"); final List expectedProducerFiles = List.of( - ASSETS_PATH + "IPublishOperationFileGeneration.java", - ASSETS_PATH + "Producer.java"); + ASSETS_PATH + "IPublishOperationFileGeneration.java", + ASSETS_PATH + "Producer.java"); final List expectedModelSchemaFiles = List.of( - ASSETS_PATH + "CreateOrderDTO.java", - ASSETS_PATH + "OrderDTO.java", - ASSETS_PATH + "OrderLineDTO.java", - ASSETS_PATH + "WaiterDTO.java" + ASSETS_PATH + "CreateOrderDTO.java", + ASSETS_PATH + "OrderDTO.java", + ASSETS_PATH + "OrderLineDTO.java", + ASSETS_PATH + "WaiterDTO.java" ); - return (path) -> commonTest(path, expectedConsumerFiles, expectedProducerFiles, DEFAULT_CONSUMER_FOLDER, DEFAULT_PRODUCER_FOLDER, Collections.emptyList(), null) && - modelTest(path, expectedModelSchemaFiles, DEFAULT_MODEL_SCHEMA_FOLDER); + return path -> commonTest(path, expectedConsumerFiles, expectedProducerFiles, DEFAULT_CONSUMER_FOLDER, DEFAULT_PRODUCER_FOLDER, Collections.emptyList(), null) && + modelTest(path, expectedModelSchemaFiles, DEFAULT_MODEL_SCHEMA_FOLDER); } static Function validateTestRareCharsGeneration() { @@ -620,21 +620,21 @@ static Function validateTestRareCharsGeneration() { final String ASSETS_PATH = COMMON_PATH + "assets/"; final List expectedConsumerFiles = List.of( - ASSETS_PATH + "ISubscribeOperationFileGeneration.java", - ASSETS_PATH + "Subscriber.java"); + ASSETS_PATH + "ISubscribeOperationFileGeneration.java", + ASSETS_PATH + "Subscriber.java"); final List expectedProducerFiles = List.of( - ASSETS_PATH + "IPublishOperationFileGeneration.java", - ASSETS_PATH + "Producer.java"); + ASSETS_PATH + "IPublishOperationFileGeneration.java", + ASSETS_PATH + "Producer.java"); final List expectedModelSchemaFiles = List.of( - ASSETS_PATH + "CreateOrderDTO.java", - ASSETS_PATH + "OrderDTO.java", - ASSETS_PATH + "WaiterDTO.java" + ASSETS_PATH + "CreateOrderDTO.java", + ASSETS_PATH + "OrderDTO.java", + ASSETS_PATH + "WaiterDTO.java" ); - return (path) -> commonTest(path, expectedConsumerFiles, expectedProducerFiles, DEFAULT_CONSUMER_FOLDER, DEFAULT_PRODUCER_FOLDER, Collections.emptyList(), null) && - modelTest(path, expectedModelSchemaFiles, DEFAULT_MODEL_SCHEMA_FOLDER); + return path -> commonTest(path, expectedConsumerFiles, expectedProducerFiles, DEFAULT_CONSUMER_FOLDER, DEFAULT_PRODUCER_FOLDER, Collections.emptyList(), null) && + modelTest(path, expectedModelSchemaFiles, DEFAULT_MODEL_SCHEMA_FOLDER); } static Function validateCustomValidators(final int springBootVersion) { @@ -655,58 +655,58 @@ static Function validateCustomValidators(final int springBootVers final String DEFAULT_EXCEPTION_API = DEFAULT_MODEL_SCHEMA_FOLDER + "/exception"; final List expectedConsumerFiles = List.of( - ASSETS_PATH + "ICustomValidatorResponse.java", - ASSETS_PATH + "Subscriber.java"); + ASSETS_PATH + "ICustomValidatorResponse.java", + ASSETS_PATH + "Subscriber.java"); final List expectedProducerFiles = List.of( - ASSETS_PATH + "ICustomValidatorClients.java", - ASSETS_PATH + "Producer.java"); + ASSETS_PATH + "ICustomValidatorClients.java", + ASSETS_PATH + "Producer.java"); final List expectedModelSchemaFiles = List.of( - ASSETS_PATH + "DataDTO.java", - ASSETS_PATH + "StatusMsgDTO.java" + ASSETS_PATH + "DataDTO.java", + ASSETS_PATH + "StatusMsgDTO.java" ); final List expectedValidatorFiles = List.of( - CUSTOM_VALIDATOR_PATH + "MaxBigDecimal.java", - CUSTOM_VALIDATOR_PATH + "MaxBigDecimalValidator.java", - CUSTOM_VALIDATOR_PATH + "MaxDouble.java", - CUSTOM_VALIDATOR_PATH + "MaxDoubleValidator.java", - CUSTOM_VALIDATOR_PATH + "MaxFloat.java", - CUSTOM_VALIDATOR_PATH + "MaxFloatValidator.java", - CUSTOM_VALIDATOR_PATH + "MaxInteger.java", - CUSTOM_VALIDATOR_PATH + "MaxIntegerValidator.java", - CUSTOM_VALIDATOR_PATH + "MaxItems.java", - CUSTOM_VALIDATOR_PATH + "MaxItemsValidator.java", - CUSTOM_VALIDATOR_PATH + "MinBigDecimal.java", - CUSTOM_VALIDATOR_PATH + "MinBigDecimalValidator.java", - CUSTOM_VALIDATOR_PATH + "MinDouble.java", - CUSTOM_VALIDATOR_PATH + "MinDoubleValidator.java", - CUSTOM_VALIDATOR_PATH + "MinFloat.java", - CUSTOM_VALIDATOR_PATH + "MinFloatValidator.java", - CUSTOM_VALIDATOR_PATH + "MinInteger.java", - CUSTOM_VALIDATOR_PATH + "MinIntegerValidator.java", - CUSTOM_VALIDATOR_PATH + "MinItems.java", - CUSTOM_VALIDATOR_PATH + "MinItemsValidator.java", - CUSTOM_VALIDATOR_PATH + "MultipleOf.java", - CUSTOM_VALIDATOR_PATH + "MultipleOfValidator.java", - CUSTOM_VALIDATOR_PATH + "NotNull.java", - CUSTOM_VALIDATOR_PATH + "NotNullValidator.java", - CUSTOM_VALIDATOR_PATH + "Pattern.java", - CUSTOM_VALIDATOR_PATH + "PatternValidator.java", - CUSTOM_VALIDATOR_PATH + "Size.java", - CUSTOM_VALIDATOR_PATH + "SizeValidator.java", - CUSTOM_VALIDATOR_PATH + "UniqueItems.java", - CUSTOM_VALIDATOR_PATH + "UniqueItemsValidator.java" + CUSTOM_VALIDATOR_PATH + "MaxBigDecimal.java", + CUSTOM_VALIDATOR_PATH + "MaxBigDecimalValidator.java", + CUSTOM_VALIDATOR_PATH + "MaxDouble.java", + CUSTOM_VALIDATOR_PATH + "MaxDoubleValidator.java", + CUSTOM_VALIDATOR_PATH + "MaxFloat.java", + CUSTOM_VALIDATOR_PATH + "MaxFloatValidator.java", + CUSTOM_VALIDATOR_PATH + "MaxInteger.java", + CUSTOM_VALIDATOR_PATH + "MaxIntegerValidator.java", + CUSTOM_VALIDATOR_PATH + "MaxItems.java", + CUSTOM_VALIDATOR_PATH + "MaxItemsValidator.java", + CUSTOM_VALIDATOR_PATH + "MinBigDecimal.java", + CUSTOM_VALIDATOR_PATH + "MinBigDecimalValidator.java", + CUSTOM_VALIDATOR_PATH + "MinDouble.java", + CUSTOM_VALIDATOR_PATH + "MinDoubleValidator.java", + CUSTOM_VALIDATOR_PATH + "MinFloat.java", + CUSTOM_VALIDATOR_PATH + "MinFloatValidator.java", + CUSTOM_VALIDATOR_PATH + "MinInteger.java", + CUSTOM_VALIDATOR_PATH + "MinIntegerValidator.java", + CUSTOM_VALIDATOR_PATH + "MinItems.java", + CUSTOM_VALIDATOR_PATH + "MinItemsValidator.java", + CUSTOM_VALIDATOR_PATH + "MultipleOf.java", + CUSTOM_VALIDATOR_PATH + "MultipleOfValidator.java", + CUSTOM_VALIDATOR_PATH + "NotNull.java", + CUSTOM_VALIDATOR_PATH + "NotNullValidator.java", + CUSTOM_VALIDATOR_PATH + "Pattern.java", + CUSTOM_VALIDATOR_PATH + "PatternValidator.java", + CUSTOM_VALIDATOR_PATH + "Size.java", + CUSTOM_VALIDATOR_PATH + "SizeValidator.java", + CUSTOM_VALIDATOR_PATH + "UniqueItems.java", + CUSTOM_VALIDATOR_PATH + "UniqueItemsValidator.java" ); final List expectedExceptionFiles = List.of( - ASSETS_PATH + "ModelClassException.java"); + 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) && - customValidatorTest(path, expectedValidatorFiles, DEFAULT_CUSTOM_VALIDATOR_FOLDER); + return path -> commonTest(path, expectedConsumerFiles, expectedProducerFiles, DEFAULT_CONSUMER_FOLDER, DEFAULT_PRODUCER_FOLDER, + expectedExceptionFiles, DEFAULT_EXCEPTION_API) && + modelTest(path, expectedModelSchemaFiles, DEFAULT_MODEL_SCHEMA_FOLDER) && + customValidatorTest(path, expectedValidatorFiles, DEFAULT_CUSTOM_VALIDATOR_FOLDER); } private static String calculateJavaEEPackage(final int springBootVersion) { @@ -736,37 +736,37 @@ static Function validateTestFileGenerationIssue() { final String DEFAULT_EXCEPTION_API = DEFAULT_COMMON_FOLDER + "/exception"; final List expectedConsumerFiles = List.of( - ASSETS_PATH + "IOnCustomerEvent.java", - ASSETS_PATH + "TestClassName.java"); + ASSETS_PATH + "IOnCustomerEvent.java", + ASSETS_PATH + "TestClassName.java"); final List expectedProducerFiles = List.of( - ASSETS_PATH + "IOnCustomerOrderEvent.java", - ASSETS_PATH + "Producer.java"); + ASSETS_PATH + "IOnCustomerOrderEvent.java", + ASSETS_PATH + "Producer.java"); final List expectedModelSchemaFiles = List.of( - ASSETS_PATH + "CustomerDTO.java", - ASSETS_PATH + "CustomerEventPayloadDTO.java", - ASSETS_PATH + "CustomerOrderDTO.java", - ASSETS_PATH + "CustomerOrderEventPayloadDTO.java", - ASSETS_PATH + "OrderedItemDTO.java", - ASSETS_PATH + "PaymentDetailsDTO.java", - ASSETS_PATH + "ShippingDetailsDTO.java" + ASSETS_PATH + "CustomerDTO.java", + ASSETS_PATH + "CustomerEventPayloadDTO.java", + ASSETS_PATH + "CustomerOrderDTO.java", + ASSETS_PATH + "CustomerOrderEventPayloadDTO.java", + ASSETS_PATH + "OrderedItemDTO.java", + ASSETS_PATH + "PaymentDetailsDTO.java", + ASSETS_PATH + "ShippingDetailsDTO.java" ); final List expectedValidatorFiles = List.of( - CUSTOM_VALIDATOR_PATH + "NotNull.java", - CUSTOM_VALIDATOR_PATH + "NotNullValidator.java", - CUSTOM_VALIDATOR_PATH + "Size.java", - CUSTOM_VALIDATOR_PATH + "SizeValidator.java" + CUSTOM_VALIDATOR_PATH + "NotNull.java", + CUSTOM_VALIDATOR_PATH + "NotNullValidator.java", + CUSTOM_VALIDATOR_PATH + "Size.java", + CUSTOM_VALIDATOR_PATH + "SizeValidator.java" ); final List expectedExceptionFiles = List.of( - ASSETS_PATH + "ModelClassException.java"); + ASSETS_PATH + "ModelClassException.java"); - return (path) -> commonTest(path, expectedConsumerFiles, expectedProducerFiles, DEFAULT_CONSUMER_FOLDER, DEFAULT_PRODUCER_FOLDER, - expectedExceptionFiles, DEFAULT_EXCEPTION_API) && - modelTest(path, expectedModelSchemaFiles, DEFAULT_COMMON_FOLDER) && - customValidatorTest(path, expectedValidatorFiles, DEFAULT_CUSTOM_VALIDATOR_FOLDER); + return path -> commonTest(path, expectedConsumerFiles, expectedProducerFiles, DEFAULT_CONSUMER_FOLDER, DEFAULT_PRODUCER_FOLDER, + expectedExceptionFiles, DEFAULT_EXCEPTION_API) && + modelTest(path, expectedModelSchemaFiles, DEFAULT_COMMON_FOLDER) && + customValidatorTest(path, expectedValidatorFiles, DEFAULT_CUSTOM_VALIDATOR_FOLDER); } static Function validateTestFileGenerationExternalAvro() { @@ -779,18 +779,18 @@ static Function validateTestFileGenerationExternalAvro() { final String ASSETS_PATH = COMMON_PATH + "assets/"; final List expectedConsumerFiles = List.of( - ASSETS_PATH + "ISubscribeOperationExternalAvro.java", - ASSETS_PATH + "ISubscribeReceiptExternalAvro.java", - ASSETS_PATH + "Subscriber.java" + ASSETS_PATH + "ISubscribeOperationExternalAvro.java", + ASSETS_PATH + "ISubscribeReceiptExternalAvro.java", + ASSETS_PATH + "Subscriber.java" ); final List expectedProducerFiles = List.of( - ASSETS_PATH + "IPublishOperation.java", - ASSETS_PATH + "Producer.java" + ASSETS_PATH + "IPublishOperation.java", + ASSETS_PATH + "Producer.java" ); - return (path) -> commonTest(path, expectedConsumerFiles, expectedProducerFiles, DEFAULT_CONSUMER_FOLDER, DEFAULT_PRODUCER_FOLDER, - Collections.emptyList(), null); + return path -> commonTest(path, expectedConsumerFiles, expectedProducerFiles, DEFAULT_CONSUMER_FOLDER, DEFAULT_PRODUCER_FOLDER, + Collections.emptyList(), null); } static Function validateTestFileGenerationStreamBridge() { @@ -808,19 +808,19 @@ static Function validateTestFileGenerationStreamBridge() { final String DEFAULT_EXCEPTION_API = DEFAULT_COMMON_FOLDER + "/exception"; final List expectedConsumerFiles = List.of( - ASSETS_PATH + "ISubscribeOperationStreamBridge.java", - ASSETS_PATH + "TestClassName.java" + ASSETS_PATH + "ISubscribeOperationStreamBridge.java", + ASSETS_PATH + "TestClassName.java" ); final List expectedProducerFiles = List.of( - ASSETS_PATH + "StreamBridgeProducer.java" + ASSETS_PATH + "StreamBridgeProducer.java" ); final List expectedExceptionFiles = List.of( - ASSETS_PATH + "ModelClassException.java"); + ASSETS_PATH + "ModelClassException.java"); - return (path) -> commonTest(path, expectedConsumerFiles, expectedProducerFiles, DEFAULT_CONSUMER_FOLDER, DEFAULT_PRODUCER_FOLDER, - expectedExceptionFiles, DEFAULT_EXCEPTION_API); + return path -> commonTest(path, expectedConsumerFiles, expectedProducerFiles, DEFAULT_CONSUMER_FOLDER, DEFAULT_PRODUCER_FOLDER, + expectedExceptionFiles, DEFAULT_EXCEPTION_API); } static Function validateTestFileGenerationWithoutIds() { @@ -838,19 +838,19 @@ static Function validateTestFileGenerationWithoutIds() { final String DEFAULT_EXCEPTION_API = DEFAULT_COMMON_FOLDER + "/exception"; final List expectedConsumerFiles = List.of( - ASSETS_PATH + "ISubscribeOperation.java", - ASSETS_PATH + "TestClassName.java" + ASSETS_PATH + "ISubscribeOperation.java", + ASSETS_PATH + "TestClassName.java" ); final List expectedProducerFiles = List.of( - ASSETS_PATH + "StreamBridgeProducer.java" + ASSETS_PATH + "StreamBridgeProducer.java" ); final List expectedExceptionFiles = List.of( - ASSETS_PATH + "ModelClassException.java"); + ASSETS_PATH + "ModelClassException.java"); - return (path) -> commonTest(path, expectedConsumerFiles, expectedProducerFiles, DEFAULT_CONSUMER_FOLDER, DEFAULT_PRODUCER_FOLDER, - expectedExceptionFiles, DEFAULT_EXCEPTION_API); + return path -> commonTest(path, expectedConsumerFiles, expectedProducerFiles, DEFAULT_CONSUMER_FOLDER, DEFAULT_PRODUCER_FOLDER, + expectedExceptionFiles, DEFAULT_EXCEPTION_API); } static Function validateTestFileGenerationArrayString() { @@ -861,7 +861,7 @@ static Function validateTestFileGenerationArrayString() { final String ASSETS_PATH = COMMON_PATH + "assets/"; final List expectedModelSchemaFiles = List.of( - ASSETS_PATH + "ObjectArrayDTO.java" + ASSETS_PATH + "ObjectArrayDTO.java" ); return path -> modelTest(path, expectedModelSchemaFiles, DEFAULT_MODEL_SCHEMA_FOLDER); @@ -871,8 +871,8 @@ 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/MailRequestDTO.java" + "asyncapigenerator/testIssueGenerateSupplier/assets/ConfigurationDTO.java", + "asyncapigenerator/testIssueGenerateSupplier/assets/MailRequestDTO.java" ); return path -> modelTest(path, expectedModelSchemaFiles, DEFAULT_MODEL_SCHEMA_FOLDER); @@ -882,8 +882,8 @@ static Function validateTestIssueInfiniteLoop() { final String DEFAULT_MODEL_SCHEMA_FOLDER = "generated/com/sngular/scsplugin/infiniteLoop/model"; final List expectedModelSchemaFiles = List.of( - "asyncapigenerator/testIssueInfiniteLoop/assets/ConfigDTO.java", - "asyncapigenerator/testIssueInfiniteLoop/assets/MailRequestInfiniteDTO.java" + "asyncapigenerator/testIssueInfiniteLoop/assets/ConfigDTO.java", + "asyncapigenerator/testIssueInfiniteLoop/assets/MailRequestInfiniteDTO.java" ); return path -> modelTest(path, expectedModelSchemaFiles, DEFAULT_MODEL_SCHEMA_FOLDER); @@ -908,33 +908,33 @@ static Function validateTestModelClassExceptionGeneration() { final String DEFAULT_EXCEPTION_API = DEFAULT_COMMON_FOLDER + "/exception"; final List expectedConsumerFiles = List.of( - ASSETS_PATH + "ISubscribeOrder.java", - ASSETS_PATH + "Subscriber.java"); + ASSETS_PATH + "ISubscribeOrder.java", + ASSETS_PATH + "Subscriber.java"); final List expectedProducerFiles = List.of( - ASSETS_PATH + "IPublishOrder.java", - ASSETS_PATH + "Producer.java"); + ASSETS_PATH + "IPublishOrder.java", + ASSETS_PATH + "Producer.java"); final List expectedModelSchemaFiles = List.of( - ASSETS_PATH + "CreateOrderEventDTO.java", - ASSETS_PATH + "OrderDTO.java", - ASSETS_PATH + "OrderLineDTO.java", - ASSETS_PATH + "OrderProductDTO.java", - ASSETS_PATH + "WaiterDTO.java" + ASSETS_PATH + "CreateOrderEventDTO.java", + ASSETS_PATH + "OrderDTO.java", + ASSETS_PATH + "OrderLineDTO.java", + ASSETS_PATH + "OrderProductDTO.java", + ASSETS_PATH + "WaiterDTO.java" ); final List expectedValidatorFiles = List.of( - CUSTOM_VALIDATOR_PATH + "NotNull.java", - CUSTOM_VALIDATOR_PATH + "NotNullValidator.java" + CUSTOM_VALIDATOR_PATH + "NotNull.java", + CUSTOM_VALIDATOR_PATH + "NotNullValidator.java" ); final List expectedExceptionFiles = List.of( - ASSETS_PATH + "ModelClassException.java"); + ASSETS_PATH + "ModelClassException.java"); - return (path) -> commonTest(path, expectedConsumerFiles, expectedProducerFiles, DEFAULT_CONSUMER_FOLDER, DEFAULT_PRODUCER_FOLDER, - expectedExceptionFiles, DEFAULT_EXCEPTION_API) && - modelTest(path, expectedModelSchemaFiles, DEFAULT_COMMON_FOLDER) && - customValidatorTest(path, expectedValidatorFiles, DEFAULT_CUSTOM_VALIDATOR_FOLDER); + return path -> commonTest(path, expectedConsumerFiles, expectedProducerFiles, DEFAULT_CONSUMER_FOLDER, DEFAULT_PRODUCER_FOLDER, + expectedExceptionFiles, DEFAULT_EXCEPTION_API) && + modelTest(path, expectedModelSchemaFiles, DEFAULT_COMMON_FOLDER) && + customValidatorTest(path, expectedValidatorFiles, DEFAULT_CUSTOM_VALIDATOR_FOLDER); } static Function validateNoSchemas() { @@ -943,18 +943,18 @@ static Function validateNoSchemas() { final String MODEL_SCHEMA_FOLDER = "generated/com/sngular/scsplugin/noschemas/model"; final List expectedModelSchemaFiles = List.of( - "asyncapigenerator/testNoSchemas/assets/TestMsg.java", - "asyncapigenerator/testNoSchemas/assets/Thing.java" + "asyncapigenerator/testNoSchemas/assets/TestMsg.java", + "asyncapigenerator/testNoSchemas/assets/Thing.java" ); final List expectedProducerFiles = List.of( - "asyncapigenerator/testNoSchemas/assets/IOnTest.java", - "asyncapigenerator/testNoSchemas/assets/IOnTest2.java", - "asyncapigenerator/testNoSchemas/assets/Producer.java" + "asyncapigenerator/testNoSchemas/assets/IOnTest.java", + "asyncapigenerator/testNoSchemas/assets/IOnTest2.java", + "asyncapigenerator/testNoSchemas/assets/Producer.java" ); return path -> modelTest(path, expectedModelSchemaFiles, MODEL_SCHEMA_FOLDER) && - modelTest(path, expectedProducerFiles, API_FOLDER); + modelTest(path, expectedProducerFiles, API_FOLDER); } static Function validateNestedObject() { @@ -963,14 +963,14 @@ static Function validateNestedObject() { final String MODEL_SCHEMA_FOLDER = "generated/com/sngular/scsplugin/nestedobject/model"; final List expectedModelSchemaFiles = List.of( - "asyncapigenerator/testNestedObjectIssue/assets/payload/SomeOtherObject.java", - "asyncapigenerator/testNestedObjectIssue/assets/payload/UserSignedUpPayload.java" + "asyncapigenerator/testNestedObjectIssue/assets/payload/SomeOtherObject.java", + "asyncapigenerator/testNestedObjectIssue/assets/payload/UserSignedUpPayload.java" ); final List expectedProducerFiles = List.of(); return path -> modelTest(path, expectedModelSchemaFiles, MODEL_SCHEMA_FOLDER) && - modelTest(path, expectedProducerFiles, API_FOLDER); + modelTest(path, expectedProducerFiles, API_FOLDER); } static Function validateConstantGeneration() { @@ -979,14 +979,14 @@ static Function validateConstantGeneration() { final String MODEL_SCHEMA_FOLDER = "generated/com/sngular/scsplugin/constantgeneration/model"; final List expectedModelSchemaFiles = List.of( - "asyncapigenerator/testConstantGeneration/assets/payload/SomeOtherObject.java", - "asyncapigenerator/testConstantGeneration/assets/payload/UserSignedUpPayload.java" + "asyncapigenerator/testConstantGeneration/assets/payload/SomeOtherObject.java", + "asyncapigenerator/testConstantGeneration/assets/payload/UserSignedUpPayload.java" ); final List expectedProducerFiles = List.of(); return path -> modelTest(path, expectedModelSchemaFiles, MODEL_SCHEMA_FOLDER) && - modelTest(path, expectedProducerFiles, API_FOLDER); + modelTest(path, expectedProducerFiles, API_FOLDER); } static Function validateNotGeneratedPropertiesIssue() { @@ -995,14 +995,14 @@ static Function validateNotGeneratedPropertiesIssue() { final String MODEL_SCHEMA_FOLDER = "generated/com/sngular/scsplugin/notgeneratedproperties/model"; final List expectedModelSchemaFiles = List.of( - "asyncapigenerator/testPropertiesNotGeneratedIssue/assets/payload/UserDetails.java", - "asyncapigenerator/testPropertiesNotGeneratedIssue/assets/payload/UserSignedUp.java" + "asyncapigenerator/testPropertiesNotGeneratedIssue/assets/payload/UserDetails.java", + "asyncapigenerator/testPropertiesNotGeneratedIssue/assets/payload/UserSignedUp.java" ); final List expectedProducerFiles = List.of(); return path -> modelTest(path, expectedModelSchemaFiles, MODEL_SCHEMA_FOLDER) && - modelTest(path, expectedProducerFiles, API_FOLDER); + modelTest(path, expectedProducerFiles, API_FOLDER); } static Function validateTestFileGenerationWithKafkaBindings() { @@ -1022,34 +1022,34 @@ static Function validateTestFileGenerationWithKafkaBindings() { final String CUSTOM_VALIDATOR_PATH = COMMON_PATH + "customvalidator/"; final List expectedConsumerFiles = List.of( - ASSETS_PATH + "IPublishOperationFileGenerationWithKafkaBindings.java", - ASSETS_PATH + "consumer/MessageWrapper.java", - ASSETS_PATH + "TestClassName.java"); + ASSETS_PATH + "IPublishOperationFileGenerationWithKafkaBindings.java", + ASSETS_PATH + "consumer/MessageWrapper.java", + ASSETS_PATH + "TestClassName.java"); final List expectedProducerFiles = List.of( - ASSETS_PATH + "ISubscribeOperationFileGenerationWithKafkaBindings.java", - ASSETS_PATH + "producer/MessageWrapper.java", - ASSETS_PATH + "Producer.java"); + ASSETS_PATH + "ISubscribeOperationFileGenerationWithKafkaBindings.java", + ASSETS_PATH + "producer/MessageWrapper.java", + ASSETS_PATH + "Producer.java"); final List expectedModelSchemaFiles = List.of( - ASSETS_PATH + "CreateOrderMapper.java", - ASSETS_PATH + "OrderDTO.java", - ASSETS_PATH + "OrderLineDTO.java", - ASSETS_PATH + "OrderLineMapper.java", - ASSETS_PATH + "OrderMapper.java", - ASSETS_PATH + "OrderProductDTO.java", - ASSETS_PATH + "OrderProductMapper.java", - ASSETS_PATH + "WaiterMapper.java" + ASSETS_PATH + "CreateOrderMapper.java", + ASSETS_PATH + "OrderDTO.java", + ASSETS_PATH + "OrderLineDTO.java", + ASSETS_PATH + "OrderLineMapper.java", + ASSETS_PATH + "OrderMapper.java", + ASSETS_PATH + "OrderProductDTO.java", + ASSETS_PATH + "OrderProductMapper.java", + ASSETS_PATH + "WaiterMapper.java" ); final List expectedValidatorFiles = List.of( - CUSTOM_VALIDATOR_PATH + "NotNull.java", - CUSTOM_VALIDATOR_PATH + "NotNullValidator.java" + CUSTOM_VALIDATOR_PATH + "NotNull.java", + CUSTOM_VALIDATOR_PATH + "NotNullValidator.java" ); - return (path) -> commonTest(path, expectedConsumerFiles, expectedProducerFiles, DEFAULT_CONSUMER_FOLDER, DEFAULT_PRODUCER_FOLDER, Collections.emptyList(), null) && - modelTest(path, expectedModelSchemaFiles, DEFAULT_COMMON_FOLDER) && - customValidatorTest(path, expectedValidatorFiles, DEFAULT_CUSTOM_VALIDATOR_FOLDER); + return path -> commonTest(path, expectedConsumerFiles, expectedProducerFiles, DEFAULT_CONSUMER_FOLDER, DEFAULT_PRODUCER_FOLDER, Collections.emptyList(), null) && + modelTest(path, expectedModelSchemaFiles, DEFAULT_COMMON_FOLDER) && + customValidatorTest(path, expectedValidatorFiles, DEFAULT_CUSTOM_VALIDATOR_FOLDER); } static Function validateTestSubObjectSameName() { @@ -1069,30 +1069,30 @@ static Function validateTestSubObjectSameName() { final String ASSETS_PATH = COMMON_PATH + "assets/"; final List expectedConsumerFiles = - List.of( - ASSETS_PATH + "input/controller/IInput.java", - ASSETS_PATH + "input/controller/Subscriber.java"); + List.of( + ASSETS_PATH + "input/controller/IInput.java", + ASSETS_PATH + "input/controller/Subscriber.java"); final List expectedProducerFiles = - List.of( - ASSETS_PATH + "output/provider/IOutput.java", - ASSETS_PATH + "output/provider/Producer.java"); + List.of( + ASSETS_PATH + "output/provider/IOutput.java", + ASSETS_PATH + "output/provider/Producer.java"); final List expectedConsumerModelSchemaFiles = - List.of(ASSETS_PATH + "input/model/Data.java", ASSETS_PATH + "input/model/Input.java"); + List.of(ASSETS_PATH + "input/model/Data.java", ASSETS_PATH + "input/model/Input.java"); final List expectedProducerModelSchemaFiles = - List.of(ASSETS_PATH + "output/model/Data.java", ASSETS_PATH + "output/model/Output.java"); - - return (path) -> - commonTest( - path, - expectedConsumerFiles, - expectedProducerFiles, - DEFAULT_CONSUMER_FOLDER, - DEFAULT_PRODUCER_FOLDER, - Collections.emptyList(), - null) - && modelTest(path, expectedConsumerModelSchemaFiles, DEFAULT_CONSUMER_MODEL_FOLDER) - && modelTest(path, expectedProducerModelSchemaFiles, DEFAULT_PRODUCER_MODEL_FOLDER); + List.of(ASSETS_PATH + "output/model/Data.java", ASSETS_PATH + "output/model/Output.java"); + + return path -> + commonTest( + path, + expectedConsumerFiles, + expectedProducerFiles, + DEFAULT_CONSUMER_FOLDER, + DEFAULT_PRODUCER_FOLDER, + Collections.emptyList(), + null) + && modelTest(path, expectedConsumerModelSchemaFiles, DEFAULT_CONSUMER_MODEL_FOLDER) + && modelTest(path, expectedProducerModelSchemaFiles, DEFAULT_PRODUCER_MODEL_FOLDER); } } diff --git a/multiapi-engine/src/test/resources/asyncapigenerator/testConstantGeneration/assets/payload/SomeOtherObject.java b/multiapi-engine/src/test/resources/asyncapigenerator/testConstantGeneration/assets/payload/SomeOtherObject.java index 2301ae40..75eafcb4 100644 --- a/multiapi-engine/src/test/resources/asyncapigenerator/testConstantGeneration/assets/payload/SomeOtherObject.java +++ b/multiapi-engine/src/test/resources/asyncapigenerator/testConstantGeneration/assets/payload/SomeOtherObject.java @@ -1,78 +1,26 @@ package com.sngular.scsplugin.constantgeneration.model; -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; +import lombok.Builder; +import lombok.Value; +import lombok.extern.jackson.Jacksonized; -@JsonDeserialize(builder = SomeOtherObject.SomeOtherObjectBuilder.class) +@Value public class SomeOtherObject { @JsonProperty(value ="property2") - private final Integer property2; - @JsonProperty(value ="property1") - private final Integer property1; - - private SomeOtherObject(SomeOtherObjectBuilder builder) { - this.property2 = builder.property2; - this.property1 = builder.property1; - - } - - public static SomeOtherObject.SomeOtherObjectBuilder builder() { - return new SomeOtherObject.SomeOtherObjectBuilder(); - } - - @JsonPOJOBuilder(buildMethodName = "build", withPrefix = "") - public static class SomeOtherObjectBuilder { - - private Integer property2 = 6; - private Integer property1 = 3; + private Integer property2 = 6; - public SomeOtherObject build() { - SomeOtherObject someOtherObject = new SomeOtherObject(this); - return someOtherObject; - } - } - - @Schema(name = "property2", required = false) - public Integer getProperty2() { - return property2; - } - - @Schema(name = "property1", required = false) - public Integer getProperty1() { - return property1; - } + @JsonProperty(value ="property1") + private Integer property1 = 3; - @Override - public boolean equals(Object o) { - if (this == o) { - return true; - } - if (o == null || getClass() != o.getClass()) { - return false; - } - SomeOtherObject someOtherObject = (SomeOtherObject) o; - return Objects.equals(this.property2, someOtherObject.property2) && Objects.equals(this.property1, someOtherObject.property1); - } - @Override - public int hashCode() { - return Objects.hash(property2, property1); - } + @Builder + @Jacksonized + private SomeOtherObject(Integer property2, Integer property1) { + this.property2 = property2; + this.property1 = property1; - @Override - public String toString() { - StringBuilder sb = new StringBuilder(); - sb.append("SomeOtherObject{"); - sb.append(" property2:").append(property2).append(","); - sb.append(" property1:").append(property1); - sb.append("}"); - return sb.toString(); } - } diff --git a/multiapi-engine/src/test/resources/asyncapigenerator/testConstantGeneration/assets/payload/UserSignedUpPayload.java b/multiapi-engine/src/test/resources/asyncapigenerator/testConstantGeneration/assets/payload/UserSignedUpPayload.java index 6cffb715..54447c7f 100644 --- a/multiapi-engine/src/test/resources/asyncapigenerator/testConstantGeneration/assets/payload/UserSignedUpPayload.java +++ b/multiapi-engine/src/test/resources/asyncapigenerator/testConstantGeneration/assets/payload/UserSignedUpPayload.java @@ -1,29 +1,33 @@ package com.sngular.scsplugin.constantgeneration.model; -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; import java.time.LocalDateTime; +import lombok.Builder; +import lombok.Value; +import lombok.extern.jackson.Jacksonized; -@JsonDeserialize(builder = UserSignedUpPayload.UserSignedUpPayloadBuilder.class) +@Value public class UserSignedUpPayload { @JsonProperty(value ="someOtherObject") private SomeOtherObject someOtherObject; + @JsonProperty(value ="email") - private final String email; + private String email = "je.garcia@oneemail.com"; + @JsonProperty(value ="firstName") - private final String firstName; + private String firstName = "Jose"; + @JsonProperty(value ="lastName") - private final String lastName; + private String lastName = "Garcia"; + @JsonProperty(value ="createdAt") private LocalDateTime createdAt; + @JsonProperty(value ="numberEnum") private NumberEnum numberEnum; + public enum NumberEnum { _1234("1234"), _2345("2345"), @@ -46,120 +50,17 @@ public String toString() { } } - private UserSignedUpPayload(UserSignedUpPayloadBuilder builder) { - this.someOtherObject = builder.someOtherObject; - this.email = builder.email; - this.firstName = builder.firstName; - this.lastName = builder.lastName; - this.createdAt = builder.createdAt; - this.numberEnum = builder.numberEnum; - - } - - public static UserSignedUpPayload.UserSignedUpPayloadBuilder builder() { - return new UserSignedUpPayload.UserSignedUpPayloadBuilder(); - } - - @JsonPOJOBuilder(buildMethodName = "build", withPrefix = "") - public static class UserSignedUpPayloadBuilder { - - private SomeOtherObject someOtherObject; - private String email = "je.garcia@oneemail.com"; - private String firstName = "Jose"; - private String lastName = "Garcia"; - private LocalDateTime createdAt; - private NumberEnum numberEnum; - - public UserSignedUpPayload.UserSignedUpPayloadBuilder someOtherObject(SomeOtherObject someOtherObject) { - this.someOtherObject = someOtherObject; - return this; - } - - public UserSignedUpPayload.UserSignedUpPayloadBuilder createdAt(LocalDateTime createdAt) { - this.createdAt = createdAt; - return this; - } - - public UserSignedUpPayload.UserSignedUpPayloadBuilder numberEnum(NumberEnum numberEnum) { - this.numberEnum = numberEnum; - return this; - } - - public UserSignedUpPayload build() { - UserSignedUpPayload userSignedUpPayload = new UserSignedUpPayload(this); - return userSignedUpPayload; - } - } - @Schema(name = "someOtherObject", required = false) - public SomeOtherObject getSomeOtherObject() { - return someOtherObject; - } - public void setSomeOtherObject(SomeOtherObject someOtherObject) { + @Builder + @Jacksonized + private UserSignedUpPayload(SomeOtherObject someOtherObject, String email, String firstName, String lastName, LocalDateTime createdAt, NumberEnum numberEnum) { this.someOtherObject = someOtherObject; - } - - @Schema(name = "email", required = false) - public String getEmail() { - return email; - } - - @Schema(name = "firstName", required = false) - public String getFirstName() { - return firstName; - } - - @Schema(name = "lastName", required = false) - public String getLastName() { - return lastName; - } - - @Schema(name = "createdAt", required = false) - public LocalDateTime getCreatedAt() { - return createdAt; - } - public void setCreatedAt(LocalDateTime createdAt) { + this.email = email; + this.firstName = firstName; + this.lastName = lastName; this.createdAt = createdAt; - } - - @Schema(name = "numberEnum", required = false) - public NumberEnum getNumberEnum() { - return numberEnum; - } - public void setNumberEnum(NumberEnum numberEnum) { this.numberEnum = numberEnum; - } - - @Override - public boolean equals(Object o) { - if (this == o) { - return true; - } - if (o == null || getClass() != o.getClass()) { - return false; - } - UserSignedUpPayload userSignedUpPayload = (UserSignedUpPayload) o; - return Objects.equals(this.someOtherObject, userSignedUpPayload.someOtherObject) && Objects.equals(this.email, userSignedUpPayload.email) && Objects.equals(this.firstName, userSignedUpPayload.firstName) && Objects.equals(this.lastName, userSignedUpPayload.lastName) && Objects.equals(this.createdAt, userSignedUpPayload.createdAt) && Objects.equals(this.numberEnum, userSignedUpPayload.numberEnum); - } - @Override - public int hashCode() { - return Objects.hash(someOtherObject, email, firstName, lastName, createdAt, numberEnum); } - @Override - public String toString() { - StringBuilder sb = new StringBuilder(); - sb.append("UserSignedUpPayload{"); - sb.append(" someOtherObject:").append(someOtherObject).append(","); - sb.append(" email:").append(email).append(","); - sb.append(" firstName:").append(firstName).append(","); - sb.append(" lastName:").append(lastName).append(","); - sb.append(" createdAt:").append(createdAt).append(","); - sb.append(" numberEnum:").append(numberEnum); - sb.append("}"); - return sb.toString(); - } - - } diff --git a/multiapi-engine/src/test/resources/asyncapigenerator/testFileGenerationArrayString/assets/ObjectArrayDTO.java b/multiapi-engine/src/test/resources/asyncapigenerator/testFileGenerationArrayString/assets/ObjectArrayDTO.java index 9fb8e1e9..b15d5201 100644 --- a/multiapi-engine/src/test/resources/asyncapigenerator/testFileGenerationArrayString/assets/ObjectArrayDTO.java +++ b/multiapi-engine/src/test/resources/asyncapigenerator/testFileGenerationArrayString/assets/ObjectArrayDTO.java @@ -1,123 +1,34 @@ package com.sngular.scsplugin.arraywithstring.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; import java.util.List; import java.util.ArrayList; +import lombok.Builder; +import lombok.Singular; +import lombok.Value; +import lombok.extern.jackson.Jacksonized; -@JsonDeserialize(builder = ObjectArrayDTO.ObjectArrayDTOBuilder.class) +@Value public class ObjectArrayDTO { @JsonProperty(value ="idObject") private Integer idObject; + @JsonProperty(value ="info") private String info; + @JsonProperty(value ="players") + @Singular("player") private List players; - private ObjectArrayDTO(ObjectArrayDTOBuilder builder) { - this.idObject = builder.idObject; - this.info = builder.info; - this.players = builder.players; - - } - - public static ObjectArrayDTO.ObjectArrayDTOBuilder builder() { - return new ObjectArrayDTO.ObjectArrayDTOBuilder(); - } - - @JsonPOJOBuilder(buildMethodName = "build", withPrefix = "") - public static class ObjectArrayDTOBuilder { - - private Integer idObject; - private String info; - private List players = new ArrayList(); - - public ObjectArrayDTO.ObjectArrayDTOBuilder idObject(Integer idObject) { - this.idObject = idObject; - return this; - } - - public ObjectArrayDTO.ObjectArrayDTOBuilder info(String info) { - this.info = info; - return this; - } - - public ObjectArrayDTO.ObjectArrayDTOBuilder players(List players) { - if (!players.isEmpty()) { - this.players.addAll(players); - } - return this; - } - - public ObjectArrayDTO.ObjectArrayDTOBuilder player(String player) { - if (Objects.nonNull(player)) { - this.players.add(player); - } - return this; - } - - public ObjectArrayDTO build() { - ObjectArrayDTO objectArrayDTO = new ObjectArrayDTO(this); - return objectArrayDTO; - } - } - @Schema(name = "idObject", required = false) - public Integer getIdObject() { - return idObject; - } - public void setIdObject(Integer idObject) { + @Builder + @Jacksonized + private ObjectArrayDTO(Integer idObject, String info, List players) { this.idObject = idObject; - } - - @Schema(name = "info", required = false) - public String getInfo() { - return info; - } - public void setInfo(String info) { this.info = info; - } - - @Schema(name = "players", required = false) - public List getPlayers() { - return players; - } - public void setPlayers(List players) { this.players = players; - } - - @Override - public boolean equals(Object o) { - if (this == o) { - return true; - } - if (o == null || getClass() != o.getClass()) { - return false; - } - ObjectArrayDTO objectArrayDTO = (ObjectArrayDTO) o; - return Objects.equals(this.idObject, objectArrayDTO.idObject) && Objects.equals(this.info, objectArrayDTO.info) && Objects.equals(this.players, objectArrayDTO.players); - } - @Override - public int hashCode() { - return Objects.hash(idObject, info, players); } - @Override - public String toString() { - StringBuilder sb = new StringBuilder(); - sb.append("ObjectArrayDTO{"); - sb.append(" idObject:").append(idObject).append(","); - sb.append(" info:").append(info).append(","); - sb.append(" players:").append(players); - sb.append("}"); - return sb.toString(); - } - - } 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 10835f26..ce21a326 100644 --- a/multiapi-engine/src/test/resources/asyncapigenerator/testIssueGenerateSupplier/assets/ConfigurationDTO.java +++ b/multiapi-engine/src/test/resources/asyncapigenerator/testIssueGenerateSupplier/assets/ConfigurationDTO.java @@ -1,76 +1,22 @@ package company.mail.model; -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; +import lombok.Builder; +import lombok.Value; +import lombok.extern.jackson.Jacksonized; -@JsonDeserialize(builder = ConfigurationDTO.ConfigurationDTOBuilder.class) +@Value public class ConfigurationDTO { @JsonProperty(value ="name") private String name; - private ConfigurationDTO(ConfigurationDTOBuilder builder) { - this.name = builder.name; - - } - - public static ConfigurationDTO.ConfigurationDTOBuilder builder() { - return new ConfigurationDTO.ConfigurationDTOBuilder(); - } - @JsonPOJOBuilder(buildMethodName = "build", withPrefix = "") - public static class ConfigurationDTOBuilder { - - private String name; - - public ConfigurationDTO.ConfigurationDTOBuilder name(String name) { - this.name = name; - return this; - } - - public ConfigurationDTO build() { - ConfigurationDTO configurationDTO = new ConfigurationDTO(this); - return configurationDTO; - } - } - - @Schema(name = "name", required = false) - public String getName() { - return name; - } - public void setName(String name) { + @Builder + @Jacksonized + private ConfigurationDTO(String name) { this.name = name; - } - - @Override - public boolean equals(Object o) { - if (this == o) { - return true; - } - if (o == null || getClass() != o.getClass()) { - return false; - } - ConfigurationDTO configurationDTO = (ConfigurationDTO) o; - return Objects.equals(this.name, configurationDTO.name); - } - - @Override - public int hashCode() { - return Objects.hash(name); - } - @Override - public String toString() { - StringBuilder sb = new StringBuilder(); - sb.append("ConfigurationDTO{"); - 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 923b667a..aaa07031 100644 --- a/multiapi-engine/src/test/resources/asyncapigenerator/testIssueGenerateSupplier/assets/MailRequestDTO.java +++ b/multiapi-engine/src/test/resources/asyncapigenerator/testIssueGenerateSupplier/assets/MailRequestDTO.java @@ -1,123 +1,34 @@ package company.mail.model; -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; import java.util.List; import java.util.ArrayList; +import lombok.Builder; +import lombok.Singular; +import lombok.Value; +import lombok.extern.jackson.Jacksonized; -@JsonDeserialize(builder = MailRequestDTO.MailRequestDTOBuilder.class) +@Value public class MailRequestDTO { @JsonProperty(value ="sender") private String sender; + @JsonProperty(value ="configuration") private ConfigurationDTO configuration; + @JsonProperty(value ="recipients") + @Singular("recipient") private List recipients; - private MailRequestDTO(MailRequestDTOBuilder builder) { - this.sender = builder.sender; - this.configuration = builder.configuration; - this.recipients = builder.recipients; - - } - - public static MailRequestDTO.MailRequestDTOBuilder builder() { - return new MailRequestDTO.MailRequestDTOBuilder(); - } - - @JsonPOJOBuilder(buildMethodName = "build", withPrefix = "") - public static class MailRequestDTOBuilder { - - private String sender; - private ConfigurationDTO configuration; - private List recipients = new ArrayList(); - - public MailRequestDTO.MailRequestDTOBuilder sender(String sender) { - this.sender = sender; - return this; - } - - public MailRequestDTO.MailRequestDTOBuilder configuration(ConfigurationDTO configuration) { - this.configuration = configuration; - return this; - } - - public MailRequestDTO.MailRequestDTOBuilder recipients(List recipients) { - if (!recipients.isEmpty()) { - this.recipients.addAll(recipients); - } - return this; - } - - public MailRequestDTO.MailRequestDTOBuilder recipient(String recipient) { - if (Objects.nonNull(recipient)) { - this.recipients.add(recipient); - } - return this; - } - - public MailRequestDTO build() { - MailRequestDTO mailRequestDTO = new MailRequestDTO(this); - return mailRequestDTO; - } - } - @Schema(name = "sender", required = false) - public String getSender() { - return sender; - } - public void setSender(String sender) { + @Builder + @Jacksonized + private MailRequestDTO(String sender, ConfigurationDTO configuration, List recipients) { this.sender = sender; - } - - @Schema(name = "configuration", required = false) - public ConfigurationDTO getConfiguration() { - return configuration; - } - public void setConfiguration(ConfigurationDTO configuration) { this.configuration = configuration; - } - - @Schema(name = "recipients", required = false) - public List getRecipients() { - return recipients; - } - public void setRecipients(List recipients) { this.recipients = recipients; - } - - @Override - public boolean equals(Object o) { - if (this == o) { - return true; - } - if (o == null || getClass() != o.getClass()) { - return false; - } - MailRequestDTO mailRequestDTO = (MailRequestDTO) o; - return Objects.equals(this.sender, mailRequestDTO.sender) && Objects.equals(this.configuration, mailRequestDTO.configuration) && Objects.equals(this.recipients, mailRequestDTO.recipients); - } - @Override - public int hashCode() { - return Objects.hash(sender, configuration, recipients); } - @Override - public String toString() { - StringBuilder sb = new StringBuilder(); - sb.append("MailRequestDTO{"); - sb.append(" sender:").append(sender).append(","); - sb.append(" configuration:").append(configuration).append(","); - sb.append(" recipients:").append(recipients); - sb.append("}"); - return sb.toString(); - } - - } diff --git a/multiapi-engine/src/test/resources/asyncapigenerator/testIssueInfiniteLoop/assets/ConfigDTO.java b/multiapi-engine/src/test/resources/asyncapigenerator/testIssueInfiniteLoop/assets/ConfigDTO.java index 7fccb09a..111caf1c 100644 --- a/multiapi-engine/src/test/resources/asyncapigenerator/testIssueInfiniteLoop/assets/ConfigDTO.java +++ b/multiapi-engine/src/test/resources/asyncapigenerator/testIssueInfiniteLoop/assets/ConfigDTO.java @@ -1,76 +1,22 @@ package com.sngular.scsplugin.infiniteLoop.model; -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; +import lombok.Builder; +import lombok.Value; +import lombok.extern.jackson.Jacksonized; -@JsonDeserialize(builder = ConfigDTO.ConfigDTOBuilder.class) +@Value public class ConfigDTO { @JsonProperty(value ="name") private String name; - private ConfigDTO(ConfigDTOBuilder builder) { - this.name = builder.name; - - } - - public static ConfigDTO.ConfigDTOBuilder builder() { - return new ConfigDTO.ConfigDTOBuilder(); - } - @JsonPOJOBuilder(buildMethodName = "build", withPrefix = "") - public static class ConfigDTOBuilder { - - private String name; - - public ConfigDTO.ConfigDTOBuilder name(String name) { - this.name = name; - return this; - } - - public ConfigDTO build() { - ConfigDTO configDTO = new ConfigDTO(this); - return configDTO; - } - } - - @Schema(name = "name", required = false) - public String getName() { - return name; - } - public void setName(String name) { + @Builder + @Jacksonized + private ConfigDTO(String name) { this.name = name; - } - - @Override - public boolean equals(Object o) { - if (this == o) { - return true; - } - if (o == null || getClass() != o.getClass()) { - return false; - } - ConfigDTO configDTO = (ConfigDTO) o; - return Objects.equals(this.name, configDTO.name); - } - - @Override - public int hashCode() { - return Objects.hash(name); - } - @Override - public String toString() { - StringBuilder sb = new StringBuilder(); - sb.append("ConfigDTO{"); - sb.append(" name:").append(name); - sb.append("}"); - return sb.toString(); } - } diff --git a/multiapi-engine/src/test/resources/asyncapigenerator/testIssueInfiniteLoop/assets/MailRequestInfiniteDTO.java b/multiapi-engine/src/test/resources/asyncapigenerator/testIssueInfiniteLoop/assets/MailRequestInfiniteDTO.java index e8444604..e371c9a3 100644 --- a/multiapi-engine/src/test/resources/asyncapigenerator/testIssueInfiniteLoop/assets/MailRequestInfiniteDTO.java +++ b/multiapi-engine/src/test/resources/asyncapigenerator/testIssueInfiniteLoop/assets/MailRequestInfiniteDTO.java @@ -1,123 +1,34 @@ package com.sngular.scsplugin.infiniteLoop.model; -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; import java.util.List; import java.util.ArrayList; +import lombok.Builder; +import lombok.Singular; +import lombok.Value; +import lombok.extern.jackson.Jacksonized; -@JsonDeserialize(builder = MailRequestInfiniteDTO.MailRequestInfiniteDTOBuilder.class) +@Value public class MailRequestInfiniteDTO { @JsonProperty(value ="sender") private String sender; + @JsonProperty(value ="config") private ConfigDTO config; + @JsonProperty(value ="recipients") + @Singular("recipient") private List recipients; - private MailRequestInfiniteDTO(MailRequestInfiniteDTOBuilder builder) { - this.sender = builder.sender; - this.config = builder.config; - this.recipients = builder.recipients; - - } - - public static MailRequestInfiniteDTO.MailRequestInfiniteDTOBuilder builder() { - return new MailRequestInfiniteDTO.MailRequestInfiniteDTOBuilder(); - } - - @JsonPOJOBuilder(buildMethodName = "build", withPrefix = "") - public static class MailRequestInfiniteDTOBuilder { - - private String sender; - private ConfigDTO config; - private List recipients = new ArrayList(); - - public MailRequestInfiniteDTO.MailRequestInfiniteDTOBuilder sender(String sender) { - this.sender = sender; - return this; - } - - public MailRequestInfiniteDTO.MailRequestInfiniteDTOBuilder config(ConfigDTO config) { - this.config = config; - return this; - } - - public MailRequestInfiniteDTO.MailRequestInfiniteDTOBuilder recipients(List recipients) { - if (!recipients.isEmpty()) { - this.recipients.addAll(recipients); - } - return this; - } - - public MailRequestInfiniteDTO.MailRequestInfiniteDTOBuilder recipient(String recipient) { - if (Objects.nonNull(recipient)) { - this.recipients.add(recipient); - } - return this; - } - - public MailRequestInfiniteDTO build() { - MailRequestInfiniteDTO mailRequestInfiniteDTO = new MailRequestInfiniteDTO(this); - return mailRequestInfiniteDTO; - } - } - @Schema(name = "sender", required = false) - public String getSender() { - return sender; - } - public void setSender(String sender) { + @Builder + @Jacksonized + private MailRequestInfiniteDTO(String sender, ConfigDTO config, List recipients) { this.sender = sender; - } - - @Schema(name = "config", required = false) - public ConfigDTO getConfig() { - return config; - } - public void setConfig(ConfigDTO config) { this.config = config; - } - - @Schema(name = "recipients", required = false) - public List getRecipients() { - return recipients; - } - public void setRecipients(List recipients) { this.recipients = recipients; - } - - @Override - public boolean equals(Object o) { - if (this == o) { - return true; - } - if (o == null || getClass() != o.getClass()) { - return false; - } - MailRequestInfiniteDTO mailRequestInfiniteDTO = (MailRequestInfiniteDTO) o; - return Objects.equals(this.sender, mailRequestInfiniteDTO.sender) && Objects.equals(this.config, mailRequestInfiniteDTO.config) && Objects.equals(this.recipients, mailRequestInfiniteDTO.recipients); - } - @Override - public int hashCode() { - return Objects.hash(sender, config, recipients); } - @Override - public String toString() { - StringBuilder sb = new StringBuilder(); - sb.append("MailRequestInfiniteDTO{"); - sb.append(" sender:").append(sender).append(","); - sb.append(" config:").append(config).append(","); - sb.append(" recipients:").append(recipients); - sb.append("}"); - return sb.toString(); - } - - } diff --git a/multiapi-engine/src/test/resources/asyncapigenerator/testNestedObjectIssue/assets/payload/SomeOtherObject.java b/multiapi-engine/src/test/resources/asyncapigenerator/testNestedObjectIssue/assets/payload/SomeOtherObject.java index 37b7cb70..36824d77 100644 --- a/multiapi-engine/src/test/resources/asyncapigenerator/testNestedObjectIssue/assets/payload/SomeOtherObject.java +++ b/multiapi-engine/src/test/resources/asyncapigenerator/testNestedObjectIssue/assets/payload/SomeOtherObject.java @@ -1,94 +1,26 @@ package com.sngular.scsplugin.nestedobject.model; -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; +import lombok.Builder; +import lombok.Value; +import lombok.extern.jackson.Jacksonized; -@JsonDeserialize(builder = SomeOtherObject.SomeOtherObjectBuilder.class) +@Value public class SomeOtherObject { @JsonProperty(value ="property2") private Integer property2; + @JsonProperty(value ="property1") private String property1; - private SomeOtherObject(SomeOtherObjectBuilder builder) { - this.property2 = builder.property2; - this.property1 = builder.property1; - - } - - public static SomeOtherObject.SomeOtherObjectBuilder builder() { - return new SomeOtherObject.SomeOtherObjectBuilder(); - } - - @JsonPOJOBuilder(buildMethodName = "build", withPrefix = "") - public static class SomeOtherObjectBuilder { - - private Integer property2; - private String property1; - - public SomeOtherObject.SomeOtherObjectBuilder property2(Integer property2) { - this.property2 = property2; - return this; - } - - public SomeOtherObject.SomeOtherObjectBuilder property1(String property1) { - this.property1 = property1; - return this; - } - - public SomeOtherObject build() { - SomeOtherObject someOtherObject = new SomeOtherObject(this); - return someOtherObject; - } - } - @Schema(name = "property2", required = false) - public Integer getProperty2() { - return property2; - } - public void setProperty2(Integer property2) { + @Builder + @Jacksonized + private SomeOtherObject(Integer property2, String property1) { this.property2 = property2; - } - - @Schema(name = "property1", required = false) - public String getProperty1() { - return property1; - } - public void setProperty1(String property1) { this.property1 = property1; - } - @Override - public boolean equals(Object o) { - if (this == o) { - return true; - } - if (o == null || getClass() != o.getClass()) { - return false; - } - SomeOtherObject someOtherObject = (SomeOtherObject) o; - return Objects.equals(this.property2, someOtherObject.property2) && Objects.equals(this.property1, someOtherObject.property1); } - @Override - public int hashCode() { - return Objects.hash(property2, property1); - } - - @Override - public String toString() { - StringBuilder sb = new StringBuilder(); - sb.append("SomeOtherObject{"); - sb.append(" property2:").append(property2).append(","); - sb.append(" property1:").append(property1); - sb.append("}"); - return sb.toString(); - } - - } diff --git a/multiapi-engine/src/test/resources/asyncapigenerator/testNestedObjectIssue/assets/payload/UserSignedUpPayload.java b/multiapi-engine/src/test/resources/asyncapigenerator/testNestedObjectIssue/assets/payload/UserSignedUpPayload.java index 707930a5..d6ed0977 100644 --- a/multiapi-engine/src/test/resources/asyncapigenerator/testNestedObjectIssue/assets/payload/UserSignedUpPayload.java +++ b/multiapi-engine/src/test/resources/asyncapigenerator/testNestedObjectIssue/assets/payload/UserSignedUpPayload.java @@ -1,149 +1,39 @@ package com.sngular.scsplugin.nestedobject.model; -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; import java.time.LocalDateTime; +import lombok.Builder; +import lombok.Value; +import lombok.extern.jackson.Jacksonized; -@JsonDeserialize(builder = UserSignedUpPayload.UserSignedUpPayloadBuilder.class) +@Value public class UserSignedUpPayload { @JsonProperty(value ="someOtherObject") private SomeOtherObject someOtherObject; + @JsonProperty(value ="email") private String email; + @JsonProperty(value ="firstName") private String firstName; + @JsonProperty(value ="lastName") private String lastName; + @JsonProperty(value ="createdAt") private LocalDateTime createdAt; - private UserSignedUpPayload(UserSignedUpPayloadBuilder builder) { - this.someOtherObject = builder.someOtherObject; - this.email = builder.email; - this.firstName = builder.firstName; - this.lastName = builder.lastName; - this.createdAt = builder.createdAt; - - } - - public static UserSignedUpPayload.UserSignedUpPayloadBuilder builder() { - return new UserSignedUpPayload.UserSignedUpPayloadBuilder(); - } - - @JsonPOJOBuilder(buildMethodName = "build", withPrefix = "") - public static class UserSignedUpPayloadBuilder { - private SomeOtherObject someOtherObject; - private String email; - private String firstName; - private String lastName; - private LocalDateTime createdAt; - - public UserSignedUpPayload.UserSignedUpPayloadBuilder someOtherObject(SomeOtherObject someOtherObject) { - this.someOtherObject = someOtherObject; - return this; - } - - public UserSignedUpPayload.UserSignedUpPayloadBuilder email(String email) { - this.email = email; - return this; - } - - public UserSignedUpPayload.UserSignedUpPayloadBuilder firstName(String firstName) { - this.firstName = firstName; - return this; - } - - public UserSignedUpPayload.UserSignedUpPayloadBuilder lastName(String lastName) { - this.lastName = lastName; - return this; - } - - public UserSignedUpPayload.UserSignedUpPayloadBuilder createdAt(LocalDateTime createdAt) { - this.createdAt = createdAt; - return this; - } - - public UserSignedUpPayload build() { - UserSignedUpPayload userSignedUpPayload = new UserSignedUpPayload(this); - return userSignedUpPayload; - } - } - - @Schema(name = "someOtherObject", required = false) - public SomeOtherObject getSomeOtherObject() { - return someOtherObject; - } - public void setSomeOtherObject(SomeOtherObject someOtherObject) { + @Builder + @Jacksonized + private UserSignedUpPayload(SomeOtherObject someOtherObject, String email, String firstName, String lastName, LocalDateTime createdAt) { this.someOtherObject = someOtherObject; - } - - @Schema(name = "email", required = false) - public String getEmail() { - return email; - } - public void setEmail(String email) { this.email = email; - } - - @Schema(name = "firstName", required = false) - public String getFirstName() { - return firstName; - } - public void setFirstName(String firstName) { this.firstName = firstName; - } - - @Schema(name = "lastName", required = false) - public String getLastName() { - return lastName; - } - public void setLastName(String lastName) { this.lastName = lastName; - } - - @Schema(name = "createdAt", required = false) - public LocalDateTime getCreatedAt() { - return createdAt; - } - public void setCreatedAt(LocalDateTime createdAt) { this.createdAt = createdAt; - } - @Override - public boolean equals(Object o) { - if (this == o) { - return true; - } - if (o == null || getClass() != o.getClass()) { - return false; - } - UserSignedUpPayload userSignedUpPayload = (UserSignedUpPayload) o; - return Objects.equals(this.someOtherObject, userSignedUpPayload.someOtherObject) && Objects.equals(this.email, userSignedUpPayload.email) && Objects.equals(this.firstName, userSignedUpPayload.firstName) && Objects.equals(this.lastName, userSignedUpPayload.lastName) && Objects.equals(this.createdAt, userSignedUpPayload.createdAt); } - @Override - public int hashCode() { - return Objects.hash(someOtherObject, email, firstName, lastName, createdAt); - } - - @Override - public String toString() { - StringBuilder sb = new StringBuilder(); - sb.append("UserSignedUpPayload{"); - sb.append(" someOtherObject:").append(someOtherObject).append(","); - sb.append(" email:").append(email).append(","); - sb.append(" firstName:").append(firstName).append(","); - sb.append(" lastName:").append(lastName).append(","); - sb.append(" createdAt:").append(createdAt); - sb.append("}"); - return sb.toString(); - } - - } diff --git a/multiapi-engine/src/test/resources/asyncapigenerator/testNoSchemas/assets/TestMsg.java b/multiapi-engine/src/test/resources/asyncapigenerator/testNoSchemas/assets/TestMsg.java index 06ea868b..9e7d3d76 100644 --- a/multiapi-engine/src/test/resources/asyncapigenerator/testNoSchemas/assets/TestMsg.java +++ b/multiapi-engine/src/test/resources/asyncapigenerator/testNoSchemas/assets/TestMsg.java @@ -1,76 +1,22 @@ package com.sngular.scsplugin.noschemas.model; -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; +import lombok.Builder; +import lombok.Value; +import lombok.extern.jackson.Jacksonized; -@JsonDeserialize(builder = TestMsg.TestMsgBuilder.class) +@Value public class TestMsg { @JsonProperty(value ="id") private Integer id; - private TestMsg(TestMsgBuilder builder) { - this.id = builder.id; - - } - - public static TestMsg.TestMsgBuilder builder() { - return new TestMsg.TestMsgBuilder(); - } - @JsonPOJOBuilder(buildMethodName = "build", withPrefix = "") - public static class TestMsgBuilder { - - private Integer id; - - public TestMsg.TestMsgBuilder id(Integer id) { - this.id = id; - return this; - } - - public TestMsg build() { - TestMsg testMsg = new TestMsg(this); - return testMsg; - } - } - - @Schema(name = "id", required = false) - public Integer getId() { - return id; - } - public void setId(Integer id) { + @Builder + @Jacksonized + private TestMsg(Integer id) { this.id = id; - } - - @Override - public boolean equals(Object o) { - if (this == o) { - return true; - } - if (o == null || getClass() != o.getClass()) { - return false; - } - TestMsg testMsg = (TestMsg) o; - return Objects.equals(this.id, testMsg.id); - } - - @Override - public int hashCode() { - return Objects.hash(id); - } - @Override - public String toString() { - StringBuilder sb = new StringBuilder(); - sb.append("TestMsg{"); - sb.append(" id:").append(id); - sb.append("}"); - return sb.toString(); } - } diff --git a/multiapi-engine/src/test/resources/asyncapigenerator/testNoSchemas/assets/Thing.java b/multiapi-engine/src/test/resources/asyncapigenerator/testNoSchemas/assets/Thing.java index f109da1a..1874e9e6 100644 --- a/multiapi-engine/src/test/resources/asyncapigenerator/testNoSchemas/assets/Thing.java +++ b/multiapi-engine/src/test/resources/asyncapigenerator/testNoSchemas/assets/Thing.java @@ -1,76 +1,22 @@ package com.sngular.scsplugin.noschemas.model; -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; +import lombok.Builder; +import lombok.Value; +import lombok.extern.jackson.Jacksonized; -@JsonDeserialize(builder = Thing.ThingBuilder.class) +@Value public class Thing { @JsonProperty(value ="id") private Integer id; - private Thing(ThingBuilder builder) { - this.id = builder.id; - - } - - public static Thing.ThingBuilder builder() { - return new Thing.ThingBuilder(); - } - @JsonPOJOBuilder(buildMethodName = "build", withPrefix = "") - public static class ThingBuilder { - - private Integer id; - - public Thing.ThingBuilder id(Integer id) { - this.id = id; - return this; - } - - public Thing build() { - Thing thing = new Thing(this); - return thing; - } - } - - @Schema(name = "id", required = false) - public Integer getId() { - return id; - } - public void setId(Integer id) { + @Builder + @Jacksonized + private Thing(Integer id) { this.id = id; - } - - @Override - public boolean equals(Object o) { - if (this == o) { - return true; - } - if (o == null || getClass() != o.getClass()) { - return false; - } - Thing thing = (Thing) o; - return Objects.equals(this.id, thing.id); - } - - @Override - public int hashCode() { - return Objects.hash(id); - } - @Override - public String toString() { - StringBuilder sb = new StringBuilder(); - sb.append("Thing{"); - sb.append(" id:").append(id); - 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 f9611c24..e67376c4 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 @@ -1,112 +1,30 @@ package com.sngular.scsplugin.notgeneratedproperties.model; -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; +import lombok.Builder; +import lombok.Value; +import lombok.extern.jackson.Jacksonized; -@JsonDeserialize(builder = UserDetails.UserDetailsBuilder.class) +@Value public class UserDetails { @JsonProperty(value ="email") private String email; + @JsonProperty(value ="firstName") private String firstName; + @JsonProperty(value ="lastName") private String lastName; - private UserDetails(UserDetailsBuilder builder) { - this.email = builder.email; - this.firstName = builder.firstName; - this.lastName = builder.lastName; - - } - - public static UserDetails.UserDetailsBuilder builder() { - return new UserDetails.UserDetailsBuilder(); - } - - @JsonPOJOBuilder(buildMethodName = "build", withPrefix = "") - public static class UserDetailsBuilder { - - private String email; - private String firstName; - private String lastName; - - public UserDetails.UserDetailsBuilder email(String email) { - this.email = email; - return this; - } - - public UserDetails.UserDetailsBuilder firstName(String firstName) { - this.firstName = firstName; - return this; - } - - public UserDetails.UserDetailsBuilder lastName(String lastName) { - this.lastName = lastName; - return this; - } - - public UserDetails build() { - UserDetails userDetails = new UserDetails(this); - return userDetails; - } - } - @Schema(name = "email", required = false) - public String getEmail() { - return email; - } - public void setEmail(String email) { + @Builder + @Jacksonized + private UserDetails(String email, String firstName, String lastName) { this.email = email; - } - - @Schema(name = "firstName", required = false) - public String getFirstName() { - return firstName; - } - public void setFirstName(String firstName) { this.firstName = firstName; - } - - @Schema(name = "lastName", required = false) - public String getLastName() { - return lastName; - } - public void setLastName(String lastName) { this.lastName = lastName; - } - - @Override - public boolean equals(Object o) { - if (this == o) { - return true; - } - if (o == null || getClass() != o.getClass()) { - return false; - } - UserDetails userDetails = (UserDetails) o; - return Objects.equals(this.email, userDetails.email) && Objects.equals(this.firstName, userDetails.firstName) && Objects.equals(this.lastName, userDetails.lastName); - } - @Override - public int hashCode() { - return Objects.hash(email, firstName, lastName); } - @Override - public String toString() { - StringBuilder sb = new StringBuilder(); - sb.append("UserDetails{"); - sb.append(" email:").append(email).append(","); - sb.append(" firstName:").append(firstName).append(","); - sb.append(" lastName:").append(lastName); - sb.append("}"); - return sb.toString(); - } - - } 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 8bac87e4..af98867d 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 @@ -1,94 +1,26 @@ package com.sngular.scsplugin.notgeneratedproperties.model; -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; +import lombok.Builder; +import lombok.Value; +import lombok.extern.jackson.Jacksonized; -@JsonDeserialize(builder = UserSignedUp.UserSignedUpBuilder.class) +@Value public class UserSignedUp { @JsonProperty(value ="details") private UserDetails details; + @JsonProperty(value ="id") private String id; - private UserSignedUp(UserSignedUpBuilder builder) { - this.details = builder.details; - this.id = builder.id; - - } - - public static UserSignedUp.UserSignedUpBuilder builder() { - return new UserSignedUp.UserSignedUpBuilder(); - } - - @JsonPOJOBuilder(buildMethodName = "build", withPrefix = "") - public static class UserSignedUpBuilder { - - private UserDetails details; - private String id; - - public UserSignedUp.UserSignedUpBuilder details(UserDetails details) { - this.details = details; - return this; - } - - public UserSignedUp.UserSignedUpBuilder id(String id) { - this.id = id; - return this; - } - - public UserSignedUp build() { - UserSignedUp userSignedUp = new UserSignedUp(this); - return userSignedUp; - } - } - @Schema(name = "details", required = false) - public UserDetails getDetails() { - return details; - } - public void setDetails(UserDetails details) { + @Builder + @Jacksonized + private UserSignedUp(UserDetails details, String id) { this.details = details; - } - - @Schema(name = "id", required = false) - public String getId() { - return id; - } - public void setId(String id) { this.id = id; - } - @Override - public boolean equals(Object o) { - if (this == o) { - return true; - } - if (o == null || getClass() != o.getClass()) { - return false; - } - UserSignedUp userSignedUp = (UserSignedUp) o; - return Objects.equals(this.details, userSignedUp.details) && Objects.equals(this.id, userSignedUp.id); } - @Override - public int hashCode() { - return Objects.hash(details, id); - } - - @Override - public String toString() { - StringBuilder sb = new StringBuilder(); - sb.append("UserSignedUp{"); - sb.append(" details:").append(details).append(","); - sb.append(" id:").append(id); - sb.append("}"); - return sb.toString(); - } - - } diff --git a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/assets/testApi/ApiErrorDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/assets/testApi/ApiErrorDTO.java index 4b79eeb5..cf7cbdd5 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/assets/testApi/ApiErrorDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/assets/testApi/ApiErrorDTO.java @@ -85,7 +85,7 @@ public ApiErrorDTO.ApiErrorDTOBuilder test(List test) { } public ApiErrorDTO.ApiErrorDTOBuilder _test(Integer _test) { - if (_test != null) { + if (Objects.nonNull(_test)) { this.test.add(_test); } return this; From ae5b07df0bc48c6dec4aeffadfe2ee9b44111403 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?jose=20enrique=20garcia=20maci=C3=B1eiras?= Date: Mon, 23 Sep 2024 23:18:48 +0200 Subject: [PATCH 17/26] Fix Openapi Generator --- .../template/CommonTemplateFactory.java | 1 + .../common/tools/MapperContentUtil.java | 1 - .../plugin/common/tools/MapperUtil.java | 10 +- .../plugin/common/tools/ModelBuilder.java | 94 +++++--- .../plugin/common/tools/SchemaUtil.java | 3 +- .../plugin/openapi/utils/MapperPathUtil.java | 26 ++- .../model/templateSchemaWithLombok.ftlh | 3 - .../openapi/OpenApiGeneratorFixtures.java | 106 +++++---- .../InlineResponse200ListGamesAnyOfDTO.java | 26 +-- .../assets/ApiTestInfoDTO.java | 1 - .../assets/ErrorDTO.java | 7 - .../assets/TestDTO.java | 7 - .../assets/TestInfoDTO.java | 1 + .../assets/model/FieldDTO.java | 146 ++++++------ .../assets/model/SchemaDTO.java | 9 +- .../assets/model/UnionFieldDTO.java | 5 +- .../assets/ApiArrayFieldDTO.java | 18 +- .../assets/ApiBooleanFieldDTO.java | 7 - .../assets/ApiDateFieldDTO.java | 8 - .../assets/ApiDefaultItemDTO.java | 211 ++++++++---------- .../assets/ApiEnumFieldDTO.java | 15 +- .../assets/ApiMapFieldDTO.java | 16 +- .../assets/ApiNumberFieldDTO.java | 18 +- .../assets/ApiObjectFieldDTO.java | 22 +- .../testComplexAnyOf/assets/ApiSchemaDTO.java | 44 +--- .../assets/ApiSequenceFieldDTO.java | 23 +- .../assets/ApiStringFieldDTO.java | 21 +- .../assets/ApiTypeArrayDTO.java | 207 ++++++++--------- .../assets/ApiUnionFieldDTO.java | 17 +- .../InlineResponse200CreateGameDTO.java | 8 +- .../assets/MessageDTO.java | 7 +- .../InlineResponse200ListGamesOneOfDTO.java | 26 +-- .../testSimpleBuild/api-rest.yaml | 15 +- .../assets/lombok/ApiErrorDTO.java | 6 +- .../assets/lombok/ApiTestAllOfDTO.java | 2 + .../assets/lombok/ApiTestDTO.java | 2 + .../assets/lombok/ApiTestInfoDTO.java | 2 + .../jakarta/MaxBigDecimal.java | 17 ++ .../jakarta/MaxBigDecimalValidator.java | 25 +++ .../customvalidator/jakarta/MaxDouble.java | 17 ++ .../jakarta/MaxDoubleValidator.java | 24 ++ .../customvalidator/jakarta/MaxFloat.java | 17 ++ .../jakarta/MaxFloatValidator.java | 24 ++ .../customvalidator/jakarta/MaxInteger.java | 4 +- .../jakarta/MaxIntegerValidator.java | 4 +- .../customvalidator/jakarta/MaxItems.java | 4 +- .../jakarta/MaxItemsValidator.java | 4 +- .../jakarta/MinBigDecimal.java | 17 ++ .../jakarta/MinBigDecimalValidator.java | 25 +++ .../customvalidator/jakarta/MinDouble.java | 17 ++ .../jakarta/MinDoubleValidator.java | 24 ++ .../customvalidator/jakarta/MinFloat.java | 17 ++ .../jakarta/MinFloatValidator.java | 24 ++ .../customvalidator/jakarta/MinInteger.java | 4 +- .../jakarta/MinIntegerValidator.java | 4 +- .../customvalidator/jakarta/MinItems.java | 4 +- .../jakarta/MinItemsValidator.java | 4 +- .../customvalidator/jakarta/MultipleOf.java | 6 +- .../jakarta/MultipleOfValidator.java | 4 +- .../customvalidator/jakarta/NotNull.java | 6 +- .../jakarta/NotNullValidator.java | 4 +- .../customvalidator/jakarta/Pattern.java | 6 +- .../jakarta/PatternValidator.java | 4 +- .../customvalidator/jakarta/Size.java | 6 +- .../jakarta/SizeValidator.java | 4 +- .../customvalidator/jakarta/UniqueItems.java | 6 +- .../jakarta/UniqueItemsValidator.java | 4 +- .../customvalidator/javax/MaxBigDecimal.java | 17 ++ .../javax/MaxBigDecimalValidator.java | 25 +++ .../customvalidator/javax/MaxDouble.java | 17 ++ .../javax/MaxDoubleValidator.java | 24 ++ .../customvalidator/javax/MaxFloat.java | 17 ++ .../javax/MaxFloatValidator.java | 24 ++ .../customvalidator/javax/MaxItems.java | 2 +- .../customvalidator/javax/MinBigDecimal.java | 17 ++ .../javax/MinBigDecimalValidator.java | 25 +++ .../customvalidator/javax/MinDouble.java | 17 ++ .../javax/MinDoubleValidator.java | 24 ++ .../customvalidator/javax/MinFloat.java | 17 ++ .../javax/MinFloatValidator.java | 24 ++ .../customvalidator/javax/MinItems.java | 2 +- .../customvalidator/javax/MultipleOf.java | 2 +- .../customvalidator/javax/NotNull.java | 2 +- .../customvalidator/javax/Pattern.java | 2 +- .../customvalidator/javax/Size.java | 2 +- .../customvalidator/javax/UniqueItems.java | 2 +- 86 files changed, 1038 insertions(+), 695 deletions(-) create mode 100644 multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/MaxBigDecimal.java create mode 100644 multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/MaxBigDecimalValidator.java create mode 100644 multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/MaxDouble.java create mode 100644 multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/MaxDoubleValidator.java create mode 100644 multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/MaxFloat.java create mode 100644 multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/MaxFloatValidator.java create mode 100644 multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/MinBigDecimal.java create mode 100644 multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/MinBigDecimalValidator.java create mode 100644 multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/MinDouble.java create mode 100644 multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/MinDoubleValidator.java create mode 100644 multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/MinFloat.java create mode 100644 multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/MinFloatValidator.java create mode 100644 multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/javax/MaxBigDecimal.java create mode 100644 multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/javax/MaxBigDecimalValidator.java create mode 100644 multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/javax/MaxDouble.java create mode 100644 multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/javax/MaxDoubleValidator.java create mode 100644 multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/javax/MaxFloat.java create mode 100644 multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/javax/MaxFloatValidator.java create mode 100644 multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/javax/MinBigDecimal.java create mode 100644 multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/javax/MinBigDecimalValidator.java create mode 100644 multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/javax/MinDouble.java create mode 100644 multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/javax/MinDoubleValidator.java create mode 100644 multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/javax/MinFloat.java create mode 100644 multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/javax/MinFloatValidator.java diff --git a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/template/CommonTemplateFactory.java b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/template/CommonTemplateFactory.java index 5a091439..d25080bc 100644 --- a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/template/CommonTemplateFactory.java +++ b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/template/CommonTemplateFactory.java @@ -239,6 +239,7 @@ protected void cleanData() { clearRoot(); addToRoot("checkBasicTypes", BASIC_DATA_TYPES); classTemplateList.clear(); + generateExceptionTemplate = false; } protected abstract void clearRoot(); diff --git a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/tools/MapperContentUtil.java b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/tools/MapperContentUtil.java index 744405f3..6371780a 100644 --- a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/tools/MapperContentUtil.java +++ b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/tools/MapperContentUtil.java @@ -15,7 +15,6 @@ public class MapperContentUtil { - private MapperContentUtil() { } diff --git a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/tools/MapperUtil.java b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/tools/MapperUtil.java index 7f95402d..2adb5c5b 100644 --- a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/tools/MapperUtil.java +++ b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/tools/MapperUtil.java @@ -62,6 +62,11 @@ public static String getRefSchemaKey(final JsonNode parameter) { return StringUtils.upperCase(pathObjectRef[pathObjectRef.length - 2] + "/" + StringCaseUtils.titleToSnakeCase(pathObjectRef[pathObjectRef.length - 1])); } + public static String getRefSchemaKey(final String parameter) { + final String[] pathObjectRef = parameter.split("/"); + return StringUtils.upperCase(pathObjectRef[pathObjectRef.length - 2] + "/" + getSchemaKey(pathObjectRef[pathObjectRef.length - 1])); + } + public static String getKeySchemaName(final String parameter) { return StringCaseUtils.toCamelCase(getKey(parameter)); } @@ -71,11 +76,6 @@ public static String getKey(final String keyString) { return pathObjectRef[pathObjectRef.length - 1]; } - public static String getRefSchemaKey(final String parameter) { - final String[] pathObjectRef = parameter.split("/"); - return StringUtils.upperCase(pathObjectRef[pathObjectRef.length - 2] + "/" + getSchemaKey(pathObjectRef[pathObjectRef.length - 1])); - } - public static String getSchemaKey(final String schemaName) { return StringCaseUtils.titleToSnakeCase(schemaName); } diff --git a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/tools/ModelBuilder.java b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/tools/ModelBuilder.java index a3135c66..e39b3675 100644 --- a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/tools/ModelBuilder.java +++ b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/tools/ModelBuilder.java @@ -23,35 +23,39 @@ public final class ModelBuilder { private static final String ADDITIONAL_PROPERTIES = "additionalProperties"; + private static final Map cachedSchemas = new HashMap<>(); public static SchemaObject buildSchemaObject( final Map totalSchemas, final String className, final JsonNode model, - final Set antiLoopList, final Map compositedSchemas, final String parentPackage, final CommonSpecFile specFile, - final Path baseDir) { + final Set antiLoopList, final Map compositedSchemas, final String parentPackage, + final CommonSpecFile specFile, final Path baseDir) { antiLoopList.add(WordUtils.capitalizeFully(className)); + final var schemaBuilder = SchemaObject.builder() + .schemaName(WordUtils.capitalizeFully(className)) + .className(MapperUtil.getPojoName(className, specFile)); - final var listSchema = getFields(null, totalSchemas, model, specFile, compositedSchemas, antiLoopList, WordUtils.capitalizeFully(className), baseDir); + if (!ApiTool.isEnum(model)) { + final var listSchema = getFields(null, totalSchemas, model, specFile, compositedSchemas, antiLoopList, WordUtils.capitalizeFully(className), baseDir); - final var schemaBuilder = SchemaObject.builder() - .schemaName(WordUtils.capitalizeFully(className)) - .className(MapperUtil.getPojoName(className, specFile)) - .importList(getImportList(listSchema, specFile.getModelPackage())); - - if (ApiTool.isAllOf(model)) { - schemaBuilder.schemaCombinator(ALL_OF_COMBINATOR); - } else if (ApiTool.isAnyOf(model)) { - schemaBuilder.schemaCombinator(ANY_OF_COMBINATOR); - } else if (ApiTool.isOneOf(model)) { - schemaBuilder.schemaCombinator(ONE_OF_COMBINATOR); - } else { - schemaBuilder.schemaCombinator(""); - } + schemaBuilder.importList(getImportList(listSchema, specFile.getModelPackage())); - return schemaBuilder - .fieldObjectList(listSchema) - .parentPackage(parentPackage.toLowerCase()) - .build(); + if (ApiTool.isAllOf(model)) { + schemaBuilder.schemaCombinator(ALL_OF_COMBINATOR); + } else if (ApiTool.isAnyOf(model)) { + schemaBuilder.schemaCombinator(ANY_OF_COMBINATOR); + } else if (ApiTool.isOneOf(model)) { + schemaBuilder.schemaCombinator(ONE_OF_COMBINATOR); + } else { + schemaBuilder.schemaCombinator(""); + } + + schemaBuilder + .fieldObjectList(listSchema) + .parentPackage(parentPackage.toLowerCase()); + } + cachedSchemas.putAll(compositedSchemas); + return schemaBuilder.build(); } private static List getImportList(final Set fieldObjectList, final String modelPackage) { @@ -233,20 +237,48 @@ private static List processObjectProperty(final String buildi final var refSchema = totalSchemas.get(MapperUtil.getRefSchemaKey(fieldBody)); if (!antiLoopList.contains(typeName) && Objects.nonNull(refSchema) && ApiTool.hasType(refSchema) && ApiTool.hasItems(refSchema) || ApiTool.getRefValue(fieldBody).contains(fieldName)) { + if (antiLoopList.contains(typeName) && ApiTool.getRefValue(fieldBody).contains(fieldName)) { + fieldObjectArrayList.add(SchemaFieldObject + .builder() + .baseName(fieldName) + .required(ApiTool.checkIfRequired(schema, fieldName)) + .dataType(SchemaFieldObjectType.fromTypeList(MapperUtil.getSimpleType(refSchema, specFile), + MapperUtil.getPojoName(typeName, specFile))) + .build()); + } else { antiLoopList.add(typeName); fieldObjectArrayList.addAll(processFieldObjectList(buildingSchema, fieldName, typeName, refSchema, specFile, totalSchemas, compositedSchemas, antiLoopList, baseDir)); + } } else if (ApiTool.isEnum(refSchema)) { fieldObjectArrayList.add(processEnumField(fieldName, refSchema, specFile, ApiTool.getEnumValues(refSchema), schema)); - } else { - compositedSchemas.put(typeName, buildSchemaObject(totalSchemas, typeName, refSchema, antiLoopList, compositedSchemas, "", specFile, baseDir )); + } else if (ApiTool.isObject(refSchema) || ApiTool.isComposed(refSchema)) { + compositedSchemas.put(typeName, buildSchemaObject(totalSchemas, typeName, refSchema, antiLoopList, compositedSchemas, "", specFile, baseDir )); + fieldObjectArrayList.add(SchemaFieldObject + .builder() + .baseName(fieldName) + .required(ApiTool.checkIfRequired(schema, fieldName)) + .dataType(SchemaFieldObjectType.fromTypeList(MapperUtil.getSimpleType(refSchema, specFile), + MapperUtil.getPojoName(typeName, specFile))) + .build()); + } else if (ApiTool.isBoolean(refSchema) || ApiTool.isString(refSchema) || ApiTool.isNumber(refSchema) || ApiTool.isDateTime(refSchema)) { fieldObjectArrayList.add(SchemaFieldObject - .builder() - .baseName(fieldName) - .required(ApiTool.checkIfRequired(schema, fieldName)) - .dataType(SchemaFieldObjectType.fromTypeList(MapperUtil.getSimpleType(refSchema, specFile), - MapperUtil.getPojoName(typeName, specFile))) - .build()); + .builder() + .baseName(fieldName) + .required(ApiTool.checkIfRequired(schema, fieldName)) + .dataType(new SchemaFieldObjectType(MapperUtil.getSimpleType(refSchema, specFile))) + .constValue(ApiTool.getConst(refSchema)) + .build()); + } else if (antiLoopList.contains(typeName)) { + if (cachedSchemas.containsKey(typeName)) { + fieldObjectArrayList.add(SchemaFieldObject + .builder() + .baseName(fieldName) + .required(ApiTool.checkIfRequired(schema, fieldName)) + .dataType(SchemaFieldObjectType.fromTypeList(MapperUtil.getSimpleType(refSchema, specFile), + MapperUtil.getPojoName(typeName, specFile))) + .build()); + } } } else if (ApiTool.isEnum(fieldBody)) { fieldObjectArrayList.add(processEnumField(fieldName, fieldBody, specFile, ApiTool.getEnumValues(fieldBody), fieldBody)); @@ -611,7 +643,6 @@ private static Set processAllOf( for (JsonNode ref : schemaList) { if (ApiTool.hasRef(ref)) { - final String schemaName = MapperUtil.getRefSchemaName(ref); final var schemaToProcess = totalSchemas.get(MapperUtil.getRefSchemaKey(ref)); ApiTool.getProperties(schemaToProcess).forEachRemaining(processProperties("", totalSchemas, compositedSchemas, fieldObjectArrayList, specFile, ref, antiLoopList, baseDir)); for (var fieldObject : fieldObjectArrayList) { @@ -635,9 +666,8 @@ private static Set processAnyOfOneOf(final String buildingSch antiLoopList.add(schemaName); fieldObjectArrayList.addAll(compositedSchemas.get(schemaName).getFieldObjectList()); } else { - final var schemaObject = solveRef(internalSchema, totalSchemas, compositedSchemas, antiLoopList, specFile, baseDir); - compositedSchemas.put(schemaName, schemaObject); antiLoopList.add(schemaName); + final var schemaObject = solveRef(internalSchema, totalSchemas, compositedSchemas, antiLoopList, specFile, baseDir); fieldObjectArrayList.addAll(schemaObject.getFieldObjectList()); } } else if (compositedSchemas.containsKey(schemaName)) { 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 index 02db5c74..4df9225e 100644 --- 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 @@ -22,9 +22,8 @@ public static JsonNode solveRef(final String refValue, final Map mapRequestObject( "InlineObject" + operationIdWithCap, globalObject, baseDir)) .build()); } else { - final var requestBodyNode = globalObject.getRequestBodyNode(MapperUtil.getRefSchemaName(requestBody)).orElseThrow(); + final var requestBodyNode = globalObject.getRequestBodyNode(MapperUtil.getRefSchemaKey(requestBody)).orElseThrow(); requestObjects.add(RequestObject.builder() .required(ApiTool.hasNode(requestBody, REQUIRED)) .contentObjects(mapContentObject(specFile, ApiTool.getNode(requestBodyNode, CONTENT), @@ -222,7 +222,7 @@ private static List mapParameterObjects( if (Objects.nonNull(parameters) && !parameters.isEmpty()) { for (final JsonNode parameter : parameters) { if (ApiTool.hasRef(parameter)) { - final JsonNode refParameter = globalObject.getParameterNode(MapperUtil.getRefSchemaName(parameter)).orElseThrow(); + final JsonNode refParameter = globalObject.getParameterNode(MapperUtil.getRefSchemaKey(parameter)).orElseThrow(); parameterObjects.add(buildParameterObject(specFile, globalObject, refParameter, baseDir)); } else if (ApiTool.hasNode(parameter, CONTENT)) { parameterObjects.addAll(buildParameterContent(contentClassName, parameter, specFile, globalObject, baseDir)); @@ -384,8 +384,7 @@ private static SchemaFieldObjectType getSchemaType( if (ApiTool.hasRef(schema)) { final String refSchemaPojoName = MapperUtil.getRef(schema, specFile); - final JsonNode refSchema = SchemaUtil.solveRef(ApiTool.getRefValue(schema), globalObject.getSchemaMap(), - baseDir.resolve(specFile.getFilePath()).getParent()); + final JsonNode refSchema = getRefSchema(schema, specFile, globalObject, baseDir); type = getSchemaType(refSchema, refSchemaPojoName, specFile, globalObject, baseDir); } else if (ApiTool.hasAdditionalProperties(schema)) { type = getMapSchemaType(schema, pojoName, specFile, globalObject, baseDir); @@ -400,6 +399,25 @@ private static SchemaFieldObjectType getSchemaType( return type; } + private static JsonNode getRefSchema(JsonNode schema, SpecFile specFile, GlobalObject globalObject, Path baseDir) { + JsonNode refSchema = null; + final String refValue = ApiTool.getRefValue(schema); + if (refValue.contains("schemas")) { + refSchema = SchemaUtil.solveRef(ApiTool.getRefValue(schema), globalObject.getSchemaMap(), + baseDir.resolve(specFile.getFilePath()).getParent()); + } else if (refValue.contains("requestBodies")) { + refSchema = SchemaUtil.solveRef(ApiTool.getRefValue(schema), globalObject.getRequestBodyMap(), + baseDir.resolve(specFile.getFilePath()).getParent()); + } else if (refValue.contains("parameters")) { + refSchema = SchemaUtil.solveRef(ApiTool.getRefValue(schema), globalObject.getParameterMap(), + baseDir.resolve(specFile.getFilePath()).getParent()); + } else if (refValue.contains("responseBodies")) { + refSchema = SchemaUtil.solveRef(ApiTool.getRefValue(schema), globalObject.getResponseMap(), + baseDir.resolve(specFile.getFilePath()).getParent()); + } + return refSchema; + } + private static SchemaFieldObjectType getObjectOrType( final JsonNode schema, final String pojoName, final SpecFile specFile, final GlobalObject globalObject, final Path baseDir) { diff --git a/multiapi-engine/src/main/resources/templates/model/templateSchemaWithLombok.ftlh b/multiapi-engine/src/main/resources/templates/model/templateSchemaWithLombok.ftlh index eb404252..a4a3c6bb 100644 --- a/multiapi-engine/src/main/resources/templates/model/templateSchemaWithLombok.ftlh +++ b/multiapi-engine/src/main/resources/templates/model/templateSchemaWithLombok.ftlh @@ -167,9 +167,6 @@ import lombok.Singular; import lombok.Value; import lombok.extern.jackson.Jacksonized; -<#if schema.schemaCombinator == "anyOf" || schema.schemaCombinator == "oneOf"> -import ${packageModel}.exception.ModelClassException; - @Value public class ${schema.className} { diff --git a/multiapi-engine/src/test/java/com/sngular/api/generator/plugin/openapi/OpenApiGeneratorFixtures.java b/multiapi-engine/src/test/java/com/sngular/api/generator/plugin/openapi/OpenApiGeneratorFixtures.java index 9dd1cff0..d203119d 100644 --- a/multiapi-engine/src/test/java/com/sngular/api/generator/plugin/openapi/OpenApiGeneratorFixtures.java +++ b/multiapi-engine/src/test/java/com/sngular/api/generator/plugin/openapi/OpenApiGeneratorFixtures.java @@ -531,7 +531,7 @@ static Function validateOneOfInResponse() { final List expectedExceptionFiles = List.of( ASSETS_PATH + "ModelClassException.java"); - return (path) -> commonTest(path, expectedTestApiFile, expectedTestApiModelFiles, DEFAULT_TARGET_API, DEFAULT_MODEL_API, expectedExceptionFiles, DEFAULT_EXCEPTION_API); + return path -> commonTest(path, expectedTestApiFile, expectedTestApiModelFiles, DEFAULT_TARGET_API, DEFAULT_MODEL_API, expectedExceptionFiles, DEFAULT_EXCEPTION_API); } static Function validateAllOf() { @@ -560,7 +560,7 @@ static Function validateAllOf() { final List expectedExceptionFiles = List.of( ASSETS_PATH + "ModelClassException.java"); - return (path) -> commonTest(path, expectedTestApiFile, expectedTestApiModelFiles, DEFAULT_TARGET_API, DEFAULT_MODEL_API, expectedExceptionFiles, DEFAULT_EXCEPTION_API); + return path -> commonTest(path, expectedTestApiFile, expectedTestApiModelFiles, DEFAULT_TARGET_API, DEFAULT_MODEL_API, expectedExceptionFiles, DEFAULT_EXCEPTION_API); } static Function validateComplexAnyOf() { @@ -598,7 +598,7 @@ static Function validateComplexAnyOf() { final List expectedExceptionFiles = List.of( ASSETS_PATH + "ModelClassException.java"); - return (path) -> commonTest(path, expectedTestApiFile, expectedTestApiModelFiles, DEFAULT_TARGET_API, DEFAULT_MODEL_API, expectedExceptionFiles, DEFAULT_EXCEPTION_API); + return path -> commonTest(path, expectedTestApiFile, expectedTestApiModelFiles, DEFAULT_TARGET_API, DEFAULT_MODEL_API, expectedExceptionFiles, DEFAULT_EXCEPTION_API); } static Function validateAllOfLombok() { @@ -622,7 +622,7 @@ static Function validateAllOfLombok() { ); - return (path) -> commonTest(path, expectedTestApiFile, expectedTestApiModelFiles, DEFAULT_LOMBOK_TARGET_API, DEFAULT_LOMBOK_MODEL_API, Collections.emptyList(), null); + return path -> commonTest(path, expectedTestApiFile, expectedTestApiModelFiles, DEFAULT_LOMBOK_TARGET_API, DEFAULT_LOMBOK_MODEL_API, Collections.emptyList(), null); } static Function validateOverwriteModeTrue() { @@ -649,7 +649,7 @@ static Function validateOverwriteModeTrue() { final List expectedExceptionFiles = List.of( ASSETS_PATH + "exception/ModelClassException.java"); - return (path) -> commonTest(path, expectedTestApiFile, expectedTestApiModelFiles, DEFAULT_TARGET_API, DEFAULT_MODEL_API, expectedExceptionFiles, DEFAULT_EXCEPTION_API); + return path -> commonTest(path, expectedTestApiFile, expectedTestApiModelFiles, DEFAULT_TARGET_API, DEFAULT_MODEL_API, expectedExceptionFiles, DEFAULT_EXCEPTION_API); } @@ -672,7 +672,7 @@ static Function validateApiClientGeneration() { ASSETS_PATH + "ApiTestInfoDTO.java" ); - return (path) -> commonTest(path, expectedTestApiFile, expectedTestApiModelFiles, DEFAULT_TARGET_API, DEFAULT_MODEL_API, Collections.emptyList(), null); + return path -> commonTest(path, expectedTestApiFile, expectedTestApiModelFiles, DEFAULT_TARGET_API, DEFAULT_MODEL_API, Collections.emptyList(), null); } @@ -698,7 +698,7 @@ static Function validateInlineSchemaCreation() { ASSETS_PATH + "ApiTestTypeDTO.java" ); - return (path) -> commonTest(path, expectedTestApiFile, expectedTestApiModelFiles, DEFAULT_TARGET_API, DEFAULT_MODEL_API, Collections.emptyList(), null); + return path -> commonTest(path, expectedTestApiFile, expectedTestApiModelFiles, DEFAULT_TARGET_API, DEFAULT_MODEL_API, Collections.emptyList(), null); } static Function validateParametersWithSchemaGeneration() { @@ -720,7 +720,7 @@ static Function validateParametersWithSchemaGeneration() { ASSETS_PATH + "ApiTestInfoDTO.java" ); - return (path) -> commonTest(path, expectedTestApiFile, expectedTestApiModelFiles, DEFAULT_TARGET_API, DEFAULT_MODEL_API, Collections.emptyList(), null); + return path -> commonTest(path, expectedTestApiFile, expectedTestApiModelFiles, DEFAULT_TARGET_API, DEFAULT_MODEL_API, Collections.emptyList(), null); } static Function validatePathWithSpecialCharGeneration() { @@ -744,7 +744,7 @@ static Function validatePathWithSpecialCharGeneration() { ASSETS_PATH + "ApiTestInfoDTO.java" ); - return (path) -> commonTest(path, expectedTestApiFile, expectedTestApiModelFiles, DEFAULT_TARGET_API, DEFAULT_MODEL_API, Collections.emptyList(), null); + return path -> commonTest(path, expectedTestApiFile, expectedTestApiModelFiles, DEFAULT_TARGET_API, DEFAULT_MODEL_API, Collections.emptyList(), null); } @@ -768,7 +768,7 @@ static Function validateApiReactiveGeneration(int springBootVersi ASSETS_PATH + "ApiTestInfoDTO.java" ); - return (path) -> commonTest(path, expectedTestApiFile, expectedTestApiModelFiles, DEFAULT_TARGET_API, DEFAULT_MODEL_API, Collections.emptyList(), null); + return path -> commonTest(path, expectedTestApiFile, expectedTestApiModelFiles, DEFAULT_TARGET_API, DEFAULT_MODEL_API, Collections.emptyList(), null); } @@ -793,7 +793,7 @@ static Function validateTagsGeneration() { ASSETS_PATH + "TestInfoDTO.java" ); - return (path) -> commonTest(path, expectedTestApiFile, expectedTestApiModelFiles, DEFAULT_TARGET_API, DEFAULT_MODEL_API, Collections.emptyList(), null); + return path -> commonTest(path, expectedTestApiFile, expectedTestApiModelFiles, DEFAULT_TARGET_API, DEFAULT_MODEL_API, Collections.emptyList(), null); } @@ -816,7 +816,7 @@ static Function validateMultipleRefGeneration() { ASSETS_PATH + "MessageDTO.java" ); - return (path) -> commonTest(path, expectedTestApiFile, expectedTestApiModelFiles, DEFAULT_TARGET_API, DEFAULT_MODEL_API, Collections.emptyList(), null); + return path -> commonTest(path, expectedTestApiFile, expectedTestApiModelFiles, DEFAULT_TARGET_API, DEFAULT_MODEL_API, Collections.emptyList(), null); } @@ -840,7 +840,7 @@ static Function validatePathParameterGeneration() { ASSETS_PATH + "TestInfoDTO.java" ); - return (path) -> commonTest(path, expectedTestApiFile, expectedTestApiModelFiles, DEFAULT_TARGET_API, DEFAULT_MODEL_API, Collections.emptyList(), null); + return path -> commonTest(path, expectedTestApiFile, expectedTestApiModelFiles, DEFAULT_TARGET_API, DEFAULT_MODEL_API, Collections.emptyList(), null); } @@ -864,7 +864,7 @@ static Function validateWebClientGeneration() { ASSETS_PATH + "ApiTestInfoDTO.java" ); - return (path) -> commonTest(path, expectedTestApiFile, expectedTestApiModelFiles, DEFAULT_TARGET_API, DEFAULT_MODEL_API, Collections.emptyList(), null); + return path -> commonTest(path, expectedTestApiFile, expectedTestApiModelFiles, DEFAULT_TARGET_API, DEFAULT_MODEL_API, Collections.emptyList(), null); } @@ -892,7 +892,7 @@ static Function validateClientPackageWebClientGeneration() { final List expectedExceptionFiles = List.of( ASSETS_PATH + "ModelClassException.java"); - return (path) -> commonTest(path, expectedTestApiFile, expectedTestApiModelFiles, DEFAULT_TARGET_API, DEFAULT_MODEL_API, expectedExceptionFiles, DEFAULT_EXCEPTION_API); + return path -> commonTest(path, expectedTestApiFile, expectedTestApiModelFiles, DEFAULT_TARGET_API, DEFAULT_MODEL_API, expectedExceptionFiles, DEFAULT_EXCEPTION_API); } @@ -921,7 +921,7 @@ static Function validateRestClientGeneration() { ASSETS_PATH + "client/auth/HttpBasicAuth.java" ); - return (path) -> + return path -> commonTest(path, expectedTestApiFile, Collections.emptyList(), DEFAULT_TARGET_API, null, Collections.emptyList(), null) && commonTest(path, expectedTestClientApiFile, expectedTestClientAuthModelFiles, CLIENT_TARGET_API, CLIENT_MODEL_API, Collections.emptyList(), null); } @@ -951,7 +951,7 @@ static Function validateRestClientWithRequestBodyGeneration() { ASSETS_PATH + "client/auth/HttpBasicAuth.java" ); - return (path) -> + return path -> commonTest(path, expectedTestApiFile, Collections.emptyList(), DEFAULT_TARGET_API, null, Collections.emptyList(), null) && commonTest(path, expectedTestClientApiFile, expectedTestClientAuthModelFiles, CLIENT_TARGET_API, CLIENT_MODEL_API, Collections.emptyList(), null); } @@ -981,7 +981,7 @@ static Function validateEnumsGeneration() { final List expectedExceptionFiles = List.of( "openapigenerator/testApiEnumsGeneration/assets/ModelClassException.java"); - return (path) -> commonTest(path, expectedTestApiFile, expectedTestApiModelFiles, DEFAULT_TARGET_API, DEFAULT_MODEL_API, expectedExceptionFiles, DEFAULT_EXCEPTION_API); + return path -> commonTest(path, expectedTestApiFile, expectedTestApiModelFiles, DEFAULT_TARGET_API, DEFAULT_MODEL_API, expectedExceptionFiles, DEFAULT_EXCEPTION_API); } static Function validateEnumsLombokGeneration() { @@ -1004,7 +1004,7 @@ static Function validateEnumsLombokGeneration() { ); - return (path) -> commonTest(path, expectedTestApiFile, expectedTestApiModelFiles, DEFAULT_TARGET_API, DEFAULT_MODEL_API, Collections.emptyList(), null); + return path -> commonTest(path, expectedTestApiFile, expectedTestApiModelFiles, DEFAULT_TARGET_API, DEFAULT_MODEL_API, Collections.emptyList(), null); } static Function validateExternalRefGeneration() { @@ -1029,7 +1029,7 @@ static Function validateExternalRefGeneration() { final List expectedExceptionFiles = List.of( ASSETS_PATH + "ModelClassException.java"); - return (path) -> commonTest(path, expectedTestApiFile, expectedTestApiModelFiles, DEFAULT_TARGET_API, DEFAULT_MODEL_API, expectedExceptionFiles, DEFAULT_EXCEPTION_API); + return path -> commonTest(path, expectedTestApiFile, expectedTestApiModelFiles, DEFAULT_TARGET_API, DEFAULT_MODEL_API, expectedExceptionFiles, DEFAULT_EXCEPTION_API); } static Function validateAnyOfInResponse() { @@ -1057,7 +1057,7 @@ static Function validateAnyOfInResponse() { final List expectedExceptionFiles = List.of( ASSETS_PATH + "ModelClassException.java"); - return (path) -> commonTest(path, expectedTestApiFile, expectedTestApiModelFiles, DEFAULT_TARGET_API, DEFAULT_MODEL_API, expectedExceptionFiles, DEFAULT_EXCEPTION_API); + return path -> commonTest(path, expectedTestApiFile, expectedTestApiModelFiles, DEFAULT_TARGET_API, DEFAULT_MODEL_API, expectedExceptionFiles, DEFAULT_EXCEPTION_API); } static Function validateAdditionalProperties() { @@ -1074,7 +1074,7 @@ static Function validateAdditionalProperties() { final List expectedTestApiModelFiles = List.of(ASSETS_PATH + "TestDTO.java"); - return (path) -> commonTest(path, expectedTestApiFile, expectedTestApiModelFiles, DEFAULT_TARGET_API, DEFAULT_MODEL_API, Collections.emptyList(), null); + return path -> commonTest(path, expectedTestApiFile, expectedTestApiModelFiles, DEFAULT_TARGET_API, DEFAULT_MODEL_API, Collections.emptyList(), null); } static Function validateAdditionalPropertiesWithSchema() { @@ -1094,7 +1094,7 @@ static Function validateAdditionalPropertiesWithSchema() { ASSETS_PATH + "TestDTO.java" ); - return (path) -> commonTest(path, expectedTestApiFile, expectedTestApiModelFiles, DEFAULT_TARGET_API, DEFAULT_MODEL_API, Collections.emptyList(), null); + return path -> commonTest(path, expectedTestApiFile, expectedTestApiModelFiles, DEFAULT_TARGET_API, DEFAULT_MODEL_API, Collections.emptyList(), null); } static Function validateAdditionalPropertiesWithUnnamedObject() { @@ -1119,7 +1119,7 @@ static Function validateAdditionalPropertiesWithUnnamedObject() { ASSETS_PATH + "ThirdTestDTO.java" ); - return (path) -> commonTest(path, expectedTestApiFile, expectedTestApiModelFiles, DEFAULT_TARGET_API, DEFAULT_MODEL_API, Collections.emptyList(), null); + return path -> commonTest(path, expectedTestApiFile, expectedTestApiModelFiles, DEFAULT_TARGET_API, DEFAULT_MODEL_API, Collections.emptyList(), null); } static Function validateCoconutSchema() { @@ -1158,7 +1158,7 @@ static Function validateCoconutSchema() { final List expectedExceptionFiles = List.of( ASSETS_PATH + "exception/ModelClassException.java"); - return (path) -> commonTest(path, expectedTestApiFile, expectedTestApiModelFiles, DEFAULT_TARGET_API, DEFAULT_MODEL_API, expectedExceptionFiles, DEFAULT_EXCEPTION_API); + return path -> commonTest(path, expectedTestApiFile, expectedTestApiModelFiles, DEFAULT_TARGET_API, DEFAULT_MODEL_API, expectedExceptionFiles, DEFAULT_EXCEPTION_API); } static Function validateRestrictionsSchema() { @@ -1199,7 +1199,7 @@ static Function validateRestrictionsSchema() { final List expectedExceptionFiles = List.of( ASSETS_PATH + "exception/ModelClassException.java"); - return (path) -> commonTest(path, expectedTestApiFile, expectedTestApiModelFiles, DEFAULT_TARGET_API, DEFAULT_MODEL_API, expectedExceptionFiles, DEFAULT_EXCEPTION_API); + return path -> commonTest(path, expectedTestApiFile, expectedTestApiModelFiles, DEFAULT_TARGET_API, DEFAULT_MODEL_API, expectedExceptionFiles, DEFAULT_EXCEPTION_API); } static Function validateSimpleBuild() { @@ -1234,7 +1234,7 @@ static Function validateSimpleBuild() { ASSETS_PATH + "model/UpdateQuoteDTO.java" ); - return (path) -> commonTest(path, expectedTestApiFile, expectedTestApiModelFiles, DEFAULT_TARGET_API, DEFAULT_MODEL_API, Collections.emptyList(), null); + return path -> commonTest(path, expectedTestApiFile, expectedTestApiModelFiles, DEFAULT_TARGET_API, DEFAULT_MODEL_API, Collections.emptyList(), null); } static Function validateValidationAnnotations(int springBootVersion) { @@ -1266,14 +1266,26 @@ static Function validateValidationAnnotations(int springBootVersi ASSETS_PATH + "ModelClassException.java"); final List expectedValidatorFiles = List.of( - CUSTOM_VALIDATOR_PATH + "MaxInteger.java", - CUSTOM_VALIDATOR_PATH + "MaxItems.java", - CUSTOM_VALIDATOR_PATH + "MaxItemsValidator.java", - CUSTOM_VALIDATOR_PATH + "MaxIntegerValidator.java", - CUSTOM_VALIDATOR_PATH + "MinInteger.java", - CUSTOM_VALIDATOR_PATH + "MinItems.java", - CUSTOM_VALIDATOR_PATH + "MinItemsValidator.java", - CUSTOM_VALIDATOR_PATH + "MinIntegerValidator.java", + CUSTOM_VALIDATOR_PATH + "MaxBigDecimal.java", + CUSTOM_VALIDATOR_PATH + "MaxBigDecimalValidator.java", + CUSTOM_VALIDATOR_PATH + "MaxDouble.java", + CUSTOM_VALIDATOR_PATH + "MaxDoubleValidator.java", + CUSTOM_VALIDATOR_PATH + "MaxFloat.java", + CUSTOM_VALIDATOR_PATH + "MaxFloatValidator.java", + CUSTOM_VALIDATOR_PATH + "MaxInteger.java", + CUSTOM_VALIDATOR_PATH + "MaxIntegerValidator.java", + CUSTOM_VALIDATOR_PATH + "MaxItems.java", + CUSTOM_VALIDATOR_PATH + "MaxItemsValidator.java", + CUSTOM_VALIDATOR_PATH + "MinBigDecimal.java", + CUSTOM_VALIDATOR_PATH + "MinBigDecimalValidator.java", + CUSTOM_VALIDATOR_PATH + "MinDouble.java", + CUSTOM_VALIDATOR_PATH + "MinDoubleValidator.java", + CUSTOM_VALIDATOR_PATH + "MinFloat.java", + CUSTOM_VALIDATOR_PATH + "MinFloatValidator.java", + CUSTOM_VALIDATOR_PATH + "MinInteger.java", + CUSTOM_VALIDATOR_PATH + "MinIntegerValidator.java", + CUSTOM_VALIDATOR_PATH + "MinItems.java", + CUSTOM_VALIDATOR_PATH + "MinItemsValidator.java", CUSTOM_VALIDATOR_PATH + "MultipleOf.java", CUSTOM_VALIDATOR_PATH + "MultipleOfValidator.java", CUSTOM_VALIDATOR_PATH + "NotNull.java", @@ -1286,7 +1298,7 @@ static Function validateValidationAnnotations(int springBootVersi CUSTOM_VALIDATOR_PATH + "UniqueItemsValidator.java" ); - return (path) -> commonTest(path, expectedTestApiFile, expectedTestApiModelFiles, DEFAULT_TARGET_API, DEFAULT_MODEL_API, expectedExceptionFiles, DEFAULT_EXCEPTION_API) + return path -> commonTest(path, expectedTestApiFile, expectedTestApiModelFiles, DEFAULT_TARGET_API, DEFAULT_MODEL_API, expectedExceptionFiles, DEFAULT_EXCEPTION_API) && customValidatorTest(path, expectedValidatorFiles); } @@ -1311,7 +1323,7 @@ static Function validateValidationAnnotationsLombok(int springBoo ); - return (path) -> commonTest(path, expectedTestApiFile, expectedTestApiModelFiles, DEFAULT_LOMBOK_TARGET_API, DEFAULT_LOMBOK_MODEL_API, Collections.emptyList(), null); + return path -> commonTest(path, expectedTestApiFile, expectedTestApiModelFiles, DEFAULT_LOMBOK_TARGET_API, DEFAULT_LOMBOK_MODEL_API, Collections.emptyList(), null); } static Function validateCreateDTO() { @@ -1336,7 +1348,7 @@ static Function validateCreateDTO() { ASSETS_PATH + "model/TestDTO.java" ); - return (path) -> commonTest(path, expectedTestApiFile, expectedTestApiModelFiles, DEFAULT_TARGET_API, DEFAULT_MODEL_API, Collections.emptyList(), DEFAULT_EXCEPTION_API); + return path -> commonTest(path, expectedTestApiFile, expectedTestApiModelFiles, DEFAULT_TARGET_API, DEFAULT_MODEL_API, Collections.emptyList(), DEFAULT_EXCEPTION_API); } static Function validateCreateBasicDTO() { @@ -1360,7 +1372,7 @@ static Function validateCreateBasicDTO() { ASSETS_PATH + "model/TestDTO.java" ); - return (path) -> commonTest(path, expectedTestApiFile, expectedTestApiModelFiles, DEFAULT_TARGET_API, DEFAULT_MODEL_API, Collections.emptyList(), DEFAULT_EXCEPTION_API); + return path -> commonTest(path, expectedTestApiFile, expectedTestApiModelFiles, DEFAULT_TARGET_API, DEFAULT_MODEL_API, Collections.emptyList(), DEFAULT_EXCEPTION_API); } static Function validateIssueFaker() { @@ -1385,7 +1397,7 @@ static Function validateIssueFaker() { ASSETS_PATH + "model/SchemaDTO.java" ); - return (path) -> commonTest(path, expectedTestApiFile, expectedTestApiModelFiles, DEFAULT_TARGET_API, DEFAULT_MODEL_API, Collections.emptyList(), null); + return path -> commonTest(path, expectedTestApiFile, expectedTestApiModelFiles, DEFAULT_TARGET_API, DEFAULT_MODEL_API, Collections.emptyList(), null); } static Function validateDateTime() { @@ -1403,7 +1415,7 @@ static Function validateDateTime() { "openapigenerator/testDateTime/assets/model/TestDateDTO.java" ); - return (path) -> commonTest(path, expectedTestApiFile, expectedTestApiModelFiles, DEFAULT_TARGET_API, DEFAULT_MODEL_API, Collections.emptyList(), DEFAULT_EXCEPTION_API); + return path -> commonTest(path, expectedTestApiFile, expectedTestApiModelFiles, DEFAULT_TARGET_API, DEFAULT_MODEL_API, Collections.emptyList(), DEFAULT_EXCEPTION_API); } static Function validateDateTimeZoned() { @@ -1421,7 +1433,7 @@ static Function validateDateTimeZoned() { "openapigenerator/testDateTimeZoned/assets/model/TestDateDTO.java" ); - return (path) -> commonTest(path, expectedTestApiFile, expectedTestApiModelFiles, DEFAULT_TARGET_API, DEFAULT_MODEL_API, Collections.emptyList(), DEFAULT_EXCEPTION_API); + return path -> commonTest(path, expectedTestApiFile, expectedTestApiModelFiles, DEFAULT_TARGET_API, DEFAULT_MODEL_API, Collections.emptyList(), DEFAULT_EXCEPTION_API); } static Function validateDateTimeOffset() { @@ -1439,7 +1451,7 @@ static Function validateDateTimeOffset() { "openapigenerator/testDateTimeOffset/assets/model/TestDateDTO.java" ); - return (path) -> commonTest(path, expectedTestApiFile, expectedTestApiModelFiles, DEFAULT_TARGET_API, DEFAULT_MODEL_API, Collections.emptyList(), DEFAULT_EXCEPTION_API); + return path -> commonTest(path, expectedTestApiFile, expectedTestApiModelFiles, DEFAULT_TARGET_API, DEFAULT_MODEL_API, Collections.emptyList(), DEFAULT_EXCEPTION_API); } static Function validateListString() { @@ -1457,7 +1469,7 @@ static Function validateListString() { final List expectedTestApiModelFiles = List.of( ); - return (path) -> commonTest(path, expectedTestApiFiles, expectedTestApiModelFiles, DEFAULT_TARGET_API, DEFAULT_MODEL_API, Collections.emptyList(), DEFAULT_EXCEPTION_API); + return path -> commonTest(path, expectedTestApiFiles, expectedTestApiModelFiles, DEFAULT_TARGET_API, DEFAULT_MODEL_API, Collections.emptyList(), DEFAULT_EXCEPTION_API); } static Function validateReferenceFile() { @@ -1475,7 +1487,7 @@ static Function validateReferenceFile() { "openapigenerator/testReferenceFile/assets/TestDTO.java" ); - return (path) -> commonTest(path, expectedTestApiFiles, expectedTestApiModelFiles, DEFAULT_TARGET_API, DEFAULT_MODEL_API, Collections.emptyList(), DEFAULT_EXCEPTION_API); + return path -> commonTest(path, expectedTestApiFiles, expectedTestApiModelFiles, DEFAULT_TARGET_API, DEFAULT_MODEL_API, Collections.emptyList(), DEFAULT_EXCEPTION_API); } static Function validateQueryParam() { @@ -1492,7 +1504,7 @@ static Function validateQueryParam() { final List expectedTestApiModelFiles = List.of( ); - return (path) -> commonTest(path, expectedTestApiFiles, expectedTestApiModelFiles, DEFAULT_TARGET_API, DEFAULT_MODEL_API, Collections.emptyList(), DEFAULT_EXCEPTION_API); + return path -> commonTest(path, expectedTestApiFiles, expectedTestApiModelFiles, DEFAULT_TARGET_API, DEFAULT_MODEL_API, Collections.emptyList(), DEFAULT_EXCEPTION_API); } static Function validateApiWithNoComponents() { @@ -1509,7 +1521,7 @@ static Function validateApiWithNoComponents() { final List expectedTestApiModelFiles = List.of( ); - return (path) -> commonTest(path, expectedTestApiFiles, expectedTestApiModelFiles, DEFAULT_TARGET_API, DEFAULT_MODEL_API, Collections.emptyList(), DEFAULT_EXCEPTION_API); + return path -> commonTest(path, expectedTestApiFiles, expectedTestApiModelFiles, DEFAULT_TARGET_API, DEFAULT_MODEL_API, Collections.emptyList(), DEFAULT_EXCEPTION_API); } diff --git a/multiapi-engine/src/test/resources/openapigenerator/testAnyOfInResponse/assets/InlineResponse200ListGamesAnyOfDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testAnyOfInResponse/assets/InlineResponse200ListGamesAnyOfDTO.java index e75cc2e8..1e865c9c 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testAnyOfInResponse/assets/InlineResponse200ListGamesAnyOfDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testAnyOfInResponse/assets/InlineResponse200ListGamesAnyOfDTO.java @@ -4,12 +4,12 @@ import com.fasterxml.jackson.annotation.JsonProperty; import java.util.List; import java.util.ArrayList; +import com.sngular.multifileplugin.testanyofinresponse.model.exception.ModelClassException; import lombok.Builder; import lombok.NonNull; import lombok.Singular; import lombok.Value; import lombok.extern.jackson.Jacksonized; -import com.sngular.multifileplugin.testanyofinresponse.model.exception.ModelClassException; @Value public class InlineResponse200ListGamesAnyOfDTO { @@ -50,20 +50,20 @@ private InlineResponse200ListGamesAnyOfDTO(@NonNull String gameName, @NonNull St private void validatePartialCombinations() { boolean satisfiedCondition = false; - if (Objects.nonNull(this.gameName)) { - satisfiedCondition = true; - } else if (Objects.nonNull(this.name)) { - satisfiedCondition = true; - } else if (Objects.nonNull(this.id)) { - satisfiedCondition = true; - } else if (Objects.nonNull(this.rooms)) { - satisfiedCondition = true; - } else if (Objects.nonNull(this.players)) { - satisfiedCondition = true; - } + if (Objects.nonNull(this.gameName)) { + satisfiedCondition = true; + } else if (Objects.nonNull(this.name)) { + satisfiedCondition = true; + } else if (Objects.nonNull(this.id)) { + satisfiedCondition = true; + } else if (Objects.nonNull(this.rooms)) { + satisfiedCondition = true; + } else if (Objects.nonNull(this.players)) { + satisfiedCondition = true; + } if (!satisfiedCondition) { - throw new ModelClassException("InlineResponse200ListGamesAnyOfDTO"); + throw new ModelClassException("InlineResponse200ListGamesAnyOfDTO"); } } } diff --git a/multiapi-engine/src/test/resources/openapigenerator/testApiEnumsGeneration/assets/ApiTestInfoDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testApiEnumsGeneration/assets/ApiTestInfoDTO.java index deca06c2..16475f30 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testApiEnumsGeneration/assets/ApiTestInfoDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testApiEnumsGeneration/assets/ApiTestInfoDTO.java @@ -5,7 +5,6 @@ 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; import java.util.List; import java.util.ArrayList; diff --git a/multiapi-engine/src/test/resources/openapigenerator/testApiPathParameterGeneration/assets/ErrorDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testApiPathParameterGeneration/assets/ErrorDTO.java index 4f8c6f58..3ca5863c 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testApiPathParameterGeneration/assets/ErrorDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testApiPathParameterGeneration/assets/ErrorDTO.java @@ -19,13 +19,6 @@ public class ErrorDTO { @NotNull private final String message; - private ErrorDTO(Integer code, String message) { - this.code = code; - this.message = message; - - validateRequiredAttributes(); - } - private ErrorDTO(ErrorDTOBuilder builder) { this.code = builder.code; this.message = builder.message; diff --git a/multiapi-engine/src/test/resources/openapigenerator/testApiPathParameterGeneration/assets/TestDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testApiPathParameterGeneration/assets/TestDTO.java index 7541e254..5797187d 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testApiPathParameterGeneration/assets/TestDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testApiPathParameterGeneration/assets/TestDTO.java @@ -19,13 +19,6 @@ public class TestDTO { @NotNull private final Integer id; - private TestDTO(String name, Integer id) { - this.name = name; - this.id = id; - - validateRequiredAttributes(); - } - private TestDTO(TestDTOBuilder builder) { this.name = builder.name; this.id = builder.id; diff --git a/multiapi-engine/src/test/resources/openapigenerator/testApiPathParameterGeneration/assets/TestInfoDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testApiPathParameterGeneration/assets/TestInfoDTO.java index d9054249..87f13b7e 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testApiPathParameterGeneration/assets/TestInfoDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testApiPathParameterGeneration/assets/TestInfoDTO.java @@ -36,6 +36,7 @@ public static class TestInfoDTOBuilder { private List testers = new ArrayList(); private String testName; + public TestInfoDTO.TestInfoDTOBuilder testers(List testers) { if (!testers.isEmpty()) { this.testers.addAll(testers); diff --git a/multiapi-engine/src/test/resources/openapigenerator/testCoconutSchema/assets/model/FieldDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testCoconutSchema/assets/model/FieldDTO.java index bf4ff502..1ea7c4b5 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testCoconutSchema/assets/model/FieldDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testCoconutSchema/assets/model/FieldDTO.java @@ -5,11 +5,11 @@ import com.fasterxml.jackson.annotation.JsonValue; import java.util.List; import java.util.ArrayList; +import com.sngular.multifileplugin.testCoconutSchema.model.exception.ModelClassException; import lombok.Builder; import lombok.Singular; import lombok.Value; import lombok.extern.jackson.Jacksonized; -import com.sngular.multifileplugin.testCoconutSchema.model.exception.ModelClassException; @Value public class FieldDTO { @@ -240,80 +240,80 @@ private FieldDTO(Integer precision, List defaultItem, Integer maximum, private void validatePartialCombinations() { boolean satisfiedCondition = false; - if (Objects.nonNull(this.precision)) { - satisfiedCondition = true; - } else if (Objects.nonNull(this.defaultItem)) { - satisfiedCondition = true; - } else if (Objects.nonNull(this.maximum)) { - satisfiedCondition = true; - } else if (Objects.nonNull(this.type)) { - satisfiedCondition = true; - } else if (Objects.nonNull(this.scale)) { - satisfiedCondition = true; - } else if (Objects.nonNull(this.minLength)) { - satisfiedCondition = true; - } else if (Objects.nonNull(this.increment)) { - satisfiedCondition = true; - } else if (Objects.nonNull(this.keyType)) { - satisfiedCondition = true; - } else if (Objects.nonNull(this.requiredValues)) { - satisfiedCondition = true; - } else if (Objects.nonNull(this.optionalUnion)) { - satisfiedCondition = true; - } else if (Objects.nonNull(this.initialValue)) { - satisfiedCondition = true; - } else if (Objects.nonNull(this.flagExclusiveMinimum)) { - satisfiedCondition = true; - } else if (Objects.nonNull(this.flagExclusiveMaximum)) { - satisfiedCondition = true; - } else if (Objects.nonNull(this.defaultValue)) { - satisfiedCondition = true; - } else if (Objects.nonNull(this.enumValues)) { - satisfiedCondition = true; - } else if (Objects.nonNull(this.properties)) { - satisfiedCondition = true; - } else if (Objects.nonNull(this.defaultValues)) { - satisfiedCondition = true; - } else if (Objects.nonNull(this.unionEnum)) { - satisfiedCondition = true; - } else if (Objects.nonNull(this.seqEnum)) { - satisfiedCondition = true; - } else if (Objects.nonNull(this.arraySize)) { - satisfiedCondition = true; - } else if (Objects.nonNull(this.multipleOf)) { - satisfiedCondition = true; - } else if (Objects.nonNull(this.mapSize)) { - satisfiedCondition = true; - } else if (Objects.nonNull(this.mapTypes)) { - satisfiedCondition = true; - } else if (Objects.nonNull(this.format)) { - satisfiedCondition = true; - } else if (Objects.nonNull(this.generatedFlag)) { - satisfiedCondition = true; - } else if (Objects.nonNull(this.maxLength)) { - satisfiedCondition = true; - } else if (Objects.nonNull(this.uniqueItems)) { - satisfiedCondition = true; - } else if (Objects.nonNull(this.elements)) { - satisfiedCondition = true; - } else if (Objects.nonNull(this.name)) { - satisfiedCondition = true; - } else if (Objects.nonNull(this.regex)) { - satisfiedCondition = true; - } else if (Objects.nonNull(this.minItems)) { - satisfiedCondition = true; - } else if (Objects.nonNull(this.values)) { - satisfiedCondition = true; - } else if (Objects.nonNull(this.minimum)) { - satisfiedCondition = true; - } else if (Objects.nonNull(this.numberEnum)) { - satisfiedCondition = true; - } else if (Objects.nonNull(this.valueLength)) { - satisfiedCondition = true; - } + if (Objects.nonNull(this.precision)) { + satisfiedCondition = true; + } else if (Objects.nonNull(this.defaultItem)) { + satisfiedCondition = true; + } else if (Objects.nonNull(this.maximum)) { + satisfiedCondition = true; + } else if (Objects.nonNull(this.type)) { + satisfiedCondition = true; + } else if (Objects.nonNull(this.scale)) { + satisfiedCondition = true; + } else if (Objects.nonNull(this.minLength)) { + satisfiedCondition = true; + } else if (Objects.nonNull(this.increment)) { + satisfiedCondition = true; + } else if (Objects.nonNull(this.keyType)) { + satisfiedCondition = true; + } else if (Objects.nonNull(this.requiredValues)) { + satisfiedCondition = true; + } else if (Objects.nonNull(this.optionalUnion)) { + satisfiedCondition = true; + } else if (Objects.nonNull(this.initialValue)) { + satisfiedCondition = true; + } else if (Objects.nonNull(this.flagExclusiveMinimum)) { + satisfiedCondition = true; + } else if (Objects.nonNull(this.flagExclusiveMaximum)) { + satisfiedCondition = true; + } else if (Objects.nonNull(this.defaultValue)) { + satisfiedCondition = true; + } else if (Objects.nonNull(this.enumValues)) { + satisfiedCondition = true; + } else if (Objects.nonNull(this.properties)) { + satisfiedCondition = true; + } else if (Objects.nonNull(this.defaultValues)) { + satisfiedCondition = true; + } else if (Objects.nonNull(this.unionEnum)) { + satisfiedCondition = true; + } else if (Objects.nonNull(this.seqEnum)) { + satisfiedCondition = true; + } else if (Objects.nonNull(this.arraySize)) { + satisfiedCondition = true; + } else if (Objects.nonNull(this.multipleOf)) { + satisfiedCondition = true; + } else if (Objects.nonNull(this.mapSize)) { + satisfiedCondition = true; + } else if (Objects.nonNull(this.mapTypes)) { + satisfiedCondition = true; + } else if (Objects.nonNull(this.format)) { + satisfiedCondition = true; + } else if (Objects.nonNull(this.generatedFlag)) { + satisfiedCondition = true; + } else if (Objects.nonNull(this.maxLength)) { + satisfiedCondition = true; + } else if (Objects.nonNull(this.uniqueItems)) { + satisfiedCondition = true; + } else if (Objects.nonNull(this.elements)) { + satisfiedCondition = true; + } else if (Objects.nonNull(this.name)) { + satisfiedCondition = true; + } else if (Objects.nonNull(this.regex)) { + satisfiedCondition = true; + } else if (Objects.nonNull(this.minItems)) { + satisfiedCondition = true; + } else if (Objects.nonNull(this.values)) { + satisfiedCondition = true; + } else if (Objects.nonNull(this.minimum)) { + satisfiedCondition = true; + } else if (Objects.nonNull(this.numberEnum)) { + satisfiedCondition = true; + } else if (Objects.nonNull(this.valueLength)) { + satisfiedCondition = true; + } if (!satisfiedCondition) { - throw new ModelClassException("FieldDTO"); + throw new ModelClassException("FieldDTO"); } } } diff --git a/multiapi-engine/src/test/resources/openapigenerator/testCoconutSchema/assets/model/SchemaDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testCoconutSchema/assets/model/SchemaDTO.java index 18aad1f2..41ba72bc 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testCoconutSchema/assets/model/SchemaDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testCoconutSchema/assets/model/SchemaDTO.java @@ -6,8 +6,9 @@ import java.util.Map; import java.util.HashMap; import lombok.Builder; -import lombok.Value; import lombok.NonNull; +import lombok.Singular; +import lombok.Value; import lombok.extern.jackson.Jacksonized; @Value @@ -18,7 +19,8 @@ public class SchemaDTO { private String type; @JsonProperty(value ="additionalProperties") - private Map additionalProperties = new HashMap(); + @Singular("additionalProperty") + private Map additionalProperties; @JsonProperty(value ="name") @NonNull @@ -33,7 +35,8 @@ public class SchemaDTO { private String subjectName; @JsonProperty(value ="requiredFields") - private List requiredFields = new ArrayList(); + @Singular("requiredField") + private List requiredFields; @Builder diff --git a/multiapi-engine/src/test/resources/openapigenerator/testCoconutSchema/assets/model/UnionFieldDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testCoconutSchema/assets/model/UnionFieldDTO.java index 64eeec2c..99360f3d 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testCoconutSchema/assets/model/UnionFieldDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testCoconutSchema/assets/model/UnionFieldDTO.java @@ -13,7 +13,7 @@ public class UnionFieldDTO { @JsonProperty(value ="defaultItem") - @Singular("defaultItem") + @Singular("_defaultItem") private List defaultItem; @JsonProperty(value ="generatedFlag") @@ -54,7 +54,8 @@ public String toString() { private Boolean optionalUnion; @JsonProperty(value ="values") - private List values = new ArrayList(); + @Singular("value") + private List values; @Builder diff --git a/multiapi-engine/src/test/resources/openapigenerator/testComplexAnyOf/assets/ApiArrayFieldDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testComplexAnyOf/assets/ApiArrayFieldDTO.java index ddf753b0..45ac84b1 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testComplexAnyOf/assets/ApiArrayFieldDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testComplexAnyOf/assets/ApiArrayFieldDTO.java @@ -29,18 +29,6 @@ public class ApiArrayFieldDTO { @JsonProperty(value ="values") private List values; - private ApiArrayFieldDTO(Boolean uniqueItems, String type, List defaultValues, String name, Integer arraySize, String regex, Integer minItems, List values) { - this.uniqueItems = uniqueItems; - this.type = type; - this.defaultValues = defaultValues; - this.name = name; - this.arraySize = arraySize; - this.regex = regex; - this.minItems = minItems; - this.values = values; - - } - private ApiArrayFieldDTO(ApiArrayFieldDTOBuilder builder) { this.uniqueItems = builder.uniqueItems; this.type = builder.type; @@ -78,6 +66,7 @@ public ApiArrayFieldDTO.ApiArrayFieldDTOBuilder type(String type) { this.type = type; return this; } + public ApiArrayFieldDTO.ApiArrayFieldDTOBuilder defaultValues(List defaultValues) { if (!defaultValues.isEmpty()) { this.defaultValues.addAll(defaultValues); @@ -86,7 +75,7 @@ public ApiArrayFieldDTO.ApiArrayFieldDTOBuilder defaultValues(List values) { if (!values.isEmpty()) { this.values.addAll(values); @@ -119,7 +109,7 @@ public ApiArrayFieldDTO.ApiArrayFieldDTOBuilder values(List val } public ApiArrayFieldDTO.ApiArrayFieldDTOBuilder value(ApiTypeArrayDTO value) { - if (value != null) { + if (Objects.nonNull(value)) { this.values.add(value); } return this; diff --git a/multiapi-engine/src/test/resources/openapigenerator/testComplexAnyOf/assets/ApiBooleanFieldDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testComplexAnyOf/assets/ApiBooleanFieldDTO.java index 1ab7e48d..35f7d601 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testComplexAnyOf/assets/ApiBooleanFieldDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testComplexAnyOf/assets/ApiBooleanFieldDTO.java @@ -17,13 +17,6 @@ public class ApiBooleanFieldDTO { @JsonProperty(value ="defaultValue") private Boolean defaultValue; - private ApiBooleanFieldDTO(String type, String name, Boolean defaultValue) { - this.type = type; - this.name = name; - this.defaultValue = defaultValue; - - } - private ApiBooleanFieldDTO(ApiBooleanFieldDTOBuilder builder) { this.type = builder.type; this.name = builder.name; diff --git a/multiapi-engine/src/test/resources/openapigenerator/testComplexAnyOf/assets/ApiDateFieldDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testComplexAnyOf/assets/ApiDateFieldDTO.java index eb19ca79..3486306d 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testComplexAnyOf/assets/ApiDateFieldDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testComplexAnyOf/assets/ApiDateFieldDTO.java @@ -19,14 +19,6 @@ public class ApiDateFieldDTO { @JsonProperty(value ="format") private String format; - private ApiDateFieldDTO(String type, Object defaultValues, String name, String format) { - this.type = type; - this.defaultValues = defaultValues; - this.name = name; - this.format = format; - - } - private ApiDateFieldDTO(ApiDateFieldDTOBuilder builder) { this.type = builder.type; this.defaultValues = builder.defaultValues; diff --git a/multiapi-engine/src/test/resources/openapigenerator/testComplexAnyOf/assets/ApiDefaultItemDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testComplexAnyOf/assets/ApiDefaultItemDTO.java index 8b1ed1da..d9b344f2 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testComplexAnyOf/assets/ApiDefaultItemDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testComplexAnyOf/assets/ApiDefaultItemDTO.java @@ -104,7 +104,7 @@ public String toString() { @JsonProperty(value ="mapSize") private Integer mapSize; @JsonProperty(value ="mapTypes") - private List mapTypes = new ArrayList(); + private List mapTypes; @JsonProperty(value ="format") private Integer format; @JsonProperty(value ="generatedFlag") @@ -122,7 +122,7 @@ public String toString() { @JsonProperty(value ="minItems") private Integer minItems; @JsonProperty(value ="values") - private List values = new ArrayList(); + private List values; @JsonProperty(value ="minimum") private Integer minimum; @JsonProperty(value ="numberEnum") @@ -150,46 +150,6 @@ public String toString() { @JsonProperty(value ="valueLength") private Integer valueLength; - private ApiDefaultItemDTO(Integer precision, ApiDefaultItemDTO defaultItem, Integer maximum, String type, Integer scale, Integer minLength, Integer increment, String keyType, List requiredValues, Boolean optionalUnion, String initialValue, Boolean flagExclusiveMinimum, Boolean flagExclusiveMaximum, Boolean defaultValue, List enumValues, List properties, List defaultValues, UnionEnum unionEnum, SeqEnum seqEnum, Integer arraySize, Integer multipleOf, Integer mapSize, List mapTypes, Integer format, Boolean generatedFlag, Integer maxLength, Boolean uniqueItems, Integer elements, String name, String regex, Integer minItems, List values, Integer minimum, NumberEnum numberEnum, Integer valueLength) { - this.precision = precision; - this.defaultItem = defaultItem; - this.maximum = maximum; - this.type = type; - this.scale = scale; - this.minLength = minLength; - this.increment = increment; - this.keyType = keyType; - this.requiredValues = requiredValues; - this.optionalUnion = optionalUnion; - this.initialValue = initialValue; - this.flagExclusiveMinimum = flagExclusiveMinimum; - this.flagExclusiveMaximum = flagExclusiveMaximum; - this.defaultValue = defaultValue; - this.enumValues = enumValues; - this.properties = properties; - this.defaultValues = defaultValues; - this.unionEnum = unionEnum; - this.seqEnum = seqEnum; - this.arraySize = arraySize; - this.multipleOf = multipleOf; - this.mapSize = mapSize; - this.mapTypes = mapTypes; - this.format = format; - this.generatedFlag = generatedFlag; - this.maxLength = maxLength; - this.uniqueItems = uniqueItems; - this.elements = elements; - this.name = name; - this.regex = regex; - this.minItems = minItems; - this.values = values; - this.minimum = minimum; - this.numberEnum = numberEnum; - this.valueLength = valueLength; - - validatePartialCombinations(); - } - private ApiDefaultItemDTO(ApiDefaultItemDTOBuilder builder) { this.precision = builder.precision; this.defaultItem = builder.defaultItem; @@ -312,6 +272,7 @@ public ApiDefaultItemDTO.ApiDefaultItemDTOBuilder keyType(String keyType) { this.keyType = keyType; return this; } + public ApiDefaultItemDTO.ApiDefaultItemDTOBuilder requiredValues(List requiredValues) { if (!requiredValues.isEmpty()) { this.requiredValues.addAll(requiredValues); @@ -320,7 +281,7 @@ public ApiDefaultItemDTO.ApiDefaultItemDTOBuilder requiredValues(List re } public ApiDefaultItemDTO.ApiDefaultItemDTOBuilder requiredValue(String requiredValue) { - if (requiredValue != null) { + if (Objects.nonNull(requiredValue)) { this.requiredValues.add(requiredValue); } return this; @@ -350,6 +311,7 @@ public ApiDefaultItemDTO.ApiDefaultItemDTOBuilder defaultValue(Boolean defaultVa this.defaultValue = defaultValue; return this; } + public ApiDefaultItemDTO.ApiDefaultItemDTOBuilder enumValues(List enumValues) { if (!enumValues.isEmpty()) { this.enumValues.addAll(enumValues); @@ -358,11 +320,12 @@ public ApiDefaultItemDTO.ApiDefaultItemDTOBuilder enumValues(List enumVa } public ApiDefaultItemDTO.ApiDefaultItemDTOBuilder enumValue(String enumValue) { - if (enumValue != null) { + if (Objects.nonNull(enumValue)) { this.enumValues.add(enumValue); } return this; } + public ApiDefaultItemDTO.ApiDefaultItemDTOBuilder properties(List properties) { if (!properties.isEmpty()) { this.properties.addAll(properties); @@ -370,12 +333,13 @@ public ApiDefaultItemDTO.ApiDefaultItemDTOBuilder properties(List proper return this; } - public ApiDefaultItemDTO.ApiDefaultItemDTOBuilder propertie(String propertie) { - if (propertie != null) { - this.properties.add(propertie); + public ApiDefaultItemDTO.ApiDefaultItemDTOBuilder property(String property) { + if (Objects.nonNull(property)) { + this.properties.add(property); } return this; } + public ApiDefaultItemDTO.ApiDefaultItemDTOBuilder defaultValues(List defaultValues) { if (!defaultValues.isEmpty()) { this.defaultValues.addAll(defaultValues); @@ -384,15 +348,17 @@ public ApiDefaultItemDTO.ApiDefaultItemDTOBuilder defaultValues(List def } public ApiDefaultItemDTO.ApiDefaultItemDTOBuilder defaultValue(String defaultValue) { - if (defaultValue != null) { + if (Objects.nonNull(defaultValue)) { this.defaultValues.add(defaultValue); } return this; } + public ApiDefaultItemDTO.ApiDefaultItemDTOBuilder unionEnum(UnionEnum unionEnum) { this.unionEnum = unionEnum; return this; } + public ApiDefaultItemDTO.ApiDefaultItemDTOBuilder seqEnum(SeqEnum seqEnum) { this.seqEnum = seqEnum; return this; @@ -412,6 +378,7 @@ public ApiDefaultItemDTO.ApiDefaultItemDTOBuilder mapSize(Integer mapSize) { this.mapSize = mapSize; return this; } + public ApiDefaultItemDTO.ApiDefaultItemDTOBuilder mapTypes(List mapTypes) { if (!mapTypes.isEmpty()) { this.mapTypes.addAll(mapTypes); @@ -420,7 +387,7 @@ public ApiDefaultItemDTO.ApiDefaultItemDTOBuilder mapTypes(List } public ApiDefaultItemDTO.ApiDefaultItemDTOBuilder mapType(ApiTypeArrayDTO mapType) { - if (mapType != null) { + if (Objects.nonNull(mapType)) { this.mapTypes.add(mapType); } return this; @@ -465,6 +432,7 @@ public ApiDefaultItemDTO.ApiDefaultItemDTOBuilder minItems(Integer minItems) { this.minItems = minItems; return this; } + public ApiDefaultItemDTO.ApiDefaultItemDTOBuilder values(List values) { if (!values.isEmpty()) { this.values.addAll(values); @@ -473,7 +441,7 @@ public ApiDefaultItemDTO.ApiDefaultItemDTOBuilder values(List v } public ApiDefaultItemDTO.ApiDefaultItemDTOBuilder value(ApiTypeArrayDTO value) { - if (value != null) { + if (Objects.nonNull(value)) { this.values.add(value); } return this; @@ -483,6 +451,7 @@ public ApiDefaultItemDTO.ApiDefaultItemDTOBuilder minimum(Integer minimum) { this.minimum = minimum; return this; } + public ApiDefaultItemDTO.ApiDefaultItemDTOBuilder numberEnum(NumberEnum numberEnum) { this.numberEnum = numberEnum; return this; @@ -842,77 +811,77 @@ public String toString() { private void validatePartialCombinations() { boolean satisfiedCondition = false; - if (Objects.nonNull(this.precision)) { - satisfiedCondition = true; - } else if (Objects.nonNull(this.defaultItem)) { - satisfiedCondition = true; - } else if (Objects.nonNull(this.maximum)) { - satisfiedCondition = true; - } else if (Objects.nonNull(this.type)) { - satisfiedCondition = true; - } else if (Objects.nonNull(this.scale)) { - satisfiedCondition = true; - } else if (Objects.nonNull(this.minLength)) { - satisfiedCondition = true; - } else if (Objects.nonNull(this.increment)) { - satisfiedCondition = true; - } else if (Objects.nonNull(this.keyType)) { - satisfiedCondition = true; - } else if (Objects.nonNull(this.requiredValues)) { - satisfiedCondition = true; - } else if (Objects.nonNull(this.optionalUnion)) { - satisfiedCondition = true; - } else if (Objects.nonNull(this.initialValue)) { - satisfiedCondition = true; - } else if (Objects.nonNull(this.flagExclusiveMinimum)) { - satisfiedCondition = true; - } else if (Objects.nonNull(this.flagExclusiveMaximum)) { - satisfiedCondition = true; - } else if (Objects.nonNull(this.defaultValue)) { - satisfiedCondition = true; - } else if (Objects.nonNull(this.enumValues)) { - satisfiedCondition = true; - } else if (Objects.nonNull(this.properties)) { - satisfiedCondition = true; - } else if (Objects.nonNull(this.defaultValues)) { - satisfiedCondition = true; - } else if (Objects.nonNull(this.unionEnum)) { - satisfiedCondition = true; - } else if (Objects.nonNull(this.seqEnum)) { - satisfiedCondition = true; - } else if (Objects.nonNull(this.arraySize)) { - satisfiedCondition = true; - } else if (Objects.nonNull(this.multipleOf)) { - satisfiedCondition = true; - } else if (Objects.nonNull(this.mapSize)) { - satisfiedCondition = true; - } else if (Objects.nonNull(this.mapTypes)) { - satisfiedCondition = true; - } else if (Objects.nonNull(this.format)) { - satisfiedCondition = true; - } else if (Objects.nonNull(this.generatedFlag)) { - satisfiedCondition = true; - } else if (Objects.nonNull(this.maxLength)) { - satisfiedCondition = true; - } else if (Objects.nonNull(this.uniqueItems)) { - satisfiedCondition = true; - } else if (Objects.nonNull(this.elements)) { - satisfiedCondition = true; - } else if (Objects.nonNull(this.name)) { - satisfiedCondition = true; - } else if (Objects.nonNull(this.regex)) { - satisfiedCondition = true; - } else if (Objects.nonNull(this.minItems)) { - satisfiedCondition = true; - } else if (Objects.nonNull(this.values)) { - satisfiedCondition = true; - } else if (Objects.nonNull(this.minimum)) { - satisfiedCondition = true; - } else if (Objects.nonNull(this.numberEnum)) { - satisfiedCondition = true; - } else if (Objects.nonNull(this.valueLength)) { - satisfiedCondition = true; - } + if (Objects.nonNull(this.precision)) { + satisfiedCondition = true; + } else if (Objects.nonNull(this.defaultItem)) { + satisfiedCondition = true; + } else if (Objects.nonNull(this.maximum)) { + satisfiedCondition = true; + } else if (Objects.nonNull(this.type)) { + satisfiedCondition = true; + } else if (Objects.nonNull(this.scale)) { + satisfiedCondition = true; + } else if (Objects.nonNull(this.minLength)) { + satisfiedCondition = true; + } else if (Objects.nonNull(this.increment)) { + satisfiedCondition = true; + } else if (Objects.nonNull(this.keyType)) { + satisfiedCondition = true; + } else if (Objects.nonNull(this.requiredValues)) { + satisfiedCondition = true; + } else if (Objects.nonNull(this.optionalUnion)) { + satisfiedCondition = true; + } else if (Objects.nonNull(this.initialValue)) { + satisfiedCondition = true; + } else if (Objects.nonNull(this.flagExclusiveMinimum)) { + satisfiedCondition = true; + } else if (Objects.nonNull(this.flagExclusiveMaximum)) { + satisfiedCondition = true; + } else if (Objects.nonNull(this.defaultValue)) { + satisfiedCondition = true; + } else if (Objects.nonNull(this.enumValues)) { + satisfiedCondition = true; + } else if (Objects.nonNull(this.properties)) { + satisfiedCondition = true; + } else if (Objects.nonNull(this.defaultValues)) { + satisfiedCondition = true; + } else if (Objects.nonNull(this.unionEnum)) { + satisfiedCondition = true; + } else if (Objects.nonNull(this.seqEnum)) { + satisfiedCondition = true; + } else if (Objects.nonNull(this.arraySize)) { + satisfiedCondition = true; + } else if (Objects.nonNull(this.multipleOf)) { + satisfiedCondition = true; + } else if (Objects.nonNull(this.mapSize)) { + satisfiedCondition = true; + } else if (Objects.nonNull(this.mapTypes)) { + satisfiedCondition = true; + } else if (Objects.nonNull(this.format)) { + satisfiedCondition = true; + } else if (Objects.nonNull(this.generatedFlag)) { + satisfiedCondition = true; + } else if (Objects.nonNull(this.maxLength)) { + satisfiedCondition = true; + } else if (Objects.nonNull(this.uniqueItems)) { + satisfiedCondition = true; + } else if (Objects.nonNull(this.elements)) { + satisfiedCondition = true; + } else if (Objects.nonNull(this.name)) { + satisfiedCondition = true; + } else if (Objects.nonNull(this.regex)) { + satisfiedCondition = true; + } else if (Objects.nonNull(this.minItems)) { + satisfiedCondition = true; + } else if (Objects.nonNull(this.values)) { + satisfiedCondition = true; + } else if (Objects.nonNull(this.minimum)) { + satisfiedCondition = true; + } else if (Objects.nonNull(this.numberEnum)) { + satisfiedCondition = true; + } else if (Objects.nonNull(this.valueLength)) { + satisfiedCondition = true; + } if (!satisfiedCondition) { throw new ModelClassException("ApiDefaultItemDTO"); diff --git a/multiapi-engine/src/test/resources/openapigenerator/testComplexAnyOf/assets/ApiEnumFieldDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testComplexAnyOf/assets/ApiEnumFieldDTO.java index 0334c5d9..c667a995 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testComplexAnyOf/assets/ApiEnumFieldDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testComplexAnyOf/assets/ApiEnumFieldDTO.java @@ -23,15 +23,6 @@ public class ApiEnumFieldDTO { @JsonProperty(value ="defaultValue") private String defaultValue; - private ApiEnumFieldDTO(List enumValues, String type, List defaultValues, String name, String defaultValue) { - this.enumValues = enumValues; - this.type = type; - this.defaultValues = defaultValues; - this.name = name; - this.defaultValue = defaultValue; - - } - private ApiEnumFieldDTO(ApiEnumFieldDTOBuilder builder) { this.enumValues = builder.enumValues; this.type = builder.type; @@ -53,6 +44,7 @@ public static class ApiEnumFieldDTOBuilder { private List defaultValues = new ArrayList(); private String name; private String defaultValue; + public ApiEnumFieldDTO.ApiEnumFieldDTOBuilder enumValues(List enumValues) { if (!enumValues.isEmpty()) { this.enumValues.addAll(enumValues); @@ -61,7 +53,7 @@ public ApiEnumFieldDTO.ApiEnumFieldDTOBuilder enumValues(List enumValues } public ApiEnumFieldDTO.ApiEnumFieldDTOBuilder enumValue(String enumValue) { - if (enumValue != null) { + if (Objects.nonNull(enumValue)) { this.enumValues.add(enumValue); } return this; @@ -71,6 +63,7 @@ public ApiEnumFieldDTO.ApiEnumFieldDTOBuilder type(String type) { this.type = type; return this; } + public ApiEnumFieldDTO.ApiEnumFieldDTOBuilder defaultValues(List defaultValues) { if (!defaultValues.isEmpty()) { this.defaultValues.addAll(defaultValues); @@ -79,7 +72,7 @@ public ApiEnumFieldDTO.ApiEnumFieldDTOBuilder defaultValues(List default } public ApiEnumFieldDTO.ApiEnumFieldDTOBuilder defaultValue(String defaultValue) { - if (defaultValue != null) { + if (Objects.nonNull(defaultValue)) { this.defaultValues.add(defaultValue); } return this; diff --git a/multiapi-engine/src/test/resources/openapigenerator/testComplexAnyOf/assets/ApiMapFieldDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testComplexAnyOf/assets/ApiMapFieldDTO.java index b6d7aa53..ad09b46c 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testComplexAnyOf/assets/ApiMapFieldDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testComplexAnyOf/assets/ApiMapFieldDTO.java @@ -25,16 +25,6 @@ public class ApiMapFieldDTO { @JsonProperty(value ="mapTypes") private List mapTypes; - private ApiMapFieldDTO(String keyType, String type, List defaultValues, String name, Integer mapSize, List mapTypes) { - this.keyType = keyType; - this.type = type; - this.defaultValues = defaultValues; - this.name = name; - this.mapSize = mapSize; - this.mapTypes = mapTypes; - - } - private ApiMapFieldDTO(ApiMapFieldDTOBuilder builder) { this.keyType = builder.keyType; this.type = builder.type; @@ -68,6 +58,7 @@ public ApiMapFieldDTO.ApiMapFieldDTOBuilder type(String type) { this.type = type; return this; } + public ApiMapFieldDTO.ApiMapFieldDTOBuilder defaultValues(List defaultValues) { if (!defaultValues.isEmpty()) { this.defaultValues.addAll(defaultValues); @@ -76,7 +67,7 @@ public ApiMapFieldDTO.ApiMapFieldDTOBuilder defaultValues(List defaultVa } public ApiMapFieldDTO.ApiMapFieldDTOBuilder defaultValue(Object defaultValue) { - if (defaultValue != null) { + if (Objects.nonNull(defaultValue)) { this.defaultValues.add(defaultValue); } return this; @@ -91,6 +82,7 @@ public ApiMapFieldDTO.ApiMapFieldDTOBuilder mapSize(Integer mapSize) { this.mapSize = mapSize; return this; } + public ApiMapFieldDTO.ApiMapFieldDTOBuilder mapTypes(List mapTypes) { if (!mapTypes.isEmpty()) { this.mapTypes.addAll(mapTypes); @@ -99,7 +91,7 @@ public ApiMapFieldDTO.ApiMapFieldDTOBuilder mapTypes(List mapTy } public ApiMapFieldDTO.ApiMapFieldDTOBuilder mapType(ApiTypeArrayDTO mapType) { - if (mapType != null) { + if (Objects.nonNull(mapType)) { this.mapTypes.add(mapType); } return this; diff --git a/multiapi-engine/src/test/resources/openapigenerator/testComplexAnyOf/assets/ApiNumberFieldDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testComplexAnyOf/assets/ApiNumberFieldDTO.java index 78ed2a5c..37508df1 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testComplexAnyOf/assets/ApiNumberFieldDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testComplexAnyOf/assets/ApiNumberFieldDTO.java @@ -58,22 +58,6 @@ public String toString() { @JsonProperty(value ="defaultValue") private Long defaultValue; - private ApiNumberFieldDTO(Integer precision, Integer maximum, String type, List defaultValues, String name, Integer multipleOf, Integer scale, Integer minimum, Boolean flagExclusiveMinimum, Boolean flagExclusiveMaximum, NumberEnum numberEnum, Long defaultValue) { - this.precision = precision; - this.maximum = maximum; - this.type = type; - this.defaultValues = defaultValues; - this.name = name; - this.multipleOf = multipleOf; - this.scale = scale; - this.minimum = minimum; - this.flagExclusiveMinimum = flagExclusiveMinimum; - this.flagExclusiveMaximum = flagExclusiveMaximum; - this.numberEnum = numberEnum; - this.defaultValue = defaultValue; - - } - private ApiNumberFieldDTO(ApiNumberFieldDTOBuilder builder) { this.precision = builder.precision; this.maximum = builder.maximum; @@ -124,6 +108,7 @@ public ApiNumberFieldDTO.ApiNumberFieldDTOBuilder type(String type) { this.type = type; return this; } + public ApiNumberFieldDTO.ApiNumberFieldDTOBuilder defaultValues(List defaultValues) { if (!defaultValues.isEmpty()) { this.defaultValues.addAll(defaultValues); @@ -167,6 +152,7 @@ public ApiNumberFieldDTO.ApiNumberFieldDTOBuilder flagExclusiveMaximum(Boolean f this.flagExclusiveMaximum = flagExclusiveMaximum; return this; } + public ApiNumberFieldDTO.ApiNumberFieldDTOBuilder numberEnum(NumberEnum numberEnum) { this.numberEnum = numberEnum; return this; diff --git a/multiapi-engine/src/test/resources/openapigenerator/testComplexAnyOf/assets/ApiObjectFieldDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testComplexAnyOf/assets/ApiObjectFieldDTO.java index 065a2c77..adf0d182 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testComplexAnyOf/assets/ApiObjectFieldDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testComplexAnyOf/assets/ApiObjectFieldDTO.java @@ -23,15 +23,6 @@ public class ApiObjectFieldDTO { @JsonProperty(value ="name") private String name; - private ApiObjectFieldDTO(List requiredValues, String type, List properties, List defaultValues, String name) { - this.requiredValues = requiredValues; - this.type = type; - this.properties = properties; - this.defaultValues = defaultValues; - this.name = name; - - } - private ApiObjectFieldDTO(ApiObjectFieldDTOBuilder builder) { this.requiredValues = builder.requiredValues; this.type = builder.type; @@ -53,6 +44,7 @@ public static class ApiObjectFieldDTOBuilder { private List properties = new ArrayList(); private List defaultValues = new ArrayList(); private String name; + public ApiObjectFieldDTO.ApiObjectFieldDTOBuilder requiredValues(List requiredValues) { if (!requiredValues.isEmpty()) { this.requiredValues.addAll(requiredValues); @@ -61,7 +53,7 @@ public ApiObjectFieldDTO.ApiObjectFieldDTOBuilder requiredValues(List re } public ApiObjectFieldDTO.ApiObjectFieldDTOBuilder requiredValue(String requiredValue) { - if (requiredValue != null) { + if (Objects.nonNull(requiredValue)) { this.requiredValues.add(requiredValue); } return this; @@ -71,6 +63,7 @@ public ApiObjectFieldDTO.ApiObjectFieldDTOBuilder type(String type) { this.type = type; return this; } + public ApiObjectFieldDTO.ApiObjectFieldDTOBuilder properties(List properties) { if (!properties.isEmpty()) { this.properties.addAll(properties); @@ -78,12 +71,13 @@ public ApiObjectFieldDTO.ApiObjectFieldDTOBuilder properties(List defaultValues) { if (!defaultValues.isEmpty()) { this.defaultValues.addAll(defaultValues); @@ -92,7 +86,7 @@ public ApiObjectFieldDTO.ApiObjectFieldDTOBuilder defaultValues(List def } public ApiObjectFieldDTO.ApiObjectFieldDTOBuilder defaultValue(Object defaultValue) { - if (defaultValue != null) { + if (Objects.nonNull(defaultValue)) { this.defaultValues.add(defaultValue); } return this; diff --git a/multiapi-engine/src/test/resources/openapigenerator/testComplexAnyOf/assets/ApiSchemaDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testComplexAnyOf/assets/ApiSchemaDTO.java index ab0cbb64..11b52242 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testComplexAnyOf/assets/ApiSchemaDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testComplexAnyOf/assets/ApiSchemaDTO.java @@ -18,9 +18,6 @@ public class ApiSchemaDTO { @JsonProperty(value ="type") @NotNull private final String type; - @JsonProperty(value ="properties") - @NotNull - private final List properties; @JsonProperty(value ="name") @NotNull private final String name; @@ -33,20 +30,8 @@ public class ApiSchemaDTO { @JsonProperty(value ="requiredFields") private List requiredFields; - private ApiSchemaDTO(String type, List properties, String name, String id, String subjectName, List requiredFields) { - this.type = type; - this.properties = properties; - this.name = name; - this.id = id; - this.subjectName = subjectName; - this.requiredFields = requiredFields; - - validateRequiredAttributes(); - } - private ApiSchemaDTO(ApiSchemaDTOBuilder builder) { this.type = builder.type; - this.properties = builder.properties; this.name = builder.name; this.id = builder.id; this.subjectName = builder.subjectName; @@ -63,7 +48,6 @@ public static ApiSchemaDTO.ApiSchemaDTOBuilder builder() { public static class ApiSchemaDTOBuilder { private String type; - private List properties = new ArrayList(); private String name; private String id; private String subjectName; @@ -73,19 +57,6 @@ public ApiSchemaDTO.ApiSchemaDTOBuilder type(String type) { this.type = type; return this; } - public ApiSchemaDTO.ApiSchemaDTOBuilder properties(List properties) { - if (!properties.isEmpty()) { - this.properties.addAll(properties); - } - return this; - } - - public ApiSchemaDTO.ApiSchemaDTOBuilder propertie(ApiTypeArrayDTO propertie) { - if (propertie != null) { - this.properties.add(propertie); - } - return this; - } public ApiSchemaDTO.ApiSchemaDTOBuilder name(String name) { this.name = name; @@ -101,6 +72,7 @@ public ApiSchemaDTO.ApiSchemaDTOBuilder subjectName(String subjectName) { this.subjectName = subjectName; return this; } + public ApiSchemaDTO.ApiSchemaDTOBuilder requiredFields(List requiredFields) { if (!requiredFields.isEmpty()) { this.requiredFields.addAll(requiredFields); @@ -109,7 +81,7 @@ public ApiSchemaDTO.ApiSchemaDTOBuilder requiredFields(List req } public ApiSchemaDTO.ApiSchemaDTOBuilder requiredField(ApiTypeArrayDTO requiredField) { - if (requiredField != null) { + if (Objects.nonNull(requiredField)) { this.requiredFields.add(requiredField); } return this; @@ -126,11 +98,6 @@ public String getType() { return type; } - @Schema(name = "properties", required = true) - public List getProperties() { - return properties; - } - @Schema(name = "name", required = true) public String getName() { return name; @@ -163,12 +130,12 @@ public boolean equals(Object o) { return false; } ApiSchemaDTO apiSchemaDTO = (ApiSchemaDTO) o; - return Objects.equals(this.type, apiSchemaDTO.type) && Objects.equals(this.properties, apiSchemaDTO.properties) && Objects.equals(this.name, apiSchemaDTO.name) && Objects.equals(this.id, apiSchemaDTO.id) && Objects.equals(this.subjectName, apiSchemaDTO.subjectName) && Objects.equals(this.requiredFields, apiSchemaDTO.requiredFields); + return Objects.equals(this.type, apiSchemaDTO.type) && Objects.equals(this.name, apiSchemaDTO.name) && Objects.equals(this.id, apiSchemaDTO.id) && Objects.equals(this.subjectName, apiSchemaDTO.subjectName) && Objects.equals(this.requiredFields, apiSchemaDTO.requiredFields); } @Override public int hashCode() { - return Objects.hash(type, properties, name, id, subjectName, requiredFields); + return Objects.hash(type, name, id, subjectName, requiredFields); } @Override @@ -176,7 +143,6 @@ public String toString() { StringBuilder sb = new StringBuilder(); sb.append("ApiSchemaDTO{"); sb.append(" type:").append(type).append(","); - sb.append(" properties:").append(properties).append(","); sb.append(" name:").append(name).append(","); sb.append(" id:").append(id).append(","); sb.append(" subjectName:").append(subjectName).append(","); @@ -190,8 +156,6 @@ private void validateRequiredAttributes() { if (!Objects.nonNull(this.type)) { satisfiedCondition = false; - } else if (!Objects.nonNull(this.properties)) { - satisfiedCondition = false; } else if (!Objects.nonNull(this.name)) { satisfiedCondition = false; } else if (!Objects.nonNull(this.id)) { diff --git a/multiapi-engine/src/test/resources/openapigenerator/testComplexAnyOf/assets/ApiSequenceFieldDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testComplexAnyOf/assets/ApiSequenceFieldDTO.java index 161cb776..a1995680 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testComplexAnyOf/assets/ApiSequenceFieldDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testComplexAnyOf/assets/ApiSequenceFieldDTO.java @@ -54,18 +54,6 @@ public String toString() { @JsonProperty(value ="increment") private Integer increment; - private ApiSequenceFieldDTO(Integer elements, String type, List properties, List defaultValues, SeqEnum seqEnum, String name, String initialValue, Integer increment) { - this.elements = elements; - this.type = type; - this.properties = properties; - this.defaultValues = defaultValues; - this.seqEnum = seqEnum; - this.name = name; - this.initialValue = initialValue; - this.increment = increment; - - } - private ApiSequenceFieldDTO(ApiSequenceFieldDTOBuilder builder) { this.elements = builder.elements; this.type = builder.type; @@ -103,6 +91,7 @@ public ApiSequenceFieldDTO.ApiSequenceFieldDTOBuilder type(String type) { this.type = type; return this; } + public ApiSequenceFieldDTO.ApiSequenceFieldDTOBuilder properties(List properties) { if (!properties.isEmpty()) { this.properties.addAll(properties); @@ -110,12 +99,13 @@ public ApiSequenceFieldDTO.ApiSequenceFieldDTOBuilder properties(List defaultValues) { if (!defaultValues.isEmpty()) { this.defaultValues.addAll(defaultValues); @@ -124,11 +114,12 @@ public ApiSequenceFieldDTO.ApiSequenceFieldDTOBuilder defaultValues(List } public ApiSequenceFieldDTO.ApiSequenceFieldDTOBuilder defaultValue(Object defaultValue) { - if (defaultValue != null) { + if (Objects.nonNull(defaultValue)) { this.defaultValues.add(defaultValue); } return this; } + public ApiSequenceFieldDTO.ApiSequenceFieldDTOBuilder seqEnum(SeqEnum seqEnum) { this.seqEnum = seqEnum; return this; diff --git a/multiapi-engine/src/test/resources/openapigenerator/testComplexAnyOf/assets/ApiStringFieldDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testComplexAnyOf/assets/ApiStringFieldDTO.java index 19c98317..19bd2493 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testComplexAnyOf/assets/ApiStringFieldDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testComplexAnyOf/assets/ApiStringFieldDTO.java @@ -31,19 +31,6 @@ public class ApiStringFieldDTO { @JsonProperty(value ="valueLength") private Integer valueLength; - private ApiStringFieldDTO(Integer maxLength, String type, List properties, List defaultValues, String name, String regex, Integer minLength, Integer format, Integer valueLength) { - this.maxLength = maxLength; - this.type = type; - this.properties = properties; - this.defaultValues = defaultValues; - this.name = name; - this.regex = regex; - this.minLength = minLength; - this.format = format; - this.valueLength = valueLength; - - } - private ApiStringFieldDTO(ApiStringFieldDTOBuilder builder) { this.maxLength = builder.maxLength; this.type = builder.type; @@ -83,6 +70,7 @@ public ApiStringFieldDTO.ApiStringFieldDTOBuilder type(String type) { this.type = type; return this; } + public ApiStringFieldDTO.ApiStringFieldDTOBuilder properties(List properties) { if (!properties.isEmpty()) { this.properties.addAll(properties); @@ -90,12 +78,13 @@ public ApiStringFieldDTO.ApiStringFieldDTOBuilder properties(List proper return this; } - public ApiStringFieldDTO.ApiStringFieldDTOBuilder propertie(String propertie) { - if (Objects.nonNull(propertie)) { - this.properties.add(propertie); + public ApiStringFieldDTO.ApiStringFieldDTOBuilder property(String property) { + if (Objects.nonNull(property)) { + this.properties.add(property); } return this; } + public ApiStringFieldDTO.ApiStringFieldDTOBuilder defaultValues(List defaultValues) { if (!defaultValues.isEmpty()) { this.defaultValues.addAll(defaultValues); diff --git a/multiapi-engine/src/test/resources/openapigenerator/testComplexAnyOf/assets/ApiTypeArrayDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testComplexAnyOf/assets/ApiTypeArrayDTO.java index 288ff72d..7ce4b742 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testComplexAnyOf/assets/ApiTypeArrayDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testComplexAnyOf/assets/ApiTypeArrayDTO.java @@ -150,46 +150,6 @@ public String toString() { @JsonProperty(value ="valueLength") private Integer valueLength; - private ApiTypeArrayDTO(Integer precision, ApiDefaultItemDTO defaultItem, Integer maximum, String type, Integer scale, Integer minLength, Integer increment, String keyType, List requiredValues, Boolean optionalUnion, String initialValue, Boolean flagExclusiveMinimum, Boolean flagExclusiveMaximum, Boolean defaultValue, List enumValues, List properties, List defaultValues, UnionEnum unionEnum, SeqEnum seqEnum, Integer arraySize, Integer multipleOf, Integer mapSize, List mapTypes, Integer format, Boolean generatedFlag, Integer maxLength, Boolean uniqueItems, Integer elements, String name, String regex, Integer minItems, List values, Integer minimum, NumberEnum numberEnum, Integer valueLength) { - this.precision = precision; - this.defaultItem = defaultItem; - this.maximum = maximum; - this.type = type; - this.scale = scale; - this.minLength = minLength; - this.increment = increment; - this.keyType = keyType; - this.requiredValues = requiredValues; - this.optionalUnion = optionalUnion; - this.initialValue = initialValue; - this.flagExclusiveMinimum = flagExclusiveMinimum; - this.flagExclusiveMaximum = flagExclusiveMaximum; - this.defaultValue = defaultValue; - this.enumValues = enumValues; - this.properties = properties; - this.defaultValues = defaultValues; - this.unionEnum = unionEnum; - this.seqEnum = seqEnum; - this.arraySize = arraySize; - this.multipleOf = multipleOf; - this.mapSize = mapSize; - this.mapTypes = mapTypes; - this.format = format; - this.generatedFlag = generatedFlag; - this.maxLength = maxLength; - this.uniqueItems = uniqueItems; - this.elements = elements; - this.name = name; - this.regex = regex; - this.minItems = minItems; - this.values = values; - this.minimum = minimum; - this.numberEnum = numberEnum; - this.valueLength = valueLength; - - validatePartialCombinations(); - } - private ApiTypeArrayDTO(ApiTypeArrayDTOBuilder builder) { this.precision = builder.precision; this.defaultItem = builder.defaultItem; @@ -312,6 +272,7 @@ public ApiTypeArrayDTO.ApiTypeArrayDTOBuilder keyType(String keyType) { this.keyType = keyType; return this; } + public ApiTypeArrayDTO.ApiTypeArrayDTOBuilder requiredValues(List requiredValues) { if (!requiredValues.isEmpty()) { this.requiredValues.addAll(requiredValues); @@ -320,7 +281,7 @@ public ApiTypeArrayDTO.ApiTypeArrayDTOBuilder requiredValues(List requir } public ApiTypeArrayDTO.ApiTypeArrayDTOBuilder requiredValue(String requiredValue) { - if (requiredValue != null) { + if (Objects.nonNull(requiredValue)) { this.requiredValues.add(requiredValue); } return this; @@ -350,6 +311,7 @@ public ApiTypeArrayDTO.ApiTypeArrayDTOBuilder defaultValue(Boolean defaultValue) this.defaultValue = defaultValue; return this; } + public ApiTypeArrayDTO.ApiTypeArrayDTOBuilder enumValues(List enumValues) { if (!enumValues.isEmpty()) { this.enumValues.addAll(enumValues); @@ -358,11 +320,12 @@ public ApiTypeArrayDTO.ApiTypeArrayDTOBuilder enumValues(List enumValues } public ApiTypeArrayDTO.ApiTypeArrayDTOBuilder enumValue(String enumValue) { - if (enumValue != null) { + if (Objects.nonNull(enumValue)) { this.enumValues.add(enumValue); } return this; } + public ApiTypeArrayDTO.ApiTypeArrayDTOBuilder properties(List properties) { if (!properties.isEmpty()) { this.properties.addAll(properties); @@ -370,12 +333,13 @@ public ApiTypeArrayDTO.ApiTypeArrayDTOBuilder properties(List properties return this; } - public ApiTypeArrayDTO.ApiTypeArrayDTOBuilder propertie(String propertie) { - if (propertie != null) { - this.properties.add(propertie); + public ApiTypeArrayDTO.ApiTypeArrayDTOBuilder property(String property) { + if (Objects.nonNull(property)) { + this.properties.add(property); } return this; } + public ApiTypeArrayDTO.ApiTypeArrayDTOBuilder defaultValues(List defaultValues) { if (!defaultValues.isEmpty()) { this.defaultValues.addAll(defaultValues); @@ -384,15 +348,17 @@ public ApiTypeArrayDTO.ApiTypeArrayDTOBuilder defaultValues(List default } public ApiTypeArrayDTO.ApiTypeArrayDTOBuilder defaultValue(String defaultValue) { - if (defaultValue != null) { + if (Objects.nonNull(defaultValue)) { this.defaultValues.add(defaultValue); } return this; } + public ApiTypeArrayDTO.ApiTypeArrayDTOBuilder unionEnum(UnionEnum unionEnum) { this.unionEnum = unionEnum; return this; } + public ApiTypeArrayDTO.ApiTypeArrayDTOBuilder seqEnum(SeqEnum seqEnum) { this.seqEnum = seqEnum; return this; @@ -412,6 +378,7 @@ public ApiTypeArrayDTO.ApiTypeArrayDTOBuilder mapSize(Integer mapSize) { this.mapSize = mapSize; return this; } + public ApiTypeArrayDTO.ApiTypeArrayDTOBuilder mapTypes(List mapTypes) { if (!mapTypes.isEmpty()) { this.mapTypes.addAll(mapTypes); @@ -420,7 +387,7 @@ public ApiTypeArrayDTO.ApiTypeArrayDTOBuilder mapTypes(List map } public ApiTypeArrayDTO.ApiTypeArrayDTOBuilder mapType(ApiTypeArrayDTO mapType) { - if (mapType != null) { + if (Objects.nonNull(mapType)) { this.mapTypes.add(mapType); } return this; @@ -465,6 +432,7 @@ public ApiTypeArrayDTO.ApiTypeArrayDTOBuilder minItems(Integer minItems) { this.minItems = minItems; return this; } + public ApiTypeArrayDTO.ApiTypeArrayDTOBuilder values(List values) { if (!values.isEmpty()) { this.values.addAll(values); @@ -473,7 +441,7 @@ public ApiTypeArrayDTO.ApiTypeArrayDTOBuilder values(List value } public ApiTypeArrayDTO.ApiTypeArrayDTOBuilder value(ApiTypeArrayDTO value) { - if (value != null) { + if (Objects.nonNull(value)) { this.values.add(value); } return this; @@ -483,6 +451,7 @@ public ApiTypeArrayDTO.ApiTypeArrayDTOBuilder minimum(Integer minimum) { this.minimum = minimum; return this; } + public ApiTypeArrayDTO.ApiTypeArrayDTOBuilder numberEnum(NumberEnum numberEnum) { this.numberEnum = numberEnum; return this; @@ -842,77 +811,77 @@ public String toString() { private void validatePartialCombinations() { boolean satisfiedCondition = false; - if (Objects.nonNull(this.precision)) { - satisfiedCondition = true; - } else if (Objects.nonNull(this.defaultItem)) { - satisfiedCondition = true; - } else if (Objects.nonNull(this.maximum)) { - satisfiedCondition = true; - } else if (Objects.nonNull(this.type)) { - satisfiedCondition = true; - } else if (Objects.nonNull(this.scale)) { - satisfiedCondition = true; - } else if (Objects.nonNull(this.minLength)) { - satisfiedCondition = true; - } else if (Objects.nonNull(this.increment)) { - satisfiedCondition = true; - } else if (Objects.nonNull(this.keyType)) { - satisfiedCondition = true; - } else if (Objects.nonNull(this.requiredValues)) { - satisfiedCondition = true; - } else if (Objects.nonNull(this.optionalUnion)) { - satisfiedCondition = true; - } else if (Objects.nonNull(this.initialValue)) { - satisfiedCondition = true; - } else if (Objects.nonNull(this.flagExclusiveMinimum)) { - satisfiedCondition = true; - } else if (Objects.nonNull(this.flagExclusiveMaximum)) { - satisfiedCondition = true; - } else if (Objects.nonNull(this.defaultValue)) { - satisfiedCondition = true; - } else if (Objects.nonNull(this.enumValues)) { - satisfiedCondition = true; - } else if (Objects.nonNull(this.properties)) { - satisfiedCondition = true; - } else if (Objects.nonNull(this.defaultValues)) { - satisfiedCondition = true; - } else if (Objects.nonNull(this.unionEnum)) { - satisfiedCondition = true; - } else if (Objects.nonNull(this.seqEnum)) { - satisfiedCondition = true; - } else if (Objects.nonNull(this.arraySize)) { - satisfiedCondition = true; - } else if (Objects.nonNull(this.multipleOf)) { - satisfiedCondition = true; - } else if (Objects.nonNull(this.mapSize)) { - satisfiedCondition = true; - } else if (Objects.nonNull(this.mapTypes)) { - satisfiedCondition = true; - } else if (Objects.nonNull(this.format)) { - satisfiedCondition = true; - } else if (Objects.nonNull(this.generatedFlag)) { - satisfiedCondition = true; - } else if (Objects.nonNull(this.maxLength)) { - satisfiedCondition = true; - } else if (Objects.nonNull(this.uniqueItems)) { - satisfiedCondition = true; - } else if (Objects.nonNull(this.elements)) { - satisfiedCondition = true; - } else if (Objects.nonNull(this.name)) { - satisfiedCondition = true; - } else if (Objects.nonNull(this.regex)) { - satisfiedCondition = true; - } else if (Objects.nonNull(this.minItems)) { - satisfiedCondition = true; - } else if (Objects.nonNull(this.values)) { - satisfiedCondition = true; - } else if (Objects.nonNull(this.minimum)) { - satisfiedCondition = true; - } else if (Objects.nonNull(this.numberEnum)) { - satisfiedCondition = true; - } else if (Objects.nonNull(this.valueLength)) { - satisfiedCondition = true; - } + if (Objects.nonNull(this.precision)) { + satisfiedCondition = true; + } else if (Objects.nonNull(this.defaultItem)) { + satisfiedCondition = true; + } else if (Objects.nonNull(this.maximum)) { + satisfiedCondition = true; + } else if (Objects.nonNull(this.type)) { + satisfiedCondition = true; + } else if (Objects.nonNull(this.scale)) { + satisfiedCondition = true; + } else if (Objects.nonNull(this.minLength)) { + satisfiedCondition = true; + } else if (Objects.nonNull(this.increment)) { + satisfiedCondition = true; + } else if (Objects.nonNull(this.keyType)) { + satisfiedCondition = true; + } else if (Objects.nonNull(this.requiredValues)) { + satisfiedCondition = true; + } else if (Objects.nonNull(this.optionalUnion)) { + satisfiedCondition = true; + } else if (Objects.nonNull(this.initialValue)) { + satisfiedCondition = true; + } else if (Objects.nonNull(this.flagExclusiveMinimum)) { + satisfiedCondition = true; + } else if (Objects.nonNull(this.flagExclusiveMaximum)) { + satisfiedCondition = true; + } else if (Objects.nonNull(this.defaultValue)) { + satisfiedCondition = true; + } else if (Objects.nonNull(this.enumValues)) { + satisfiedCondition = true; + } else if (Objects.nonNull(this.properties)) { + satisfiedCondition = true; + } else if (Objects.nonNull(this.defaultValues)) { + satisfiedCondition = true; + } else if (Objects.nonNull(this.unionEnum)) { + satisfiedCondition = true; + } else if (Objects.nonNull(this.seqEnum)) { + satisfiedCondition = true; + } else if (Objects.nonNull(this.arraySize)) { + satisfiedCondition = true; + } else if (Objects.nonNull(this.multipleOf)) { + satisfiedCondition = true; + } else if (Objects.nonNull(this.mapSize)) { + satisfiedCondition = true; + } else if (Objects.nonNull(this.mapTypes)) { + satisfiedCondition = true; + } else if (Objects.nonNull(this.format)) { + satisfiedCondition = true; + } else if (Objects.nonNull(this.generatedFlag)) { + satisfiedCondition = true; + } else if (Objects.nonNull(this.maxLength)) { + satisfiedCondition = true; + } else if (Objects.nonNull(this.uniqueItems)) { + satisfiedCondition = true; + } else if (Objects.nonNull(this.elements)) { + satisfiedCondition = true; + } else if (Objects.nonNull(this.name)) { + satisfiedCondition = true; + } else if (Objects.nonNull(this.regex)) { + satisfiedCondition = true; + } else if (Objects.nonNull(this.minItems)) { + satisfiedCondition = true; + } else if (Objects.nonNull(this.values)) { + satisfiedCondition = true; + } else if (Objects.nonNull(this.minimum)) { + satisfiedCondition = true; + } else if (Objects.nonNull(this.numberEnum)) { + satisfiedCondition = true; + } else if (Objects.nonNull(this.valueLength)) { + satisfiedCondition = true; + } if (!satisfiedCondition) { throw new ModelClassException("ApiTypeArrayDTO"); diff --git a/multiapi-engine/src/test/resources/openapigenerator/testComplexAnyOf/assets/ApiUnionFieldDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testComplexAnyOf/assets/ApiUnionFieldDTO.java index 760cb946..9f622415 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testComplexAnyOf/assets/ApiUnionFieldDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testComplexAnyOf/assets/ApiUnionFieldDTO.java @@ -47,18 +47,7 @@ public String toString() { @JsonProperty(value ="optionalUnion") private Boolean optionalUnion; @JsonProperty(value ="values") - private List values = new ArrayList(); - - private ApiUnionFieldDTO(ApiDefaultItemDTO defaultItem, Boolean generatedFlag, String type, UnionEnum unionEnum, String name, Boolean optionalUnion, List values) { - this.defaultItem = defaultItem; - this.generatedFlag = generatedFlag; - this.type = type; - this.unionEnum = unionEnum; - this.name = name; - this.optionalUnion = optionalUnion; - this.values = values; - - } + private List values; private ApiUnionFieldDTO(ApiUnionFieldDTOBuilder builder) { this.defaultItem = builder.defaultItem; @@ -100,6 +89,7 @@ public ApiUnionFieldDTO.ApiUnionFieldDTOBuilder type(String type) { this.type = type; return this; } + public ApiUnionFieldDTO.ApiUnionFieldDTOBuilder unionEnum(UnionEnum unionEnum) { this.unionEnum = unionEnum; return this; @@ -114,6 +104,7 @@ public ApiUnionFieldDTO.ApiUnionFieldDTOBuilder optionalUnion(Boolean optionalUn this.optionalUnion = optionalUnion; return this; } + public ApiUnionFieldDTO.ApiUnionFieldDTOBuilder values(List values) { if (!values.isEmpty()) { this.values.addAll(values); @@ -122,7 +113,7 @@ public ApiUnionFieldDTO.ApiUnionFieldDTOBuilder values(List val } public ApiUnionFieldDTO.ApiUnionFieldDTOBuilder value(ApiTypeArrayDTO value) { - if (value != null) { + if (Objects.nonNull(value)) { this.values.add(value); } return this; diff --git a/multiapi-engine/src/test/resources/openapigenerator/testMultipleRefGeneration/assets/InlineResponse200CreateGameDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testMultipleRefGeneration/assets/InlineResponse200CreateGameDTO.java index 676adf64..11944e9e 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testMultipleRefGeneration/assets/InlineResponse200CreateGameDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testMultipleRefGeneration/assets/InlineResponse200CreateGameDTO.java @@ -17,13 +17,6 @@ public class InlineResponse200CreateGameDTO { @JsonProperty(value ="message") private MessageDTO message; - private InlineResponse200CreateGameDTO(String description, Integer code, MessageDTO message) { - this.description = description; - this.code = code; - this.message = message; - - } - private InlineResponse200CreateGameDTO(InlineResponse200CreateGameDTOBuilder builder) { this.description = builder.description; this.code = builder.code; @@ -51,6 +44,7 @@ public InlineResponse200CreateGameDTO.InlineResponse200CreateGameDTOBuilder code this.code = code; return this; } + public InlineResponse200CreateGameDTO.InlineResponse200CreateGameDTOBuilder message(MessageDTO message) { this.message = message; return this; diff --git a/multiapi-engine/src/test/resources/openapigenerator/testMultipleRefGeneration/assets/MessageDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testMultipleRefGeneration/assets/MessageDTO.java index e5efc1c0..328a6015 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testMultipleRefGeneration/assets/MessageDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testMultipleRefGeneration/assets/MessageDTO.java @@ -15,12 +15,6 @@ public class MessageDTO { @JsonProperty(value ="message") private MessageDTO message; - private MessageDTO(String description, MessageDTO message) { - this.description = description; - this.message = message; - - } - private MessageDTO(MessageDTOBuilder builder) { this.description = builder.description; this.message = builder.message; @@ -41,6 +35,7 @@ public MessageDTO.MessageDTOBuilder description(String description) { this.description = description; return this; } + public MessageDTO.MessageDTOBuilder message(MessageDTO message) { this.message = message; return this; diff --git a/multiapi-engine/src/test/resources/openapigenerator/testOneOfInResponse/assets/InlineResponse200ListGamesOneOfDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testOneOfInResponse/assets/InlineResponse200ListGamesOneOfDTO.java index eb6b99af..2b67c8fa 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testOneOfInResponse/assets/InlineResponse200ListGamesOneOfDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testOneOfInResponse/assets/InlineResponse200ListGamesOneOfDTO.java @@ -4,12 +4,12 @@ import com.fasterxml.jackson.annotation.JsonProperty; import java.util.List; import java.util.ArrayList; +import com.sngular.multifileplugin.testoneofinresponse.model.exception.ModelClassException; import lombok.Builder; import lombok.NonNull; import lombok.Singular; import lombok.Value; import lombok.extern.jackson.Jacksonized; -import com.sngular.multifileplugin.testoneofinresponse.model.exception.ModelClassException; @Value public class InlineResponse200ListGamesOneOfDTO { @@ -50,20 +50,20 @@ private InlineResponse200ListGamesOneOfDTO(@NonNull String gameName, @NonNull St private void validatePartialCombinations() { boolean satisfiedCondition = false; - if (Objects.nonNull(this.gameName)) { - satisfiedCondition = true; - } else if (Objects.nonNull(this.name)) { - satisfiedCondition = true; - } else if (Objects.nonNull(this.id)) { - satisfiedCondition = true; - } else if (Objects.nonNull(this.rooms)) { - satisfiedCondition = true; - } else if (Objects.nonNull(this.players)) { - satisfiedCondition = true; - } + if (Objects.nonNull(this.gameName)) { + satisfiedCondition = true; + } else if (Objects.nonNull(this.name)) { + satisfiedCondition = true; + } else if (Objects.nonNull(this.id)) { + satisfiedCondition = true; + } else if (Objects.nonNull(this.rooms)) { + satisfiedCondition = true; + } else if (Objects.nonNull(this.players)) { + satisfiedCondition = true; + } if (!satisfiedCondition) { - throw new ModelClassException("InlineResponse200ListGamesOneOfDTO"); + throw new ModelClassException("InlineResponse200ListGamesOneOfDTO"); } } } diff --git a/multiapi-engine/src/test/resources/openapigenerator/testSimpleBuild/api-rest.yaml b/multiapi-engine/src/test/resources/openapigenerator/testSimpleBuild/api-rest.yaml index deece974..87a3cab8 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testSimpleBuild/api-rest.yaml +++ b/multiapi-engine/src/test/resources/openapigenerator/testSimpleBuild/api-rest.yaml @@ -146,10 +146,7 @@ paths: schema: type: integer requestBody: - content: - application/json: - schema: - $ref: '#/components/requestBodies/UpdateQuote' + $ref: '#/components/requestBodies/UpdateQuote' responses: '200': description: Successful operation @@ -184,10 +181,7 @@ paths: schema: type: integer requestBody: - content: - application/json: - schema: - $ref: '#/components/requestBodies/ActivatePolicy' + $ref: '#/components/requestBodies/ActivatePolicy' responses: '200': description: Successful operation @@ -215,10 +209,7 @@ paths: description: Once the debtor has paid for the insurance, we settle it using this endpoint. operationId: settle requestBody: - content: - application/json: - schema: - $ref: '#/components/requestBodies/PolicySettlement' + $ref: '#/components/requestBodies/PolicySettlement' parameters: - name: policyIdInProvider in: path diff --git a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/assets/lombok/ApiErrorDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/assets/lombok/ApiErrorDTO.java index 509d1f49..9d43910e 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/assets/lombok/ApiErrorDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/assets/lombok/ApiErrorDTO.java @@ -3,16 +3,17 @@ import com.fasterxml.jackson.annotation.JsonProperty; import java.util.List; import java.util.ArrayList; -import com.sngular.multifileplugin.lombok.testapi.model.customvalidator.Size; import com.sngular.multifileplugin.lombok.testapi.model.customvalidator.MaxInteger; import com.sngular.multifileplugin.lombok.testapi.model.customvalidator.MinInteger; -import com.sngular.multifileplugin.lombok.testapi.model.customvalidator.Pattern; import com.sngular.multifileplugin.lombok.testapi.model.customvalidator.MultipleOf; +import com.sngular.multifileplugin.lombok.testapi.model.customvalidator.Size; +import com.sngular.multifileplugin.lombok.testapi.model.customvalidator.Pattern; import com.sngular.multifileplugin.lombok.testapi.model.customvalidator.MaxItems; import com.sngular.multifileplugin.lombok.testapi.model.customvalidator.MinItems; import com.sngular.multifileplugin.lombok.testapi.model.customvalidator.UniqueItems; import lombok.Builder; import lombok.NonNull; +import lombok.Singular; import lombok.Value; import lombok.extern.jackson.Jacksonized; @@ -39,6 +40,7 @@ public class ApiErrorDTO { @MaxItems(maximum = 10) @MinItems(minimum = 5) @UniqueItems + @Singular("_test") private List test; diff --git a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/assets/lombok/ApiTestAllOfDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/assets/lombok/ApiTestAllOfDTO.java index a44d32a4..fc3abdeb 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/assets/lombok/ApiTestAllOfDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/assets/lombok/ApiTestAllOfDTO.java @@ -4,6 +4,7 @@ import java.util.List; import java.util.ArrayList; import lombok.Builder; +import lombok.Singular; import lombok.Value; import lombok.extern.jackson.Jacksonized; @@ -11,6 +12,7 @@ public class ApiTestAllOfDTO { @JsonProperty(value ="testers") + @Singular("tester") private List testers; @JsonProperty(value ="testName") diff --git a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/assets/lombok/ApiTestDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/assets/lombok/ApiTestDTO.java index ff436632..72e183ab 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/assets/lombok/ApiTestDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/assets/lombok/ApiTestDTO.java @@ -5,6 +5,7 @@ import java.util.ArrayList; import lombok.Builder; import lombok.NonNull; +import lombok.Singular; import lombok.Value; import lombok.extern.jackson.Jacksonized; @@ -13,6 +14,7 @@ public class ApiTestDTO { @JsonProperty(value ="testers") @NonNull + @Singular("tester") private List testers; @JsonProperty(value ="testName") diff --git a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/assets/lombok/ApiTestInfoDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/assets/lombok/ApiTestInfoDTO.java index 12fbc638..b23d1429 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/assets/lombok/ApiTestInfoDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/assets/lombok/ApiTestInfoDTO.java @@ -5,6 +5,7 @@ import java.util.ArrayList; import lombok.Builder; import lombok.NonNull; +import lombok.Singular; import lombok.Value; import lombok.extern.jackson.Jacksonized; @@ -12,6 +13,7 @@ public class ApiTestInfoDTO { @JsonProperty(value ="testers") + @Singular("tester") private List testers; @JsonProperty(value ="testName") diff --git a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/MaxBigDecimal.java b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/MaxBigDecimal.java new file mode 100644 index 00000000..920678a5 --- /dev/null +++ b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/MaxBigDecimal.java @@ -0,0 +1,17 @@ +package com.sngular.multifileplugin.testapi.model.customvalidator; + +import javax.validation.Constraint; +import javax.validation.Payload; +import java.lang.annotation.*; + +@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, ElementType.ANNOTATION_TYPE}) +@Retention(RetentionPolicy.RUNTIME) +@Constraint(validatedBy = MaxBigDecimalValidator.class) +@Documented +public @interface MaxBigDecimal { + String maximum(); + boolean exclusive(); + String message() default "Value is bigger than the maximum."; + Class[] groups() default {}; + Class[] payload() default {}; +} \ No newline at end of file diff --git a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/MaxBigDecimalValidator.java b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/MaxBigDecimalValidator.java new file mode 100644 index 00000000..20921d22 --- /dev/null +++ b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/MaxBigDecimalValidator.java @@ -0,0 +1,25 @@ +package com.sngular.multifileplugin.testapi.model.customvalidator; + +import java.math.BigDecimal; +import java.util.Objects; + +import javax.validation.ConstraintValidator; +import javax.validation.ConstraintValidatorContext; + +public class MaxBigDecimalValidator implements ConstraintValidator { + + private BigDecimal maximum; + private boolean exclusive; + + @Override + public void initialize(MaxBigDecimal constraintAnnotation) { + ConstraintValidator.super.initialize(constraintAnnotation); + this.maximum = new BigDecimal(constraintAnnotation.maximum()); + this.exclusive = constraintAnnotation.exclusive(); + } + + @Override + public boolean isValid(BigDecimal value, ConstraintValidatorContext context) { + return Objects.isNull(value) || (value.compareTo(this.maximum) < 0 || (!exclusive && value.compareTo(this.maximum) == 0); + } +} \ No newline at end of file diff --git a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/MaxDouble.java b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/MaxDouble.java new file mode 100644 index 00000000..66d07798 --- /dev/null +++ b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/MaxDouble.java @@ -0,0 +1,17 @@ +package com.sngular.multifileplugin.testapi.model.customvalidator; + +import javax.validation.Constraint; +import javax.validation.Payload; +import java.lang.annotation.*; + +@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, ElementType.ANNOTATION_TYPE}) +@Retention(RetentionPolicy.RUNTIME) +@Constraint(validatedBy = MaxDoubleValidator.class) +@Documented +public @interface MaxDouble { + String maximum(); + boolean exclusive(); + String message() default "Value is bigger than the maximum."; + Class[] groups() default {}; + Class[] payload() default {}; +} \ No newline at end of file diff --git a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/MaxDoubleValidator.java b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/MaxDoubleValidator.java new file mode 100644 index 00000000..490cd7a1 --- /dev/null +++ b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/MaxDoubleValidator.java @@ -0,0 +1,24 @@ +package com.sngular.multifileplugin.testapi.model.customvalidator; + +import java.util.Objects; + +import javax.validation.ConstraintValidator; +import javax.validation.ConstraintValidatorContext; + +public class MaxDoubleValidator implements ConstraintValidator { + + private double maximum; + private boolean exclusive; + + @Override + public void initialize(MaxDouble constraintAnnotation) { + ConstraintValidator.super.initialize(constraintAnnotation); + this.maximum = Double.parseDouble(constraintAnnotation.maximum()); + this.exclusive = constraintAnnotation.exclusive(); + } + + @Override + public boolean isValid(Double value, ConstraintValidatorContext context) { + return Objects.isNull(value) || (value.doubleValue() < this.maximum || (!exclusive && value.doubleValue() == this.maximum)); + } +} \ No newline at end of file diff --git a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/MaxFloat.java b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/MaxFloat.java new file mode 100644 index 00000000..8e889066 --- /dev/null +++ b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/MaxFloat.java @@ -0,0 +1,17 @@ +package com.sngular.multifileplugin.testapi.model.customvalidator; + +import javax.validation.Constraint; +import javax.validation.Payload; +import java.lang.annotation.*; + +@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, ElementType.ANNOTATION_TYPE}) +@Retention(RetentionPolicy.RUNTIME) +@Constraint(validatedBy = MaxFloatValidator.class) +@Documented +public @interface MaxFloat { + String maximum(); + boolean exclusive(); + String message() default "Value is bigger than the maximum."; + Class[] groups() default {}; + Class[] payload() default {}; +} \ No newline at end of file diff --git a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/MaxFloatValidator.java b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/MaxFloatValidator.java new file mode 100644 index 00000000..a656e06e --- /dev/null +++ b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/MaxFloatValidator.java @@ -0,0 +1,24 @@ +package com.sngular.multifileplugin.testapi.model.customvalidator; + +import java.util.Objects; + +import javax.validation.ConstraintValidator; +import javax.validation.ConstraintValidatorContext; + +public class MaxFloatValidator implements ConstraintValidator { + + private float maximum; + private boolean exclusive; + + @Override + public void initialize(MaxFloat constraintAnnotation) { + ConstraintValidator.super.initialize(constraintAnnotation); + this.maximum = Float.parseFloat(constraintAnnotation.maximum()); + this.exclusive = constraintAnnotation.exclusive(); + } + + @Override + public boolean isValid(Float value, ConstraintValidatorContext context) { + return Objects.isNull(value) || (value.floatValue() < this.maximum || (!exclusive && value.floatValue() == this.maximum)); + } +} \ No newline at end of file diff --git a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/MaxInteger.java b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/MaxInteger.java index 253dfde6..98db09d4 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/MaxInteger.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/MaxInteger.java @@ -1,7 +1,7 @@ package com.sngular.multifileplugin.testapi.model.customvalidator; -import jakarta.validation.Constraint; -import jakarta.validation.Payload; +import javax.validation.Constraint; +import javax.validation.Payload; import java.lang.annotation.*; @Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, ElementType.ANNOTATION_TYPE}) diff --git a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/MaxIntegerValidator.java b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/MaxIntegerValidator.java index 806cc0ae..3071e7e7 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/MaxIntegerValidator.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/MaxIntegerValidator.java @@ -2,8 +2,8 @@ import java.util.Objects; -import jakarta.validation.ConstraintValidator; -import jakarta.validation.ConstraintValidatorContext; +import javax.validation.ConstraintValidator; +import javax.validation.ConstraintValidatorContext; public class MaxIntegerValidator implements ConstraintValidator { diff --git a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/MaxItems.java b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/MaxItems.java index 948eb094..c140599d 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/MaxItems.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/MaxItems.java @@ -1,7 +1,7 @@ package com.sngular.multifileplugin.testapi.model.customvalidator; -import jakarta.validation.Constraint; -import jakarta.validation.Payload; +import javax.validation.Constraint; +import javax.validation.Payload; import java.lang.annotation.*; @Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, ElementType.ANNOTATION_TYPE}) diff --git a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/MaxItemsValidator.java b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/MaxItemsValidator.java index 38b23174..411963fd 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/MaxItemsValidator.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/MaxItemsValidator.java @@ -3,8 +3,8 @@ import java.util.List; import java.util.Objects; -import jakarta.validation.ConstraintValidator; -import jakarta.validation.ConstraintValidatorContext; +import javax.validation.ConstraintValidator; +import javax.validation.ConstraintValidatorContext; public class MaxItemsValidator implements ConstraintValidator> { diff --git a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/MinBigDecimal.java b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/MinBigDecimal.java new file mode 100644 index 00000000..1a6e383d --- /dev/null +++ b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/MinBigDecimal.java @@ -0,0 +1,17 @@ +package com.sngular.multifileplugin.testapi.model.customvalidator; + +import javax.validation.Constraint; +import javax.validation.Payload; +import java.lang.annotation.*; + +@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, ElementType.ANNOTATION_TYPE}) +@Retention(RetentionPolicy.RUNTIME) +@Constraint(validatedBy = MinBigDecimalValidator.class) +@Documented +public @interface MinBigDecimal { + String minimum(); + boolean exclusive(); + String message() default "Value is smaller than the minimum."; + Class[] groups() default {}; + Class[] payload() default {}; +} \ No newline at end of file diff --git a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/MinBigDecimalValidator.java b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/MinBigDecimalValidator.java new file mode 100644 index 00000000..2853538f --- /dev/null +++ b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/MinBigDecimalValidator.java @@ -0,0 +1,25 @@ +package com.sngular.multifileplugin.testapi.model.customvalidator; + +import java.math.BigDecimal; +import java.util.Objects; + +import javax.validation.ConstraintValidator; +import javax.validation.ConstraintValidatorContext; + +public class MinBigDecimalValidator implements ConstraintValidator { + + private BigDecimal minimum; + private boolean exclusive; + + @Override + public void initialize(MinBigDecimal constraintAnnotation) { + ConstraintValidator.super.initialize(constraintAnnotation); + this.minimum = new BigDecimal(constraintAnnotation.minimum()); + this.exclusive = constraintAnnotation.exclusive(); + } + + @Override + public boolean isValid(BigDecimal value, ConstraintValidatorContext context) { + return Objects.isNull(value) || (value.compareTo(this.minimum) > 0 || (!exclusive && value.compareTo(this.minimum) == 0); + } +} \ No newline at end of file diff --git a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/MinDouble.java b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/MinDouble.java new file mode 100644 index 00000000..d39ff710 --- /dev/null +++ b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/MinDouble.java @@ -0,0 +1,17 @@ +package com.sngular.multifileplugin.testapi.model.customvalidator; + +import javax.validation.Constraint; +import javax.validation.Payload; +import java.lang.annotation.*; + +@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, ElementType.ANNOTATION_TYPE}) +@Retention(RetentionPolicy.RUNTIME) +@Constraint(validatedBy = MinDoubleValidator.class) +@Documented +public @interface MinDouble { + String minimum(); + boolean exclusive(); + String message() default "Value is smaller than the minimum."; + Class[] groups() default {}; + Class[] payload() default {}; +} \ No newline at end of file diff --git a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/MinDoubleValidator.java b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/MinDoubleValidator.java new file mode 100644 index 00000000..4440be41 --- /dev/null +++ b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/MinDoubleValidator.java @@ -0,0 +1,24 @@ +package com.sngular.multifileplugin.testapi.model.customvalidator; + +import java.util.Objects; + +import javax.validation.ConstraintValidator; +import javax.validation.ConstraintValidatorContext; + +public class MinDoubleValidator implements ConstraintValidator { + + private double minimum; + private boolean exclusive; + + @Override + public void initialize(MinDouble constraintAnnotation) { + ConstraintValidator.super.initialize(constraintAnnotation); + this.minimum = Double.parseDouble(constraintAnnotation.minimum()); + this.exclusive = constraintAnnotation.exclusive(); + } + + @Override + public boolean isValid(Double value, ConstraintValidatorContext context) { + return Objects.isNull(value) || (value.doubleValue() > this.minimum || (!exclusive && value.doubleValue() == this.minimum)); + } +} \ No newline at end of file diff --git a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/MinFloat.java b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/MinFloat.java new file mode 100644 index 00000000..a2faf299 --- /dev/null +++ b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/MinFloat.java @@ -0,0 +1,17 @@ +package com.sngular.multifileplugin.testapi.model.customvalidator; + +import javax.validation.Constraint; +import javax.validation.Payload; +import java.lang.annotation.*; + +@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, ElementType.ANNOTATION_TYPE}) +@Retention(RetentionPolicy.RUNTIME) +@Constraint(validatedBy = MinFloatValidator.class) +@Documented +public @interface MinFloat { + String minimum(); + boolean exclusive(); + String message() default "Value is smaller than the minimum."; + Class[] groups() default {}; + Class[] payload() default {}; +} \ No newline at end of file diff --git a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/MinFloatValidator.java b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/MinFloatValidator.java new file mode 100644 index 00000000..3381b63e --- /dev/null +++ b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/MinFloatValidator.java @@ -0,0 +1,24 @@ +package com.sngular.multifileplugin.testapi.model.customvalidator; + +import java.util.Objects; + +import javax.validation.ConstraintValidator; +import javax.validation.ConstraintValidatorContext; + +public class MinFloatValidator implements ConstraintValidator { + + private float minimum; + private boolean exclusive; + + @Override + public void initialize(MinFloat constraintAnnotation) { + ConstraintValidator.super.initialize(constraintAnnotation); + this.minimum = Float.parseFloat(constraintAnnotation.minimum()); + this.exclusive = constraintAnnotation.exclusive(); + } + + @Override + public boolean isValid(Float value, ConstraintValidatorContext context) { + return Objects.isNull(value) || (value.floatValue() > this.minimum || (!exclusive && value.floatValue() == this.minimum)); + } +} \ No newline at end of file diff --git a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/MinInteger.java b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/MinInteger.java index b58a31b6..535c63c0 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/MinInteger.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/MinInteger.java @@ -1,7 +1,7 @@ package com.sngular.multifileplugin.testapi.model.customvalidator; -import jakarta.validation.Constraint; -import jakarta.validation.Payload; +import javax.validation.Constraint; +import javax.validation.Payload; import java.lang.annotation.*; @Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, ElementType.ANNOTATION_TYPE}) diff --git a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/MinIntegerValidator.java b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/MinIntegerValidator.java index 978d73e7..6a377bff 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/MinIntegerValidator.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/MinIntegerValidator.java @@ -2,8 +2,8 @@ import java.util.Objects; -import jakarta.validation.ConstraintValidator; -import jakarta.validation.ConstraintValidatorContext; +import javax.validation.ConstraintValidator; +import javax.validation.ConstraintValidatorContext; public class MinIntegerValidator implements ConstraintValidator { diff --git a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/MinItems.java b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/MinItems.java index 6c234dcb..c1534895 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/MinItems.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/MinItems.java @@ -1,7 +1,7 @@ package com.sngular.multifileplugin.testapi.model.customvalidator; -import jakarta.validation.Constraint; -import jakarta.validation.Payload; +import javax.validation.Constraint; +import javax.validation.Payload; import java.lang.annotation.*; @Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, ElementType.ANNOTATION_TYPE}) diff --git a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/MinItemsValidator.java b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/MinItemsValidator.java index 6cfaf061..0edffa6f 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/MinItemsValidator.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/MinItemsValidator.java @@ -3,8 +3,8 @@ import java.util.List; import java.util.Objects; -import jakarta.validation.ConstraintValidator; -import jakarta.validation.ConstraintValidatorContext; +import javax.validation.ConstraintValidator; +import javax.validation.ConstraintValidatorContext; public class MinItemsValidator implements ConstraintValidator> { diff --git a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/MultipleOf.java b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/MultipleOf.java index 3b5987b9..871f5e67 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/MultipleOf.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/MultipleOf.java @@ -1,10 +1,10 @@ package com.sngular.multifileplugin.testapi.model.customvalidator; -import jakarta.validation.Constraint; -import jakarta.validation.Payload; +import javax.validation.Constraint; +import javax.validation.Payload; import java.lang.annotation.*; -@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, ElementType.ANNOTATION_TYPE}) +@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, ElementType.ANNOTATION_TYPE}) @Retention(RetentionPolicy.RUNTIME) @Constraint(validatedBy = MultipleOfValidator.class) @Documented diff --git a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/MultipleOfValidator.java b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/MultipleOfValidator.java index 10647a98..4e346f04 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/MultipleOfValidator.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/MultipleOfValidator.java @@ -2,8 +2,8 @@ import java.util.Objects; -import jakarta.validation.ConstraintValidator; -import jakarta.validation.ConstraintValidatorContext; +import javax.validation.ConstraintValidator; +import javax.validation.ConstraintValidatorContext; public class MultipleOfValidator implements ConstraintValidator { diff --git a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/NotNull.java b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/NotNull.java index 5f8dd237..8c92eaaa 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/NotNull.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/NotNull.java @@ -1,10 +1,10 @@ package com.sngular.multifileplugin.testapi.model.customvalidator; -import jakarta.validation.Constraint; -import jakarta.validation.Payload; +import javax.validation.Constraint; +import javax.validation.Payload; import java.lang.annotation.*; -@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, ElementType.ANNOTATION_TYPE}) +@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, ElementType.ANNOTATION_TYPE}) @Retention(RetentionPolicy.RUNTIME) @Constraint(validatedBy = NotNullValidator.class) @Documented diff --git a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/NotNullValidator.java b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/NotNullValidator.java index c88f07b1..260166ad 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/NotNullValidator.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/NotNullValidator.java @@ -1,7 +1,7 @@ package com.sngular.multifileplugin.testapi.model.customvalidator; -import jakarta.validation.ConstraintValidator; -import jakarta.validation.ConstraintValidatorContext; +import javax.validation.ConstraintValidator; +import javax.validation.ConstraintValidatorContext; import java.util.Objects; public class NotNullValidator implements ConstraintValidator { diff --git a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/Pattern.java b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/Pattern.java index 3dcecd5c..2da77421 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/Pattern.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/Pattern.java @@ -1,11 +1,11 @@ package com.sngular.multifileplugin.testapi.model.customvalidator; -import jakarta.validation.Constraint; -import jakarta.validation.Payload; +import javax.validation.Constraint; +import javax.validation.Payload; import java.lang.annotation.*; -@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, ElementType.ANNOTATION_TYPE}) +@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, ElementType.ANNOTATION_TYPE}) @Retention(RetentionPolicy.RUNTIME) @Constraint(validatedBy = PatternValidator.class) @Documented diff --git a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/PatternValidator.java b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/PatternValidator.java index 7ec927b8..0e201fca 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/PatternValidator.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/PatternValidator.java @@ -2,8 +2,8 @@ import java.util.Objects; -import jakarta.validation.ConstraintValidator; -import jakarta.validation.ConstraintValidatorContext; +import javax.validation.ConstraintValidator; +import javax.validation.ConstraintValidatorContext; public class PatternValidator implements ConstraintValidator { diff --git a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/Size.java b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/Size.java index 4476390a..dc4bfd77 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/Size.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/Size.java @@ -1,10 +1,10 @@ package com.sngular.multifileplugin.testapi.model.customvalidator; -import jakarta.validation.Constraint; -import jakarta.validation.Payload; +import javax.validation.Constraint; +import javax.validation.Payload; import java.lang.annotation.*; -@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, ElementType.ANNOTATION_TYPE}) +@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, ElementType.ANNOTATION_TYPE}) @Retention(RetentionPolicy.RUNTIME) @Constraint(validatedBy = SizeValidator.class) @Documented diff --git a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/SizeValidator.java b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/SizeValidator.java index be2c485c..45d0d634 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/SizeValidator.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/SizeValidator.java @@ -2,8 +2,8 @@ import java.util.Objects; -import jakarta.validation.ConstraintValidator; -import jakarta.validation.ConstraintValidatorContext; +import javax.validation.ConstraintValidator; +import javax.validation.ConstraintValidatorContext; public class SizeValidator implements ConstraintValidator { diff --git a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/UniqueItems.java b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/UniqueItems.java index c0ab9f15..01b08a46 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/UniqueItems.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/UniqueItems.java @@ -1,10 +1,10 @@ package com.sngular.multifileplugin.testapi.model.customvalidator; -import jakarta.validation.Constraint; -import jakarta.validation.Payload; +import javax.validation.Constraint; +import javax.validation.Payload; import java.lang.annotation.*; -@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, ElementType.ANNOTATION_TYPE}) +@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, ElementType.ANNOTATION_TYPE}) @Retention(RetentionPolicy.RUNTIME) @Constraint(validatedBy = UniqueItemsValidator.class) @Documented diff --git a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/UniqueItemsValidator.java b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/UniqueItemsValidator.java index 53071973..e3743829 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/UniqueItemsValidator.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/UniqueItemsValidator.java @@ -6,8 +6,8 @@ import java.util.Objects; import java.util.Set; -import jakarta.validation.ConstraintValidator; -import jakarta.validation.ConstraintValidatorContext; +import javax.validation.ConstraintValidator; +import javax.validation.ConstraintValidatorContext; public class UniqueItemsValidator implements ConstraintValidator> { diff --git a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/javax/MaxBigDecimal.java b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/javax/MaxBigDecimal.java new file mode 100644 index 00000000..920678a5 --- /dev/null +++ b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/javax/MaxBigDecimal.java @@ -0,0 +1,17 @@ +package com.sngular.multifileplugin.testapi.model.customvalidator; + +import javax.validation.Constraint; +import javax.validation.Payload; +import java.lang.annotation.*; + +@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, ElementType.ANNOTATION_TYPE}) +@Retention(RetentionPolicy.RUNTIME) +@Constraint(validatedBy = MaxBigDecimalValidator.class) +@Documented +public @interface MaxBigDecimal { + String maximum(); + boolean exclusive(); + String message() default "Value is bigger than the maximum."; + Class[] groups() default {}; + Class[] payload() default {}; +} \ No newline at end of file diff --git a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/javax/MaxBigDecimalValidator.java b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/javax/MaxBigDecimalValidator.java new file mode 100644 index 00000000..20921d22 --- /dev/null +++ b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/javax/MaxBigDecimalValidator.java @@ -0,0 +1,25 @@ +package com.sngular.multifileplugin.testapi.model.customvalidator; + +import java.math.BigDecimal; +import java.util.Objects; + +import javax.validation.ConstraintValidator; +import javax.validation.ConstraintValidatorContext; + +public class MaxBigDecimalValidator implements ConstraintValidator { + + private BigDecimal maximum; + private boolean exclusive; + + @Override + public void initialize(MaxBigDecimal constraintAnnotation) { + ConstraintValidator.super.initialize(constraintAnnotation); + this.maximum = new BigDecimal(constraintAnnotation.maximum()); + this.exclusive = constraintAnnotation.exclusive(); + } + + @Override + public boolean isValid(BigDecimal value, ConstraintValidatorContext context) { + return Objects.isNull(value) || (value.compareTo(this.maximum) < 0 || (!exclusive && value.compareTo(this.maximum) == 0); + } +} \ No newline at end of file diff --git a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/javax/MaxDouble.java b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/javax/MaxDouble.java new file mode 100644 index 00000000..66d07798 --- /dev/null +++ b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/javax/MaxDouble.java @@ -0,0 +1,17 @@ +package com.sngular.multifileplugin.testapi.model.customvalidator; + +import javax.validation.Constraint; +import javax.validation.Payload; +import java.lang.annotation.*; + +@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, ElementType.ANNOTATION_TYPE}) +@Retention(RetentionPolicy.RUNTIME) +@Constraint(validatedBy = MaxDoubleValidator.class) +@Documented +public @interface MaxDouble { + String maximum(); + boolean exclusive(); + String message() default "Value is bigger than the maximum."; + Class[] groups() default {}; + Class[] payload() default {}; +} \ No newline at end of file diff --git a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/javax/MaxDoubleValidator.java b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/javax/MaxDoubleValidator.java new file mode 100644 index 00000000..490cd7a1 --- /dev/null +++ b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/javax/MaxDoubleValidator.java @@ -0,0 +1,24 @@ +package com.sngular.multifileplugin.testapi.model.customvalidator; + +import java.util.Objects; + +import javax.validation.ConstraintValidator; +import javax.validation.ConstraintValidatorContext; + +public class MaxDoubleValidator implements ConstraintValidator { + + private double maximum; + private boolean exclusive; + + @Override + public void initialize(MaxDouble constraintAnnotation) { + ConstraintValidator.super.initialize(constraintAnnotation); + this.maximum = Double.parseDouble(constraintAnnotation.maximum()); + this.exclusive = constraintAnnotation.exclusive(); + } + + @Override + public boolean isValid(Double value, ConstraintValidatorContext context) { + return Objects.isNull(value) || (value.doubleValue() < this.maximum || (!exclusive && value.doubleValue() == this.maximum)); + } +} \ No newline at end of file diff --git a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/javax/MaxFloat.java b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/javax/MaxFloat.java new file mode 100644 index 00000000..8e889066 --- /dev/null +++ b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/javax/MaxFloat.java @@ -0,0 +1,17 @@ +package com.sngular.multifileplugin.testapi.model.customvalidator; + +import javax.validation.Constraint; +import javax.validation.Payload; +import java.lang.annotation.*; + +@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, ElementType.ANNOTATION_TYPE}) +@Retention(RetentionPolicy.RUNTIME) +@Constraint(validatedBy = MaxFloatValidator.class) +@Documented +public @interface MaxFloat { + String maximum(); + boolean exclusive(); + String message() default "Value is bigger than the maximum."; + Class[] groups() default {}; + Class[] payload() default {}; +} \ No newline at end of file diff --git a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/javax/MaxFloatValidator.java b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/javax/MaxFloatValidator.java new file mode 100644 index 00000000..a656e06e --- /dev/null +++ b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/javax/MaxFloatValidator.java @@ -0,0 +1,24 @@ +package com.sngular.multifileplugin.testapi.model.customvalidator; + +import java.util.Objects; + +import javax.validation.ConstraintValidator; +import javax.validation.ConstraintValidatorContext; + +public class MaxFloatValidator implements ConstraintValidator { + + private float maximum; + private boolean exclusive; + + @Override + public void initialize(MaxFloat constraintAnnotation) { + ConstraintValidator.super.initialize(constraintAnnotation); + this.maximum = Float.parseFloat(constraintAnnotation.maximum()); + this.exclusive = constraintAnnotation.exclusive(); + } + + @Override + public boolean isValid(Float value, ConstraintValidatorContext context) { + return Objects.isNull(value) || (value.floatValue() < this.maximum || (!exclusive && value.floatValue() == this.maximum)); + } +} \ No newline at end of file diff --git a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/javax/MaxItems.java b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/javax/MaxItems.java index 7e828803..c140599d 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/javax/MaxItems.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/javax/MaxItems.java @@ -4,7 +4,7 @@ import javax.validation.Payload; import java.lang.annotation.*; -@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, ElementType.ANNOTATION_TYPE}) +@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, ElementType.ANNOTATION_TYPE}) @Retention(RetentionPolicy.RUNTIME) @Constraint(validatedBy = MaxItemsValidator.class) @Documented diff --git a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/javax/MinBigDecimal.java b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/javax/MinBigDecimal.java new file mode 100644 index 00000000..1a6e383d --- /dev/null +++ b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/javax/MinBigDecimal.java @@ -0,0 +1,17 @@ +package com.sngular.multifileplugin.testapi.model.customvalidator; + +import javax.validation.Constraint; +import javax.validation.Payload; +import java.lang.annotation.*; + +@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, ElementType.ANNOTATION_TYPE}) +@Retention(RetentionPolicy.RUNTIME) +@Constraint(validatedBy = MinBigDecimalValidator.class) +@Documented +public @interface MinBigDecimal { + String minimum(); + boolean exclusive(); + String message() default "Value is smaller than the minimum."; + Class[] groups() default {}; + Class[] payload() default {}; +} \ No newline at end of file diff --git a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/javax/MinBigDecimalValidator.java b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/javax/MinBigDecimalValidator.java new file mode 100644 index 00000000..2853538f --- /dev/null +++ b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/javax/MinBigDecimalValidator.java @@ -0,0 +1,25 @@ +package com.sngular.multifileplugin.testapi.model.customvalidator; + +import java.math.BigDecimal; +import java.util.Objects; + +import javax.validation.ConstraintValidator; +import javax.validation.ConstraintValidatorContext; + +public class MinBigDecimalValidator implements ConstraintValidator { + + private BigDecimal minimum; + private boolean exclusive; + + @Override + public void initialize(MinBigDecimal constraintAnnotation) { + ConstraintValidator.super.initialize(constraintAnnotation); + this.minimum = new BigDecimal(constraintAnnotation.minimum()); + this.exclusive = constraintAnnotation.exclusive(); + } + + @Override + public boolean isValid(BigDecimal value, ConstraintValidatorContext context) { + return Objects.isNull(value) || (value.compareTo(this.minimum) > 0 || (!exclusive && value.compareTo(this.minimum) == 0); + } +} \ No newline at end of file diff --git a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/javax/MinDouble.java b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/javax/MinDouble.java new file mode 100644 index 00000000..d39ff710 --- /dev/null +++ b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/javax/MinDouble.java @@ -0,0 +1,17 @@ +package com.sngular.multifileplugin.testapi.model.customvalidator; + +import javax.validation.Constraint; +import javax.validation.Payload; +import java.lang.annotation.*; + +@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, ElementType.ANNOTATION_TYPE}) +@Retention(RetentionPolicy.RUNTIME) +@Constraint(validatedBy = MinDoubleValidator.class) +@Documented +public @interface MinDouble { + String minimum(); + boolean exclusive(); + String message() default "Value is smaller than the minimum."; + Class[] groups() default {}; + Class[] payload() default {}; +} \ No newline at end of file diff --git a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/javax/MinDoubleValidator.java b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/javax/MinDoubleValidator.java new file mode 100644 index 00000000..4440be41 --- /dev/null +++ b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/javax/MinDoubleValidator.java @@ -0,0 +1,24 @@ +package com.sngular.multifileplugin.testapi.model.customvalidator; + +import java.util.Objects; + +import javax.validation.ConstraintValidator; +import javax.validation.ConstraintValidatorContext; + +public class MinDoubleValidator implements ConstraintValidator { + + private double minimum; + private boolean exclusive; + + @Override + public void initialize(MinDouble constraintAnnotation) { + ConstraintValidator.super.initialize(constraintAnnotation); + this.minimum = Double.parseDouble(constraintAnnotation.minimum()); + this.exclusive = constraintAnnotation.exclusive(); + } + + @Override + public boolean isValid(Double value, ConstraintValidatorContext context) { + return Objects.isNull(value) || (value.doubleValue() > this.minimum || (!exclusive && value.doubleValue() == this.minimum)); + } +} \ No newline at end of file diff --git a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/javax/MinFloat.java b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/javax/MinFloat.java new file mode 100644 index 00000000..a2faf299 --- /dev/null +++ b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/javax/MinFloat.java @@ -0,0 +1,17 @@ +package com.sngular.multifileplugin.testapi.model.customvalidator; + +import javax.validation.Constraint; +import javax.validation.Payload; +import java.lang.annotation.*; + +@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, ElementType.ANNOTATION_TYPE}) +@Retention(RetentionPolicy.RUNTIME) +@Constraint(validatedBy = MinFloatValidator.class) +@Documented +public @interface MinFloat { + String minimum(); + boolean exclusive(); + String message() default "Value is smaller than the minimum."; + Class[] groups() default {}; + Class[] payload() default {}; +} \ No newline at end of file diff --git a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/javax/MinFloatValidator.java b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/javax/MinFloatValidator.java new file mode 100644 index 00000000..3381b63e --- /dev/null +++ b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/javax/MinFloatValidator.java @@ -0,0 +1,24 @@ +package com.sngular.multifileplugin.testapi.model.customvalidator; + +import java.util.Objects; + +import javax.validation.ConstraintValidator; +import javax.validation.ConstraintValidatorContext; + +public class MinFloatValidator implements ConstraintValidator { + + private float minimum; + private boolean exclusive; + + @Override + public void initialize(MinFloat constraintAnnotation) { + ConstraintValidator.super.initialize(constraintAnnotation); + this.minimum = Float.parseFloat(constraintAnnotation.minimum()); + this.exclusive = constraintAnnotation.exclusive(); + } + + @Override + public boolean isValid(Float value, ConstraintValidatorContext context) { + return Objects.isNull(value) || (value.floatValue() > this.minimum || (!exclusive && value.floatValue() == this.minimum)); + } +} \ No newline at end of file diff --git a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/javax/MinItems.java b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/javax/MinItems.java index d70d4a83..c1534895 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/javax/MinItems.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/javax/MinItems.java @@ -4,7 +4,7 @@ import javax.validation.Payload; import java.lang.annotation.*; -@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, ElementType.ANNOTATION_TYPE}) +@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, ElementType.ANNOTATION_TYPE}) @Retention(RetentionPolicy.RUNTIME) @Constraint(validatedBy = MinItemsValidator.class) @Documented diff --git a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/javax/MultipleOf.java b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/javax/MultipleOf.java index 64f01632..871f5e67 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/javax/MultipleOf.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/javax/MultipleOf.java @@ -4,7 +4,7 @@ import javax.validation.Payload; import java.lang.annotation.*; -@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, ElementType.ANNOTATION_TYPE}) +@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, ElementType.ANNOTATION_TYPE}) @Retention(RetentionPolicy.RUNTIME) @Constraint(validatedBy = MultipleOfValidator.class) @Documented diff --git a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/javax/NotNull.java b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/javax/NotNull.java index 467b2857..8c92eaaa 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/javax/NotNull.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/javax/NotNull.java @@ -4,7 +4,7 @@ import javax.validation.Payload; import java.lang.annotation.*; -@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, ElementType.ANNOTATION_TYPE}) +@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, ElementType.ANNOTATION_TYPE}) @Retention(RetentionPolicy.RUNTIME) @Constraint(validatedBy = NotNullValidator.class) @Documented diff --git a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/javax/Pattern.java b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/javax/Pattern.java index 849464f0..2da77421 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/javax/Pattern.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/javax/Pattern.java @@ -5,7 +5,7 @@ import java.lang.annotation.*; -@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, ElementType.ANNOTATION_TYPE}) +@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, ElementType.ANNOTATION_TYPE}) @Retention(RetentionPolicy.RUNTIME) @Constraint(validatedBy = PatternValidator.class) @Documented diff --git a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/javax/Size.java b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/javax/Size.java index 4665c3b0..dc4bfd77 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/javax/Size.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/javax/Size.java @@ -4,7 +4,7 @@ import javax.validation.Payload; import java.lang.annotation.*; -@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, ElementType.ANNOTATION_TYPE}) +@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, ElementType.ANNOTATION_TYPE}) @Retention(RetentionPolicy.RUNTIME) @Constraint(validatedBy = SizeValidator.class) @Documented diff --git a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/javax/UniqueItems.java b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/javax/UniqueItems.java index a61e12b7..01b08a46 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/javax/UniqueItems.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/javax/UniqueItems.java @@ -4,7 +4,7 @@ import javax.validation.Payload; import java.lang.annotation.*; -@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, ElementType.ANNOTATION_TYPE}) +@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, ElementType.ANNOTATION_TYPE}) @Retention(RetentionPolicy.RUNTIME) @Constraint(validatedBy = UniqueItemsValidator.class) @Documented From 6c35935489350bfd299e99187d95963d874ae531 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?jose=20enrique=20garcia=20maci=C3=B1eiras?= Date: Tue, 24 Sep 2024 01:10:15 +0200 Subject: [PATCH 18/26] Fix Engine --- .../template/TemplateIndexConstants.java | 2 - .../plugin/common/model/SchemaObject.java | 1 + .../template/CommonTemplateFactory.java | 116 ++++++------ .../CommonTemplateIndexConstants.java | 4 + .../common/template/CommonTemplateLoader.java | 51 +++--- .../plugin/common/tools/ModelBuilder.java | 13 +- .../template/ClasspathTemplateLoader.java | 15 +- .../templates/model/templateContentEnum.ftlh | 87 +++++++++ .../assets/EnumSchemaDTO.java | 2 +- .../assets/SecondTestDTO.java | 4 +- .../assets/TestDTO.java | 4 +- .../assets/TestValueDTO.java | 6 +- .../assets/TestValueValueDTO.java | 8 +- .../assets/ThirdTestDTO.java | 4 +- .../assets/ApiDefaultItemDTO.java | 125 +++---------- .../assets/model/ArrayFieldDTO.java | 7 +- .../assets/model/EnumFieldDTO.java | 4 +- .../assets/model/FieldValueDTO.java | 166 +++++++++--------- .../assets/model/MapFieldDTO.java | 7 +- .../assets/model/ObjectFieldDTO.java | 10 +- .../assets/model/SchemaDTO.java | 4 +- .../assets/model/StringFieldDTO.java | 4 +- .../assets/model/UnionFieldDTO.java | 4 +- .../jakarta/MaxBigDecimal.java | 4 +- .../jakarta/MaxBigDecimalValidator.java | 4 +- .../customvalidator/jakarta/MaxDouble.java | 4 +- .../jakarta/MaxDoubleValidator.java | 4 +- .../customvalidator/jakarta/MaxFloat.java | 4 +- .../jakarta/MaxFloatValidator.java | 4 +- .../customvalidator/jakarta/MaxInteger.java | 4 +- .../jakarta/MaxIntegerValidator.java | 4 +- .../customvalidator/jakarta/MaxItems.java | 4 +- .../jakarta/MaxItemsValidator.java | 4 +- .../jakarta/MinBigDecimal.java | 4 +- .../jakarta/MinBigDecimalValidator.java | 4 +- .../customvalidator/jakarta/MinDouble.java | 4 +- .../jakarta/MinDoubleValidator.java | 4 +- .../customvalidator/jakarta/MinFloat.java | 4 +- .../jakarta/MinFloatValidator.java | 4 +- .../customvalidator/jakarta/MinInteger.java | 4 +- .../jakarta/MinIntegerValidator.java | 4 +- .../customvalidator/jakarta/MinItems.java | 4 +- .../jakarta/MinItemsValidator.java | 4 +- .../customvalidator/jakarta/MultipleOf.java | 4 +- .../jakarta/MultipleOfValidator.java | 4 +- .../customvalidator/jakarta/NotNull.java | 4 +- .../jakarta/NotNullValidator.java | 4 +- .../customvalidator/jakarta/Pattern.java | 4 +- .../jakarta/PatternValidator.java | 4 +- .../customvalidator/jakarta/Size.java | 4 +- .../jakarta/SizeValidator.java | 4 +- .../customvalidator/jakarta/UniqueItems.java | 4 +- .../jakarta/UniqueItemsValidator.java | 4 +- 53 files changed, 415 insertions(+), 353 deletions(-) create mode 100644 multiapi-engine/src/main/resources/templates/model/templateContentEnum.ftlh diff --git a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/asyncapi/template/TemplateIndexConstants.java b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/asyncapi/template/TemplateIndexConstants.java index 71f0dbec..0eb92c5b 100644 --- a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/asyncapi/template/TemplateIndexConstants.java +++ b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/asyncapi/template/TemplateIndexConstants.java @@ -20,8 +20,6 @@ public class TemplateIndexConstants extends CommonTemplateIndexConstants { public static final String TEMPLATE_INTERFACE_CONSUMERS = "interfaceConsumer.ftlh"; - public static final String TEMPLATE_NOT_NULL_ANNOTATION = "templateNotNull.ftlh"; - public static final String TEMPLATE_MESSAGE_WRAPPER = "templateMessageWrapper.ftlh"; public static final String KAFKA_BINDINGS_FTLH = "WithKafkaBindings.ftlh"; diff --git a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/model/SchemaObject.java b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/model/SchemaObject.java index 51146538..1efed898 100644 --- a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/model/SchemaObject.java +++ b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/model/SchemaObject.java @@ -13,6 +13,7 @@ @AllArgsConstructor @EqualsAndHashCode(of = {"schemaName", "className"}) public class SchemaObject { + private boolean isEnum; private String schemaName; diff --git a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/template/CommonTemplateFactory.java b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/template/CommonTemplateFactory.java index d25080bc..85217a3c 100644 --- a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/template/CommonTemplateFactory.java +++ b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/template/CommonTemplateFactory.java @@ -3,7 +3,6 @@ import com.sngular.api.generator.plugin.asyncapi.exception.FileSystemException; import com.sngular.api.generator.plugin.asyncapi.parameter.OperationParameterObject; import com.sngular.api.generator.plugin.asyncapi.template.ClassTemplate; -import com.sngular.api.generator.plugin.asyncapi.template.TemplateIndexConstants; import com.sngular.api.generator.plugin.common.model.SchemaFieldObject; import com.sngular.api.generator.plugin.common.model.SchemaObject; import com.sngular.api.generator.plugin.common.tools.MapperUtil; @@ -13,7 +12,6 @@ import freemarker.template.Template; import freemarker.template.TemplateException; import freemarker.template.TemplateExceptionHandler; -import org.apache.commons.lang3.StringUtils; import java.io.File; import java.io.FileWriter; @@ -72,6 +70,32 @@ protected CommonTemplateFactory(boolean checkOverwrite, this.baseDir = baseDir; } + private static String getTemplateName(ClassTemplate classTemplate) { + String templateName; + if (classTemplate.getClassSchema().isEnum()) { + templateName = CommonTemplateIndexConstants.TEMPLATE_CONTENT_ENUM; + } else { + templateName = classTemplate.isUseLombok() ? CommonTemplateIndexConstants.TEMPLATE_CONTENT_SCHEMA_LOMBOK : CommonTemplateIndexConstants.TEMPLATE_CONTENT_SCHEMA; + } + return templateName; + } + + private ClassTemplate getClassTemplate() { + ClassTemplate ourClassTemplate = null; + final var classTemplateListIt = classTemplateList.iterator(); + while (Objects.isNull(ourClassTemplate) && classTemplateListIt.hasNext()) { + final var classTemplate = classTemplateListIt.next(); + if (classTemplate.getFilePath().endsWith("schemas")) { + ourClassTemplate = classTemplate; + } + } + if (ourClassTemplate == null) { + ourClassTemplate = classTemplateList.get(0); + } + + return ourClassTemplate; + } + protected void generateTemplates() { final String exceptionPackage; @@ -88,85 +112,69 @@ protected void generateTemplates() { if (generateExceptionTemplate) { fillTemplateModelClassException(classTemplate.getModelPackage()); } - } catch (final IOException | TemplateException exception) { + } catch (final IOException exception) { throw new FileSystemException(exception); } }); } - private ClassTemplate getClassTemplate() { - ClassTemplate ourClassTemplate = null; - final var classTemplateListIt = classTemplateList.iterator(); - while (Objects.isNull(ourClassTemplate) && classTemplateListIt.hasNext()) { - final var classTemplate = classTemplateListIt.next(); - if (classTemplate.getFilePath().endsWith("schemas")) { - ourClassTemplate = classTemplate; - } - } - if (ourClassTemplate == null) { - ourClassTemplate = classTemplateList.get(0); - } - - return ourClassTemplate; - } - - protected void fillTemplate(final String filePathToSave, final String className, final String templateName) throws IOException, TemplateException { + protected void fillTemplate(final String filePathToSave, final String className, final String templateName) throws IOException { final var fileToSave = Paths.get(filePathToSave); fileToSave.toFile().mkdirs(); writeTemplateToFile(templateName, fileToSave, className); } @SuppressWarnings("checkstyle:CyclomaticComplexity") - protected void fillTemplates(final Path filePathToSave, final String modelPackage, final Set fieldProperties) throws TemplateException, IOException { + protected void fillTemplates(final Path filePathToSave, final String modelPackage, final Set fieldProperties) throws IOException { for (final String current : fieldProperties) { switch (current) { case "Size": - fillTemplateCustom(filePathToSave, modelPackage, "Size", TemplateIndexConstants.TEMPLATE_SIZE_ANNOTATION, "SizeValidator", - TemplateIndexConstants.TEMPLATE_SIZE_VALIDATOR_ANNOTATION); + fillTemplateCustom(filePathToSave, modelPackage, "Size", CommonTemplateIndexConstants.TEMPLATE_SIZE_ANNOTATION, "SizeValidator", + CommonTemplateIndexConstants.TEMPLATE_SIZE_VALIDATOR_ANNOTATION); break; case "Pattern": - fillTemplateCustom(filePathToSave, modelPackage, "Pattern", TemplateIndexConstants.TEMPLATE_PATTERN_ANNOTATION, - "PatternValidator", TemplateIndexConstants.TEMPLATE_PATTERN_VALIDATOR_ANNOTATION); + fillTemplateCustom(filePathToSave, modelPackage, "Pattern", CommonTemplateIndexConstants.TEMPLATE_PATTERN_ANNOTATION, + "PatternValidator", CommonTemplateIndexConstants.TEMPLATE_PATTERN_VALIDATOR_ANNOTATION); break; case "MultipleOf": - fillTemplateCustom(filePathToSave, modelPackage, "MultipleOf", TemplateIndexConstants.TEMPLATE_MULTIPLEOF_ANNOTATION, - "MultipleOfValidator", TemplateIndexConstants.TEMPLATE_MULTIPLEOF_VALIDATOR_ANNOTATION); + fillTemplateCustom(filePathToSave, modelPackage, "MultipleOf", CommonTemplateIndexConstants.TEMPLATE_MULTIPLEOF_ANNOTATION, + "MultipleOfValidator", CommonTemplateIndexConstants.TEMPLATE_MULTIPLEOF_VALIDATOR_ANNOTATION); break; case "Maximum": - fillTemplateCustom(filePathToSave, modelPackage, "MaxInteger", TemplateIndexConstants.TEMPLATE_MAX_INTEGER_ANNOTATION, - "MaxIntegerValidator", TemplateIndexConstants.TEMPLATE_MAX_INTEGER_VALIDATOR_ANNOTATION); - fillTemplateCustom(filePathToSave, modelPackage, "MaxBigDecimal", TemplateIndexConstants.TEMPLATE_MAX_BIG_DECIMAL_ANNOTATION, - "MaxBigDecimalValidator", TemplateIndexConstants.TEMPLATE_MAX_BIG_DECIMAL_VALIDATOR_ANNOTATION); - fillTemplateCustom(filePathToSave, modelPackage, "MaxDouble", TemplateIndexConstants.TEMPLATE_MAX_DOUBLE_ANNOTATION, - "MaxDoubleValidator", TemplateIndexConstants.TEMPLATE_MAX_DOUBLE_VALIDATOR_ANNOTATION); - fillTemplateCustom(filePathToSave, modelPackage, "MaxFloat", TemplateIndexConstants.TEMPLATE_MAX_FLOAT_ANNOTATION, - "MaxFloatValidator", TemplateIndexConstants.TEMPLATE_MAX_FLOAT_VALIDATOR_ANNOTATION); + fillTemplateCustom(filePathToSave, modelPackage, "MaxInteger", CommonTemplateIndexConstants.TEMPLATE_MAX_INTEGER_ANNOTATION, + "MaxIntegerValidator", CommonTemplateIndexConstants.TEMPLATE_MAX_INTEGER_VALIDATOR_ANNOTATION); + fillTemplateCustom(filePathToSave, modelPackage, "MaxBigDecimal", CommonTemplateIndexConstants.TEMPLATE_MAX_BIG_DECIMAL_ANNOTATION, + "MaxBigDecimalValidator", CommonTemplateIndexConstants.TEMPLATE_MAX_BIG_DECIMAL_VALIDATOR_ANNOTATION); + fillTemplateCustom(filePathToSave, modelPackage, "MaxDouble", CommonTemplateIndexConstants.TEMPLATE_MAX_DOUBLE_ANNOTATION, + "MaxDoubleValidator", CommonTemplateIndexConstants.TEMPLATE_MAX_DOUBLE_VALIDATOR_ANNOTATION); + fillTemplateCustom(filePathToSave, modelPackage, "MaxFloat", CommonTemplateIndexConstants.TEMPLATE_MAX_FLOAT_ANNOTATION, + "MaxFloatValidator", CommonTemplateIndexConstants.TEMPLATE_MAX_FLOAT_VALIDATOR_ANNOTATION); break; case "Minimum": - fillTemplateCustom(filePathToSave, modelPackage, "MinInteger", TemplateIndexConstants.TEMPLATE_MIN_INTEGER_ANNOTATION, - "MinIntegerValidator", TemplateIndexConstants.TEMPLATE_MIN_INTEGER_VALIDATOR_ANNOTATION); - fillTemplateCustom(filePathToSave, modelPackage, "MinDouble", TemplateIndexConstants.TEMPLATE_MIN_DOUBLE_ANNOTATION, - "MinDoubleValidator", TemplateIndexConstants.TEMPLATE_MIN_DOUBLE_VALIDATOR_ANNOTATION); - fillTemplateCustom(filePathToSave, modelPackage, "MinFloat", TemplateIndexConstants.TEMPLATE_MIN_FLOAT_ANNOTATION, - "MinFloatValidator", TemplateIndexConstants.TEMPLATE_MIN_FLOAT_VALIDATOR_ANNOTATION); - fillTemplateCustom(filePathToSave, modelPackage, "MinBigDecimal", TemplateIndexConstants.TEMPLATE_MIN_BIG_DECIMAL_ANNOTATION, - "MinBigDecimalValidator", TemplateIndexConstants.TEMPLATE_MIN_BIG_DECIMAL_VALIDATOR_ANNOTATION); + fillTemplateCustom(filePathToSave, modelPackage, "MinInteger", CommonTemplateIndexConstants.TEMPLATE_MIN_INTEGER_ANNOTATION, + "MinIntegerValidator", CommonTemplateIndexConstants.TEMPLATE_MIN_INTEGER_VALIDATOR_ANNOTATION); + fillTemplateCustom(filePathToSave, modelPackage, "MinDouble", CommonTemplateIndexConstants.TEMPLATE_MIN_DOUBLE_ANNOTATION, + "MinDoubleValidator", CommonTemplateIndexConstants.TEMPLATE_MIN_DOUBLE_VALIDATOR_ANNOTATION); + fillTemplateCustom(filePathToSave, modelPackage, "MinFloat", CommonTemplateIndexConstants.TEMPLATE_MIN_FLOAT_ANNOTATION, + "MinFloatValidator", CommonTemplateIndexConstants.TEMPLATE_MIN_FLOAT_VALIDATOR_ANNOTATION); + fillTemplateCustom(filePathToSave, modelPackage, "MinBigDecimal", CommonTemplateIndexConstants.TEMPLATE_MIN_BIG_DECIMAL_ANNOTATION, + "MinBigDecimalValidator", CommonTemplateIndexConstants.TEMPLATE_MIN_BIG_DECIMAL_VALIDATOR_ANNOTATION); break; case "MaxItems": - fillTemplateCustom(filePathToSave, modelPackage, "MaxItems", TemplateIndexConstants.TEMPLATE_MAX_ITEMS_ANNOTATION, - "MaxItemsValidator", TemplateIndexConstants.TEMPLATE_MAX_ITEMS_VALIDATOR_ANNOTATION); + fillTemplateCustom(filePathToSave, modelPackage, "MaxItems", CommonTemplateIndexConstants.TEMPLATE_MAX_ITEMS_ANNOTATION, + "MaxItemsValidator", CommonTemplateIndexConstants.TEMPLATE_MAX_ITEMS_VALIDATOR_ANNOTATION); break; case "MinItems": - fillTemplateCustom(filePathToSave, modelPackage, "MinItems", TemplateIndexConstants.TEMPLATE_MIN_ITEMS_ANNOTATION, - "MinItemsValidator", TemplateIndexConstants.TEMPLATE_MIN_ITEMS_VALIDATOR_ANNOTATION); + fillTemplateCustom(filePathToSave, modelPackage, "MinItems", CommonTemplateIndexConstants.TEMPLATE_MIN_ITEMS_ANNOTATION, + "MinItemsValidator", CommonTemplateIndexConstants.TEMPLATE_MIN_ITEMS_VALIDATOR_ANNOTATION); break; case "NotNull": - fillTemplateCustom(filePathToSave, modelPackage, "NotNull", TemplateIndexConstants.TEMPLATE_NOT_NULL_ANNOTATION, - "NotNullValidator", TemplateIndexConstants.TEMPLATE_NOT_NULL_VALIDATOR_ANNOTATION); + fillTemplateCustom(filePathToSave, modelPackage, "NotNull", CommonTemplateIndexConstants.TEMPLATE_NOT_NULL_ANNOTATION, + "NotNullValidator", CommonTemplateIndexConstants.TEMPLATE_NOT_NULL_VALIDATOR_ANNOTATION); break; case "UniqueItems": - fillTemplateCustom(filePathToSave, modelPackage, "UniqueItems", TemplateIndexConstants.TEMPLATE_UNIQUE_ITEMS_ANNOTATION, - "UniqueItemsValidator", TemplateIndexConstants.TEMPLATE_UNIQUE_ITEMS_VALIDATOR_ANNOTATION); + fillTemplateCustom(filePathToSave, modelPackage, "UniqueItems", CommonTemplateIndexConstants.TEMPLATE_UNIQUE_ITEMS_ANNOTATION, + "UniqueItemsValidator", CommonTemplateIndexConstants.TEMPLATE_UNIQUE_ITEMS_VALIDATOR_ANNOTATION); break; default: break; @@ -176,13 +184,13 @@ protected void fillTemplates(final Path filePathToSave, final String modelPackag @SuppressWarnings("checkstyle:CyclomaticComplexity") private Set fillTemplateSchema(final ClassTemplate classTemplate, final String exceptionPackage) - throws IOException, TemplateException { + throws IOException { final var propertiesSet = new HashSet(); final var schemaObject = classTemplate.getClassSchema(); final var filePath = classTemplate.getFilePath(); if (Objects.nonNull(schemaObject) && Objects.nonNull(schemaObject.getFieldObjectList()) && !schemaObject.getFieldObjectList().isEmpty()) { addToRoot("schema", schemaObject); - final String templateName = classTemplate.isUseLombok() ? TemplateIndexConstants.TEMPLATE_CONTENT_SCHEMA_LOMBOK : TemplateIndexConstants.TEMPLATE_CONTENT_SCHEMA; + final String templateName = getTemplateName(classTemplate); if (Objects.nonNull(classTemplate.getModelPackage())) { addToRoot("packageModel", classTemplate.getModelPackage()); } @@ -215,7 +223,7 @@ private void fillTemplateCustom( final Path pathToCustomValidatorPackage = filePathToSave.resolve("customvalidator"); if (!pathToCustomValidatorPackage.toFile().exists()) { if (!pathToCustomValidatorPackage.toFile().mkdirs()) { - throw new RuntimeException("Can't create custom validator directory"); + throw new IOException("Can't create custom validator directory"); } } root.put("packageModel", modelPackage); diff --git a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/template/CommonTemplateIndexConstants.java b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/template/CommonTemplateIndexConstants.java index c8fbf291..3ffd08f4 100644 --- a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/template/CommonTemplateIndexConstants.java +++ b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/template/CommonTemplateIndexConstants.java @@ -4,10 +4,14 @@ public abstract class CommonTemplateIndexConstants { public static final String TEMPLATE_CONTENT_SCHEMA = "templateSchema.ftlh"; + public static final String TEMPLATE_CONTENT_ENUM = "templateContentEnum.ftlh"; + public static final String TEMPLATE_CONTENT_SCHEMA_LOMBOK = "templateSchemaWithLombok.ftlh"; public static final String TEMPLATE_MODEL_EXCEPTION = "templateModelClassException.ftlh"; + public static final String TEMPLATE_NOT_NULL_ANNOTATION = "templateNotNull.ftlh"; + public static final String TEMPLATE_NOT_NULL_VALIDATOR_ANNOTATION = "templateNotNullValidator.ftlh"; public static final String TEMPLATE_MIN_INTEGER_ANNOTATION = "templateMinInteger.ftlh"; diff --git a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/template/CommonTemplateLoader.java b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/template/CommonTemplateLoader.java index 6f6d04db..dd199667 100644 --- a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/template/CommonTemplateLoader.java +++ b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/template/CommonTemplateLoader.java @@ -1,34 +1,37 @@ package com.sngular.api.generator.plugin.common.template; -import com.sngular.api.generator.plugin.asyncapi.template.TemplateIndexConstants; import freemarker.cache.TemplateLoader; import java.util.List; + public abstract class CommonTemplateLoader implements TemplateLoader { - protected static final List TEMPLATE_MODEL_FILES = List.of( "templateSchema.ftlh", - "templateSchemaWithLombok.ftlh", "templateModelClassException.ftlh"); + protected static final List TEMPLATE_MODEL_FILES = List.of(CommonTemplateIndexConstants.TEMPLATE_CONTENT_SCHEMA, + CommonTemplateIndexConstants.TEMPLATE_CONTENT_ENUM, CommonTemplateIndexConstants.TEMPLATE_CONTENT_SCHEMA_LOMBOK, CommonTemplateIndexConstants.TEMPLATE_MODEL_EXCEPTION); + + protected static final List TEMPLATE_ANNOTATION_FILES = List.of(CommonTemplateIndexConstants.TEMPLATE_NOT_NULL_ANNOTATION, + CommonTemplateIndexConstants.TEMPLATE_NOT_NULL_VALIDATOR_ANNOTATION, + CommonTemplateIndexConstants.TEMPLATE_MAX_INTEGER_ANNOTATION, CommonTemplateIndexConstants.TEMPLATE_MAX_INTEGER_VALIDATOR_ANNOTATION, + CommonTemplateIndexConstants.TEMPLATE_MAX_BIG_DECIMAL_ANNOTATION, CommonTemplateIndexConstants.TEMPLATE_MAX_BIG_DECIMAL_VALIDATOR_ANNOTATION, + CommonTemplateIndexConstants.TEMPLATE_MAX_DOUBLE_ANNOTATION, CommonTemplateIndexConstants.TEMPLATE_MAX_DOUBLE_VALIDATOR_ANNOTATION, + CommonTemplateIndexConstants.TEMPLATE_MAX_FLOAT_ANNOTATION, CommonTemplateIndexConstants.TEMPLATE_MAX_FLOAT_VALIDATOR_ANNOTATION, + CommonTemplateIndexConstants.TEMPLATE_MIN_INTEGER_ANNOTATION, CommonTemplateIndexConstants.TEMPLATE_MIN_INTEGER_VALIDATOR_ANNOTATION, + CommonTemplateIndexConstants.TEMPLATE_MIN_DOUBLE_ANNOTATION, CommonTemplateIndexConstants.TEMPLATE_MIN_DOUBLE_VALIDATOR_ANNOTATION, + CommonTemplateIndexConstants.TEMPLATE_MIN_FLOAT_ANNOTATION, CommonTemplateIndexConstants.TEMPLATE_MIN_FLOAT_VALIDATOR_ANNOTATION, + CommonTemplateIndexConstants.TEMPLATE_MIN_BIG_DECIMAL_ANNOTATION, CommonTemplateIndexConstants.TEMPLATE_MIN_BIG_DECIMAL_VALIDATOR_ANNOTATION, + CommonTemplateIndexConstants.TEMPLATE_SIZE_ANNOTATION, CommonTemplateIndexConstants.TEMPLATE_SIZE_VALIDATOR_ANNOTATION, + CommonTemplateIndexConstants.TEMPLATE_PATTERN_ANNOTATION, + CommonTemplateIndexConstants.TEMPLATE_PATTERN_VALIDATOR_ANNOTATION, + CommonTemplateIndexConstants.TEMPLATE_MULTIPLEOF_ANNOTATION, + CommonTemplateIndexConstants.TEMPLATE_MULTIPLEOF_VALIDATOR_ANNOTATION, + CommonTemplateIndexConstants.TEMPLATE_MAX_ITEMS_ANNOTATION, + CommonTemplateIndexConstants.TEMPLATE_MAX_ITEMS_VALIDATOR_ANNOTATION, + CommonTemplateIndexConstants.TEMPLATE_MIN_ITEMS_ANNOTATION, + CommonTemplateIndexConstants.TEMPLATE_MIN_ITEMS_VALIDATOR_ANNOTATION, + CommonTemplateIndexConstants.TEMPLATE_UNIQUE_ITEMS_ANNOTATION, + CommonTemplateIndexConstants.TEMPLATE_UNIQUE_ITEMS_VALIDATOR_ANNOTATION); - protected static final List TEMPLATE_ANNOTATION_FILES = List.of(TemplateIndexConstants.TEMPLATE_NOT_NULL_ANNOTATION, - TemplateIndexConstants.TEMPLATE_NOT_NULL_VALIDATOR_ANNOTATION, - TemplateIndexConstants.TEMPLATE_MAX_INTEGER_ANNOTATION, TemplateIndexConstants.TEMPLATE_MAX_INTEGER_VALIDATOR_ANNOTATION, - TemplateIndexConstants.TEMPLATE_MAX_BIG_DECIMAL_ANNOTATION, TemplateIndexConstants.TEMPLATE_MAX_BIG_DECIMAL_VALIDATOR_ANNOTATION, - TemplateIndexConstants.TEMPLATE_MAX_DOUBLE_ANNOTATION, TemplateIndexConstants.TEMPLATE_MAX_DOUBLE_VALIDATOR_ANNOTATION, - TemplateIndexConstants.TEMPLATE_MAX_FLOAT_ANNOTATION, TemplateIndexConstants.TEMPLATE_MAX_FLOAT_VALIDATOR_ANNOTATION, - TemplateIndexConstants.TEMPLATE_MIN_INTEGER_ANNOTATION, TemplateIndexConstants.TEMPLATE_MIN_INTEGER_VALIDATOR_ANNOTATION, - TemplateIndexConstants.TEMPLATE_MIN_DOUBLE_ANNOTATION, TemplateIndexConstants.TEMPLATE_MIN_DOUBLE_VALIDATOR_ANNOTATION, - TemplateIndexConstants.TEMPLATE_MIN_FLOAT_ANNOTATION, TemplateIndexConstants.TEMPLATE_MIN_FLOAT_VALIDATOR_ANNOTATION, - TemplateIndexConstants.TEMPLATE_MIN_BIG_DECIMAL_ANNOTATION, TemplateIndexConstants.TEMPLATE_MIN_BIG_DECIMAL_VALIDATOR_ANNOTATION, - TemplateIndexConstants.TEMPLATE_SIZE_ANNOTATION, TemplateIndexConstants.TEMPLATE_SIZE_VALIDATOR_ANNOTATION, - TemplateIndexConstants.TEMPLATE_PATTERN_ANNOTATION, - TemplateIndexConstants.TEMPLATE_PATTERN_VALIDATOR_ANNOTATION, - TemplateIndexConstants.TEMPLATE_MULTIPLEOF_ANNOTATION, - TemplateIndexConstants.TEMPLATE_MULTIPLEOF_VALIDATOR_ANNOTATION, - TemplateIndexConstants.TEMPLATE_MAX_ITEMS_ANNOTATION, - TemplateIndexConstants.TEMPLATE_MAX_ITEMS_VALIDATOR_ANNOTATION, - TemplateIndexConstants.TEMPLATE_MIN_ITEMS_ANNOTATION, - TemplateIndexConstants.TEMPLATE_MIN_ITEMS_VALIDATOR_ANNOTATION, - TemplateIndexConstants.TEMPLATE_UNIQUE_ITEMS_ANNOTATION, - TemplateIndexConstants.TEMPLATE_UNIQUE_ITEMS_VALIDATOR_ANNOTATION); + protected CommonTemplateLoader() { + } } diff --git a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/tools/ModelBuilder.java b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/tools/ModelBuilder.java index e39b3675..e5fca153 100644 --- a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/tools/ModelBuilder.java +++ b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/tools/ModelBuilder.java @@ -53,6 +53,10 @@ public static SchemaObject buildSchemaObject( schemaBuilder .fieldObjectList(listSchema) .parentPackage(parentPackage.toLowerCase()); + } else { + schemaBuilder + .isEnum(true) + .fieldObject(processEnumField(className, model, specFile, ApiTool.getEnumValues(model), model)); } cachedSchemas.putAll(compositedSchemas); return schemaBuilder.build(); @@ -130,7 +134,7 @@ private static Set getFields(final String buildingSchema, baseDir)); fieldObjectArrayList.addAll(processAdditionalProperties(ADDITIONAL_PROPERTIES, schema, specFile, totalSchemas, compositedSchemas, antiLoopList, nameSchema, baseDir)); } else { - ApiTool.getProperties(schema).forEachRemaining(processProperties(buildingSchema, totalSchemas, compositedSchemas, fieldObjectArrayList, specFile, schema, antiLoopList, + ApiTool.getProperties(schema).forEachRemaining(processProperties(nameSchema, totalSchemas, compositedSchemas, fieldObjectArrayList, specFile, schema, antiLoopList, baseDir)); } } else if (TypeConstants.ARRAY.equalsIgnoreCase(ApiTool.getType(schema))) { @@ -547,7 +551,7 @@ private static SchemaObject createComposedSchema(final String buildingSchema, schemaCombinatorType = ALL_OF_COMBINATOR; } else if (ApiTool.isAnyOf(schema)) { fieldObjectArrayList.addAll( - processAnyOfOneOf(buildingSchema, totalSchemas, ApiTool.getAnyOf(schema), specFile, compositedSchemas, antiLoopList, baseDir)); + processAnyOfOneOf(fieldName, totalSchemas, ApiTool.getAnyOf(schema), specFile, compositedSchemas, antiLoopList, baseDir)); schemaCombinatorType = ANY_OF_COMBINATOR; } else if (ApiTool.isOneOf(schema)) { fieldObjectArrayList.addAll( @@ -673,7 +677,10 @@ private static Set processAnyOfOneOf(final String buildingSch } else if (compositedSchemas.containsKey(schemaName)) { fieldObjectArrayList.addAll(compositedSchemas.get(schemaName).getFieldObjectList()); } else if (!schemaName.equalsIgnoreCase(buildingSchema)) { - fieldObjectArrayList.addAll(getFields(schemaName, totalSchemas, internalSchema, specFile, compositedSchemas, antiLoopList, ApiTool.getName(internalSchema), baseDir)); + fieldObjectArrayList.add(SchemaFieldObject.builder() + .baseName(schemaName) + .dataType(new SchemaFieldObjectType(MapperUtil.getSimpleType(internalSchema, specFile))) + .build()); } } else { fieldObjectArrayList.addAll(getFields(buildingSchema, totalSchemas, internalSchema, specFile, compositedSchemas, antiLoopList, ApiTool.getName(internalSchema), baseDir)); diff --git a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/openapi/template/ClasspathTemplateLoader.java b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/openapi/template/ClasspathTemplateLoader.java index 67b5894c..2d6a767a 100644 --- a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/openapi/template/ClasspathTemplateLoader.java +++ b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/openapi/template/ClasspathTemplateLoader.java @@ -6,6 +6,9 @@ package com.sngular.api.generator.plugin.openapi.template; +import com.sngular.api.generator.plugin.common.template.CommonTemplateLoader; +import com.sngular.api.generator.plugin.exception.GeneratorTemplateException; + import java.io.IOException; import java.io.InputStream; import java.io.Reader; @@ -15,9 +18,6 @@ import java.util.Map; import java.util.Objects; -import com.sngular.api.generator.plugin.common.template.CommonTemplateLoader; -import freemarker.cache.TemplateLoader; - public class ClasspathTemplateLoader extends CommonTemplateLoader { private static final List TEMPLATE_FILES = List.of(TemplateIndexConstants.TEMPLATE_INTERFACE_API, TemplateIndexConstants.TEMPLATE_CALL_WEB_API, @@ -33,6 +33,7 @@ public class ClasspathTemplateLoader extends CommonTemplateLoader { private final Map templatesMap = new HashMap<>(); public ClasspathTemplateLoader() { + super(); templatesMap.putAll(getResourceFolderFiles()); } @@ -62,21 +63,21 @@ private Map getResourceFolderFiles() { try { templates.put(templateFile, readFile((InputStream) Objects.requireNonNull(LOADER.getResource("templates/model/" + templateFile)).getContent())); } catch (final IOException e) { - e.printStackTrace(); + throw new GeneratorTemplateException("Error loading Model Templates", e); } }); TEMPLATE_FILES.forEach(templateFile -> { try { templates.put(templateFile, readFile((InputStream) Objects.requireNonNull(LOADER.getResource("templates/openapi/" + templateFile)).getContent())); } catch (final IOException e) { - e.printStackTrace(); + throw new GeneratorTemplateException("Error loading Api Templates", e); } }); TEMPLATE_AUTH_FILES.forEach(templateAuthFile -> { try { templates.put(templateAuthFile, readFile((InputStream) Objects.requireNonNull(LOADER.getResource("templates/openapi/authTemplates/" + templateAuthFile)).getContent())); } catch (final IOException e) { - e.printStackTrace(); + throw new GeneratorTemplateException("Error loading Auth Templates", e); } }); TEMPLATE_ANNOTATION_FILES.forEach(templateAnnotationFile -> { @@ -84,7 +85,7 @@ private Map getResourceFolderFiles() { templates.put(templateAnnotationFile, readFile((InputStream) Objects.requireNonNull(LOADER.getResource("templates/customannotations/" + templateAnnotationFile)).getContent())); } catch (final IOException e) { - e.printStackTrace(); + throw new GeneratorTemplateException("Error loading Annotation Templates", e); } }); diff --git a/multiapi-engine/src/main/resources/templates/model/templateContentEnum.ftlh b/multiapi-engine/src/main/resources/templates/model/templateContentEnum.ftlh new file mode 100644 index 00000000..141aca9c --- /dev/null +++ b/multiapi-engine/src/main/resources/templates/model/templateContentEnum.ftlh @@ -0,0 +1,87 @@ +<#ftl output_format="plainText"> +<#assign words = ["abstract", "assert", "boolean", "break", "byte", "case", "catch", "char", "class", "const", "continue", "default", "double", "do", "else", "enum", "extends", "false", "final", "finally", "float", "for", "goto", "if", "implements", "import", "instanceof", "int", "interface", "long", "native", "new", "null", "package", "private", "protected", "public", "return", "short", "static", "strictfp", "super", "switch", "synchronized", "this", "throw", "throws", "transient", "true", "try", "void", "volatile", "while"]> +<#function calculateSafeName propertyName ender const=""> + <#if words?seq_contains(propertyName?uncap_first) || propertyName?matches("[0-9].*")> + <#if const?has_content> + <#return getConstValue("_"+propertyName, ender, const)/> + <#else> + <#return getConstValue ("_"+propertyName, ender)/> + + <#else > + <#return getConstValue(propertyName, ender, const)/> + + +<#function createSimpleType field> + ${calculateSafeName (field.baseName, ";", field.constValue)} + +<#function singularizeName propertyName> + <#if propertyName?matches(".*ies")> + <#return propertyName?remove_ending("ies")+"y"/> + <#elseif propertyName?matches(".*s")> + <#return propertyName?remove_ending("s")/> + <#elseif propertyName?matches(".*List")> + <#return propertyName?remove_ending("List")/> + <#else > + <#return "_"+propertyName/> + + +<#function hasConstValue field> + <#return field.constValue?has_content /> + +<#function requireFinal field> + <#if field.required == true || hasConstValue(field)> + <#return "final "/> + <#else > + <#return ""/> + + +<#function checkIfShouldSet field> + <<#return !(field.required == true || hasConstValue(field))> + +<#function getConstValue fieldName ender value=""> + <#if value?has_content> + <#return fieldName +" = " + renderValue (value) + ender/> + <#else > + <#return fieldName + ender/> + + +<#function renderValue value=""> + <#if value?is_boolean> + <#return value == true> + <#elseif value?is_number> + <#return value> + <#elseif value?is_string> + <#return '\"${value}\"'> + + +package ${packageModel}; + +import com.fasterxml.jackson.annotation.JsonValue; + +public enum ${schema.className} { +<#list schema.fieldObjectList as field> + <#list field.enumValues as key, value> + <#if key?matches("[0-9].*")> + ${"_"+key}(${value})<#sep>, + <#else> + ${key}(${value})<#sep>, + + ; + + private ${field.dataType.innerType?cap_first} value; + + ${schema.className?cap_first}(${field.dataType.innerType?cap_first} value) { + this.value = value; + } + + @JsonValue + public ${field.dataType.innerType?cap_first} getValue() { + return value; + } + + @Override + public String toString() { + return String.valueOf(value); + } + +} \ No newline at end of file diff --git a/multiapi-engine/src/test/resources/openapigenerator/testAdditionalPropertiesWithUnnamedObject/assets/EnumSchemaDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testAdditionalPropertiesWithUnnamedObject/assets/EnumSchemaDTO.java index 46fbdea4..95e94476 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testAdditionalPropertiesWithUnnamedObject/assets/EnumSchemaDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testAdditionalPropertiesWithUnnamedObject/assets/EnumSchemaDTO.java @@ -21,4 +21,4 @@ public String getValue() { public String toString() { return String.valueOf(value); } -} +} \ No newline at end of file diff --git a/multiapi-engine/src/test/resources/openapigenerator/testAdditionalPropertiesWithUnnamedObject/assets/SecondTestDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testAdditionalPropertiesWithUnnamedObject/assets/SecondTestDTO.java index c3d4b396..ee7c029a 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testAdditionalPropertiesWithUnnamedObject/assets/SecondTestDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testAdditionalPropertiesWithUnnamedObject/assets/SecondTestDTO.java @@ -5,6 +5,7 @@ import java.util.HashMap; import lombok.Builder; import lombok.NonNull; +import lombok.Singular; import lombok.Value; import lombok.extern.jackson.Jacksonized; @@ -12,7 +13,8 @@ public class SecondTestDTO { @JsonProperty(value ="additionalProperties") - private Map additionalProperties = new HashMap(); + @Singular("additionalProperty") + private Map additionalProperties; @JsonProperty(value ="id") @NonNull diff --git a/multiapi-engine/src/test/resources/openapigenerator/testAdditionalPropertiesWithUnnamedObject/assets/TestDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testAdditionalPropertiesWithUnnamedObject/assets/TestDTO.java index 4e3e408b..66ed1c0f 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testAdditionalPropertiesWithUnnamedObject/assets/TestDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testAdditionalPropertiesWithUnnamedObject/assets/TestDTO.java @@ -5,6 +5,7 @@ import java.util.HashMap; import lombok.Builder; import lombok.NonNull; +import lombok.Singular; import lombok.Value; import lombok.extern.jackson.Jacksonized; @@ -12,7 +13,8 @@ public class TestDTO { @JsonProperty(value ="additionalProperties") - private Map additionalProperties = new HashMap(); + @Singular("additionalProperty") + private Map additionalProperties; @JsonProperty(value ="id") @NonNull diff --git a/multiapi-engine/src/test/resources/openapigenerator/testAdditionalPropertiesWithUnnamedObject/assets/TestValueDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testAdditionalPropertiesWithUnnamedObject/assets/TestValueDTO.java index 2427c476..1ee25568 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testAdditionalPropertiesWithUnnamedObject/assets/TestValueDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testAdditionalPropertiesWithUnnamedObject/assets/TestValueDTO.java @@ -5,6 +5,7 @@ import java.util.HashMap; import lombok.Builder; import lombok.NonNull; +import lombok.Singular; import lombok.Value; import lombok.extern.jackson.Jacksonized; @@ -12,7 +13,8 @@ public class TestValueDTO { @JsonProperty(value ="additionalProperties") - private Map additionalProperties = new HashMap(); + @Singular("additionalProperty") + private Map additionalProperties; @JsonProperty(value ="code") @NonNull @@ -25,7 +27,7 @@ public class TestValueDTO { @Builder @Jacksonized - private TestValueDTO(Map additionalProperties, @NonNull Integer code, @NonNull String text) { + private TestValueDTO(Map additionalProperties, @NonNull Integer code, @NonNull String text) { this.additionalProperties = additionalProperties; this.code = code; this.text = text; diff --git a/multiapi-engine/src/test/resources/openapigenerator/testAdditionalPropertiesWithUnnamedObject/assets/TestValueValueDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testAdditionalPropertiesWithUnnamedObject/assets/TestValueValueDTO.java index 414f6fc7..f5386bde 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testAdditionalPropertiesWithUnnamedObject/assets/TestValueValueDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testAdditionalPropertiesWithUnnamedObject/assets/TestValueValueDTO.java @@ -7,14 +7,16 @@ import java.util.HashMap; import lombok.Builder; import lombok.NonNull; +import lombok.Singular; import lombok.Value; import lombok.extern.jackson.Jacksonized; @Value -public class TestValueValueDTO { +public class TestvalueValueDTO { @JsonProperty(value ="additionalProperties") - private Map> additionalProperties = new HashMap>(); + @Singular("additionalProperty") + private Map> additionalProperties; @JsonProperty(value ="name") @NonNull @@ -23,7 +25,7 @@ public class TestValueValueDTO { @Builder @Jacksonized - private TestValueValueDTO(Map> additionalProperties, @NonNull String name) { + private TestvalueValueDTO(Map> additionalProperties, @NonNull String name) { this.additionalProperties = additionalProperties; this.name = name; diff --git a/multiapi-engine/src/test/resources/openapigenerator/testAdditionalPropertiesWithUnnamedObject/assets/ThirdTestDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testAdditionalPropertiesWithUnnamedObject/assets/ThirdTestDTO.java index 68d269b5..883d9d35 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testAdditionalPropertiesWithUnnamedObject/assets/ThirdTestDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testAdditionalPropertiesWithUnnamedObject/assets/ThirdTestDTO.java @@ -5,6 +5,7 @@ import java.util.HashMap; import lombok.Builder; import lombok.NonNull; +import lombok.Singular; import lombok.Value; import lombok.extern.jackson.Jacksonized; @@ -12,7 +13,8 @@ public class ThirdTestDTO { @JsonProperty(value ="additionalProperties") - private Map additionalProperties = new HashMap(); + @Singular("additionalProperty") + private Map additionalProperties; @JsonProperty(value ="id") @NonNull diff --git a/multiapi-engine/src/test/resources/openapigenerator/testComplexAnyOf/assets/ApiDefaultItemDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testComplexAnyOf/assets/ApiDefaultItemDTO.java index d9b344f2..0c288579 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testComplexAnyOf/assets/ApiDefaultItemDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testComplexAnyOf/assets/ApiDefaultItemDTO.java @@ -16,8 +16,6 @@ public class ApiDefaultItemDTO { @JsonProperty(value ="precision") private Integer precision; - @JsonProperty(value ="defaultItem") - private ApiDefaultItemDTO defaultItem; @JsonProperty(value ="maximum") private Integer maximum; @JsonProperty(value ="type") @@ -28,12 +26,12 @@ public class ApiDefaultItemDTO { private Integer minLength; @JsonProperty(value ="increment") private Integer increment; + @JsonProperty(value ="unionField") + private ApiUnionFieldDTO unionField; @JsonProperty(value ="keyType") private String keyType; @JsonProperty(value ="requiredValues") private List requiredValues; - @JsonProperty(value ="optionalUnion") - private Boolean optionalUnion; @JsonProperty(value ="initialValue") private String initialValue; @JsonProperty(value ="flagExclusiveMinimum") @@ -48,29 +46,6 @@ public class ApiDefaultItemDTO { private List properties; @JsonProperty(value ="defaultValues") private List defaultValues; - @JsonProperty(value ="unionEnum") - private UnionEnum unionEnum; - public enum UnionEnum { - ONEOF("oneof"), - ANYOF("anyof"), - ALLOF("allof"); - - private String value; - - UnionEnum(String value) { - this.value = value; - } - - @JsonValue - public String getValue() { - return value; - } - - @Override - public String toString() { - return String.valueOf(value); - } - } @JsonProperty(value ="seqEnum") private SeqEnum seqEnum; public enum SeqEnum { @@ -107,8 +82,6 @@ public String toString() { private List mapTypes; @JsonProperty(value ="format") private Integer format; - @JsonProperty(value ="generatedFlag") - private Boolean generatedFlag; @JsonProperty(value ="maxLength") private Integer maxLength; @JsonProperty(value ="uniqueItems") @@ -152,15 +125,14 @@ public String toString() { private ApiDefaultItemDTO(ApiDefaultItemDTOBuilder builder) { this.precision = builder.precision; - this.defaultItem = builder.defaultItem; this.maximum = builder.maximum; this.type = builder.type; this.scale = builder.scale; this.minLength = builder.minLength; this.increment = builder.increment; + this.unionField = builder.unionField; this.keyType = builder.keyType; this.requiredValues = builder.requiredValues; - this.optionalUnion = builder.optionalUnion; this.initialValue = builder.initialValue; this.flagExclusiveMinimum = builder.flagExclusiveMinimum; this.flagExclusiveMaximum = builder.flagExclusiveMaximum; @@ -168,14 +140,12 @@ private ApiDefaultItemDTO(ApiDefaultItemDTOBuilder builder) { this.enumValues = builder.enumValues; this.properties = builder.properties; this.defaultValues = builder.defaultValues; - this.unionEnum = builder.unionEnum; this.seqEnum = builder.seqEnum; this.arraySize = builder.arraySize; this.multipleOf = builder.multipleOf; this.mapSize = builder.mapSize; this.mapTypes = builder.mapTypes; this.format = builder.format; - this.generatedFlag = builder.generatedFlag; this.maxLength = builder.maxLength; this.uniqueItems = builder.uniqueItems; this.elements = builder.elements; @@ -198,15 +168,14 @@ public static ApiDefaultItemDTO.ApiDefaultItemDTOBuilder builder() { public static class ApiDefaultItemDTOBuilder { private Integer precision; - private ApiDefaultItemDTO defaultItem; private Integer maximum; private String type; private Integer scale; private Integer minLength; private Integer increment; + private ApiUnionFieldDTO unionField; private String keyType; private List requiredValues = new ArrayList(); - private Boolean optionalUnion; private String initialValue; private Boolean flagExclusiveMinimum; private Boolean flagExclusiveMaximum; @@ -214,14 +183,12 @@ public static class ApiDefaultItemDTOBuilder { private List enumValues = new ArrayList(); private List properties = new ArrayList(); private List defaultValues = new ArrayList(); - private UnionEnum unionEnum; private SeqEnum seqEnum; private Integer arraySize; private Integer multipleOf; private Integer mapSize; private List mapTypes = new ArrayList(); private Integer format; - private Boolean generatedFlag; private Integer maxLength; private Boolean uniqueItems; private Integer elements; @@ -238,11 +205,6 @@ public ApiDefaultItemDTO.ApiDefaultItemDTOBuilder precision(Integer precision) { return this; } - public ApiDefaultItemDTO.ApiDefaultItemDTOBuilder defaultItem(ApiDefaultItemDTO defaultItem) { - this.defaultItem = defaultItem; - return this; - } - public ApiDefaultItemDTO.ApiDefaultItemDTOBuilder maximum(Integer maximum) { this.maximum = maximum; return this; @@ -268,6 +230,11 @@ public ApiDefaultItemDTO.ApiDefaultItemDTOBuilder increment(Integer increment) { return this; } + public ApiDefaultItemDTO.ApiDefaultItemDTOBuilder unionField(ApiUnionFieldDTO unionField) { + this.unionField = unionField; + return this; + } + public ApiDefaultItemDTO.ApiDefaultItemDTOBuilder keyType(String keyType) { this.keyType = keyType; return this; @@ -287,11 +254,6 @@ public ApiDefaultItemDTO.ApiDefaultItemDTOBuilder requiredValue(String requiredV return this; } - public ApiDefaultItemDTO.ApiDefaultItemDTOBuilder optionalUnion(Boolean optionalUnion) { - this.optionalUnion = optionalUnion; - return this; - } - public ApiDefaultItemDTO.ApiDefaultItemDTOBuilder initialValue(String initialValue) { this.initialValue = initialValue; return this; @@ -354,11 +316,6 @@ public ApiDefaultItemDTO.ApiDefaultItemDTOBuilder defaultValue(String defaultVal return this; } - public ApiDefaultItemDTO.ApiDefaultItemDTOBuilder unionEnum(UnionEnum unionEnum) { - this.unionEnum = unionEnum; - return this; - } - public ApiDefaultItemDTO.ApiDefaultItemDTOBuilder seqEnum(SeqEnum seqEnum) { this.seqEnum = seqEnum; return this; @@ -398,11 +355,6 @@ public ApiDefaultItemDTO.ApiDefaultItemDTOBuilder format(Integer format) { return this; } - public ApiDefaultItemDTO.ApiDefaultItemDTOBuilder generatedFlag(Boolean generatedFlag) { - this.generatedFlag = generatedFlag; - return this; - } - public ApiDefaultItemDTO.ApiDefaultItemDTOBuilder maxLength(Integer maxLength) { this.maxLength = maxLength; return this; @@ -476,14 +428,6 @@ public void setPrecision(Integer precision) { this.precision = precision; } - @Schema(name = "defaultItem", required = false) - public ApiDefaultItemDTO getDefaultItem() { - return defaultItem; - } - public void setDefaultItem(ApiDefaultItemDTO defaultItem) { - this.defaultItem = defaultItem; - } - @Schema(name = "maximum", required = false) public Integer getMaximum() { return maximum; @@ -524,6 +468,14 @@ public void setIncrement(Integer increment) { this.increment = increment; } + @Schema(name = "unionField", required = false) + public ApiUnionFieldDTO getUnionField() { + return unionField; + } + public void setUnionField(ApiUnionFieldDTO unionField) { + this.unionField = unionField; + } + @Schema(name = "keyType", required = false) public String getKeyType() { return keyType; @@ -540,14 +492,6 @@ public void setRequiredValues(List requiredValues) { this.requiredValues = requiredValues; } - @Schema(name = "optionalUnion", required = false) - public Boolean getOptionalUnion() { - return optionalUnion; - } - public void setOptionalUnion(Boolean optionalUnion) { - this.optionalUnion = optionalUnion; - } - @Schema(name = "initialValue", required = false) public String getInitialValue() { return initialValue; @@ -604,14 +548,6 @@ public void setDefaultValues(List defaultValues) { this.defaultValues = defaultValues; } - @Schema(name = "unionEnum", required = false) - public UnionEnum getUnionEnum() { - return unionEnum; - } - public void setUnionEnum(UnionEnum unionEnum) { - this.unionEnum = unionEnum; - } - @Schema(name = "seqEnum", required = false) public SeqEnum getSeqEnum() { return seqEnum; @@ -660,14 +596,6 @@ public void setFormat(Integer format) { this.format = format; } - @Schema(name = "generatedFlag", required = false) - public Boolean getGeneratedFlag() { - return generatedFlag; - } - public void setGeneratedFlag(Boolean generatedFlag) { - this.generatedFlag = generatedFlag; - } - @Schema(name = "maxLength", required = false) public Integer getMaxLength() { return maxLength; @@ -757,12 +685,12 @@ public boolean equals(Object o) { return false; } ApiDefaultItemDTO apiDefaultItemDTO = (ApiDefaultItemDTO) o; - return Objects.equals(this.precision, apiDefaultItemDTO.precision) && Objects.equals(this.defaultItem, apiDefaultItemDTO.defaultItem) && Objects.equals(this.maximum, apiDefaultItemDTO.maximum) && Objects.equals(this.type, apiDefaultItemDTO.type) && Objects.equals(this.scale, apiDefaultItemDTO.scale) && Objects.equals(this.minLength, apiDefaultItemDTO.minLength) && Objects.equals(this.increment, apiDefaultItemDTO.increment) && Objects.equals(this.keyType, apiDefaultItemDTO.keyType) && Objects.equals(this.requiredValues, apiDefaultItemDTO.requiredValues) && Objects.equals(this.optionalUnion, apiDefaultItemDTO.optionalUnion) && Objects.equals(this.initialValue, apiDefaultItemDTO.initialValue) && Objects.equals(this.flagExclusiveMinimum, apiDefaultItemDTO.flagExclusiveMinimum) && Objects.equals(this.flagExclusiveMaximum, apiDefaultItemDTO.flagExclusiveMaximum) && Objects.equals(this.defaultValue, apiDefaultItemDTO.defaultValue) && Objects.equals(this.enumValues, apiDefaultItemDTO.enumValues) && Objects.equals(this.properties, apiDefaultItemDTO.properties) && Objects.equals(this.defaultValues, apiDefaultItemDTO.defaultValues) && Objects.equals(this.unionEnum, apiDefaultItemDTO.unionEnum) && Objects.equals(this.seqEnum, apiDefaultItemDTO.seqEnum) && Objects.equals(this.arraySize, apiDefaultItemDTO.arraySize) && Objects.equals(this.multipleOf, apiDefaultItemDTO.multipleOf) && Objects.equals(this.mapSize, apiDefaultItemDTO.mapSize) && Objects.equals(this.mapTypes, apiDefaultItemDTO.mapTypes) && Objects.equals(this.format, apiDefaultItemDTO.format) && Objects.equals(this.generatedFlag, apiDefaultItemDTO.generatedFlag) && Objects.equals(this.maxLength, apiDefaultItemDTO.maxLength) && Objects.equals(this.uniqueItems, apiDefaultItemDTO.uniqueItems) && Objects.equals(this.elements, apiDefaultItemDTO.elements) && Objects.equals(this.name, apiDefaultItemDTO.name) && Objects.equals(this.regex, apiDefaultItemDTO.regex) && Objects.equals(this.minItems, apiDefaultItemDTO.minItems) && Objects.equals(this.values, apiDefaultItemDTO.values) && Objects.equals(this.minimum, apiDefaultItemDTO.minimum) && Objects.equals(this.numberEnum, apiDefaultItemDTO.numberEnum) && Objects.equals(this.valueLength, apiDefaultItemDTO.valueLength); + return Objects.equals(this.precision, apiDefaultItemDTO.precision) && Objects.equals(this.maximum, apiDefaultItemDTO.maximum) && Objects.equals(this.type, apiDefaultItemDTO.type) && Objects.equals(this.scale, apiDefaultItemDTO.scale) && Objects.equals(this.minLength, apiDefaultItemDTO.minLength) && Objects.equals(this.increment, apiDefaultItemDTO.increment) && Objects.equals(this.unionField, apiDefaultItemDTO.unionField) && Objects.equals(this.keyType, apiDefaultItemDTO.keyType) && Objects.equals(this.requiredValues, apiDefaultItemDTO.requiredValues) && Objects.equals(this.initialValue, apiDefaultItemDTO.initialValue) && Objects.equals(this.flagExclusiveMinimum, apiDefaultItemDTO.flagExclusiveMinimum) && Objects.equals(this.flagExclusiveMaximum, apiDefaultItemDTO.flagExclusiveMaximum) && Objects.equals(this.defaultValue, apiDefaultItemDTO.defaultValue) && Objects.equals(this.enumValues, apiDefaultItemDTO.enumValues) && Objects.equals(this.properties, apiDefaultItemDTO.properties) && Objects.equals(this.defaultValues, apiDefaultItemDTO.defaultValues) && Objects.equals(this.seqEnum, apiDefaultItemDTO.seqEnum) && Objects.equals(this.arraySize, apiDefaultItemDTO.arraySize) && Objects.equals(this.multipleOf, apiDefaultItemDTO.multipleOf) && Objects.equals(this.mapSize, apiDefaultItemDTO.mapSize) && Objects.equals(this.mapTypes, apiDefaultItemDTO.mapTypes) && Objects.equals(this.format, apiDefaultItemDTO.format) && Objects.equals(this.maxLength, apiDefaultItemDTO.maxLength) && Objects.equals(this.uniqueItems, apiDefaultItemDTO.uniqueItems) && Objects.equals(this.elements, apiDefaultItemDTO.elements) && Objects.equals(this.name, apiDefaultItemDTO.name) && Objects.equals(this.regex, apiDefaultItemDTO.regex) && Objects.equals(this.minItems, apiDefaultItemDTO.minItems) && Objects.equals(this.values, apiDefaultItemDTO.values) && Objects.equals(this.minimum, apiDefaultItemDTO.minimum) && Objects.equals(this.numberEnum, apiDefaultItemDTO.numberEnum) && Objects.equals(this.valueLength, apiDefaultItemDTO.valueLength); } @Override public int hashCode() { - return Objects.hash(precision, defaultItem, maximum, type, scale, minLength, increment, keyType, requiredValues, optionalUnion, initialValue, flagExclusiveMinimum, flagExclusiveMaximum, defaultValue, enumValues, properties, defaultValues, unionEnum, seqEnum, arraySize, multipleOf, mapSize, mapTypes, format, generatedFlag, maxLength, uniqueItems, elements, name, regex, minItems, values, minimum, numberEnum, valueLength); + return Objects.hash(precision, maximum, type, scale, minLength, increment, unionField, keyType, requiredValues, initialValue, flagExclusiveMinimum, flagExclusiveMaximum, defaultValue, enumValues, properties, defaultValues, seqEnum, arraySize, multipleOf, mapSize, mapTypes, format, maxLength, uniqueItems, elements, name, regex, minItems, values, minimum, numberEnum, valueLength); } @Override @@ -770,15 +698,14 @@ public String toString() { StringBuilder sb = new StringBuilder(); sb.append("ApiDefaultItemDTO{"); sb.append(" precision:").append(precision).append(","); - sb.append(" defaultItem:").append(defaultItem).append(","); sb.append(" maximum:").append(maximum).append(","); sb.append(" type:").append(type).append(","); sb.append(" scale:").append(scale).append(","); sb.append(" minLength:").append(minLength).append(","); sb.append(" increment:").append(increment).append(","); + sb.append(" unionField:").append(unionField).append(","); sb.append(" keyType:").append(keyType).append(","); sb.append(" requiredValues:").append(requiredValues).append(","); - sb.append(" optionalUnion:").append(optionalUnion).append(","); sb.append(" initialValue:").append(initialValue).append(","); sb.append(" flagExclusiveMinimum:").append(flagExclusiveMinimum).append(","); sb.append(" flagExclusiveMaximum:").append(flagExclusiveMaximum).append(","); @@ -786,14 +713,12 @@ public String toString() { sb.append(" enumValues:").append(enumValues).append(","); sb.append(" properties:").append(properties).append(","); sb.append(" defaultValues:").append(defaultValues).append(","); - sb.append(" unionEnum:").append(unionEnum).append(","); sb.append(" seqEnum:").append(seqEnum).append(","); sb.append(" arraySize:").append(arraySize).append(","); sb.append(" multipleOf:").append(multipleOf).append(","); sb.append(" mapSize:").append(mapSize).append(","); sb.append(" mapTypes:").append(mapTypes).append(","); sb.append(" format:").append(format).append(","); - sb.append(" generatedFlag:").append(generatedFlag).append(","); sb.append(" maxLength:").append(maxLength).append(","); sb.append(" uniqueItems:").append(uniqueItems).append(","); sb.append(" elements:").append(elements).append(","); @@ -813,8 +738,6 @@ private void validatePartialCombinations() { if (Objects.nonNull(this.precision)) { satisfiedCondition = true; - } else if (Objects.nonNull(this.defaultItem)) { - satisfiedCondition = true; } else if (Objects.nonNull(this.maximum)) { satisfiedCondition = true; } else if (Objects.nonNull(this.type)) { @@ -825,12 +748,12 @@ private void validatePartialCombinations() { satisfiedCondition = true; } else if (Objects.nonNull(this.increment)) { satisfiedCondition = true; + } else if (Objects.nonNull(this.unionField)) { + satisfiedCondition = true; } else if (Objects.nonNull(this.keyType)) { satisfiedCondition = true; } else if (Objects.nonNull(this.requiredValues)) { satisfiedCondition = true; - } else if (Objects.nonNull(this.optionalUnion)) { - satisfiedCondition = true; } else if (Objects.nonNull(this.initialValue)) { satisfiedCondition = true; } else if (Objects.nonNull(this.flagExclusiveMinimum)) { @@ -845,8 +768,6 @@ private void validatePartialCombinations() { satisfiedCondition = true; } else if (Objects.nonNull(this.defaultValues)) { satisfiedCondition = true; - } else if (Objects.nonNull(this.unionEnum)) { - satisfiedCondition = true; } else if (Objects.nonNull(this.seqEnum)) { satisfiedCondition = true; } else if (Objects.nonNull(this.arraySize)) { @@ -859,8 +780,6 @@ private void validatePartialCombinations() { satisfiedCondition = true; } else if (Objects.nonNull(this.format)) { satisfiedCondition = true; - } else if (Objects.nonNull(this.generatedFlag)) { - satisfiedCondition = true; } else if (Objects.nonNull(this.maxLength)) { satisfiedCondition = true; } else if (Objects.nonNull(this.uniqueItems)) { diff --git a/multiapi-engine/src/test/resources/openapigenerator/testRestrictionsSchema/assets/model/ArrayFieldDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testRestrictionsSchema/assets/model/ArrayFieldDTO.java index be71bcf2..2ba32da6 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testRestrictionsSchema/assets/model/ArrayFieldDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testRestrictionsSchema/assets/model/ArrayFieldDTO.java @@ -4,6 +4,7 @@ import java.util.List; import java.util.ArrayList; import lombok.Builder; +import lombok.Singular; import lombok.Value; import lombok.extern.jackson.Jacksonized; @@ -32,10 +33,12 @@ public class ArrayFieldDTO { private Integer minItems; @JsonProperty(value ="values") - private List values = new ArrayList(); + @Singular("value") + private List values; @JsonProperty(value ="defaultValue") - private List defaultValue = new ArrayList(); + @Singular("_defaultValue") + private List defaultValue; @Builder diff --git a/multiapi-engine/src/test/resources/openapigenerator/testRestrictionsSchema/assets/model/EnumFieldDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testRestrictionsSchema/assets/model/EnumFieldDTO.java index c68f5bf6..5e98e85c 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testRestrictionsSchema/assets/model/EnumFieldDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testRestrictionsSchema/assets/model/EnumFieldDTO.java @@ -4,6 +4,7 @@ import java.util.List; import java.util.ArrayList; import lombok.Builder; +import lombok.Singular; import lombok.Value; import lombok.extern.jackson.Jacksonized; @@ -14,7 +15,8 @@ public class EnumFieldDTO { private Boolean mandatory; @JsonProperty(value ="enumValues") - private List enumValues = new ArrayList(); + @Singular("enumValue") + private List enumValues; @JsonProperty(value ="type") private String type; diff --git a/multiapi-engine/src/test/resources/openapigenerator/testRestrictionsSchema/assets/model/FieldValueDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testRestrictionsSchema/assets/model/FieldValueDTO.java index 391ae8ee..e435781d 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testRestrictionsSchema/assets/model/FieldValueDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testRestrictionsSchema/assets/model/FieldValueDTO.java @@ -5,10 +5,11 @@ import com.fasterxml.jackson.annotation.JsonValue; import java.util.List; import java.util.ArrayList; +import com.sngular.multifileplugin.testRestrictionsSchema.model.exception.ModelClassException; import lombok.Builder; +import lombok.Singular; import lombok.Value; import lombok.extern.jackson.Jacksonized; -import com.sngular.multifileplugin.testRestrictionsSchema.model.exception.ModelClassException; @Value public class FieldValueDTO { @@ -41,7 +42,8 @@ public class FieldValueDTO { private String keyType; @JsonProperty(value ="requiredValues") - private List requiredValues = new ArrayList(); + @Singular("requiredValue") + private List requiredValues; @JsonProperty(value ="optionalUnion") private Boolean optionalUnion; @@ -62,10 +64,12 @@ public class FieldValueDTO { private FieldDTO property; @JsonProperty(value ="enumValues") - private List enumValues = new ArrayList(); + @Singular("enumValue") + private List enumValues; @JsonProperty(value ="properties") - private List properties = new ArrayList(); + @Singular("property") + private List properties; @JsonProperty(value ="unionEnum") private UnionEnum unionEnum; @@ -130,7 +134,8 @@ public String toString() { private Integer mapSize; @JsonProperty(value ="mapTypes") - private List mapTypes = new ArrayList(); + @Singular("mapType") + private List mapTypes; @JsonProperty(value ="format") private String format; @@ -157,7 +162,8 @@ public String toString() { private Integer minItems; @JsonProperty(value ="values") - private List values = new ArrayList(); + @Singular("value") + private List values; @JsonProperty(value ="minimum") private Integer minimum; @@ -240,82 +246,82 @@ private FieldValueDTO(Boolean mandatory, Integer precision, FieldDTO defaultItem private void validatePartialCombinations() { boolean satisfiedCondition = false; - if (Objects.nonNull(this.mandatory)) { - satisfiedCondition = true; - } else if (Objects.nonNull(this.precision)) { - satisfiedCondition = true; - } else if (Objects.nonNull(this.defaultItem)) { - satisfiedCondition = true; - } else if (Objects.nonNull(this.maximum)) { - satisfiedCondition = true; - } else if (Objects.nonNull(this.type)) { - satisfiedCondition = true; - } else if (Objects.nonNull(this.scale)) { - satisfiedCondition = true; - } else if (Objects.nonNull(this.minLength)) { - satisfiedCondition = true; - } else if (Objects.nonNull(this.increment)) { - satisfiedCondition = true; - } else if (Objects.nonNull(this.keyType)) { - satisfiedCondition = true; - } else if (Objects.nonNull(this.requiredValues)) { - satisfiedCondition = true; - } else if (Objects.nonNull(this.optionalUnion)) { - satisfiedCondition = true; - } else if (Objects.nonNull(this.initialValue)) { - satisfiedCondition = true; - } else if (Objects.nonNull(this.flagExclusiveMinimum)) { - satisfiedCondition = true; - } else if (Objects.nonNull(this.flagExclusiveMaximum)) { - satisfiedCondition = true; - } else if (Objects.nonNull(this.defaultValue)) { - satisfiedCondition = true; - } else if (Objects.nonNull(this.property)) { - satisfiedCondition = true; - } else if (Objects.nonNull(this.enumValues)) { - satisfiedCondition = true; - } else if (Objects.nonNull(this.properties)) { - satisfiedCondition = true; - } else if (Objects.nonNull(this.unionEnum)) { - satisfiedCondition = true; - } else if (Objects.nonNull(this.seqEnum)) { - satisfiedCondition = true; - } else if (Objects.nonNull(this.arraySize)) { - satisfiedCondition = true; - } else if (Objects.nonNull(this.multipleOf)) { - satisfiedCondition = true; - } else if (Objects.nonNull(this.mapSize)) { - satisfiedCondition = true; - } else if (Objects.nonNull(this.mapTypes)) { - satisfiedCondition = true; - } else if (Objects.nonNull(this.format)) { - satisfiedCondition = true; - } else if (Objects.nonNull(this.generatedFlag)) { - satisfiedCondition = true; - } else if (Objects.nonNull(this.maxLength)) { - satisfiedCondition = true; - } else if (Objects.nonNull(this.uniqueItems)) { - satisfiedCondition = true; - } else if (Objects.nonNull(this.elements)) { - satisfiedCondition = true; - } else if (Objects.nonNull(this.name)) { - satisfiedCondition = true; - } else if (Objects.nonNull(this.regex)) { - satisfiedCondition = true; - } else if (Objects.nonNull(this.minItems)) { - satisfiedCondition = true; - } else if (Objects.nonNull(this.values)) { - satisfiedCondition = true; - } else if (Objects.nonNull(this.minimum)) { - satisfiedCondition = true; - } else if (Objects.nonNull(this.numberEnum)) { - satisfiedCondition = true; - } else if (Objects.nonNull(this.valueLength)) { - satisfiedCondition = true; - } + if (Objects.nonNull(this.mandatory)) { + satisfiedCondition = true; + } else if (Objects.nonNull(this.precision)) { + satisfiedCondition = true; + } else if (Objects.nonNull(this.defaultItem)) { + satisfiedCondition = true; + } else if (Objects.nonNull(this.maximum)) { + satisfiedCondition = true; + } else if (Objects.nonNull(this.type)) { + satisfiedCondition = true; + } else if (Objects.nonNull(this.scale)) { + satisfiedCondition = true; + } else if (Objects.nonNull(this.minLength)) { + satisfiedCondition = true; + } else if (Objects.nonNull(this.increment)) { + satisfiedCondition = true; + } else if (Objects.nonNull(this.keyType)) { + satisfiedCondition = true; + } else if (Objects.nonNull(this.requiredValues)) { + satisfiedCondition = true; + } else if (Objects.nonNull(this.optionalUnion)) { + satisfiedCondition = true; + } else if (Objects.nonNull(this.initialValue)) { + satisfiedCondition = true; + } else if (Objects.nonNull(this.flagExclusiveMinimum)) { + satisfiedCondition = true; + } else if (Objects.nonNull(this.flagExclusiveMaximum)) { + satisfiedCondition = true; + } else if (Objects.nonNull(this.defaultValue)) { + satisfiedCondition = true; + } else if (Objects.nonNull(this.property)) { + satisfiedCondition = true; + } else if (Objects.nonNull(this.enumValues)) { + satisfiedCondition = true; + } else if (Objects.nonNull(this.properties)) { + satisfiedCondition = true; + } else if (Objects.nonNull(this.unionEnum)) { + satisfiedCondition = true; + } else if (Objects.nonNull(this.seqEnum)) { + satisfiedCondition = true; + } else if (Objects.nonNull(this.arraySize)) { + satisfiedCondition = true; + } else if (Objects.nonNull(this.multipleOf)) { + satisfiedCondition = true; + } else if (Objects.nonNull(this.mapSize)) { + satisfiedCondition = true; + } else if (Objects.nonNull(this.mapTypes)) { + satisfiedCondition = true; + } else if (Objects.nonNull(this.format)) { + satisfiedCondition = true; + } else if (Objects.nonNull(this.generatedFlag)) { + satisfiedCondition = true; + } else if (Objects.nonNull(this.maxLength)) { + satisfiedCondition = true; + } else if (Objects.nonNull(this.uniqueItems)) { + satisfiedCondition = true; + } else if (Objects.nonNull(this.elements)) { + satisfiedCondition = true; + } else if (Objects.nonNull(this.name)) { + satisfiedCondition = true; + } else if (Objects.nonNull(this.regex)) { + satisfiedCondition = true; + } else if (Objects.nonNull(this.minItems)) { + satisfiedCondition = true; + } else if (Objects.nonNull(this.values)) { + satisfiedCondition = true; + } else if (Objects.nonNull(this.minimum)) { + satisfiedCondition = true; + } else if (Objects.nonNull(this.numberEnum)) { + satisfiedCondition = true; + } else if (Objects.nonNull(this.valueLength)) { + satisfiedCondition = true; + } if (!satisfiedCondition) { - throw new ModelClassException("FieldValueDTO"); + throw new ModelClassException("FieldValueDTO"); } } } diff --git a/multiapi-engine/src/test/resources/openapigenerator/testRestrictionsSchema/assets/model/MapFieldDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testRestrictionsSchema/assets/model/MapFieldDTO.java index 8d76cd6c..6508f9c5 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testRestrictionsSchema/assets/model/MapFieldDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testRestrictionsSchema/assets/model/MapFieldDTO.java @@ -4,6 +4,7 @@ import java.util.List; import java.util.ArrayList; import lombok.Builder; +import lombok.Singular; import lombok.Value; import lombok.extern.jackson.Jacksonized; @@ -26,10 +27,12 @@ public class MapFieldDTO { private Integer mapSize; @JsonProperty(value ="mapTypes") - private List mapTypes = new ArrayList(); + @Singular("mapType") + private List mapTypes; @JsonProperty(value ="defaultValue") - private List defaultValue = new ArrayList(); + @Singular("_defaultValue") + private List defaultValue; @Builder diff --git a/multiapi-engine/src/test/resources/openapigenerator/testRestrictionsSchema/assets/model/ObjectFieldDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testRestrictionsSchema/assets/model/ObjectFieldDTO.java index 8e1c3193..55b81020 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testRestrictionsSchema/assets/model/ObjectFieldDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testRestrictionsSchema/assets/model/ObjectFieldDTO.java @@ -4,6 +4,7 @@ import java.util.List; import java.util.ArrayList; import lombok.Builder; +import lombok.Singular; import lombok.Value; import lombok.extern.jackson.Jacksonized; @@ -14,19 +15,22 @@ public class ObjectFieldDTO { private Boolean mandatory; @JsonProperty(value ="requiredValues") - private List requiredValues = new ArrayList(); + @Singular("requiredValue") + private List requiredValues; @JsonProperty(value ="type") private String type; @JsonProperty(value ="properties") - private List properties = new ArrayList(); + @Singular("property") + private List properties; @JsonProperty(value ="name") private String name; @JsonProperty(value ="defaultValue") - private List defaultValue = new ArrayList(); + @Singular("_defaultValue") + private List defaultValue; @Builder diff --git a/multiapi-engine/src/test/resources/openapigenerator/testRestrictionsSchema/assets/model/SchemaDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testRestrictionsSchema/assets/model/SchemaDTO.java index 749ca408..9ab2ff07 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testRestrictionsSchema/assets/model/SchemaDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testRestrictionsSchema/assets/model/SchemaDTO.java @@ -5,6 +5,7 @@ import java.util.ArrayList; import lombok.Builder; import lombok.NonNull; +import lombok.Singular; import lombok.Value; import lombok.extern.jackson.Jacksonized; @@ -12,7 +13,8 @@ public class SchemaDTO { @JsonProperty(value ="properties") - private List properties = new ArrayList(); + @Singular("property") + private List properties; @JsonProperty(value ="type") @NonNull diff --git a/multiapi-engine/src/test/resources/openapigenerator/testRestrictionsSchema/assets/model/StringFieldDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testRestrictionsSchema/assets/model/StringFieldDTO.java index 488eb241..98e7b7d1 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testRestrictionsSchema/assets/model/StringFieldDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testRestrictionsSchema/assets/model/StringFieldDTO.java @@ -4,6 +4,7 @@ import java.util.List; import java.util.ArrayList; import lombok.Builder; +import lombok.Singular; import lombok.Value; import lombok.extern.jackson.Jacksonized; @@ -20,7 +21,8 @@ public class StringFieldDTO { private String type; @JsonProperty(value ="properties") - private List properties = new ArrayList(); + @Singular("property") + private List properties; @JsonProperty(value ="name") private String name; diff --git a/multiapi-engine/src/test/resources/openapigenerator/testRestrictionsSchema/assets/model/UnionFieldDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testRestrictionsSchema/assets/model/UnionFieldDTO.java index f6dc1427..88012205 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testRestrictionsSchema/assets/model/UnionFieldDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testRestrictionsSchema/assets/model/UnionFieldDTO.java @@ -5,6 +5,7 @@ import java.util.List; import java.util.ArrayList; import lombok.Builder; +import lombok.Singular; import lombok.Value; import lombok.extern.jackson.Jacksonized; @@ -55,7 +56,8 @@ public String toString() { private Boolean optionalUnion; @JsonProperty(value ="values") - private List values = new ArrayList(); + @Singular("value") + private List values; @Builder diff --git a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/MaxBigDecimal.java b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/MaxBigDecimal.java index 920678a5..432758cf 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/MaxBigDecimal.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/MaxBigDecimal.java @@ -1,7 +1,7 @@ package com.sngular.multifileplugin.testapi.model.customvalidator; -import javax.validation.Constraint; -import javax.validation.Payload; +import jakarta.validation.Constraint; +import jakarta.validation.Payload; import java.lang.annotation.*; @Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, ElementType.ANNOTATION_TYPE}) diff --git a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/MaxBigDecimalValidator.java b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/MaxBigDecimalValidator.java index 20921d22..ab2dd2e4 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/MaxBigDecimalValidator.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/MaxBigDecimalValidator.java @@ -3,8 +3,8 @@ import java.math.BigDecimal; import java.util.Objects; -import javax.validation.ConstraintValidator; -import javax.validation.ConstraintValidatorContext; +import jakarta.validation.ConstraintValidator; +import jakarta.validation.ConstraintValidatorContext; public class MaxBigDecimalValidator implements ConstraintValidator { diff --git a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/MaxDouble.java b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/MaxDouble.java index 66d07798..4a5a4ee8 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/MaxDouble.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/MaxDouble.java @@ -1,7 +1,7 @@ package com.sngular.multifileplugin.testapi.model.customvalidator; -import javax.validation.Constraint; -import javax.validation.Payload; +import jakarta.validation.Constraint; +import jakarta.validation.Payload; import java.lang.annotation.*; @Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, ElementType.ANNOTATION_TYPE}) diff --git a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/MaxDoubleValidator.java b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/MaxDoubleValidator.java index 490cd7a1..2895e986 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/MaxDoubleValidator.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/MaxDoubleValidator.java @@ -2,8 +2,8 @@ import java.util.Objects; -import javax.validation.ConstraintValidator; -import javax.validation.ConstraintValidatorContext; +import jakarta.validation.ConstraintValidator; +import jakarta.validation.ConstraintValidatorContext; public class MaxDoubleValidator implements ConstraintValidator { diff --git a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/MaxFloat.java b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/MaxFloat.java index 8e889066..2d30d168 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/MaxFloat.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/MaxFloat.java @@ -1,7 +1,7 @@ package com.sngular.multifileplugin.testapi.model.customvalidator; -import javax.validation.Constraint; -import javax.validation.Payload; +import jakarta.validation.Constraint; +import jakarta.validation.Payload; import java.lang.annotation.*; @Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, ElementType.ANNOTATION_TYPE}) diff --git a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/MaxFloatValidator.java b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/MaxFloatValidator.java index a656e06e..bed7784d 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/MaxFloatValidator.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/MaxFloatValidator.java @@ -2,8 +2,8 @@ import java.util.Objects; -import javax.validation.ConstraintValidator; -import javax.validation.ConstraintValidatorContext; +import jakarta.validation.ConstraintValidator; +import jakarta.validation.ConstraintValidatorContext; public class MaxFloatValidator implements ConstraintValidator { diff --git a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/MaxInteger.java b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/MaxInteger.java index 98db09d4..253dfde6 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/MaxInteger.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/MaxInteger.java @@ -1,7 +1,7 @@ package com.sngular.multifileplugin.testapi.model.customvalidator; -import javax.validation.Constraint; -import javax.validation.Payload; +import jakarta.validation.Constraint; +import jakarta.validation.Payload; import java.lang.annotation.*; @Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, ElementType.ANNOTATION_TYPE}) diff --git a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/MaxIntegerValidator.java b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/MaxIntegerValidator.java index 3071e7e7..806cc0ae 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/MaxIntegerValidator.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/MaxIntegerValidator.java @@ -2,8 +2,8 @@ import java.util.Objects; -import javax.validation.ConstraintValidator; -import javax.validation.ConstraintValidatorContext; +import jakarta.validation.ConstraintValidator; +import jakarta.validation.ConstraintValidatorContext; public class MaxIntegerValidator implements ConstraintValidator { diff --git a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/MaxItems.java b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/MaxItems.java index c140599d..948eb094 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/MaxItems.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/MaxItems.java @@ -1,7 +1,7 @@ package com.sngular.multifileplugin.testapi.model.customvalidator; -import javax.validation.Constraint; -import javax.validation.Payload; +import jakarta.validation.Constraint; +import jakarta.validation.Payload; import java.lang.annotation.*; @Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, ElementType.ANNOTATION_TYPE}) diff --git a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/MaxItemsValidator.java b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/MaxItemsValidator.java index 411963fd..38b23174 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/MaxItemsValidator.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/MaxItemsValidator.java @@ -3,8 +3,8 @@ import java.util.List; import java.util.Objects; -import javax.validation.ConstraintValidator; -import javax.validation.ConstraintValidatorContext; +import jakarta.validation.ConstraintValidator; +import jakarta.validation.ConstraintValidatorContext; public class MaxItemsValidator implements ConstraintValidator> { diff --git a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/MinBigDecimal.java b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/MinBigDecimal.java index 1a6e383d..4ca67dbb 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/MinBigDecimal.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/MinBigDecimal.java @@ -1,7 +1,7 @@ package com.sngular.multifileplugin.testapi.model.customvalidator; -import javax.validation.Constraint; -import javax.validation.Payload; +import jakarta.validation.Constraint; +import jakarta.validation.Payload; import java.lang.annotation.*; @Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, ElementType.ANNOTATION_TYPE}) diff --git a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/MinBigDecimalValidator.java b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/MinBigDecimalValidator.java index 2853538f..5408257a 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/MinBigDecimalValidator.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/MinBigDecimalValidator.java @@ -3,8 +3,8 @@ import java.math.BigDecimal; import java.util.Objects; -import javax.validation.ConstraintValidator; -import javax.validation.ConstraintValidatorContext; +import jakarta.validation.ConstraintValidator; +import jakarta.validation.ConstraintValidatorContext; public class MinBigDecimalValidator implements ConstraintValidator { diff --git a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/MinDouble.java b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/MinDouble.java index d39ff710..07ab579f 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/MinDouble.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/MinDouble.java @@ -1,7 +1,7 @@ package com.sngular.multifileplugin.testapi.model.customvalidator; -import javax.validation.Constraint; -import javax.validation.Payload; +import jakarta.validation.Constraint; +import jakarta.validation.Payload; import java.lang.annotation.*; @Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, ElementType.ANNOTATION_TYPE}) diff --git a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/MinDoubleValidator.java b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/MinDoubleValidator.java index 4440be41..ac727c0e 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/MinDoubleValidator.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/MinDoubleValidator.java @@ -2,8 +2,8 @@ import java.util.Objects; -import javax.validation.ConstraintValidator; -import javax.validation.ConstraintValidatorContext; +import jakarta.validation.ConstraintValidator; +import jakarta.validation.ConstraintValidatorContext; public class MinDoubleValidator implements ConstraintValidator { diff --git a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/MinFloat.java b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/MinFloat.java index a2faf299..2c817bdd 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/MinFloat.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/MinFloat.java @@ -1,7 +1,7 @@ package com.sngular.multifileplugin.testapi.model.customvalidator; -import javax.validation.Constraint; -import javax.validation.Payload; +import jakarta.validation.Constraint; +import jakarta.validation.Payload; import java.lang.annotation.*; @Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, ElementType.ANNOTATION_TYPE}) diff --git a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/MinFloatValidator.java b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/MinFloatValidator.java index 3381b63e..d97088cb 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/MinFloatValidator.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/MinFloatValidator.java @@ -2,8 +2,8 @@ import java.util.Objects; -import javax.validation.ConstraintValidator; -import javax.validation.ConstraintValidatorContext; +import jakarta.validation.ConstraintValidator; +import jakarta.validation.ConstraintValidatorContext; public class MinFloatValidator implements ConstraintValidator { diff --git a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/MinInteger.java b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/MinInteger.java index 535c63c0..b58a31b6 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/MinInteger.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/MinInteger.java @@ -1,7 +1,7 @@ package com.sngular.multifileplugin.testapi.model.customvalidator; -import javax.validation.Constraint; -import javax.validation.Payload; +import jakarta.validation.Constraint; +import jakarta.validation.Payload; import java.lang.annotation.*; @Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, ElementType.ANNOTATION_TYPE}) diff --git a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/MinIntegerValidator.java b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/MinIntegerValidator.java index 6a377bff..978d73e7 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/MinIntegerValidator.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/MinIntegerValidator.java @@ -2,8 +2,8 @@ import java.util.Objects; -import javax.validation.ConstraintValidator; -import javax.validation.ConstraintValidatorContext; +import jakarta.validation.ConstraintValidator; +import jakarta.validation.ConstraintValidatorContext; public class MinIntegerValidator implements ConstraintValidator { diff --git a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/MinItems.java b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/MinItems.java index c1534895..6c234dcb 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/MinItems.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/MinItems.java @@ -1,7 +1,7 @@ package com.sngular.multifileplugin.testapi.model.customvalidator; -import javax.validation.Constraint; -import javax.validation.Payload; +import jakarta.validation.Constraint; +import jakarta.validation.Payload; import java.lang.annotation.*; @Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, ElementType.ANNOTATION_TYPE}) diff --git a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/MinItemsValidator.java b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/MinItemsValidator.java index 0edffa6f..6cfaf061 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/MinItemsValidator.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/MinItemsValidator.java @@ -3,8 +3,8 @@ import java.util.List; import java.util.Objects; -import javax.validation.ConstraintValidator; -import javax.validation.ConstraintValidatorContext; +import jakarta.validation.ConstraintValidator; +import jakarta.validation.ConstraintValidatorContext; public class MinItemsValidator implements ConstraintValidator> { diff --git a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/MultipleOf.java b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/MultipleOf.java index 871f5e67..fce0b8cc 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/MultipleOf.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/MultipleOf.java @@ -1,7 +1,7 @@ package com.sngular.multifileplugin.testapi.model.customvalidator; -import javax.validation.Constraint; -import javax.validation.Payload; +import jakarta.validation.Constraint; +import jakarta.validation.Payload; import java.lang.annotation.*; @Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, ElementType.ANNOTATION_TYPE}) diff --git a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/MultipleOfValidator.java b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/MultipleOfValidator.java index 4e346f04..10647a98 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/MultipleOfValidator.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/MultipleOfValidator.java @@ -2,8 +2,8 @@ import java.util.Objects; -import javax.validation.ConstraintValidator; -import javax.validation.ConstraintValidatorContext; +import jakarta.validation.ConstraintValidator; +import jakarta.validation.ConstraintValidatorContext; public class MultipleOfValidator implements ConstraintValidator { diff --git a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/NotNull.java b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/NotNull.java index 8c92eaaa..291b2623 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/NotNull.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/NotNull.java @@ -1,7 +1,7 @@ package com.sngular.multifileplugin.testapi.model.customvalidator; -import javax.validation.Constraint; -import javax.validation.Payload; +import jakarta.validation.Constraint; +import jakarta.validation.Payload; import java.lang.annotation.*; @Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, ElementType.ANNOTATION_TYPE}) diff --git a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/NotNullValidator.java b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/NotNullValidator.java index 260166ad..c88f07b1 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/NotNullValidator.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/NotNullValidator.java @@ -1,7 +1,7 @@ package com.sngular.multifileplugin.testapi.model.customvalidator; -import javax.validation.ConstraintValidator; -import javax.validation.ConstraintValidatorContext; +import jakarta.validation.ConstraintValidator; +import jakarta.validation.ConstraintValidatorContext; import java.util.Objects; public class NotNullValidator implements ConstraintValidator { diff --git a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/Pattern.java b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/Pattern.java index 2da77421..0efbbc7b 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/Pattern.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/Pattern.java @@ -1,7 +1,7 @@ package com.sngular.multifileplugin.testapi.model.customvalidator; -import javax.validation.Constraint; -import javax.validation.Payload; +import jakarta.validation.Constraint; +import jakarta.validation.Payload; import java.lang.annotation.*; diff --git a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/PatternValidator.java b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/PatternValidator.java index 0e201fca..7ec927b8 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/PatternValidator.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/PatternValidator.java @@ -2,8 +2,8 @@ import java.util.Objects; -import javax.validation.ConstraintValidator; -import javax.validation.ConstraintValidatorContext; +import jakarta.validation.ConstraintValidator; +import jakarta.validation.ConstraintValidatorContext; public class PatternValidator implements ConstraintValidator { diff --git a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/Size.java b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/Size.java index dc4bfd77..a66e69b7 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/Size.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/Size.java @@ -1,7 +1,7 @@ package com.sngular.multifileplugin.testapi.model.customvalidator; -import javax.validation.Constraint; -import javax.validation.Payload; +import jakarta.validation.Constraint; +import jakarta.validation.Payload; import java.lang.annotation.*; @Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, ElementType.ANNOTATION_TYPE}) diff --git a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/SizeValidator.java b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/SizeValidator.java index 45d0d634..be2c485c 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/SizeValidator.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/SizeValidator.java @@ -2,8 +2,8 @@ import java.util.Objects; -import javax.validation.ConstraintValidator; -import javax.validation.ConstraintValidatorContext; +import jakarta.validation.ConstraintValidator; +import jakarta.validation.ConstraintValidatorContext; public class SizeValidator implements ConstraintValidator { diff --git a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/UniqueItems.java b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/UniqueItems.java index 01b08a46..f6e380de 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/UniqueItems.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/UniqueItems.java @@ -1,7 +1,7 @@ package com.sngular.multifileplugin.testapi.model.customvalidator; -import javax.validation.Constraint; -import javax.validation.Payload; +import jakarta.validation.Constraint; +import jakarta.validation.Payload; import java.lang.annotation.*; @Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, ElementType.ANNOTATION_TYPE}) diff --git a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/UniqueItemsValidator.java b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/UniqueItemsValidator.java index e3743829..53071973 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/UniqueItemsValidator.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testValidationAnnotations/customvalidator/jakarta/UniqueItemsValidator.java @@ -6,8 +6,8 @@ import java.util.Objects; import java.util.Set; -import javax.validation.ConstraintValidator; -import javax.validation.ConstraintValidatorContext; +import jakarta.validation.ConstraintValidator; +import jakarta.validation.ConstraintValidatorContext; public class UniqueItemsValidator implements ConstraintValidator> { From fe660787c84e3fc435c8e7eca7534654bb9ac85a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?jose=20enrique=20garcia=20maci=C3=B1eiras?= Date: Tue, 24 Sep 2024 01:17:54 +0200 Subject: [PATCH 19/26] Fix Test --- .../assets/ApiErrorDTO.java | 7 ------- .../assets/ApiTestDTO.java | 7 ------- .../assets/ApiTestInfoDTO.java | 11 ++--------- .../assets/ApiErrorDTO.java | 7 ------- .../testScsMultiapiGeneration/assets/ApiTestDTO.java | 7 ------- .../assets/ApiTestInfoDTO.java | 12 +++--------- .../assets/ApiTestsDTO.java | 5 ----- 7 files changed, 5 insertions(+), 51 deletions(-) diff --git a/scs-multiapi-maven-plugin/src/test/resources-its/com/sngular/api/generator/multiapi/integration/test/ScsMultiapiGenerationIT/testMultiapiGeneratedSourcesFolder/assets/ApiErrorDTO.java b/scs-multiapi-maven-plugin/src/test/resources-its/com/sngular/api/generator/multiapi/integration/test/ScsMultiapiGenerationIT/testMultiapiGeneratedSourcesFolder/assets/ApiErrorDTO.java index 72c337c1..76a9e019 100644 --- a/scs-multiapi-maven-plugin/src/test/resources-its/com/sngular/api/generator/multiapi/integration/test/ScsMultiapiGenerationIT/testMultiapiGeneratedSourcesFolder/assets/ApiErrorDTO.java +++ b/scs-multiapi-maven-plugin/src/test/resources-its/com/sngular/api/generator/multiapi/integration/test/ScsMultiapiGenerationIT/testMultiapiGeneratedSourcesFolder/assets/ApiErrorDTO.java @@ -19,13 +19,6 @@ public class ApiErrorDTO { @NotNull private final String message; - private ApiErrorDTO(Integer code, String message) { - this.code = code; - this.message = message; - - validateRequiredAttributes(); - } - private ApiErrorDTO(ApiErrorDTOBuilder builder) { this.code = builder.code; this.message = builder.message; diff --git a/scs-multiapi-maven-plugin/src/test/resources-its/com/sngular/api/generator/multiapi/integration/test/ScsMultiapiGenerationIT/testMultiapiGeneratedSourcesFolder/assets/ApiTestDTO.java b/scs-multiapi-maven-plugin/src/test/resources-its/com/sngular/api/generator/multiapi/integration/test/ScsMultiapiGenerationIT/testMultiapiGeneratedSourcesFolder/assets/ApiTestDTO.java index caeaaed4..9ff1f6cf 100644 --- a/scs-multiapi-maven-plugin/src/test/resources-its/com/sngular/api/generator/multiapi/integration/test/ScsMultiapiGenerationIT/testMultiapiGeneratedSourcesFolder/assets/ApiTestDTO.java +++ b/scs-multiapi-maven-plugin/src/test/resources-its/com/sngular/api/generator/multiapi/integration/test/ScsMultiapiGenerationIT/testMultiapiGeneratedSourcesFolder/assets/ApiTestDTO.java @@ -19,13 +19,6 @@ public class ApiTestDTO { @NotNull private final Integer id; - private ApiTestDTO(String name, Integer id) { - this.name = name; - this.id = id; - - validateRequiredAttributes(); - } - private ApiTestDTO(ApiTestDTOBuilder builder) { this.name = builder.name; this.id = builder.id; diff --git a/scs-multiapi-maven-plugin/src/test/resources-its/com/sngular/api/generator/multiapi/integration/test/ScsMultiapiGenerationIT/testMultiapiGeneratedSourcesFolder/assets/ApiTestInfoDTO.java b/scs-multiapi-maven-plugin/src/test/resources-its/com/sngular/api/generator/multiapi/integration/test/ScsMultiapiGenerationIT/testMultiapiGeneratedSourcesFolder/assets/ApiTestInfoDTO.java index 7616f7ad..a570e86d 100644 --- a/scs-multiapi-maven-plugin/src/test/resources-its/com/sngular/api/generator/multiapi/integration/test/ScsMultiapiGenerationIT/testMultiapiGeneratedSourcesFolder/assets/ApiTestInfoDTO.java +++ b/scs-multiapi-maven-plugin/src/test/resources-its/com/sngular/api/generator/multiapi/integration/test/ScsMultiapiGenerationIT/testMultiapiGeneratedSourcesFolder/assets/ApiTestInfoDTO.java @@ -15,18 +15,11 @@ public class ApiTestInfoDTO { @JsonProperty(value ="testers") - private List testers = new ArrayList(); + private List testers; @JsonProperty(value ="testName") @NotNull private final String testName; - private ApiTestInfoDTO(List testers, String testName) { - this.testers = testers; - this.testName = testName; - - validateRequiredAttributes(); - } - private ApiTestInfoDTO(ApiTestInfoDTOBuilder builder) { this.testers = builder.testers; this.testName = builder.testName; @@ -51,7 +44,7 @@ public ApiTestInfoDTO.ApiTestInfoDTOBuilder testers(List testers) { } public ApiTestInfoDTO.ApiTestInfoDTOBuilder tester(String tester) { - if (tester != null) { + if (Objects.nonNull(tester)) { this.testers.add(tester); } return this; diff --git a/scs-multiapi-maven-plugin/src/test/resources-its/com/sngular/api/generator/multiapi/integration/test/ScsMultiapiGenerationIT/testScsMultiapiGeneration/assets/ApiErrorDTO.java b/scs-multiapi-maven-plugin/src/test/resources-its/com/sngular/api/generator/multiapi/integration/test/ScsMultiapiGenerationIT/testScsMultiapiGeneration/assets/ApiErrorDTO.java index 72c337c1..76a9e019 100644 --- a/scs-multiapi-maven-plugin/src/test/resources-its/com/sngular/api/generator/multiapi/integration/test/ScsMultiapiGenerationIT/testScsMultiapiGeneration/assets/ApiErrorDTO.java +++ b/scs-multiapi-maven-plugin/src/test/resources-its/com/sngular/api/generator/multiapi/integration/test/ScsMultiapiGenerationIT/testScsMultiapiGeneration/assets/ApiErrorDTO.java @@ -19,13 +19,6 @@ public class ApiErrorDTO { @NotNull private final String message; - private ApiErrorDTO(Integer code, String message) { - this.code = code; - this.message = message; - - validateRequiredAttributes(); - } - private ApiErrorDTO(ApiErrorDTOBuilder builder) { this.code = builder.code; this.message = builder.message; diff --git a/scs-multiapi-maven-plugin/src/test/resources-its/com/sngular/api/generator/multiapi/integration/test/ScsMultiapiGenerationIT/testScsMultiapiGeneration/assets/ApiTestDTO.java b/scs-multiapi-maven-plugin/src/test/resources-its/com/sngular/api/generator/multiapi/integration/test/ScsMultiapiGenerationIT/testScsMultiapiGeneration/assets/ApiTestDTO.java index caeaaed4..9ff1f6cf 100644 --- a/scs-multiapi-maven-plugin/src/test/resources-its/com/sngular/api/generator/multiapi/integration/test/ScsMultiapiGenerationIT/testScsMultiapiGeneration/assets/ApiTestDTO.java +++ b/scs-multiapi-maven-plugin/src/test/resources-its/com/sngular/api/generator/multiapi/integration/test/ScsMultiapiGenerationIT/testScsMultiapiGeneration/assets/ApiTestDTO.java @@ -19,13 +19,6 @@ public class ApiTestDTO { @NotNull private final Integer id; - private ApiTestDTO(String name, Integer id) { - this.name = name; - this.id = id; - - validateRequiredAttributes(); - } - private ApiTestDTO(ApiTestDTOBuilder builder) { this.name = builder.name; this.id = builder.id; diff --git a/scs-multiapi-maven-plugin/src/test/resources-its/com/sngular/api/generator/multiapi/integration/test/ScsMultiapiGenerationIT/testScsMultiapiGeneration/assets/ApiTestInfoDTO.java b/scs-multiapi-maven-plugin/src/test/resources-its/com/sngular/api/generator/multiapi/integration/test/ScsMultiapiGenerationIT/testScsMultiapiGeneration/assets/ApiTestInfoDTO.java index 7616f7ad..c72b7b64 100644 --- a/scs-multiapi-maven-plugin/src/test/resources-its/com/sngular/api/generator/multiapi/integration/test/ScsMultiapiGenerationIT/testScsMultiapiGeneration/assets/ApiTestInfoDTO.java +++ b/scs-multiapi-maven-plugin/src/test/resources-its/com/sngular/api/generator/multiapi/integration/test/ScsMultiapiGenerationIT/testScsMultiapiGeneration/assets/ApiTestInfoDTO.java @@ -15,18 +15,11 @@ public class ApiTestInfoDTO { @JsonProperty(value ="testers") - private List testers = new ArrayList(); + private List testers; @JsonProperty(value ="testName") @NotNull private final String testName; - private ApiTestInfoDTO(List testers, String testName) { - this.testers = testers; - this.testName = testName; - - validateRequiredAttributes(); - } - private ApiTestInfoDTO(ApiTestInfoDTOBuilder builder) { this.testers = builder.testers; this.testName = builder.testName; @@ -43,6 +36,7 @@ public static class ApiTestInfoDTOBuilder { private List testers = new ArrayList(); private String testName; + public ApiTestInfoDTO.ApiTestInfoDTOBuilder testers(List testers) { if (!testers.isEmpty()) { this.testers.addAll(testers); @@ -51,7 +45,7 @@ public ApiTestInfoDTO.ApiTestInfoDTOBuilder testers(List testers) { } public ApiTestInfoDTO.ApiTestInfoDTOBuilder tester(String tester) { - if (tester != null) { + if (Objects.nonNull(tester)) { this.testers.add(tester); } return this; diff --git a/scs-multiapi-maven-plugin/src/test/resources-its/com/sngular/api/generator/multiapi/integration/test/ScsMultiapiGenerationIT/testScsMultiapiGeneration/assets/ApiTestsDTO.java b/scs-multiapi-maven-plugin/src/test/resources-its/com/sngular/api/generator/multiapi/integration/test/ScsMultiapiGenerationIT/testScsMultiapiGeneration/assets/ApiTestsDTO.java index 10b62a07..f3bed37e 100644 --- a/scs-multiapi-maven-plugin/src/test/resources-its/com/sngular/api/generator/multiapi/integration/test/ScsMultiapiGenerationIT/testScsMultiapiGeneration/assets/ApiTestsDTO.java +++ b/scs-multiapi-maven-plugin/src/test/resources-its/com/sngular/api/generator/multiapi/integration/test/ScsMultiapiGenerationIT/testScsMultiapiGeneration/assets/ApiTestsDTO.java @@ -10,11 +10,6 @@ public class ApiTestsDTO { @JsonProperty(value ="apiTestDTO") private ApiTestDTO apiTestDTO; - private ApiTestsDTO(ApiTestDTO apiTestDTO) { - this.apiTestDTO = apiTestDTO; - - } - private ApiTestsDTO(ApiTestsDTOBuilder builder) { this.apiTestDTO = builder.apiTestDTO; From e44a9b57cd6517cddc49e51a19d3389b8a8c6748 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?jose=20enrique=20garcia=20maci=C3=B1eiras?= Date: Wed, 25 Sep 2024 20:37:12 +0200 Subject: [PATCH 20/26] Fix Test --- multiapi-engine/pom.xml | 2 +- .../plugin/asyncapi/AsyncApiGenerator.java | 25 ++++++--- .../plugin/common/tools/ApiTool.java | 7 ++- .../plugin/openapi/OpenApiGenerator.java | 49 +++++----------- .../openapi/template/TemplateFactory.java | 34 ++++------- .../asyncapi/AsyncApiGeneratorFixtures.java | 34 +++++++++++ .../asyncapi/AsyncApiGeneratorTest.java | 1 + .../testMessageNaming/assets/IOnTest.java | 8 +++ .../testMessageNaming/assets/IOnTest2.java | 8 +++ .../testMessageNaming/assets/IOnTest3.java | 8 +++ .../testMessageNaming/assets/OnTest3.java | 26 +++++++++ .../testMessageNaming/assets/Producer.java | 42 ++++++++++++++ .../testMessageNaming/assets/TestMsg.java | 22 ++++++++ .../testMessageNaming/assets/TestMsg2.java | 26 +++++++++ .../testMessageNaming/event-api.yml | 48 ++++++++++++++++ scs-multiapi-gradle-plugin/build.gradle | 6 +- scs-multiapi-maven-plugin/pom.xml | 4 +- .../integration/test/OpenApiGenerationIT.java | 35 +++++++----- .../api/generator/test/utils/TestUtils.java | 9 +-- .../testDependencyYml/assets/model/Order.java | 56 +++++++------------ .../assets/ApiTestInfoDTO.java | 1 + 21 files changed, 323 insertions(+), 128 deletions(-) create mode 100644 multiapi-engine/src/test/resources/asyncapigenerator/testMessageNaming/assets/IOnTest.java create mode 100644 multiapi-engine/src/test/resources/asyncapigenerator/testMessageNaming/assets/IOnTest2.java create mode 100644 multiapi-engine/src/test/resources/asyncapigenerator/testMessageNaming/assets/IOnTest3.java create mode 100644 multiapi-engine/src/test/resources/asyncapigenerator/testMessageNaming/assets/OnTest3.java create mode 100644 multiapi-engine/src/test/resources/asyncapigenerator/testMessageNaming/assets/Producer.java create mode 100644 multiapi-engine/src/test/resources/asyncapigenerator/testMessageNaming/assets/TestMsg.java create mode 100644 multiapi-engine/src/test/resources/asyncapigenerator/testMessageNaming/assets/TestMsg2.java create mode 100644 multiapi-engine/src/test/resources/asyncapigenerator/testMessageNaming/event-api.yml diff --git a/multiapi-engine/pom.xml b/multiapi-engine/pom.xml index a7f67a9a..a3a8932b 100644 --- a/multiapi-engine/pom.xml +++ b/multiapi-engine/pom.xml @@ -4,7 +4,7 @@ com.sngular multiapi-engine - 5.4.3 + 6.0.0 jar 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 95bedcd9..ca9710e6 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 @@ -19,7 +19,6 @@ import com.sngular.api.generator.plugin.asyncapi.template.TemplateFactory; import com.sngular.api.generator.plugin.asyncapi.util.BindingTypeEnum; import com.sngular.api.generator.plugin.asyncapi.util.FactoryTypeEnum; -import com.sngular.api.generator.plugin.common.tools.MapperContentUtil; import com.sngular.api.generator.plugin.asyncapi.util.ReferenceProcessor; import com.sngular.api.generator.plugin.common.files.ClasspathFileLocation; import com.sngular.api.generator.plugin.common.files.DirectoryFileLocation; @@ -27,6 +26,7 @@ import com.sngular.api.generator.plugin.common.model.CommonSpecFile; import com.sngular.api.generator.plugin.common.model.SchemaObject; import com.sngular.api.generator.plugin.common.tools.ApiTool; +import com.sngular.api.generator.plugin.common.tools.MapperContentUtil; import com.sngular.api.generator.plugin.common.tools.MapperUtil; import com.sngular.api.generator.plugin.exception.InvalidAPIException; import freemarker.template.TemplateException; @@ -215,14 +215,23 @@ private void getMessageSchemas( } private String calculateMessageName(final String messageName, final JsonNode message) { - return Objects.toString(ApiTool.getName(message), messageName); + final String finalMessageName; + if (ApiTool.hasNode(message, "messageId")) { + finalMessageName = ApiTool.getNodeAsString(message, "messageId"); + } else if (ApiTool.hasName(message)) { + finalMessageName = ApiTool.getName(message); + } else { + finalMessageName = messageName; + } + return StringUtils.capitalize(finalMessageName); } private void getChannelSchemas(final JsonNode channel, final Map totalSchemas, final FileLocation ymlParent) { final List options = List.of(PUBLISH, SUBSCRIBE); options.forEach(option -> { - if (channel.has(option) && channel.get(option).has(MESSAGE)) { - getMessageSchemas(null, channel.get(option).get(MESSAGE), ymlParent, totalSchemas); + if (ApiTool.hasNode(channel, option) && ApiTool.hasNode(ApiTool.getNode(channel, option), MESSAGE)) { + final var optionNode = ApiTool.getNode(channel, option); + getMessageSchemas(ApiTool.getNodeAsString(optionNode, "operationId"), ApiTool.getNode(optionNode, MESSAGE), ymlParent, totalSchemas); } }); } @@ -427,15 +436,15 @@ private void writeSchemaObject(final boolean usingLombok, final String modelPack private ProcessMethodResult processMethod( final JsonNode channel, final OperationParameterObject operationObject, final FileLocation ymlParent, final Map totalSchemas) throws IOException { - final JsonNode message = channel.get(MESSAGE); - final String operationId = channel.get(OPERATION_ID).asText(); + final JsonNode message = ApiTool.getNode(channel, MESSAGE); + final String operationId = ApiTool.getNodeAsString(channel, OPERATION_ID); final Pair payloadInfo; final var processBindingsResultBuilder = ProcessBindingsResult.builder(); if (message.has(REF)) { payloadInfo = processMethodRef(processBindingsResultBuilder, ApiTool.getRefValue(message), operationObject, ymlParent, totalSchemas, message); } else if (message.has(PAYLOAD)) { - payloadInfo = processPayload(operationObject, ApiTool.getName(message), ApiTool.getNode(message, PAYLOAD), ymlParent); + payloadInfo = processPayload(operationObject, calculateMessageName(operationId, message), ApiTool.getNode(message, PAYLOAD), ymlParent); if (ApiTool.hasNode(message, BINDINGS)) { processBindings(processBindingsResultBuilder, message, operationObject); } @@ -504,7 +513,7 @@ private String processExternalAvro(final FileLocation ymlParent, final String me if (avroNamespace == null) throw new InvalidAvroException(avroFilePath); - namespace = avroNamespace.asText() + PACKAGE_SEPARATOR + fileTree.get("name").asText();;//processModelPackage(fullNamespace, avroPackage); + namespace = avroNamespace.asText() + PACKAGE_SEPARATOR + fileTree.get("name").asText();//processModelPackage(fullNamespace, avroPackage); } catch (final IOException e) { throw new FileSystemException(e); } 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 5d931733..a65b69ec 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 @@ -10,7 +10,6 @@ import org.apache.commons.collections4.IteratorUtils; import org.apache.commons.collections4.Transformer; import org.apache.commons.lang3.StringUtils; -import org.apache.commons.text.CaseUtils; import java.io.FileInputStream; import java.io.IOException; @@ -199,6 +198,10 @@ public static boolean hasRequired(final JsonNode schema) { return hasNode(schema, REQUIRED); } + public static boolean hasName(JsonNode message) { + return hasNode(message, "name"); + } + public static boolean hasType(final JsonNode schema) { return hasNode(schema, "type"); } @@ -376,6 +379,4 @@ private static Object getValue(final JsonNode aConst) { } return value; } - - } 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 96cfcaa0..48145633 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 @@ -6,41 +6,33 @@ package com.sngular.api.generator.plugin.openapi; -import java.io.File; -import java.io.FilenameFilter; -import java.io.IOException; -import java.nio.file.Path; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -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.model.SchemaObject; +import com.sngular.api.generator.plugin.common.model.TypeConstants; import com.sngular.api.generator.plugin.common.tools.ApiTool; +import com.sngular.api.generator.plugin.common.tools.MapperContentUtil; +import com.sngular.api.generator.plugin.common.tools.MapperUtil; import com.sngular.api.generator.plugin.exception.GeneratorTemplateException; import com.sngular.api.generator.plugin.openapi.exception.CodeGenerationException; import com.sngular.api.generator.plugin.openapi.exception.DuplicateModelClassException; import com.sngular.api.generator.plugin.openapi.model.AuthObject; import com.sngular.api.generator.plugin.openapi.model.GlobalObject; import com.sngular.api.generator.plugin.openapi.model.PathObject; -import com.sngular.api.generator.plugin.common.model.TypeConstants; import com.sngular.api.generator.plugin.openapi.parameter.SpecFile; import com.sngular.api.generator.plugin.openapi.template.TemplateFactory; import com.sngular.api.generator.plugin.openapi.utils.MapperAuthUtil; -import com.sngular.api.generator.plugin.common.tools.MapperContentUtil; import com.sngular.api.generator.plugin.openapi.utils.MapperPathUtil; -import com.sngular.api.generator.plugin.common.tools.MapperUtil; import com.sngular.api.generator.plugin.openapi.utils.OpenApiUtil; import freemarker.template.TemplateException; import org.apache.commons.collections4.MultiValuedMap; import org.apache.commons.lang3.StringUtils; +import java.io.File; +import java.io.IOException; +import java.nio.file.Path; +import java.util.*; + public class OpenApiGenerator { private static final String SLASH = "/"; @@ -51,24 +43,14 @@ public class OpenApiGenerator { private static final String DEFAULT_OPENAPI_CLIENT_PACKAGE = DEFAULT_OPENAPI_API_PACKAGE + ".client"; - private static final Pattern PACKAGE_SEPARATOR = Pattern.compile("\\."); - private final Boolean overwriteModel; - private boolean generateExceptionTemplate; - - private final FilenameFilter targetFileFilter; - private final Set overwriteModelList = new HashSet<>(); private final TemplateFactory templateFactory; - private final String processedGeneratedSourcesFolder; - private final String groupId; - private final File targetFolder; - private final Path baseDir; private Boolean isWebClient = false; @@ -87,18 +69,14 @@ public OpenApiGenerator( final String groupId, final File basedir) { this.overwriteModel = overwriteModel; - this.processedGeneratedSourcesFolder = processedGeneratedSourcesFolder; this.groupId = groupId; - this.targetFolder = targetFolder; this.baseDir = basedir.toPath().toAbsolutePath(); this.templateFactory = new TemplateFactory(overwriteModel, targetFolder, processedGeneratedSourcesFolder, basedir); - this.targetFileFilter = (dir, name) -> name.toLowerCase().contains(targetFolder.toPath().getFileName().toString()); this.springBootVersion = springBootVersion; } public final void processFileSpec(final List specsListFile) { for (SpecFile specFile : specsListFile) { - generateExceptionTemplate = false; try { processPackage(specFile.getApiPackage()); processFile(specFile); @@ -123,7 +101,7 @@ private void processFile(final SpecFile specFile) throws IOException { } templateFactory.calculateJavaEEPackage(springBootVersion); - final var globalObject = createApiTemplate(specFile, specFile.getApiPackage(), openAPI); + final var globalObject = createApiTemplate(specFile, openAPI); createModelTemplate(specFile, openAPI, globalObject); templateFactory.fillTemplates(); @@ -162,7 +140,7 @@ private void createAuthTemplates(final SpecFile specFile) throws TemplateExcepti } } - private GlobalObject createApiTemplate(final SpecFile specFile, final String apiPackage, final JsonNode openAPI) { + private GlobalObject createApiTemplate(final SpecFile specFile, final JsonNode openAPI) { final MultiValuedMap> apis = OpenApiUtil.mapApiGroups(openAPI, specFile.isUseTagsGroup()); final var authSchemaList = MapperAuthUtil.createAuthSchemaList(openAPI); final GlobalObject globalObject = MapperPathUtil.mapOpenApiObjectToOurModels(openAPI, authSchemaList); @@ -173,7 +151,7 @@ private GlobalObject createApiTemplate(final SpecFile specFile, final String api final AuthObject authObject = MapperAuthUtil.getApiAuthObject(globalObject.getAuthSchemas(), pathObjects); try { - templateFactory.fillTemplate(apiPackage, specFile, javaFileName, pathObjects, authObject); + templateFactory.fillTemplate(specFile, javaFileName, pathObjects, authObject); } catch (IOException | TemplateException e) { throw new GeneratorTemplateException("Error filling the template", specFile.getFilePath(), e); } @@ -272,8 +250,9 @@ private void writeSchemaObject( } private void writeSchemaObject(final boolean usingLombok, final String modelPackageReceived, final String keyClassName, final SchemaObject schemaObject) { - final var destinationPackage = StringUtils.defaultIfEmpty(modelPackageReceived, DEFAULT_OPENAPI_API_PACKAGE + SLASH + schemaObject.getParentPackage()); - templateFactory.addSchemaObject(modelPackageReceived, keyClassName, schemaObject, destinationPackage, usingLombok); + final var finalModelPackageReceived = StringUtils.defaultIfEmpty(modelPackageReceived, DEFAULT_OPENAPI_API_PACKAGE); + final var destinationPackage = StringUtils.defaultIfEmpty(finalModelPackageReceived, DEFAULT_OPENAPI_API_PACKAGE + SLASH + schemaObject.getParentPackage()); + templateFactory.addSchemaObject(finalModelPackageReceived, keyClassName, schemaObject, destinationPackage, usingLombok); templateFactory.checkRequiredOrCombinatorExists(schemaObject, usingLombok); } } 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 a40b124e..9faa44be 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 @@ -6,32 +6,22 @@ package com.sngular.api.generator.plugin.openapi.template; -import java.io.File; -import java.io.FileWriter; -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.util.List; -import java.util.Map; -import java.util.Objects; -import java.util.Set; - -import com.sngular.api.generator.plugin.common.model.SchemaFieldObject; -import com.sngular.api.generator.plugin.common.model.SchemaObject; import com.sngular.api.generator.plugin.common.template.CommonTemplateFactory; -import com.sngular.api.generator.plugin.exception.GeneratorTemplateException; -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; import com.sngular.api.generator.plugin.openapi.parameter.SpecFile; -import freemarker.template.Configuration; -import freemarker.template.Template; import freemarker.template.TemplateException; -import freemarker.template.TemplateExceptionHandler; +import org.apache.commons.lang3.StringUtils; + +import java.io.File; +import java.io.IOException; +import java.util.List; +import java.util.Objects; public class TemplateFactory extends CommonTemplateFactory { + private static final String DEFAULT_API_PACKAGE = "com.sngular.api"; + public TemplateFactory(boolean enableOverwrite, final File targetFolder, final String processedGeneratedSourcesFolder, @@ -71,15 +61,14 @@ public final void fillTemplateAuth(final String apiPackage, final String authNam writeTemplateToFile(createNameTemplate(authName), apiPackage, authName); } - public final void fillTemplate( - final String filePathToSave, final SpecFile specFile, final String className, + public final void fillTemplate(final SpecFile specFile, final String className, final List pathObjects, final AuthObject authObject) throws IOException, TemplateException { addToRoot("className", className); addToRoot("pathObjects", pathObjects); if (Objects.nonNull(specFile.getApiPackage())) { - addToRoot("packageApi", specFile.getApiPackage()); + addToRoot("packageApi", StringUtils.defaultIfEmpty(specFile.getApiPackage(), DEFAULT_API_PACKAGE)); } if (Objects.nonNull(specFile.getModelPackage())) { addToRoot("packageModel", specFile.getModelPackage()); @@ -91,7 +80,8 @@ public final void fillTemplate( addToRoot("clientPackage", specFile.getClientPackage()); } - writeTemplateToFile(specFile.isCallMode() ? getTemplateClientApi(specFile) : getTemplateApi(specFile), filePathToSave, className + "Api"); + writeTemplateToFile(specFile.isCallMode() ? getTemplateClientApi(specFile) : getTemplateApi(specFile), + StringUtils.defaultIfEmpty(specFile.getApiPackage(), DEFAULT_API_PACKAGE), className + "Api"); } public final void calculateJavaEEPackage(final Integer springBootVersion) { 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 1f33d5f3..f97757bf 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 @@ -313,6 +313,18 @@ public class AsyncApiGeneratorFixtures { .build()) .build()); + static final List TEST_MESSAGE_NAMING = List.of( + SpecFile + .builder() + .filePath("src/test/resources/asyncapigenerator/testMessageNaming/event-api.yml") + .supplier(OperationParameterObject.builder() + .modelNameSuffix("") + .apiPackage("com.sngular.scsplugin.messagenaming") + .modelPackage("com.sngular.scsplugin.messagenaming.model") + .useLombokModelAnnotation(true) + .build()) + .build()); + static final List TEST_NESTED_OBJECT = List.of( SpecFile .builder() @@ -957,6 +969,28 @@ static Function validateNoSchemas() { modelTest(path, expectedProducerFiles, API_FOLDER); } + static Function validateMessageNaming() { + final String API_FOLDER = "generated/com/sngular/scsplugin/messagenaming"; + + final String MODEL_SCHEMA_FOLDER = "generated/com/sngular/scsplugin/messagenaming/model"; + + final List expectedModelSchemaFiles = List.of( + "asyncapigenerator/testMessageNaming/assets/OnTest3.java", + "asyncapigenerator/testMessageNaming/assets/TestMsg.java", + "asyncapigenerator/testMessageNaming/assets/TestMsg2.java" + ); + + final List expectedProducerFiles = List.of( + "asyncapigenerator/testMessageNaming/assets/IOnTest.java", + "asyncapigenerator/testMessageNaming/assets/IOnTest2.java", + "asyncapigenerator/testMessageNaming/assets/IOnTest3.java", + "asyncapigenerator/testMessageNaming/assets/Producer.java" + ); + + return path -> modelTest(path, expectedModelSchemaFiles, MODEL_SCHEMA_FOLDER) && + modelTest(path, expectedProducerFiles, API_FOLDER); + } + static Function validateNestedObject() { final String API_FOLDER = "generated/com/sngular/scsplugin/nestedobject"; 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 49edd58d..c94c8663 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 @@ -72,6 +72,7 @@ static Stream fileSpecToProcess() { Arguments.of("TestModelClassExceptionGeneration", AsyncApiGeneratorFixtures.TEST_MODEL_CLASS_EXCEPTION_GENERATION, AsyncApiGeneratorFixtures.validateTestModelClassExceptionGeneration()), Arguments.of("TestNoSchemas", AsyncApiGeneratorFixtures.TEST_NO_SCHEMAS, AsyncApiGeneratorFixtures.validateNoSchemas()), + Arguments.of("TestMessageNaming", AsyncApiGeneratorFixtures.TEST_MESSAGE_NAMING, AsyncApiGeneratorFixtures.validateMessageNaming()), Arguments.of("TestNestedObjectIssue", AsyncApiGeneratorFixtures.TEST_NESTED_OBJECT, AsyncApiGeneratorFixtures.validateNestedObject()), Arguments.of("TestConstantGeneration", AsyncApiGeneratorFixtures.TEST_CONSTANT_GENERATION, AsyncApiGeneratorFixtures.validateConstantGeneration()), Arguments.of("testPropertiesNotGeneratedIssue", AsyncApiGeneratorFixtures.PROPERTIES_NOT_GENERATED_ISSUE, AsyncApiGeneratorFixtures.validateNotGeneratedPropertiesIssue()), diff --git a/multiapi-engine/src/test/resources/asyncapigenerator/testMessageNaming/assets/IOnTest.java b/multiapi-engine/src/test/resources/asyncapigenerator/testMessageNaming/assets/IOnTest.java new file mode 100644 index 00000000..8a790b70 --- /dev/null +++ b/multiapi-engine/src/test/resources/asyncapigenerator/testMessageNaming/assets/IOnTest.java @@ -0,0 +1,8 @@ +package com.sngular.scsplugin.messagenaming; + +import com.sngular.scsplugin.messagenaming.model.TestMsg; + +public interface IOnTest { + + TestMsg onTest(); +} \ No newline at end of file diff --git a/multiapi-engine/src/test/resources/asyncapigenerator/testMessageNaming/assets/IOnTest2.java b/multiapi-engine/src/test/resources/asyncapigenerator/testMessageNaming/assets/IOnTest2.java new file mode 100644 index 00000000..5bb99a4a --- /dev/null +++ b/multiapi-engine/src/test/resources/asyncapigenerator/testMessageNaming/assets/IOnTest2.java @@ -0,0 +1,8 @@ +package com.sngular.scsplugin.messagenaming; + +import com.sngular.scsplugin.messagenaming.model.TestMsg2; + +public interface IOnTest2 { + + TestMsg2 onTest2(); +} \ No newline at end of file diff --git a/multiapi-engine/src/test/resources/asyncapigenerator/testMessageNaming/assets/IOnTest3.java b/multiapi-engine/src/test/resources/asyncapigenerator/testMessageNaming/assets/IOnTest3.java new file mode 100644 index 00000000..265f4fc4 --- /dev/null +++ b/multiapi-engine/src/test/resources/asyncapigenerator/testMessageNaming/assets/IOnTest3.java @@ -0,0 +1,8 @@ +package com.sngular.scsplugin.messagenaming; + +import com.sngular.scsplugin.messagenaming.model.OnTest3; + +public interface IOnTest3 { + + OnTest3 onTest3(); +} \ No newline at end of file diff --git a/multiapi-engine/src/test/resources/asyncapigenerator/testMessageNaming/assets/OnTest3.java b/multiapi-engine/src/test/resources/asyncapigenerator/testMessageNaming/assets/OnTest3.java new file mode 100644 index 00000000..43c181c0 --- /dev/null +++ b/multiapi-engine/src/test/resources/asyncapigenerator/testMessageNaming/assets/OnTest3.java @@ -0,0 +1,26 @@ +package com.sngular.scsplugin.messagenaming.model; + +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.Builder; +import lombok.Value; +import lombok.extern.jackson.Jacksonized; + +@Value +public class OnTest3 { + + @JsonProperty(value ="id") + private Integer id; + + @JsonProperty(value ="age") + private Integer age; + + + @Builder + @Jacksonized + private OnTest3(Integer id, Integer age) { + this.id = id; + this.age = age; + + } + +} diff --git a/multiapi-engine/src/test/resources/asyncapigenerator/testMessageNaming/assets/Producer.java b/multiapi-engine/src/test/resources/asyncapigenerator/testMessageNaming/assets/Producer.java new file mode 100644 index 00000000..d3d24ce9 --- /dev/null +++ b/multiapi-engine/src/test/resources/asyncapigenerator/testMessageNaming/assets/Producer.java @@ -0,0 +1,42 @@ +package com.sngular.scsplugin.messagenaming; + +import java.util.function.Supplier; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import com.sngular.scsplugin.messagenaming.model.TestMsg; +import com.sngular.scsplugin.messagenaming.model.TestMsg2; +import com.sngular.scsplugin.messagenaming.model.OnTest3; + +@Configuration +public class Producer { + + private final IOnTest onTest; + + private final IOnTest2 onTest2; + + private final IOnTest3 onTest3; + + protected Producer(final IOnTest onTest, final IOnTest2 onTest2, final IOnTest3 onTest3) { + this.onTest = onTest; + this.onTest2 = onTest2; + this.onTest3 = onTest3; + } + + @Bean + public Supplier onTest() { + return () -> onTest.onTest(); + } + + @Bean + public Supplier onTest2() { + return () -> onTest2.onTest2(); + } + + @Bean + public Supplier onTest3() { + return () -> onTest3.onTest3(); + } + + +} diff --git a/multiapi-engine/src/test/resources/asyncapigenerator/testMessageNaming/assets/TestMsg.java b/multiapi-engine/src/test/resources/asyncapigenerator/testMessageNaming/assets/TestMsg.java new file mode 100644 index 00000000..76a51fe6 --- /dev/null +++ b/multiapi-engine/src/test/resources/asyncapigenerator/testMessageNaming/assets/TestMsg.java @@ -0,0 +1,22 @@ +package com.sngular.scsplugin.messagenaming.model; + +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.Builder; +import lombok.Value; +import lombok.extern.jackson.Jacksonized; + +@Value +public class TestMsg { + + @JsonProperty(value ="id") + private Integer id; + + + @Builder + @Jacksonized + private TestMsg(Integer id) { + this.id = id; + + } + +} diff --git a/multiapi-engine/src/test/resources/asyncapigenerator/testMessageNaming/assets/TestMsg2.java b/multiapi-engine/src/test/resources/asyncapigenerator/testMessageNaming/assets/TestMsg2.java new file mode 100644 index 00000000..5f3eaf41 --- /dev/null +++ b/multiapi-engine/src/test/resources/asyncapigenerator/testMessageNaming/assets/TestMsg2.java @@ -0,0 +1,26 @@ +package com.sngular.scsplugin.messagenaming.model; + +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.Builder; +import lombok.Value; +import lombok.extern.jackson.Jacksonized; + +@Value +public class TestMsg2 { + + @JsonProperty(value ="name") + private String name; + + @JsonProperty(value ="id") + private Integer id; + + + @Builder + @Jacksonized + private TestMsg2(String name, Integer id) { + this.name = name; + this.id = id; + + } + +} diff --git a/multiapi-engine/src/test/resources/asyncapigenerator/testMessageNaming/event-api.yml b/multiapi-engine/src/test/resources/asyncapigenerator/testMessageNaming/event-api.yml new file mode 100644 index 00000000..88412d81 --- /dev/null +++ b/multiapi-engine/src/test/resources/asyncapigenerator/testMessageNaming/event-api.yml @@ -0,0 +1,48 @@ +asyncapi: '2.5.0' +info: + title: Test API + version: '1.0.0' + description: Some test API +servers: + default: + url: mqtt://localhost + protocol: mqtt +channels: + test: + publish: + summary: This is just a test. + operationId: onTest + message: + name: TestMsg + payload: + type: object + properties: + id: + type: integer + test2: + publish: + summary: This is just a test2. + operationId: onTest2 + message: + messageId: TestMsg2 + payload: + type: object + properties: + id: + type: integer + name: + type: string + test3: + publish: + summary: This is just a test2. + operationId: onTest3 + message: + payload: + type: object + properties: + id: + type: integer + age: + type: integer + + diff --git a/scs-multiapi-gradle-plugin/build.gradle b/scs-multiapi-gradle-plugin/build.gradle index 351cdd7d..248045d1 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.4.3' +version = '6.0.0' def SCSMultiApiPluginGroupId = group def SCSMultiApiPluginVersion = version @@ -30,7 +30,7 @@ dependencies { shadow localGroovy() shadow gradleApi() - implementation 'com.sngular:multiapi-engine:5.4.3' + implementation 'com.sngular:multiapi-engine:6.0.0' testImplementation 'org.assertj:assertj-core:3.24.2' testImplementation 'com.puppycrawl.tools:checkstyle:10.12.3' } @@ -98,7 +98,7 @@ testing { integrationTest(JvmTestSuite) { dependencies { - implementation 'com.sngular:scs-multiapi-gradle-plugin:5.4.3' + implementation 'com.sngular:scs-multiapi-gradle-plugin:6.0.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 0df6bc3c..a9e6f239 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.4.3 + 6.0.0 maven-plugin AsyncApi - OpenApi Code Generator Maven Plugin @@ -271,7 +271,7 @@ com.sngular multiapi-engine - 5.4.3 + 6.0.0 org.apache.maven diff --git a/scs-multiapi-maven-plugin/src/test/java/com/sngular/api/generator/openapi/integration/test/OpenApiGenerationIT.java b/scs-multiapi-maven-plugin/src/test/java/com/sngular/api/generator/openapi/integration/test/OpenApiGenerationIT.java index 1b86409a..8ac0ff0c 100644 --- a/scs-multiapi-maven-plugin/src/test/java/com/sngular/api/generator/openapi/integration/test/OpenApiGenerationIT.java +++ b/scs-multiapi-maven-plugin/src/test/java/com/sngular/api/generator/openapi/integration/test/OpenApiGenerationIT.java @@ -6,14 +6,6 @@ package com.sngular.api.generator.openapi.integration.test; -import static com.soebes.itf.extension.assertj.MavenITAssertions.assertThat; - -import java.io.File; -import java.io.IOException; -import java.nio.file.Path; -import java.util.Collections; -import java.util.List; - import com.sngular.api.generator.test.utils.TestUtils; import com.soebes.itf.jupiter.extension.MavenGoal; import com.soebes.itf.jupiter.extension.MavenJupiterExtension; @@ -23,6 +15,14 @@ import org.junit.jupiter.api.parallel.Execution; import org.junit.jupiter.api.parallel.ExecutionMode; +import java.io.File; +import java.io.IOException; +import java.nio.file.Path; +import java.util.List; + +import static com.soebes.itf.extension.assertj.MavenITAssertions.assertThat; +import static java.util.Collections.singletonList; + @MavenRepository @MavenJupiterExtension @Execution(ExecutionMode.SAME_THREAD) @@ -31,15 +31,15 @@ public class OpenApiGenerationIT { @MavenTest @MavenGoal("generate-sources") void testApiMultiGeneration(MavenProjectResult result) throws IOException { - List expectedFileFirst = Collections.singletonList( + List expectedFileFirst = singletonList( "com/sngular/api/generator/openapi/integration/test/OpenApiGenerationIT/testApiMultiGeneration/assets/TestFirstApi.java"); - List expectedFileSecond = Collections.singletonList( + List expectedFileSecond = singletonList( "com/sngular/api/generator/openapi/integration/test/OpenApiGenerationIT/testApiMultiGeneration/assets/TestSecondApi.java"); - List expectedExceptionFilesFirst = Collections.singletonList( + List expectedExceptionFilesFirst = singletonList( "com/sngular/api/generator/openapi/integration/test/OpenApiGenerationIT/testApiMultiGeneration/assets/ModelClassExceptionFirst.java"); - List expectedExceptionFilesSecond = Collections.singletonList( + List expectedExceptionFilesSecond = singletonList( "com/sngular/api/generator/openapi/integration/test/OpenApiGenerationIT/testApiMultiGeneration/assets/ModelClassExceptionSecond.java"); assertThat(result).hasTarget(); @@ -70,12 +70,17 @@ void testApiMultiGeneration(MavenProjectResult result) throws IOException { @MavenTest @MavenGoal("generate-sources") void testDependencyYml(MavenProjectResult result) throws IOException { - List expectedFiles = List.of("TestApi.java", "TestObj.java"); + List expectedModel = singletonList("TestObj.java"); assertThat(result).hasTarget(); Path pathToTarget = result.getTargetProjectDirectory().toAbsolutePath(); - File targetDirectory = pathToTarget.resolve("target/generated-sources/apigenerator/com/sngular").toFile(); + File targetModelDirectory = pathToTarget.resolve("target/generated-sources/apigenerator/com/sngular/apigenerator/openapi").toFile(); + + TestUtils.checkTargetFiles(expectedModel, targetModelDirectory); + + List expectedApi = singletonList("TestApi.java"); + File targetApiDirectory = pathToTarget.resolve("target/generated-sources/apigenerator/com/sngular/api").toFile(); + TestUtils.checkTargetFiles(expectedApi, targetApiDirectory); - TestUtils.checkTargetFiles(expectedFiles, targetDirectory); } } diff --git a/scs-multiapi-maven-plugin/src/test/java/com/sngular/api/generator/test/utils/TestUtils.java b/scs-multiapi-maven-plugin/src/test/java/com/sngular/api/generator/test/utils/TestUtils.java index e6790c52..73e3fdde 100644 --- a/scs-multiapi-maven-plugin/src/test/java/com/sngular/api/generator/test/utils/TestUtils.java +++ b/scs-multiapi-maven-plugin/src/test/java/com/sngular/api/generator/test/utils/TestUtils.java @@ -6,8 +6,6 @@ package com.sngular.api.generator.test.utils; -import static org.assertj.core.api.Assertions.assertThat; - import java.io.File; import java.io.FileInputStream; import java.io.IOException; @@ -17,6 +15,8 @@ import java.util.List; import java.util.Objects; +import static org.assertj.core.api.Assertions.assertThat; + public class TestUtils { public static void validateFiles(final List expectedFiles, final File targetDirectory) throws IOException { @@ -28,10 +28,11 @@ public static void validateFiles(final List expectedFiles, final File ta outputFiles.sort(Comparator.comparing(File::getPath)); assertThat(outputFiles).hasSize(expectedFiles.size()); for (int i = 0; i < outputFiles.size(); i++) { - reader1 = new FileInputStream(outputFiles.get(i)); + final File outputFile = outputFiles.get(i); + reader1 = new FileInputStream(outputFile); final String sourceName = expectedFiles.get(i); reader2 = TestUtils.resourceAsFile(sourceName); - assertThat(reader1).as(() -> "Unexpected content for file " + sourceName).hasSameContentAs(reader2); + assertThat(reader2).as(() -> "Unexpected content for file " + outputFile.getAbsolutePath()).hasSameContentAs(reader1); } } diff --git a/scs-multiapi-maven-plugin/src/test/resources-its/com/sngular/api/generator/asyncapi/integration/test/AsyncApiGenerationIT/testDependencyYml/assets/model/Order.java b/scs-multiapi-maven-plugin/src/test/resources-its/com/sngular/api/generator/asyncapi/integration/test/AsyncApiGenerationIT/testDependencyYml/assets/model/Order.java index 977dee56..6f2ef345 100644 --- a/scs-multiapi-maven-plugin/src/test/resources-its/com/sngular/api/generator/asyncapi/integration/test/AsyncApiGenerationIT/testDependencyYml/assets/model/Order.java +++ b/scs-multiapi-maven-plugin/src/test/resources-its/com/sngular/api/generator/asyncapi/integration/test/AsyncApiGenerationIT/testDependencyYml/assets/model/Order.java @@ -11,17 +11,17 @@ @JsonDeserialize(builder = Order.OrderBuilder.class) public class Order { - @JsonProperty(value ="ref") - private String ref; @JsonProperty(value ="clientRef") private String clientRef; @JsonProperty(value ="amount") private BigDecimal amount; + @JsonProperty(value ="ref") + private String ref; private Order(OrderBuilder builder) { - this.ref = builder.ref; this.clientRef = builder.clientRef; this.amount = builder.amount; + this.ref = builder.ref; } @@ -32,16 +32,9 @@ public static Order.OrderBuilder builder() { @JsonPOJOBuilder(buildMethodName = "build", withPrefix = "") public static class OrderBuilder { - private String ref; - private String clientRef; - private BigDecimal amount; - - public Order.OrderBuilder ref(String ref) { - this.ref = ref; - return this; - } + private String ref; public Order.OrderBuilder clientRef(String clientRef) { this.clientRef = clientRef; @@ -53,28 +46,17 @@ public Order.OrderBuilder amount(BigDecimal amount) { return this; } + public Order.OrderBuilder ref(String ref) { + this.ref = ref; + return this; + } + public Order build() { Order order = new Order(this); return order; } } - /** - * Get ref - * @return ref - */ - @Schema(name = "ref", required = false) - public String getRef() { - return ref; - } - public void setRef(String ref) { - this.ref = ref; - } - - /** - * Get clientRef - * @return clientRef - */ @Schema(name = "clientRef", required = false) public String getClientRef() { return clientRef; @@ -83,10 +65,6 @@ public void setClientRef(String clientRef) { this.clientRef = clientRef; } - /** - * Get amount - * @return amount - */ @Schema(name = "amount", required = false) public BigDecimal getAmount() { return amount; @@ -95,6 +73,14 @@ public void setAmount(BigDecimal amount) { this.amount = amount; } + @Schema(name = "ref", required = false) + public String getRef() { + return ref; + } + public void setRef(String ref) { + this.ref = ref; + } + @Override public boolean equals(Object o) { if (this == o) { @@ -104,21 +90,21 @@ public boolean equals(Object o) { return false; } Order order = (Order) o; - return Objects.equals(this.ref, order.ref) && Objects.equals(this.clientRef, order.clientRef) && Objects.equals(this.amount, order.amount); + return Objects.equals(this.clientRef, order.clientRef) && Objects.equals(this.amount, order.amount) && Objects.equals(this.ref, order.ref); } @Override public int hashCode() { - return Objects.hash(ref, clientRef, amount); + return Objects.hash(clientRef, amount, ref); } @Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append("Order{"); - sb.append(" ref:").append(ref).append(","); sb.append(" clientRef:").append(clientRef).append(","); - sb.append(" amount:").append(amount); + sb.append(" amount:").append(amount).append(","); + sb.append(" ref:").append(ref); sb.append("}"); return sb.toString(); } diff --git a/scs-multiapi-maven-plugin/src/test/resources-its/com/sngular/api/generator/multiapi/integration/test/ScsMultiapiGenerationIT/testMultiapiGeneratedSourcesFolder/assets/ApiTestInfoDTO.java b/scs-multiapi-maven-plugin/src/test/resources-its/com/sngular/api/generator/multiapi/integration/test/ScsMultiapiGenerationIT/testMultiapiGeneratedSourcesFolder/assets/ApiTestInfoDTO.java index a570e86d..c72b7b64 100644 --- a/scs-multiapi-maven-plugin/src/test/resources-its/com/sngular/api/generator/multiapi/integration/test/ScsMultiapiGenerationIT/testMultiapiGeneratedSourcesFolder/assets/ApiTestInfoDTO.java +++ b/scs-multiapi-maven-plugin/src/test/resources-its/com/sngular/api/generator/multiapi/integration/test/ScsMultiapiGenerationIT/testMultiapiGeneratedSourcesFolder/assets/ApiTestInfoDTO.java @@ -36,6 +36,7 @@ public static class ApiTestInfoDTOBuilder { private List testers = new ArrayList(); private String testName; + public ApiTestInfoDTO.ApiTestInfoDTOBuilder testers(List testers) { if (!testers.isEmpty()) { this.testers.addAll(testers); From 6e3bc7992905333191ab69f63e71188c45c2c691 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?jose=20enrique=20garcia=20maci=C3=B1eiras?= Date: Thu, 26 Sep 2024 13:17:04 +0200 Subject: [PATCH 21/26] Improve test --- multiapi-engine/pom.xml | 2 +- .../templates/model/templateContentEnum.ftlh | 22 ++++++++-------- .../asyncapi/AsyncApiGeneratorFixtures.java | 8 +++--- .../openapi/OpenApiGeneratorFixtures.java | 18 ++++++------- .../api/generator/test/utils/TestUtils.java | 25 +++++++++---------- 5 files changed, 37 insertions(+), 38 deletions(-) diff --git a/multiapi-engine/pom.xml b/multiapi-engine/pom.xml index a3a8932b..b1527a26 100644 --- a/multiapi-engine/pom.xml +++ b/multiapi-engine/pom.xml @@ -4,7 +4,7 @@ com.sngular multiapi-engine - 6.0.0 + 6.0.0 jar diff --git a/multiapi-engine/src/main/resources/templates/model/templateContentEnum.ftlh b/multiapi-engine/src/main/resources/templates/model/templateContentEnum.ftlh index 141aca9c..912c8659 100644 --- a/multiapi-engine/src/main/resources/templates/model/templateContentEnum.ftlh +++ b/multiapi-engine/src/main/resources/templates/model/templateContentEnum.ftlh @@ -60,28 +60,28 @@ import com.fasterxml.jackson.annotation.JsonValue; public enum ${schema.className} { <#list schema.fieldObjectList as field> - <#list field.enumValues as key, value> - <#if key?matches("[0-9].*")> - ${"_"+key}(${value})<#sep>, - <#else> - ${key}(${value})<#sep>, - - ; +<#list field.enumValues as key, value> +<#if key?matches("[0-9].*")> + ${"_"+key}(${value})<#sep>, +<#else> + ${key}(${value})<#sep>, + +; private ${field.dataType.innerType?cap_first} value; - ${schema.className?cap_first}(${field.dataType.innerType?cap_first} value) { - this.value = value; + ${schema.className?cap_first}(${field.dataType.innerType?cap_first} value) { + this.value = value; } @JsonValue public ${field.dataType.innerType?cap_first} getValue() { - return value; + return value; } @Override public String toString() { - return String.valueOf(value); + return String.valueOf(value); } } \ No newline at end of file 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 f97757bf..a0196caa 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 @@ -13,7 +13,7 @@ import org.assertj.core.api.Assertions; import java.io.File; -import java.io.IOException; +import java.net.URISyntaxException; import java.nio.file.Path; import java.util.Collections; import java.util.List; @@ -492,7 +492,7 @@ private static Boolean commonTest( Assertions.assertThat(targetModelException).isNotEmptyDirectory(); TestUtils.validateFiles(expectedExceptionFiles, targetModelException); } - } catch (final IOException e) { + } catch (final URISyntaxException e) { result = Boolean.FALSE; } return result; @@ -509,7 +509,7 @@ private static boolean modelTest(final Path resultPath, final List expec Assertions.assertThat(targetModelFolder).isNotEmptyDirectory(); TestUtils.validateFiles(expectedModelFiles, targetModelFolder); } - } catch (final IOException e) { + } catch (final URISyntaxException e) { result = Boolean.FALSE; } return result; @@ -526,7 +526,7 @@ private static boolean customValidatorTest(final Path resultPath, final List expectedFiles, final File targetDirectory) throws IOException { - InputStream reader1; - InputStream reader2; + public static void validateFiles(final List expectedFiles, final File targetDirectory) throws URISyntaxException { + File reader1; + File reader2; List outputFiles = new ArrayList<>(List.of(Objects.requireNonNull(targetDirectory.listFiles()))); outputFiles.removeIf(File::isDirectory); @@ -30,17 +29,17 @@ public static void validateFiles(final List expectedFiles, final File ta .overridingErrorMessage("Wrong Number of files %d vs %d: %s", outputFiles.size(), expectedFiles.size(), outputFiles) .hasSize(expectedFiles.size()); for (int i = 0; i < outputFiles.size(); i++) { - reader1 = new FileInputStream(outputFiles.get(i)); + reader1 = outputFiles.get(i); assertThat(reader1).overridingErrorMessage("Generated file %s should not be null", outputFiles.get(i)).isNotNull(); final String sourceName = expectedFiles.get(i); reader2 = TestUtils.resourceAsFile(sourceName); assertThat(reader2).overridingErrorMessage("Expected file %s should not be null", sourceName).isNotNull(); - int finalI = i; - assertThat(reader1).as(() -> "Unexpected content for file " + outputFiles.get(finalI)).hasSameContentAs(reader2); + assertThat(reader1) + .hasSameTextualContentAs(reader2); } } - public static InputStream resourceAsFile(String resourceName) { - return TestUtils.class.getClassLoader().getResourceAsStream(resourceName); + public static File resourceAsFile(String resourceName) throws URISyntaxException { + return Paths.get(TestUtils.class.getClassLoader().getResource(resourceName).toURI()).toFile(); } } From 37aeaf73837f9afdcb38214010c5728ccc0cc18a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?jose=20enrique=20garcia=20maci=C3=B1eiras?= Date: Mon, 30 Sep 2024 14:20:30 +0200 Subject: [PATCH 22/26] improve code style --- .../plugin/asyncapi/AsyncApiGenerator.java | 35 +++++++++++++------ .../plugin/asyncapi/model/MethodObject.java | 1 - .../parameter/OperationParameterObject.java | 9 ++--- .../asyncapi/template/ClassTemplate.java | 1 - .../template/ClasspathTemplateLoader.java | 1 - .../asyncapi/template/TemplateFactory.java | 18 +++++----- .../asyncapi/util/ReferenceProcessor.java | 1 - .../common/files/DirectoryFileLocation.java | 1 - .../plugin/common/model/CommonSpecFile.java | 3 +- .../common/model/SchemaFieldObject.java | 6 ++-- .../model/SchemaFieldObjectProperties.java | 1 - .../common/model/SchemaFieldObjectType.java | 19 +++++----- .../plugin/common/model/SchemaObject.java | 7 ++-- .../template/CommonTemplateFactory.java | 23 +++++++----- .../common/template/CommonTemplateLoader.java | 3 +- .../plugin/common/tools/ApiTool.java | 25 +++++++------ .../common/tools/MapperContentUtil.java | 10 ++++-- .../plugin/common/tools/MapperUtil.java | 1 - .../plugin/common/tools/ModelBuilder.java | 20 ++++++++--- .../plugin/common/tools/SchemaUtil.java | 1 - .../plugin/openapi/OpenApiGenerator.java | 18 ++++++---- .../plugin/openapi/model/AuthObject.java | 1 - .../plugin/openapi/model/GlobalObject.java | 1 - .../plugin/openapi/model/OperationObject.java | 1 - .../plugin/openapi/model/PathObject.java | 1 - .../plugin/openapi/model/RequestObject.java | 1 - .../plugin/openapi/model/ResponseObject.java | 1 - .../plugin/openapi/parameter/SpecFile.java | 5 ++- .../template/ClasspathTemplateLoader.java | 5 ++- .../openapi/template/TemplateFactory.java | 16 ++++----- .../plugin/openapi/utils/MapperAuthUtil.java | 1 - .../plugin/openapi/utils/MapperPathUtil.java | 30 ++++++++++++---- .../plugin/openapi/utils/OpenApiUtil.java | 1 - 33 files changed, 157 insertions(+), 111 deletions(-) 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 ca9710e6..2a57a28c 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 @@ -6,11 +6,33 @@ package com.sngular.api.generator.plugin.asyncapi; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.InputStream; +import java.nio.file.Path; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Objects; +import java.util.regex.Pattern; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.dataformat.yaml.YAMLFactory; import com.sngular.api.generator.plugin.PluginConstants; -import com.sngular.api.generator.plugin.asyncapi.exception.*; +import com.sngular.api.generator.plugin.asyncapi.exception.ChannelNameException; +import com.sngular.api.generator.plugin.asyncapi.exception.DuplicateClassException; +import com.sngular.api.generator.plugin.asyncapi.exception.DuplicatedOperationException; +import com.sngular.api.generator.plugin.asyncapi.exception.ExternalRefComponentNotFoundException; +import com.sngular.api.generator.plugin.asyncapi.exception.FileSystemException; +import com.sngular.api.generator.plugin.asyncapi.exception.InvalidAsyncAPIException; +import com.sngular.api.generator.plugin.asyncapi.exception.InvalidAvroException; import com.sngular.api.generator.plugin.asyncapi.model.ProcessBindingsResult; import com.sngular.api.generator.plugin.asyncapi.model.ProcessBindingsResult.ProcessBindingsResultBuilder; import com.sngular.api.generator.plugin.asyncapi.model.ProcessMethodResult; @@ -36,12 +58,6 @@ import org.apache.commons.lang3.tuple.ImmutablePair; import org.apache.commons.lang3.tuple.Pair; -import java.io.*; -import java.nio.file.Path; -import java.util.*; -import java.util.Map.Entry; -import java.util.regex.Pattern; - @Slf4j public class AsyncApiGenerator { @@ -64,7 +80,6 @@ public class AsyncApiGenerator { private static final String SUBSCRIBE = "subscribe"; private static final String PUBLISH = "publish"; - private static final String OPERATION_ID = "operationId"; private static final String AVSC = "avsc"; @@ -231,7 +246,7 @@ private void getChannelSchemas(final JsonNode channel, final Map { if (ApiTool.hasNode(channel, option) && ApiTool.hasNode(ApiTool.getNode(channel, option), MESSAGE)) { final var optionNode = ApiTool.getNode(channel, option); - getMessageSchemas(ApiTool.getNodeAsString(optionNode, "operationId"), ApiTool.getNode(optionNode, MESSAGE), ymlParent, totalSchemas); + getMessageSchemas(ApiTool.getNodeAsString(optionNode, OPERATION_ID), ApiTool.getNode(optionNode, MESSAGE), ymlParent, totalSchemas); } }); } @@ -513,7 +528,7 @@ private String processExternalAvro(final FileLocation ymlParent, final String me if (avroNamespace == null) throw new InvalidAvroException(avroFilePath); - namespace = avroNamespace.asText() + PACKAGE_SEPARATOR + fileTree.get("name").asText();//processModelPackage(fullNamespace, avroPackage); + namespace = avroNamespace.asText() + PACKAGE_SEPARATOR + fileTree.get("name").asText(); } catch (final IOException e) { throw new FileSystemException(e); } 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 6222580f..6b2d2ae5 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,7 +7,6 @@ package com.sngular.api.generator.plugin.asyncapi.model; import java.util.Objects; - import com.sngular.api.generator.plugin.asyncapi.util.BindingTypeEnum; import com.sngular.api.generator.plugin.common.model.SchemaObject; import lombok.Builder; diff --git a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/asyncapi/parameter/OperationParameterObject.java b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/asyncapi/parameter/OperationParameterObject.java index 1dec6a89..f332414c 100644 --- a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/asyncapi/parameter/OperationParameterObject.java +++ b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/asyncapi/parameter/OperationParameterObject.java @@ -12,14 +12,15 @@ package com.sngular.api.generator.plugin.asyncapi.parameter; - +import java.util.List; import com.sngular.api.generator.plugin.common.model.CommonSpecFile; -import lombok.*; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.NoArgsConstructor; import lombok.experimental.SuperBuilder; import org.apache.commons.lang3.StringUtils; -import java.util.List; - @Data @SuperBuilder @NoArgsConstructor diff --git a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/asyncapi/template/ClassTemplate.java b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/asyncapi/template/ClassTemplate.java index 811b2de2..30a8ce46 100644 --- a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/asyncapi/template/ClassTemplate.java +++ b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/asyncapi/template/ClassTemplate.java @@ -7,7 +7,6 @@ package com.sngular.api.generator.plugin.asyncapi.template; import java.nio.file.Path; - import com.sngular.api.generator.plugin.common.model.SchemaObject; import lombok.Builder; import lombok.Value; diff --git a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/asyncapi/template/ClasspathTemplateLoader.java b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/asyncapi/template/ClasspathTemplateLoader.java index 5f905731..c8035e0b 100644 --- a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/asyncapi/template/ClasspathTemplateLoader.java +++ b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/asyncapi/template/ClasspathTemplateLoader.java @@ -14,7 +14,6 @@ import java.util.List; import java.util.Map; import java.util.Objects; - import com.sngular.api.generator.plugin.common.template.CommonTemplateLoader; import com.sngular.api.generator.plugin.exception.GeneratorTemplateException; 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 4ba588a4..f2da5871 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 @@ -6,14 +6,6 @@ package com.sngular.api.generator.plugin.asyncapi.template; -import com.sngular.api.generator.plugin.asyncapi.exception.NonSupportedBindingException; -import com.sngular.api.generator.plugin.asyncapi.model.MethodObject; -import com.sngular.api.generator.plugin.asyncapi.parameter.SpecFile; -import com.sngular.api.generator.plugin.asyncapi.util.BindingTypeEnum; -import com.sngular.api.generator.plugin.common.template.CommonTemplateFactory; -import com.sngular.api.generator.plugin.common.tools.MapperUtil; -import freemarker.template.TemplateException; - import java.io.File; import java.io.IOException; import java.nio.file.Path; @@ -21,6 +13,12 @@ import java.util.List; import java.util.Map; import java.util.Objects; +import com.sngular.api.generator.plugin.asyncapi.exception.NonSupportedBindingException; +import com.sngular.api.generator.plugin.asyncapi.model.MethodObject; +import com.sngular.api.generator.plugin.asyncapi.parameter.SpecFile; +import com.sngular.api.generator.plugin.asyncapi.util.BindingTypeEnum; +import com.sngular.api.generator.plugin.common.template.CommonTemplateFactory; +import com.sngular.api.generator.plugin.common.tools.MapperUtil; public class TemplateFactory extends CommonTemplateFactory { @@ -63,7 +61,7 @@ public TemplateFactory(boolean enableOverwrite, super(enableOverwrite, targetFolder, processedGeneratedSourcesFolder, baseDir, new ClasspathTemplateLoader()); } - public final void fillTemplates() throws IOException, TemplateException { + public final void fillTemplates() throws IOException { addToRoot("publishMethods", publishMethods); addToRoot("subscribeMethods", subscribeMethods); addToRoot("streamBridgeMethods", streamBridgeMethods); @@ -229,7 +227,7 @@ public void processFilePaths(final SpecFile fileParameter, final String defaultA setSubscribeFilePath(processPath(pathToCreate)); } } - private void generateInterfaces() throws IOException, TemplateException { + private void generateInterfaces() throws IOException { final ArrayList allMethods = new ArrayList<>(subscribeMethods); allMethods.addAll(publishMethods); diff --git a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/asyncapi/util/ReferenceProcessor.java b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/asyncapi/util/ReferenceProcessor.java index d04d00f3..8e22b9a7 100644 --- a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/asyncapi/util/ReferenceProcessor.java +++ b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/asyncapi/util/ReferenceProcessor.java @@ -5,7 +5,6 @@ import java.util.List; import java.util.Map; import java.util.Objects; - import com.fasterxml.jackson.databind.JsonNode; import com.sngular.api.generator.plugin.asyncapi.exception.FileSystemException; import com.sngular.api.generator.plugin.asyncapi.exception.NonSupportedSchemaException; 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 7fa976e1..119879a1 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,7 +10,6 @@ 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/model/CommonSpecFile.java b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/model/CommonSpecFile.java index a05190ed..19361ff7 100644 --- a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/model/CommonSpecFile.java +++ b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/model/CommonSpecFile.java @@ -1,13 +1,12 @@ package com.sngular.api.generator.plugin.common.model; +import java.util.Map; import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; import lombok.NoArgsConstructor; import lombok.experimental.SuperBuilder; -import java.util.Map; - @Data @SuperBuilder(toBuilder = true) @NoArgsConstructor diff --git a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/model/SchemaFieldObject.java b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/model/SchemaFieldObject.java index b9688889..601b17ba 100644 --- a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/model/SchemaFieldObject.java +++ b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/model/SchemaFieldObject.java @@ -1,8 +1,10 @@ package com.sngular.api.generator.plugin.common.model; -import lombok.*; - import java.util.Map; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.EqualsAndHashCode; @Data @Builder diff --git a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/model/SchemaFieldObjectProperties.java b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/model/SchemaFieldObjectProperties.java index 0e961b52..e644f6f3 100644 --- a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/model/SchemaFieldObjectProperties.java +++ b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/model/SchemaFieldObjectProperties.java @@ -3,7 +3,6 @@ import java.util.HashSet; import java.util.Objects; import java.util.Set; - import lombok.Data; @Data diff --git a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/model/SchemaFieldObjectType.java b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/model/SchemaFieldObjectType.java index fbfb1f4f..42144d46 100644 --- a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/model/SchemaFieldObjectType.java +++ b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/model/SchemaFieldObjectType.java @@ -9,7 +9,6 @@ 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; @@ -17,6 +16,8 @@ @Data public class SchemaFieldObjectType { + public static final String ZONED_DATE_TIME = "ZonedDateTime"; + public static final String OFFSET_DATE_TIME = "OffsetDateTime"; private static final Map TYPE_MAPPINGS = Map.ofEntries( new SimpleImmutableEntry<>(TypeConstants.OBJECT, "Object"), new SimpleImmutableEntry<>(TypeConstants.ARRAY, "List"), @@ -30,10 +31,10 @@ public class SchemaFieldObjectType { new SimpleImmutableEntry<>(TypeConstants.ENUM, "Enum"), new SimpleImmutableEntry<>(TypeConstants.LOCALDATE, "LocalDate"), new SimpleImmutableEntry<>(TypeConstants.LOCALDATETIME, "LocalDateTime"), - new SimpleImmutableEntry<>(TypeConstants.ZONEDDATE, "ZonedDateTime"), - new SimpleImmutableEntry<>(TypeConstants.ZONEDDATETIME, "ZonedDateTime"), - new SimpleImmutableEntry<>(TypeConstants.OFFSETDATE, "OffsetDateTime"), - new SimpleImmutableEntry<>(TypeConstants.OFFSETDATETIME, "OffsetDateTime") + new SimpleImmutableEntry<>(TypeConstants.ZONEDDATE, ZONED_DATE_TIME), + new SimpleImmutableEntry<>(TypeConstants.ZONEDDATETIME, ZONED_DATE_TIME), + new SimpleImmutableEntry<>(TypeConstants.OFFSETDATE, OFFSET_DATE_TIME), + new SimpleImmutableEntry<>(TypeConstants.OFFSETDATETIME, OFFSET_DATE_TIME) ); private static final Map IMPL_TYPE_MAPPINGS = Map.ofEntries( @@ -49,10 +50,10 @@ public class SchemaFieldObjectType { new SimpleImmutableEntry<>(TypeConstants.ENUM, "Enum"), new SimpleImmutableEntry<>(TypeConstants.LOCALDATE, "LocalDate"), new SimpleImmutableEntry<>(TypeConstants.LOCALDATETIME, "LocalDateTime"), - new SimpleImmutableEntry<>(TypeConstants.ZONEDDATE, "ZonedDateTime"), - new SimpleImmutableEntry<>(TypeConstants.ZONEDDATETIME, "ZonedDateTime"), - new SimpleImmutableEntry<>(TypeConstants.OFFSETDATE, "OffsetDateTime"), - new SimpleImmutableEntry<>(TypeConstants.OFFSETDATETIME, "OffsetDateTime") + new SimpleImmutableEntry<>(TypeConstants.ZONEDDATE, ZONED_DATE_TIME), + new SimpleImmutableEntry<>(TypeConstants.ZONEDDATETIME, ZONED_DATE_TIME), + new SimpleImmutableEntry<>(TypeConstants.OFFSETDATE, OFFSET_DATE_TIME), + new SimpleImmutableEntry<>(TypeConstants.OFFSETDATETIME, OFFSET_DATE_TIME) ); private SchemaFieldObjectType innerType; diff --git a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/model/SchemaObject.java b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/model/SchemaObject.java index 1efed898..a3ddc3f2 100644 --- a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/model/SchemaObject.java +++ b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/model/SchemaObject.java @@ -1,11 +1,14 @@ package com.sngular.api.generator.plugin.common.model; -import lombok.*; - import java.util.ArrayList; import java.util.HashSet; import java.util.List; import java.util.Set; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.NoArgsConstructor; @Data @Builder(toBuilder = true) diff --git a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/template/CommonTemplateFactory.java b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/template/CommonTemplateFactory.java index 85217a3c..cda1b706 100644 --- a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/template/CommonTemplateFactory.java +++ b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/template/CommonTemplateFactory.java @@ -1,5 +1,19 @@ package com.sngular.api.generator.plugin.common.template; +import java.io.File; +import java.io.FileWriter; +import java.io.FilenameFilter; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.HashMap; +import java.util.HashSet; +import java.util.LinkedList; +import java.util.List; +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.parameter.OperationParameterObject; import com.sngular.api.generator.plugin.asyncapi.template.ClassTemplate; @@ -13,15 +27,6 @@ import freemarker.template.TemplateException; import freemarker.template.TemplateExceptionHandler; -import java.io.File; -import java.io.FileWriter; -import java.io.FilenameFilter; -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.util.*; - public abstract class CommonTemplateFactory { private static final List BASIC_DATA_TYPES = List.of("Integer", "Long", "Float", "Double", "Boolean", "String", "Char", "Byte", "Short"); diff --git a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/template/CommonTemplateLoader.java b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/template/CommonTemplateLoader.java index dd199667..2dc23fbc 100644 --- a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/template/CommonTemplateLoader.java +++ b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/template/CommonTemplateLoader.java @@ -1,8 +1,7 @@ package com.sngular.api.generator.plugin.common.template; -import freemarker.cache.TemplateLoader; - import java.util.List; +import freemarker.cache.TemplateLoader; public abstract class CommonTemplateLoader implements TemplateLoader { 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 a65b69ec..8f15e272 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 @@ -1,5 +1,19 @@ package com.sngular.api.generator.plugin.common.tools; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.math.BigDecimal; +import java.math.BigInteger; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +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; @@ -11,14 +25,6 @@ import org.apache.commons.collections4.Transformer; import org.apache.commons.lang3.StringUtils; -import java.io.FileInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.math.BigDecimal; -import java.math.BigInteger; -import java.util.*; -import java.util.Map.Entry; - public final class ApiTool { public static final String FORMAT = "format"; @@ -28,7 +34,6 @@ public final class ApiTool { public static final String ANY_OF = "anyOf"; public static final String ONE_OF = "oneOf"; - public static final String COMPONENTS = "components"; public static final String SCHEMAS = "schemas"; @@ -301,7 +306,7 @@ private static Transformer getTextValue() { } public static boolean hasComponents(final JsonNode node) { - return hasNode(node, "components"); + return hasNode(node, COMPONENTS); } public static Iterator> getComponent(final JsonNode node, final String componentType) { diff --git a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/tools/MapperContentUtil.java b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/tools/MapperContentUtil.java index 6371780a..bf119fcc 100644 --- a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/tools/MapperContentUtil.java +++ b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/tools/MapperContentUtil.java @@ -6,13 +6,17 @@ package com.sngular.api.generator.plugin.common.tools; +import java.nio.file.Path; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Objects; import com.fasterxml.jackson.databind.JsonNode; import com.sngular.api.generator.plugin.common.model.CommonSpecFile; import com.sngular.api.generator.plugin.common.model.SchemaObject; -import java.nio.file.Path; -import java.util.*; - public class MapperContentUtil { private MapperContentUtil() { diff --git a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/tools/MapperUtil.java b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/tools/MapperUtil.java index 2adb5c5b..432f4721 100644 --- a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/tools/MapperUtil.java +++ b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/tools/MapperUtil.java @@ -12,7 +12,6 @@ import org.apache.commons.lang3.ArrayUtils; import org.apache.commons.lang3.ObjectUtils; import org.apache.commons.lang3.StringUtils; -import org.apache.commons.text.CaseUtils; public class MapperUtil { diff --git a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/tools/ModelBuilder.java b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/tools/ModelBuilder.java index e5fca153..fad2dae7 100644 --- a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/tools/ModelBuilder.java +++ b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/tools/ModelBuilder.java @@ -1,16 +1,26 @@ package com.sngular.api.generator.plugin.common.tools; +import java.nio.file.Path; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.HashSet; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +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.model.*; +import com.sngular.api.generator.plugin.common.model.CommonSpecFile; +import com.sngular.api.generator.plugin.common.model.SchemaFieldObject; +import com.sngular.api.generator.plugin.common.model.SchemaFieldObjectType; +import com.sngular.api.generator.plugin.common.model.SchemaObject; +import com.sngular.api.generator.plugin.common.model.TypeConstants; import com.sngular.api.generator.plugin.openapi.exception.BadDefinedEnumException; import org.apache.commons.lang3.ObjectUtils; import org.apache.commons.lang3.StringUtils; import org.apache.commons.text.WordUtils; -import java.nio.file.Path; -import java.util.*; -import java.util.function.Consumer; - public final class ModelBuilder { private static final String ADDITIONAL_PROPERTY_NAME = "AdditionalProperty"; 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 index 4df9225e..8a4573b3 100644 --- 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 @@ -2,7 +2,6 @@ import java.nio.file.Path; import java.util.Map; - import com.fasterxml.jackson.databind.JsonNode; import com.sngular.api.generator.plugin.openapi.utils.OpenApiUtil; import org.apache.commons.lang3.StringUtils; 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 48145633..140e28c6 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 @@ -6,6 +6,15 @@ package com.sngular.api.generator.plugin.openapi; +import java.io.File; +import java.io.IOException; +import java.nio.file.Path; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.Set; import com.fasterxml.jackson.databind.JsonNode; import com.sngular.api.generator.plugin.PluginConstants; import com.sngular.api.generator.plugin.common.model.SchemaObject; @@ -28,11 +37,6 @@ import org.apache.commons.collections4.MultiValuedMap; import org.apache.commons.lang3.StringUtils; -import java.io.File; -import java.io.IOException; -import java.nio.file.Path; -import java.util.*; - public class OpenApiGenerator { private static final String SLASH = "/"; @@ -126,7 +130,7 @@ private void createClients(final SpecFile specFile) { } } - private void createAuthTemplates(final SpecFile specFile) throws TemplateException, IOException { + private void createAuthTemplates(final SpecFile specFile) throws IOException { final String clientPackage = specFile.getClientPackage(); final var authFileRoot = (StringUtils.isNotBlank(clientPackage) ? clientPackage : DEFAULT_OPENAPI_CLIENT_PACKAGE) + ".auth"; @@ -175,7 +179,7 @@ private void addAuthentications(final AuthObject authObject) { } } - private void createModelTemplate(final SpecFile specFile, final JsonNode openAPI, final GlobalObject globalObject) throws IOException { + private void createModelTemplate(final SpecFile specFile, final JsonNode openAPI, final GlobalObject globalObject) { final var modelPackage = processModelPackage(specFile.getModelPackage()); final var totalSchemas = OpenApiUtil.processPaths(openAPI, globalObject.getSchemaMap()); diff --git a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/openapi/model/AuthObject.java b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/openapi/model/AuthObject.java index a63b14b2..c479c801 100644 --- a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/openapi/model/AuthObject.java +++ b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/openapi/model/AuthObject.java @@ -8,7 +8,6 @@ import java.util.ArrayList; import java.util.List; - import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; 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 a5109e00..8d12752a 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,7 +11,6 @@ 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/OperationObject.java b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/openapi/model/OperationObject.java index 9f20fb70..61158a40 100644 --- a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/openapi/model/OperationObject.java +++ b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/openapi/model/OperationObject.java @@ -8,7 +8,6 @@ import java.util.ArrayList; import java.util.List; - import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; diff --git a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/openapi/model/PathObject.java b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/openapi/model/PathObject.java index a1921fc1..6240c11e 100644 --- a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/openapi/model/PathObject.java +++ b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/openapi/model/PathObject.java @@ -8,7 +8,6 @@ import java.util.ArrayList; import java.util.List; - import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; diff --git a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/openapi/model/RequestObject.java b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/openapi/model/RequestObject.java index f7e5537f..2221b1f7 100644 --- a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/openapi/model/RequestObject.java +++ b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/openapi/model/RequestObject.java @@ -8,7 +8,6 @@ import java.util.ArrayList; import java.util.List; - import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; diff --git a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/openapi/model/ResponseObject.java b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/openapi/model/ResponseObject.java index 156f8277..92b75b5d 100644 --- a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/openapi/model/ResponseObject.java +++ b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/openapi/model/ResponseObject.java @@ -8,7 +8,6 @@ import java.util.ArrayList; import java.util.List; - import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; diff --git a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/openapi/parameter/SpecFile.java b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/openapi/parameter/SpecFile.java index 21abc6e2..4bcdc386 100644 --- a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/openapi/parameter/SpecFile.java +++ b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/openapi/parameter/SpecFile.java @@ -7,7 +7,10 @@ package com.sngular.api.generator.plugin.openapi.parameter; import com.sngular.api.generator.plugin.common.model.CommonSpecFile; -import lombok.*; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.NoArgsConstructor; import lombok.experimental.SuperBuilder; @Data diff --git a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/openapi/template/ClasspathTemplateLoader.java b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/openapi/template/ClasspathTemplateLoader.java index 2d6a767a..98479fea 100644 --- a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/openapi/template/ClasspathTemplateLoader.java +++ b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/openapi/template/ClasspathTemplateLoader.java @@ -6,9 +6,6 @@ package com.sngular.api.generator.plugin.openapi.template; -import com.sngular.api.generator.plugin.common.template.CommonTemplateLoader; -import com.sngular.api.generator.plugin.exception.GeneratorTemplateException; - import java.io.IOException; import java.io.InputStream; import java.io.Reader; @@ -17,6 +14,8 @@ import java.util.List; import java.util.Map; import java.util.Objects; +import com.sngular.api.generator.plugin.common.template.CommonTemplateLoader; +import com.sngular.api.generator.plugin.exception.GeneratorTemplateException; public class ClasspathTemplateLoader extends CommonTemplateLoader { 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 9faa44be..255ea19d 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 @@ -6,18 +6,16 @@ package com.sngular.api.generator.plugin.openapi.template; +import java.io.File; +import java.io.IOException; +import java.util.List; +import java.util.Objects; import com.sngular.api.generator.plugin.common.template.CommonTemplateFactory; import com.sngular.api.generator.plugin.openapi.model.AuthObject; import com.sngular.api.generator.plugin.openapi.model.PathObject; import com.sngular.api.generator.plugin.openapi.parameter.SpecFile; -import freemarker.template.TemplateException; import org.apache.commons.lang3.StringUtils; -import java.io.File; -import java.io.IOException; -import java.util.List; -import java.util.Objects; - public class TemplateFactory extends CommonTemplateFactory { private static final String DEFAULT_API_PACKAGE = "com.sngular.api"; @@ -49,11 +47,11 @@ public final void fillTemplates() { generateTemplates(); } - public final void fillTemplateWebClient(final String filePathToSave) throws IOException, TemplateException { + public final void fillTemplateWebClient(final String filePathToSave) throws IOException { writeTemplateToFile(TemplateIndexConstants.TEMPLATE_WEB_CLIENT, filePathToSave, "ApiWebClient"); } - public final void fillTemplateRestClient(final String filePathToSave) throws IOException, TemplateException { + public final void fillTemplateRestClient(final String filePathToSave) throws IOException { writeTemplateToFile(TemplateIndexConstants.TEMPLATE_REST_CLIENT, filePathToSave, "ApiRestClient"); } @@ -62,7 +60,7 @@ public final void fillTemplateAuth(final String apiPackage, final String authNam } public final void fillTemplate(final SpecFile specFile, final String className, - final List pathObjects, final AuthObject authObject) throws IOException, TemplateException { + final List pathObjects, final AuthObject authObject) throws IOException { addToRoot("className", className); addToRoot("pathObjects", pathObjects); 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 0af9f1a5..cefde8e2 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,7 +10,6 @@ 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.common.tools.MapperUtil; 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 31ee7e99..857beb76 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 @@ -6,24 +6,40 @@ package com.sngular.api.generator.plugin.openapi.utils; +import java.nio.file.Path; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +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.model.SchemaFieldObjectType; import com.sngular.api.generator.plugin.common.model.SchemaObject; import com.sngular.api.generator.plugin.common.model.TypeConstants; -import com.sngular.api.generator.plugin.common.tools.*; +import com.sngular.api.generator.plugin.common.tools.ApiTool; +import com.sngular.api.generator.plugin.common.tools.MapperContentUtil; +import com.sngular.api.generator.plugin.common.tools.MapperUtil; +import com.sngular.api.generator.plugin.common.tools.SchemaUtil; +import com.sngular.api.generator.plugin.common.tools.StringCaseUtils; 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.*; +import com.sngular.api.generator.plugin.openapi.model.AuthSchemaObject; +import com.sngular.api.generator.plugin.openapi.model.ContentObject; +import com.sngular.api.generator.plugin.openapi.model.GlobalObject; import com.sngular.api.generator.plugin.openapi.model.GlobalObject.GlobalObjectBuilder; +import com.sngular.api.generator.plugin.openapi.model.OperationObject; +import com.sngular.api.generator.plugin.openapi.model.ParameterObject; +import com.sngular.api.generator.plugin.openapi.model.PathObject; +import com.sngular.api.generator.plugin.openapi.model.RequestObject; +import com.sngular.api.generator.plugin.openapi.model.ResponseObject; import com.sngular.api.generator.plugin.openapi.parameter.SpecFile; import org.apache.commons.collections4.IteratorUtils; import org.apache.commons.lang3.StringUtils; -import java.nio.file.Path; -import java.util.*; -import java.util.Map.Entry; -import java.util.function.BiConsumer; - public class MapperPathUtil { public static final String INLINE_PARAMETER = "InlineParameter"; 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 c08f23a5..40be35a0 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,7 +21,6 @@ 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; From 05d0543178ed8c4ea7f899599d7f3c33ccf256ce Mon Sep 17 00:00:00 2001 From: "joseenrique.garcia" Date: Mon, 30 Sep 2024 20:40:42 +0200 Subject: [PATCH 23/26] Fix github comments --- .../api/generator/plugin/common/tools/MapperUtil.java | 5 ----- .../api/generator/plugin/common/tools/ModelBuilder.java | 5 ++--- .../api/generator/plugin/openapi/OpenApiGenerator.java | 4 ++-- .../api/generator/plugin/openapi/utils/MapperPathUtil.java | 2 +- 4 files changed, 5 insertions(+), 11 deletions(-) diff --git a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/tools/MapperUtil.java b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/tools/MapperUtil.java index 432f4721..d2d80ed1 100644 --- a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/tools/MapperUtil.java +++ b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/tools/MapperUtil.java @@ -46,11 +46,6 @@ public static String packageToFolder(final String packageName) { return StringUtils.replace(packageName, ".", SLASH); } - public static String buildKey(final JsonNode parameter) { - final String[] pathObjectRef = ApiTool.getRefValue(parameter).split("/"); - return StringUtils.upperCase(pathObjectRef[pathObjectRef.length - 2] + "/" + StringCaseUtils.titleToSnakeCase(pathObjectRef[pathObjectRef.length - 1])); - } - public static String getRefSchemaName(final JsonNode parameter) { final String[] pathObjectRef = ApiTool.getRefValue(parameter).split("/"); return pathObjectRef[pathObjectRef.length - 1]; diff --git a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/tools/ModelBuilder.java b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/tools/ModelBuilder.java index fad2dae7..86bb5d5f 100644 --- a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/tools/ModelBuilder.java +++ b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/tools/ModelBuilder.java @@ -283,8 +283,8 @@ private static List processObjectProperty(final String buildi .dataType(new SchemaFieldObjectType(MapperUtil.getSimpleType(refSchema, specFile))) .constValue(ApiTool.getConst(refSchema)) .build()); - } else if (antiLoopList.contains(typeName)) { - if (cachedSchemas.containsKey(typeName)) { + } else if (antiLoopList.contains(typeName) && + cachedSchemas.containsKey(typeName)) { fieldObjectArrayList.add(SchemaFieldObject .builder() .baseName(fieldName) @@ -292,7 +292,6 @@ private static List processObjectProperty(final String buildi .dataType(SchemaFieldObjectType.fromTypeList(MapperUtil.getSimpleType(refSchema, specFile), MapperUtil.getPojoName(typeName, specFile))) .build()); - } } } else if (ApiTool.isEnum(fieldBody)) { fieldObjectArrayList.add(processEnumField(fieldName, fieldBody, specFile, ApiTool.getEnumValues(fieldBody), fieldBody)); 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 140e28c6..0db2cdf1 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 @@ -124,7 +124,7 @@ private void createClients(final SpecFile specFile) { templateFactory.fillTemplateRestClient(clientPath); } createAuthTemplates(specFile); - } catch (IOException | TemplateException e) { + } catch (IOException e) { throw new GeneratorTemplateException("Template Generator problem", e); } } @@ -156,7 +156,7 @@ private GlobalObject createApiTemplate(final SpecFile specFile, final JsonNode o try { templateFactory.fillTemplate(specFile, javaFileName, pathObjects, authObject); - } catch (IOException | TemplateException e) { + } catch (IOException e) { throw new GeneratorTemplateException("Error filling the template", specFile.getFilePath(), e); } 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 857beb76..13a6cdee 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 @@ -338,7 +338,7 @@ private static void buildResponse( final JsonNode response) { var realResponse = response; if (ApiTool.hasRef(response)) { - realResponse = globalObject.getResponseNode(MapperUtil.buildKey(response)).orElseThrow(); + realResponse = globalObject.getResponseNode(MapperUtil.getRefSchemaKey(response)).orElseThrow(); } final String operationIdWithCap = operationId.substring(0, 1).toUpperCase() + operationId.substring(1); final var content = ApiTool.getNode(realResponse, CONTENT); From ef22e5f3eab951caf996a013ceca34965c4e5fe1 Mon Sep 17 00:00:00 2001 From: "joseenrique.garcia" Date: Sun, 13 Oct 2024 21:05:47 +0200 Subject: [PATCH 24/26] Fix Codacy comments --- .../common/template/CommonTemplateFactory.java | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/template/CommonTemplateFactory.java b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/template/CommonTemplateFactory.java index cda1b706..8b35d71d 100644 --- a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/template/CommonTemplateFactory.java +++ b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/template/CommonTemplateFactory.java @@ -226,10 +226,8 @@ private void fillTemplateCustom( final Path filePathToSave, final String modelPackage, final String fileNameAnnotation, final String templateAnnotation, final String fileNameValidator, final String templateValidator) throws IOException { final Path pathToCustomValidatorPackage = filePathToSave.resolve("customvalidator"); - if (!pathToCustomValidatorPackage.toFile().exists()) { - if (!pathToCustomValidatorPackage.toFile().mkdirs()) { - throw new IOException("Can't create custom validator directory"); - } + if (!pathToCustomValidatorPackage.toFile().exists() && !pathToCustomValidatorPackage.toFile().mkdirs()) { + throw new IOException("Can't create custom validator directory"); } root.put("packageModel", modelPackage); writeTemplateToFile(templateAnnotation, pathToCustomValidatorPackage, fileNameAnnotation); @@ -283,10 +281,8 @@ protected void writeTemplateToFile(final String templateName, final String apiPa } protected void writeTemplateToFile(final String templateName, final Path filePathToSave, final String partialPath) throws IOException { - if (!filePathToSave.toFile().exists()) { - if (!filePathToSave.toFile().mkdirs()) { - throw new IOException("Could not create directory: " + filePathToSave.toFile().getAbsolutePath()); - } + if (!filePathToSave.toFile().exists() && !filePathToSave.toFile().mkdirs()) { + throw new IOException("Could not create directory: " + filePathToSave.toFile().getAbsolutePath()); } final String path = filePathToSave.resolve(partialPath + FILE_TYPE_JAVA).toString(); final Template template = cfg.getTemplate(templateName); From ce8074118d93304a1aa0581e6fbfa18a8001c73c Mon Sep 17 00:00:00 2001 From: "joseenrique.garcia" Date: Sun, 13 Oct 2024 23:54:17 +0200 Subject: [PATCH 25/26] Fix Codacy comments --- .../template/ClasspathTemplateLoader.java | 39 +++------------- .../common/template/CommonTemplateLoader.java | 44 +++++++++++++++++++ .../template/ClasspathTemplateLoader.java | 38 ++-------------- 3 files changed, 53 insertions(+), 68 deletions(-) diff --git a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/asyncapi/template/ClasspathTemplateLoader.java b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/asyncapi/template/ClasspathTemplateLoader.java index c8035e0b..0310bfec 100644 --- a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/asyncapi/template/ClasspathTemplateLoader.java +++ b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/asyncapi/template/ClasspathTemplateLoader.java @@ -6,16 +6,15 @@ package com.sngular.api.generator.plugin.asyncapi.template; +import com.sngular.api.generator.plugin.common.template.CommonTemplateLoader; +import com.sngular.api.generator.plugin.exception.GeneratorTemplateException; + import java.io.IOException; import java.io.InputStream; -import java.io.Reader; -import java.io.StringReader; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Objects; -import com.sngular.api.generator.plugin.common.template.CommonTemplateLoader; -import com.sngular.api.generator.plugin.exception.GeneratorTemplateException; public class ClasspathTemplateLoader extends CommonTemplateLoader { @@ -25,33 +24,9 @@ public class ClasspathTemplateLoader extends CommonTemplateLoader { "interfaceSupplierWithKafkaBindings.ftlh", "templateSuppliersWithKafkaBindings.ftlh", "interfaceConsumerWithKafkaBindings.ftlh", "templateConsumersWithKafkaBindings.ftlh", "templateStreamBridgeWithKafkaBindings.ftlh", "templateMessageWrapper.ftlh"); - - private static final ClassLoader LOADER = ClasspathTemplateLoader.class.getClassLoader(); - - private final Map templatesMap = new HashMap<>(); - public ClasspathTemplateLoader() { - templatesMap.putAll(getResourceFolderFiles()); - } - - @Override - public final Object findTemplateSource(final String templateName) { - return templatesMap.get(templateName); - } - - @Override - public final long getLastModified(final Object o) { - return 0; - } - - @Override - public final Reader getReader(final Object template, final String charSet) { - return new StringReader(template.toString()); - } - - @Override - public void closeTemplateSource(final Object o) { - // Not required to implement + super(); + init(getResourceFolderFiles()); } private Map getResourceFolderFiles() { @@ -75,8 +50,4 @@ private Map getResourceFolderFiles() { return templates; } - - private String readFile(final InputStream file) throws IOException { - return new String(file.readAllBytes()); - } } diff --git a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/template/CommonTemplateLoader.java b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/template/CommonTemplateLoader.java index 2dc23fbc..456daa65 100644 --- a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/template/CommonTemplateLoader.java +++ b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/template/CommonTemplateLoader.java @@ -1,11 +1,28 @@ package com.sngular.api.generator.plugin.common.template; +import java.io.IOException; +import java.io.InputStream; +import java.io.Reader; +import java.io.StringReader; +import java.util.HashMap; import java.util.List; +import java.util.Map; + +import com.sngular.api.generator.plugin.openapi.template.ClasspathTemplateLoader; import freemarker.cache.TemplateLoader; public abstract class CommonTemplateLoader implements TemplateLoader { + private final Map templatesMap = new HashMap<>(); + + protected static final ClassLoader LOADER = ClasspathTemplateLoader.class.getClassLoader(); + + + protected String readFile(final InputStream file) throws IOException { + return new String(file.readAllBytes()); + } + protected static final List TEMPLATE_MODEL_FILES = List.of(CommonTemplateIndexConstants.TEMPLATE_CONTENT_SCHEMA, CommonTemplateIndexConstants.TEMPLATE_CONTENT_ENUM, CommonTemplateIndexConstants.TEMPLATE_CONTENT_SCHEMA_LOMBOK, CommonTemplateIndexConstants.TEMPLATE_MODEL_EXCEPTION); @@ -32,5 +49,32 @@ public abstract class CommonTemplateLoader implements TemplateLoader { CommonTemplateIndexConstants.TEMPLATE_UNIQUE_ITEMS_VALIDATOR_ANNOTATION); protected CommonTemplateLoader() { + } + + protected void init(final Map resourceFiles) { + templatesMap.putAll(resourceFiles); + } + + + @Override + public final Object findTemplateSource(final String templateName) { + return templatesMap.get(templateName); + } + + @Override + public final long getLastModified(final Object o) { + return 0; + } + + @Override + public final Reader getReader(final Object template, final String charSet) { + return new StringReader(template.toString()); + } + + @Override + public void closeTemplateSource(final Object o) { + // Not required to implement + } + } diff --git a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/openapi/template/ClasspathTemplateLoader.java b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/openapi/template/ClasspathTemplateLoader.java index 98479fea..ab977b65 100644 --- a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/openapi/template/ClasspathTemplateLoader.java +++ b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/openapi/template/ClasspathTemplateLoader.java @@ -6,16 +6,15 @@ package com.sngular.api.generator.plugin.openapi.template; +import com.sngular.api.generator.plugin.common.template.CommonTemplateLoader; +import com.sngular.api.generator.plugin.exception.GeneratorTemplateException; + import java.io.IOException; import java.io.InputStream; -import java.io.Reader; -import java.io.StringReader; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Objects; -import com.sngular.api.generator.plugin.common.template.CommonTemplateLoader; -import com.sngular.api.generator.plugin.exception.GeneratorTemplateException; public class ClasspathTemplateLoader extends CommonTemplateLoader { @@ -26,34 +25,9 @@ public class ClasspathTemplateLoader extends CommonTemplateLoader { private static final List TEMPLATE_AUTH_FILES = List.of(TemplateIndexConstants.TEMPLATE_API_KEY, TemplateIndexConstants.TEMPLATE_AUTHENTICATION, TemplateIndexConstants.TEMPLATE_HTTP_BASIC, TemplateIndexConstants.TEMPLATE_HTTP_BEARER, TemplateIndexConstants.TEMPLATE_OAUTH, TemplateIndexConstants.TEMPLATE_OAUTH_FLOW); - - private static final ClassLoader LOADER = ClasspathTemplateLoader.class.getClassLoader(); - - private final Map templatesMap = new HashMap<>(); - public ClasspathTemplateLoader() { super(); - templatesMap.putAll(getResourceFolderFiles()); - } - - @Override - public final Object findTemplateSource(final String templateName) { - return templatesMap.get(templateName); - } - - @Override - public final long getLastModified(final Object o) { - return 0; - } - - @Override - public final Reader getReader(final Object template, final String charSet) { - return new StringReader(template.toString()); - } - - @Override - public void closeTemplateSource(final Object o) { - // Not required to implement + init(getResourceFolderFiles()); } private Map getResourceFolderFiles() { @@ -90,8 +64,4 @@ private Map getResourceFolderFiles() { return templates; } - - private String readFile(final InputStream file) throws IOException { - return new String(file.readAllBytes()); - } } From 341dd008fb28bc019a04b9261d24f76ebd01d0f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?jose=20enrique=20garcia=20maci=C3=B1eiras?= Date: Wed, 16 Oct 2024 08:41:59 +0200 Subject: [PATCH 26/26] Codacy comments --- .../common/template/CommonTemplateLoader.java | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/template/CommonTemplateLoader.java b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/template/CommonTemplateLoader.java index 456daa65..c92b96c5 100644 --- a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/template/CommonTemplateLoader.java +++ b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/template/CommonTemplateLoader.java @@ -1,5 +1,8 @@ package com.sngular.api.generator.plugin.common.template; +import com.sngular.api.generator.plugin.openapi.template.ClasspathTemplateLoader; +import freemarker.cache.TemplateLoader; + import java.io.IOException; import java.io.InputStream; import java.io.Reader; @@ -8,9 +11,6 @@ import java.util.List; import java.util.Map; -import com.sngular.api.generator.plugin.openapi.template.ClasspathTemplateLoader; -import freemarker.cache.TemplateLoader; - public abstract class CommonTemplateLoader implements TemplateLoader { @@ -18,11 +18,6 @@ public abstract class CommonTemplateLoader implements TemplateLoader { protected static final ClassLoader LOADER = ClasspathTemplateLoader.class.getClassLoader(); - - protected String readFile(final InputStream file) throws IOException { - return new String(file.readAllBytes()); - } - protected static final List TEMPLATE_MODEL_FILES = List.of(CommonTemplateIndexConstants.TEMPLATE_CONTENT_SCHEMA, CommonTemplateIndexConstants.TEMPLATE_CONTENT_ENUM, CommonTemplateIndexConstants.TEMPLATE_CONTENT_SCHEMA_LOMBOK, CommonTemplateIndexConstants.TEMPLATE_MODEL_EXCEPTION); @@ -52,6 +47,10 @@ protected CommonTemplateLoader() { } + protected String readFile(final InputStream file) throws IOException { + return new String(file.readAllBytes()); + } + protected void init(final Map resourceFiles) { templatesMap.putAll(resourceFiles); }