From 4b0f8d9232034c15bb6a3a3edf2493d076215cfa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jose=20Enrique=20Garc=C3=ADa=20Maci=C3=B1eiras?= Date: Tue, 20 Jun 2023 13:21:08 +0200 Subject: [PATCH] #160 Fix creation problems for AnyOf, OneOf --- .../plugin/openapi/OpenApiGenerator.java | 36 +- .../plugin/openapi/model/GlobalObject.java | 9 +- .../plugin/openapi/model/SchemaObject.java | 18 +- .../openapi/template/TemplateFactory.java | 6 +- .../openapi/utils/MapperContentUtil.java | 367 ++++---- .../plugin/openapi/utils/MapperPathUtil.java | 13 +- .../plugin/openapi/utils/MapperUtil.java | 45 +- .../plugin/openapi/utils/OpenApiUtil.java | 17 +- .../templates/openapi/templateEnumSchema.ftlh | 2 +- .../openapi/OpenApiGeneratorFixtures.java | 58 +- .../plugin/openapi/OpenApiGeneratorTest.java | 4 +- .../api/generator/test/utils/TestUtils.java | 7 +- .../assets/TestDTO.java | 1 - .../assets/SecondTestDTO.java | 1 - .../testCoconutSchema/api-test.yml | 1 - .../assets/model/SchemaDTO.java | 1 - .../assets/ApiArrayFieldDTO.java | 1 - .../assets/ApiDefaultItemDTO.java | 834 +++++++++++++++--- .../assets/ApiMapFieldDTO.java | 1 - .../assets/ApiObjectFieldDTO.java | 1 - .../assets/ApiSequenceFieldDTO.java | 1 - .../assets/ApiTypeArrayDTO.java | 121 ++- .../assets/ApiUnionFieldDTO.java | 1 - .../testRestrictionsSchema/api-rest.yaml | 208 +++++ .../assets/SchemaApi.java | 124 +++ .../assets/SchemaMasterApi.java | 73 ++ .../assets/SchemasApi.java | 96 ++ .../assets/exception/ModelClassException.java | 10 + .../assets/model/ArrayFieldDTO.java | 56 ++ .../assets/model/BooleanFieldDTO.java | 34 + .../assets/model/DateFieldDTO.java | 38 + .../assets/model/EnumFieldDTO.java | 40 + .../assets/model/FieldDTO.java | 57 ++ .../assets/model/FieldValueDTO.java | 321 +++++++ .../assets/model/MapFieldDTO.java | 48 + .../assets/model/NumberFieldDTO.java | 92 ++ .../assets/model/ObjectFieldDTO.java | 44 + .../assets/model/SchemaDTO.java | 48 + .../assets/model/SequenceFieldDTO.java | 76 ++ .../assets/model/StringFieldDTO.java | 60 ++ .../assets/model/UUIDFieldDTO.java | 42 + .../assets/model/UnionFieldDTO.java | 75 ++ .../testRestrictionsSchema/components.yml | 304 +++++++ .../schema-restriction/components.yml | 304 +++++++ 44 files changed, 3269 insertions(+), 427 deletions(-) create mode 100644 multiapi-engine/src/test/resources/openapigenerator/testRestrictionsSchema/api-rest.yaml create mode 100644 multiapi-engine/src/test/resources/openapigenerator/testRestrictionsSchema/assets/SchemaApi.java create mode 100644 multiapi-engine/src/test/resources/openapigenerator/testRestrictionsSchema/assets/SchemaMasterApi.java create mode 100644 multiapi-engine/src/test/resources/openapigenerator/testRestrictionsSchema/assets/SchemasApi.java create mode 100644 multiapi-engine/src/test/resources/openapigenerator/testRestrictionsSchema/assets/exception/ModelClassException.java create mode 100644 multiapi-engine/src/test/resources/openapigenerator/testRestrictionsSchema/assets/model/ArrayFieldDTO.java create mode 100644 multiapi-engine/src/test/resources/openapigenerator/testRestrictionsSchema/assets/model/BooleanFieldDTO.java create mode 100644 multiapi-engine/src/test/resources/openapigenerator/testRestrictionsSchema/assets/model/DateFieldDTO.java create mode 100644 multiapi-engine/src/test/resources/openapigenerator/testRestrictionsSchema/assets/model/EnumFieldDTO.java create mode 100644 multiapi-engine/src/test/resources/openapigenerator/testRestrictionsSchema/assets/model/FieldDTO.java create mode 100644 multiapi-engine/src/test/resources/openapigenerator/testRestrictionsSchema/assets/model/FieldValueDTO.java create mode 100644 multiapi-engine/src/test/resources/openapigenerator/testRestrictionsSchema/assets/model/MapFieldDTO.java create mode 100644 multiapi-engine/src/test/resources/openapigenerator/testRestrictionsSchema/assets/model/NumberFieldDTO.java create mode 100644 multiapi-engine/src/test/resources/openapigenerator/testRestrictionsSchema/assets/model/ObjectFieldDTO.java create mode 100644 multiapi-engine/src/test/resources/openapigenerator/testRestrictionsSchema/assets/model/SchemaDTO.java create mode 100644 multiapi-engine/src/test/resources/openapigenerator/testRestrictionsSchema/assets/model/SequenceFieldDTO.java create mode 100644 multiapi-engine/src/test/resources/openapigenerator/testRestrictionsSchema/assets/model/StringFieldDTO.java create mode 100644 multiapi-engine/src/test/resources/openapigenerator/testRestrictionsSchema/assets/model/UUIDFieldDTO.java create mode 100644 multiapi-engine/src/test/resources/openapigenerator/testRestrictionsSchema/assets/model/UnionFieldDTO.java create mode 100644 multiapi-engine/src/test/resources/openapigenerator/testRestrictionsSchema/components.yml create mode 100644 multiapi-engine/src/test/resources/openapigenerator/testRestrictionsSchema/schema-restriction/components.yml 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 a92e1d28..c10aa92c 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 @@ -11,6 +11,7 @@ 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; @@ -202,7 +203,7 @@ private void createModelTemplate(final SpecFile specFile, final JsonNode openAPI final var modelPackage = processModelPackage(specFile.getModelPackage()); final var basicSchemaMap = OpenApiUtil.processBasicJsonNodes(openAPI, globalObject.getSchemaMap()); templateFactory.setModelPackageName(modelPackage); - processModels(specFile, openAPI, fileModelToSave, modelPackage, basicSchemaMap, Boolean.TRUE.equals(overwriteModel)); + processModels(specFile, fileModelToSave, modelPackage, basicSchemaMap, Boolean.TRUE.equals(overwriteModel)); } private void processPackage(final String apiPackage) { @@ -250,9 +251,9 @@ private String convertPackageToTargetPath(final String fileSpecPackage, final bo } private void processModels( - final SpecFile specFile, final JsonNode openAPI, final String fileModelToSave, final String modelPackage, final Map basicSchemaMap, - final boolean overwrite) { - + final SpecFile specFile, final String fileModelToSave, final String modelPackage, final Map basicSchemaMap, + final boolean overwrite) { + final Map builtSchemasMap = new HashMap<>(); basicSchemaMap.forEach((schemaName, basicSchema) -> { if (!overwrite && !overwriteModelList.add(schemaName + modelPackage)) { throw new DuplicateModelClassException(schemaName, modelPackage); @@ -260,32 +261,30 @@ private void processModels( if (ApiTool.hasRef(basicSchema)) { final var refSchema = MapperUtil.getRefSchemaName(basicSchema); - writeModel(specFile, openAPI, fileModelToSave, refSchema, basicSchemaMap.get(refSchema)); + builtSchemasMap.putAll(writeModel(specFile, fileModelToSave, refSchema, basicSchemaMap.get(refSchema), basicSchemaMap, builtSchemasMap)); } else if (!ApiTool.isArray(basicSchema) && !TypeConstants.STRING.equalsIgnoreCase(ApiTool.getType(basicSchema))) { - writeModel(specFile, openAPI, fileModelToSave, schemaName, basicSchema); + builtSchemasMap.putAll(writeModel(specFile, fileModelToSave, schemaName, basicSchema, basicSchemaMap, builtSchemasMap)); } }); } - private void writeModel(final SpecFile specFile, final JsonNode openAPI, final String fileModelToSave, final String schemaName, final JsonNode basicSchema) { - final var schemaObjectList = MapperContentUtil.mapComponentToSchemaObject(ApiTool.getComponentSchemas(openAPI), basicSchema, schemaName, specFile); - final Set propertiesSet = new HashSet<>(); - checkRequiredOrCombinatorExists(schemaObjectList); - schemaObjectList.values().forEach(schemaObject -> { + private Map writeModel(final SpecFile specFile, final String fileModelToSave, + final String schemaName, final JsonNode basicSchema, + final Map basicSchemaMap, final Map builtSchemasMap) { + final var schemaObjectMap = MapperContentUtil + .mapComponentToSchemaObject(basicSchemaMap, builtSchemasMap, basicSchema, schemaName, specFile, baseDir); + checkRequiredOrCombinatorExists(schemaObjectMap); + schemaObjectMap.values().forEach(schemaObject -> { try { + final Set propertiesSet = new HashSet<>(); templateFactory.fillTemplateSchema(fileModelToSave, specFile.isUseLombokModelAnnotation(), schemaObject, propertiesSet); + fillTemplates(fileModelToSave, propertiesSet); } catch (IOException | TemplateException e) { - throw new GeneratedSourcesException(fileModelToSave, e); + throw new GeneratedSourcesException(schemaObject.getClassName(), e); } }); - try { - fillTemplates(fileModelToSave, propertiesSet); - } catch (IOException | TemplateException e) { - throw new GeneratedSourcesException(fileModelToSave, e); - } - if (Boolean.TRUE.equals(generateExceptionTemplate)) { try { templateFactory.fillTemplateModelClassException(fileModelToSave, true); @@ -293,6 +292,7 @@ private void writeModel(final SpecFile specFile, final JsonNode openAPI, final S throw new GeneratedSourcesException(fileModelToSave, e); } } + return schemaObjectMap; } private void fillTemplates(final String filePathToSave, final Set fieldProperties) throws TemplateException, IOException { 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 b17ad45d..00f21b08 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 @@ -6,17 +6,16 @@ package com.sngular.api.generator.plugin.openapi.model; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + import com.fasterxml.jackson.databind.JsonNode; import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; import lombok.NoArgsConstructor; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; - - @Data @Builder @NoArgsConstructor 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 index c961c430..451c990d 100644 --- 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 @@ -6,20 +6,22 @@ package com.sngular.api.generator.plugin.openapi.model; -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Data; -import lombok.NoArgsConstructor; - 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 +@Builder(toBuilder = true) @NoArgsConstructor @AllArgsConstructor +@EqualsAndHashCode(of = {"schemaName", "className"}) public class SchemaObject { private boolean isEnum; @@ -36,7 +38,7 @@ public class SchemaObject { public static final class SchemaObjectBuilder { - private boolean isEnum = false; + private boolean isEnum; private final List importList = new ArrayList<>(); @@ -52,7 +54,7 @@ public SchemaObjectBuilder importItem(final String importItem) { return this; } - public SchemaObjectBuilder fieldObjectList(final List fieldObjectList) { + public SchemaObjectBuilder fieldObjectList(final Set fieldObjectList) { this.fieldObjectList.addAll(fieldObjectList); return this; } 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 4b934026..5986ba33 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 @@ -47,7 +47,9 @@ public TemplateFactory() { } - public final void fillTemplateSchema(final String filePathToSave, final Boolean useLombok, final SchemaObject schemaObject, final Set propertiesSet) throws IOException, + 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()) { @@ -148,7 +150,7 @@ public final void fillTemplate( } - public void calculateJavaEEPackage(final Integer springBootVersion) { + public final void calculateJavaEEPackage(final Integer springBootVersion) { if (3 <= springBootVersion) { root.put("javaEEPackage", "jakarta"); } else { 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 1a642519..1b5649ea 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,12 +6,15 @@ package com.sngular.api.generator.plugin.openapi.utils; +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; @@ -35,25 +38,40 @@ public class MapperContentUtil { private static final String ONE_OF_COMBINATOR = "oneOf"; private static final String ALL_OF_COMBINATOR = "allOf"; - public static final String ADDITIONAL_PROPERTIES = "additionalProperties"; + + private static final String ADDITIONAL_PROPERTIES = "additionalProperties"; private MapperContentUtil() { } public static Map mapComponentToSchemaObject( - final Map totalSchemas, final JsonNode schema, final String schemaName, - final SpecFile specFile) { - return mapComponentToSchemaObject(totalSchemas, new HashMap<>(), new ArrayList<>(), schema, - StringUtils.defaultIfEmpty(ApiTool.getNodeAsString(schema, "name"), schemaName), specFile, specFile.getModelPackage()); + final Map totalSchemas, final Map compositedSchemas, final JsonNode schema, + final String schemaName, final SpecFile specFile, final Path baseDir) { + + return mapComponentToSchemaObject(totalSchemas, compositedSchemas, new ArrayList<>(), schema, + StringUtils.defaultIfEmpty(ApiTool.getNodeAsString(schema, "name"), schemaName), specFile, baseDir); } private static Map mapComponentToSchemaObject( final Map totalSchemas, final Map compositedSchemas, final List antiLoopList, final JsonNode schema, final String schemaName, final SpecFile specFile, - final String modelPackage) { + final Path baseDir) { + final var name = StringUtils.defaultIfBlank(ApiTool.getNodeAsString(schema, "name"), schemaName); + if (!compositedSchemas.containsKey(name)) { + compositedSchemas + .put(name, toSchemaObject(name, totalSchemas, compositedSchemas, antiLoopList, schema, schemaName, specFile, baseDir)); + } + return compositedSchemas; + } + + private static SchemaObject toSchemaObject( + final String name, final Map totalSchemas, final Map compositedSchemas, + final List antiLoopList, final JsonNode schema, final String schemaName, final SpecFile specFile, + final Path baseDir) { + antiLoopList.add(schemaName); - final var listSchema = getFields(totalSchemas, schema, specFile, compositedSchemas, antiLoopList, schemaName); + final var listSchema = getFields(totalSchemas, schema, specFile, compositedSchemas, antiLoopList, schemaName, baseDir); String schemaCombinatorType = ""; if (ApiTool.isAllOf(schema)) { @@ -68,20 +86,16 @@ private static Map mapComponentToSchemaObject( schemaCombinatorType = ONE_OF_COMBINATOR; } - final var name = StringUtils.defaultIfBlank(ApiTool.getNodeAsString(schema, "name"), schemaName); - compositedSchemas - .put(name, - SchemaObject.builder() + return SchemaObject.builder() .schemaName(name) - .className(MapperUtil.getPojoName(name, specFile)) - .importList(getImportList(listSchema, modelPackage)) + .className(MapperUtil.getPojoName(schemaName, specFile)) + .importList(getImportList(listSchema, specFile.getModelPackage())) .schemaCombinator(schemaCombinatorType) .fieldObjectList(listSchema) - .build()); - return compositedSchemas; + .build(); } - private static List getImportList(final List fieldObjectList, final String modelPackage) { + private static List getImportList(final Set fieldObjectList, final String modelPackage) { final var listHashMap = new HashMap>(); final var importList = new ArrayList(); @@ -140,38 +154,38 @@ private static void getTypeImports(final HashMap> listHashM } } - private static List getFields( + private static Set getFields( final Map totalSchemas, final JsonNode schema, final SpecFile specFile, - final Map compositedSchemas, final List antiLoopList, final String nameSchema) { - final var fieldObjectArrayList = new ArrayList(); + final Map compositedSchemas, final List 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(totalSchemas, compositedSchemas, fieldObjectArrayList, specFile, schema, antiLoopList)); + ApiTool.getProperties(schema) + .forEachRemaining(processProperties(totalSchemas, compositedSchemas, fieldObjectArrayList, specFile, schema, antiLoopList, baseDir)); fieldObjectArrayList.addAll( - processAdditionalProperties(ADDITIONAL_PROPERTIES, schema, specFile, totalSchemas, compositedSchemas, antiLoopList, nameSchema)); + processAdditionalProperties(ADDITIONAL_PROPERTIES, schema, specFile, totalSchemas, compositedSchemas, antiLoopList, nameSchema, baseDir)); } else { - ApiTool.getProperties(schema).forEachRemaining(processProperties(totalSchemas, compositedSchemas, fieldObjectArrayList, specFile, schema, antiLoopList)); + ApiTool.getProperties(schema).forEachRemaining(processProperties(totalSchemas, compositedSchemas, fieldObjectArrayList, specFile, schema, antiLoopList, baseDir)); } } else if (TypeConstants.ARRAY.equalsIgnoreCase(ApiTool.getType(schema))) { - final String itemType = ApiTool.hasRef(ApiTool.getItems(schema)) ? getRef(ApiTool.getItems(schema), specFile) : ApiTool.getType(ApiTool.getItems(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)); + fieldObjectArrayList.addAll(processAllOf(totalSchemas, ApiTool.getAllOf(schema), specFile, compositedSchemas, antiLoopList, baseDir)); } else if (ApiTool.isAnyOf(schema)) { - fieldObjectArrayList.addAll(processAnyOfOneOf(totalSchemas, ApiTool.getAnyOf(schema), specFile, compositedSchemas, antiLoopList)); + fieldObjectArrayList.addAll(processAnyOfOneOf(totalSchemas, ApiTool.getAnyOf(schema), specFile, compositedSchemas, antiLoopList, baseDir)); } else if (ApiTool.isOneOf(schema)) { - fieldObjectArrayList.addAll(processAnyOfOneOf(totalSchemas, ApiTool.getOneOf(schema), specFile, compositedSchemas, antiLoopList)); + fieldObjectArrayList.addAll(processAnyOfOneOf(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(cleanRefName(ApiTool.getRefValue(schema))); - ApiTool.getProperties(refSchema).forEachRemaining(processProperties(totalSchemas, compositedSchemas, fieldObjectArrayList, specFile, schema, antiLoopList)); + final var refSchema = totalSchemas.get(MapperUtil.getRefSchemaName(schema)); + ApiTool.getProperties(refSchema).forEachRemaining(processProperties(totalSchemas, compositedSchemas, fieldObjectArrayList, specFile, schema, antiLoopList, baseDir)); } else { fieldObjectArrayList.add(SchemaFieldObject.builder() .baseName(ApiTool.getName(schema)) @@ -182,17 +196,16 @@ private static List getFields( return fieldObjectArrayList; } - private static List processAllOf( - final Map totalSchemas, final JsonNode schemaList, final SpecFile specFile, - final Map compositedSchemas, final List antiLoopList) { - final var fieldObjectArrayList = new ArrayList(); + private static Set processAllOf( + final Map totalSchemas, final JsonNode schemaList, final SpecFile specFile, + final Map compositedSchemas, final List antiLoopList, final Path baseDir) { + final Set fieldObjectArrayList = new HashSet<>(); for (JsonNode ref : schemaList) { if (ApiTool.hasRef(ref)) { - final String[] pathObjectRef = ApiTool.getRefValue(ref).split("/"); - final String schemaName = pathObjectRef[pathObjectRef.length - 1]; + final String schemaName = MapperUtil.getRefSchemaName(ref); final var schemaToProcess = totalSchemas.get(schemaName); - ApiTool.getProperties(schemaToProcess).forEachRemaining(processProperties(totalSchemas, compositedSchemas, fieldObjectArrayList, specFile, ref, antiLoopList)); + ApiTool.getProperties(schemaToProcess).forEachRemaining(processProperties(totalSchemas, compositedSchemas, fieldObjectArrayList, specFile, ref, antiLoopList, baseDir)); for (var fieldObject : fieldObjectArrayList) { fieldObject.setRequired(true); } @@ -201,29 +214,30 @@ private static List processAllOf( return fieldObjectArrayList; } - private static List processAnyOfOneOf( - final Map totalSchemas, final JsonNode schemaList, final SpecFile specFile, - final Map compositedSchemas, final List antiLoopList) { - final var fieldObjectArrayList = new ArrayList(); + private static Set processAnyOfOneOf( + final Map totalSchemas, final JsonNode schemaList, final SpecFile specFile, + final Map compositedSchemas, final List antiLoopList, final Path baseDir) { + final Set fieldObjectArrayList = new HashSet<>(); for (JsonNode internalSchema : schemaList) { if (ApiTool.hasRef(internalSchema)) { - final String[] pathObjectRef = ApiTool.getRefValue(internalSchema).split("/"); - final String schemaName = pathObjectRef[pathObjectRef.length - 1]; - final var schemaToProcess = totalSchemas.get(schemaName); - if (compositedSchemas.containsKey(schemaName) || antiLoopList.contains(schemaName)) { - fieldObjectArrayList.add(SchemaFieldObject - .builder() - .baseName(schemaName) - .dataType(SchemaFieldObjectType.fromTypeList(MapperUtil.getSimpleType(totalSchemas.get(schemaName), specFile), - MapperUtil.getPojoName(schemaName, specFile))) - .build()); + 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); + fieldObjectArrayList.addAll(schemaObject.getFieldObjectList()); + antiLoopList.add(schemaName); + } } else { - antiLoopList.add(schemaName); - ApiTool.getProperties(schemaToProcess) - .forEachRemaining(processProperties(totalSchemas, compositedSchemas, fieldObjectArrayList, specFile, schemaToProcess, antiLoopList)); + if (compositedSchemas.containsKey(schemaName)) { + fieldObjectArrayList.addAll(compositedSchemas.get(schemaName).getFieldObjectList()); + } } } else { + fieldObjectArrayList.addAll(getFields(totalSchemas, internalSchema, specFile, compositedSchemas, antiLoopList, ApiTool.getName(internalSchema), baseDir)); for (var fieldObject : fieldObjectArrayList) { if (ApiTool.checkIfRequired(internalSchema, fieldObject.getBaseName())) { fieldObject.setRequired(true); @@ -235,16 +249,16 @@ private static List processAnyOfOneOf( } private static List processFieldObjectList( - final String fieldName, final String className, final JsonNode schema, final SpecFile specFile, final Map totalSchemas, - final Map compositedSchemas, final List antiLoopList) { + final String fieldName, final String className, final JsonNode schema, final SpecFile specFile, final Map totalSchemas, + final Map compositedSchemas, final List 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)); + 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)); + fieldObjectArrayList.addAll(processMap(fieldName, schema, specFile, totalSchemas, compositedSchemas, antiLoopList, baseDir)); } else if (ApiTool.hasRef(schema)) { - fieldObjectArrayList.add(processRef(fieldName, schema, specFile, new SchemaFieldObjectType(MapperUtil.getSimpleType(schema, specFile)))); + 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() @@ -258,13 +272,13 @@ private static List processFieldObjectList( .dataType(new SchemaFieldObjectType(TypeConstants.OBJECT)) .build()); } else if (ApiTool.isObject(schema)) { - fieldObjectArrayList.addAll(processObject(fieldName, className, schema, specFile, totalSchemas, compositedSchemas, antiLoopList)); + 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(StringUtils.defaultIfBlank(className, fieldName), schema, specFile, - totalSchemas, compositedSchemas, antiLoopList); + totalSchemas, compositedSchemas, antiLoopList, baseDir); compositedSchemas.put(composedSchemaName, schemaObjectComposed); } @@ -278,75 +292,97 @@ private static List processFieldObjectList( return fieldObjectArrayList; } - private static SchemaFieldObject processRef(final String fieldName, final JsonNode schema, final SpecFile specFile, - final SchemaFieldObjectType dataType) { - final String refSchemaName = getRef(schema, specFile); + private static SchemaFieldObject processRef( + final String fieldName, final JsonNode schema, final SchemaFieldObjectType dataType, + final Map totalSchemas, final Map compositedSchemas, + final List antiLoopList, final SpecFile specFile, final Path baseDir) { final var field = SchemaFieldObject.builder() - .baseName(fieldName) - .dataType(dataType) - .build(); - setFieldType(field, schema, schema, specFile, refSchemaName); + .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 List antiLoopList, final SpecFile specFile, + final Path baseDir) { + + final var referredSchema = OpenApiUtil.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 Map totalSchemas, final Map compositedSchemas, final List fieldObjectArrayList, final SpecFile specFile, - final JsonNode schema, final List antiLoopList) { + final Map totalSchemas, final Map compositedSchemas, final Set fieldObjectArrayList, final SpecFile specFile, + final JsonNode schema, final List 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(totalSchemas, nodeName, nodeValue, compositedSchemas, specFile, schema, antiLoopList)); + fieldObjectArrayList.addAll(processObjectProperty(totalSchemas, nodeName, nodeValue, compositedSchemas, specFile, schema, antiLoopList, baseDir)); } }; } private static List processObjectProperty( - final Map totalSchemas, final String key, final JsonNode value, final Map compositedSchemas, final SpecFile specFile, - final JsonNode schema, final List antiLoopList) { + final Map totalSchemas, final String fieldName, final JsonNode fieldBody, final Map compositedSchemas, final SpecFile specFile, + final JsonNode schema, final List antiLoopList, final Path baseDir) { final List fieldObjectArrayList = new LinkedList<>(); - final var isRequired = ApiTool.checkIfRequired(value, key); + final var isRequired = ApiTool.checkIfRequired(fieldBody, fieldName); final SchemaFieldObject field; - if (ApiTool.hasRef(value)) { - final var typeName = cleanRefName(ApiTool.getRefValue(value)); + if (ApiTool.hasRef(fieldBody)) { + final var typeName = MapperUtil.getRefSchemaName(fieldBody); if (!antiLoopList.contains(typeName) && totalSchemas.containsKey(typeName) && ApiTool.hasType(totalSchemas.get(typeName)) - && ApiTool.hasItems(totalSchemas.get(typeName)) || ApiTool.getRefValue(value).contains(key)) { + && ApiTool.hasItems(totalSchemas.get(typeName)) || ApiTool.getRefValue(fieldBody).contains(fieldName)) { antiLoopList.add(typeName); - fieldObjectArrayList.addAll(processFieldObjectList(key, typeName, totalSchemas.get(typeName), specFile, totalSchemas, compositedSchemas, antiLoopList)); + fieldObjectArrayList.addAll(processFieldObjectList(fieldName, typeName, totalSchemas.get(typeName), specFile, totalSchemas, compositedSchemas, antiLoopList, baseDir)); } else { fieldObjectArrayList.add(SchemaFieldObject .builder() - .baseName(key) + .baseName(fieldName) .required(isRequired) .dataType(SchemaFieldObjectType.fromTypeList(MapperUtil.getSimpleType(totalSchemas.get(typeName), specFile), MapperUtil.getPojoName(typeName, specFile))) .build()); } - } else if (TypeConstants.STRING.equalsIgnoreCase(ApiTool.getType(value))) { - field = processStringProperty(key, value, specFile); - setFieldType(field, value, schema, specFile, key); + } 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(value)) { + } else if (isBasicType(fieldBody)) { field = SchemaFieldObject .builder() - .baseName(key) + .baseName(fieldName) .required(isRequired) - .dataType(new SchemaFieldObjectType(MapperUtil.getSimpleType(value, specFile))) + .dataType(new SchemaFieldObjectType(MapperUtil.getSimpleType(fieldBody, specFile))) .build(); - addPropertiesToFieldObject(field, value); - setFieldType(field, value, schema, specFile, key); + addPropertiesToFieldObject(field, fieldBody); + setFieldType(field, fieldBody, schema, specFile, fieldName); fieldObjectArrayList.add(field); } else { - fieldObjectArrayList.addAll(processFieldObjectList(key, key, value, specFile, totalSchemas, compositedSchemas, antiLoopList)); + fieldObjectArrayList.addAll(processFieldObjectList(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) ? getDateType(schema, specFile) : TypeConstants.STRING; + final String resultingType = ApiTool.isDateTime(schema) ? MapperUtil.getDateType(schema, specFile) : TypeConstants.STRING; final SchemaFieldObject field = SchemaFieldObject .builder() @@ -403,8 +439,8 @@ private static void addPropertiesToFieldObject(final SchemaFieldObject fieldObje } private static List processArray( - final String fieldName, final String className, final JsonNode schema, final SpecFile specFile, final Map totalSchemas, - final Map compositedSchemas, final List antiLoopList) { + final String fieldName, final String className, final JsonNode schema, final SpecFile specFile, final Map totalSchemas, + final Map compositedSchemas, final List antiLoopList, final Path baseDir) { final List fieldObjectArrayList = new LinkedList<>(); if (!ApiTool.hasItems(schema)) { @@ -416,21 +452,13 @@ private static List processArray( } else { final var items = ApiTool.getItems(schema); if (ApiTool.hasRef(items)) { - fieldObjectArrayList.add(processRef(fieldName, items, specFile, - SchemaFieldObjectType.fromTypeList(TypeConstants.ARRAY, MapperUtil.getSimpleType(items, specFile)))); - if (totalSchemas.containsKey(cleanRefName(items))) { - final var refSchema = totalSchemas.get(cleanRefName(items)); - if (ApiTool.isEnum(refSchema)) { - final String refSchemaName = getRef(schema, specFile); - fieldObjectArrayList.add(processEnumField(refSchemaName, refSchema, specFile, ApiTool.getEnumValues(refSchema), schema)); - } - } + 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); + totalSchemas, compositedSchemas, antiLoopList, baseDir); compositedSchemas.put(composedSchemaName, schemaObjectComposed); } @@ -441,7 +469,7 @@ private static List processArray( .importClass(schemaObjectComposed.getClassName()) .build()); } else if (ApiTool.hasProperties(items)) { - compositedSchemas.putAll(mapComponentToSchemaObject(totalSchemas, items, fieldName, specFile)); + compositedSchemas.putAll(mapComponentToSchemaObject(totalSchemas, compositedSchemas, items, fieldName, specFile, baseDir)); fieldObjectArrayList.add(SchemaFieldObject .builder() .baseName(fieldName) @@ -461,14 +489,15 @@ private static List processArray( return fieldObjectArrayList; } - private static List processObject( - final String fieldName, final String className, final JsonNode schema, final SpecFile specFile, final Map totalSchemas, - final Map compositedSchemas, final List antiLoopList) { - final List fieldObjectArrayList = new LinkedList<>(); + private static Set processObject( + final String fieldName, final String className, final JsonNode schema, final SpecFile specFile, + final Map totalSchemas, final Map compositedSchemas, + final List 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)); + processProperties(totalSchemas, compositedSchemas, fieldObjectArrayList, specFile, schema, antiLoopList, baseDir)); } else if (antiLoopList.contains(className)) { fieldObjectArrayList .add(SchemaFieldObject @@ -487,7 +516,7 @@ private static List processObject( final String name = StringUtils.defaultIfBlank(className, fieldName); compositedSchemas.putAll( mapComponentToSchemaObject(totalSchemas, compositedSchemas, antiLoopList, schema, name, specFile, - specFile.getModelPackage())); + baseDir)); fieldObjectArrayList .add(SchemaFieldObject .builder() @@ -499,19 +528,19 @@ private static List processObject( return fieldObjectArrayList; } - private static List processMap( - final String fieldName, final JsonNode schema, final SpecFile specFile, final Map totalSchemas, - final Map compositedSchemas, final List antiLoopList) { - final var fieldObjectArrayList = new ArrayList(); + private static Set processMap( + final String fieldName, final JsonNode schema, final SpecFile specFile, final Map totalSchemas, + final Map compositedSchemas, final List antiLoopList, final Path baseDir) { + final Set fieldObjectArrayList = new HashSet<>(); if (TypeConstants.OBJECT.equalsIgnoreCase(ApiTool.getType(schema))) { ApiTool.getProperties(schema).forEachRemaining( - processProperties(totalSchemas, compositedSchemas, fieldObjectArrayList, specFile, schema, antiLoopList)); + processProperties(totalSchemas, compositedSchemas, fieldObjectArrayList, specFile, schema, antiLoopList, baseDir)); } if (ApiTool.hasProperties(schema)) { fieldObjectArrayList.addAll(processAdditionalProperties(fieldName, schema, specFile, totalSchemas, compositedSchemas, - antiLoopList, ADDITIONAL_PROPERTIES)); + antiLoopList, ADDITIONAL_PROPERTIES, baseDir)); } return fieldObjectArrayList; @@ -519,7 +548,8 @@ private static List processMap( private static List processAdditionalProperties( final String fieldName, final JsonNode schema, final SpecFile specFile, final Map totalSchemas, - final Map compositedSchemas, final List antiLoopList, final String nameSchema) { + final Map compositedSchemas, final List antiLoopList, final String nameSchema, + final Path baseDir) { final var fieldObjectArrayList = new ArrayList(); final var addPropObj = ApiTool.getAdditionalProperties(schema); @@ -531,22 +561,10 @@ private static List processAdditionalProperties( .dataType(SchemaFieldObjectType.fromTypeList(TypeConstants.MAP, TypeConstants.OBJECT)) .build()); } else if (ApiTool.hasRef(addPropObj)) { - final String refSchemaName = getRef(addPropObj, specFile); - final var field = SchemaFieldObject.builder() - .baseName(fieldName) - .dataType(SchemaFieldObjectType.fromTypeList(TypeConstants.MAP, refSchemaName)) - .build(); - setFieldType(field, schema, addPropObj, specFile, refSchemaName); - fieldObjectArrayList.add(field); - final var refSchema = totalSchemas.get(cleanRefName(addPropObj)); - if (ApiTool.isEnum(refSchema)) { - compositedSchemas.put(refSchemaName, SchemaObject - .builder() - .className(refSchemaName) - .isEnum(true) - .fieldObject(processEnumField(refSchemaName, refSchema, specFile, ApiTool.getEnumValues(refSchema), schema)) - .build()); - } + 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 @@ -558,7 +576,7 @@ private static List processAdditionalProperties( } else if (ApiTool.isObject(addPropObj)) { compositedSchemas.putAll( mapComponentToSchemaObject(totalSchemas, compositedSchemas, antiLoopList, addPropObj, nameSchema + "Value", specFile, - specFile.getModelPackage())); + baseDir)); fieldObjectArrayList .add(SchemaFieldObject .builder() @@ -585,22 +603,22 @@ private static boolean isBasicType(final JsonNode value) { } private static SchemaObject createComposedSchema( - final String fieldName, final JsonNode schema, final SpecFile specFile, final Map totalSchemas, - final Map compositedSchemas, - final List antiLoopList) { - final var fieldObjectArrayList = new ArrayList(); + final String fieldName, final JsonNode schema, final SpecFile specFile, final Map totalSchemas, + final Map compositedSchemas, + final List 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)); + processAllOf(totalSchemas, ApiTool.getAllOf(schema), specFile, compositedSchemas, antiLoopList, baseDir)); schemaCombinatorType = ALL_OF_COMBINATOR; } else if (ApiTool.isAnyOf(schema)) { fieldObjectArrayList.addAll( - processAnyOfOneOf(totalSchemas, ApiTool.getAnyOf(schema), specFile, compositedSchemas, antiLoopList)); + processAnyOfOneOf(totalSchemas, ApiTool.getAnyOf(schema), specFile, compositedSchemas, antiLoopList, baseDir)); schemaCombinatorType = ANY_OF_COMBINATOR; } else if (ApiTool.isOneOf(schema)) { fieldObjectArrayList.addAll( - processAnyOfOneOf(totalSchemas, ApiTool.getOneOf(schema), specFile, compositedSchemas, antiLoopList)); + processAnyOfOneOf(totalSchemas, ApiTool.getOneOf(schema), specFile, compositedSchemas, antiLoopList, baseDir)); schemaCombinatorType = ONE_OF_COMBINATOR; } @@ -613,27 +631,27 @@ private static SchemaObject createComposedSchema( .build(); } - private static void setFieldType(final SchemaFieldObject field, final JsonNode value, final JsonNode schema, + 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(value)) { + if (ApiTool.isArray(schemaProperty)) { final String typeArray; - if (ApiTool.hasItems(value)) { - typeArray = MapperUtil.getTypeArray(value, specFile); + 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(value)) { - final String typeObject = getMapTypeObject(value, specFile); + } 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(value)) { - var typeObject = ApiTool.getType(value); - if (ApiTool.hasRef(value)) { - typeObject = getRef(schema, specFile); + } 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); @@ -647,7 +665,7 @@ private static String getMapTypeObject(final JsonNode schema, final SpecFile spe } else { final JsonNode additionalProperties = ApiTool.getAdditionalProperties(schema); if (ApiTool.hasRef(additionalProperties)) { - type = getRef(additionalProperties, specFile); + type = MapperUtil.getRef(additionalProperties, specFile); } else if (ApiTool.isObject(schema)) { final var additionalPropertiesField = SchemaFieldObject .builder() @@ -684,21 +702,6 @@ private static String getMapFieldType(final SchemaFieldObject schemaFieldObject) return type; } - public static String getRef(final JsonNode schema, final SpecFile specFile) { - final String typeObject; - typeObject = MapperUtil.getPojoName(cleanRefName(schema), specFile); - return typeObject; - } - - public static String cleanRefName(final String schemaRef) { - final String[] pathObjectRef = schemaRef.split("/"); - return pathObjectRef[pathObjectRef.length - 1]; - } - - public static String cleanRefName(final JsonNode schema) { - return cleanRefName(ApiTool.getRefValue(schema)); - } - private static SchemaFieldObject processEnumField( final String key, final JsonNode value, final SpecFile specFile, final List enumValues, final JsonNode schema) { final var field = SchemaFieldObject @@ -751,38 +754,4 @@ private static String getImportClass(final String type) { return StringUtils.isNotBlank(type) && !TypeConstants.NO_IMPORT_TYPE.contains(type) ? StringUtils.capitalize(type) : ""; } - public static String getDateType(final JsonNode schema, final SpecFile specFile) { - final String dateType; - switch (ApiTool.getFormat(schema)) { - - case "date": - switch (specFile.getUseTimeType()) { - case ZONED: - dateType = TypeConstants.ZONEDDATE; - break; - case OFFSET: - dateType = TypeConstants.OFFSETDATE; - break; - default: - dateType = TypeConstants.LOCALDATE; - } - break; - case "date-time": - switch (specFile.getUseTimeType()) { - case ZONED: - dateType = TypeConstants.ZONEDDATETIME; - break; - case OFFSET: - dateType = TypeConstants.OFFSETDATETIME; - break; - default: - dateType = TypeConstants.LOCALDATETIME; - } - break; - default: - dateType = TypeConstants.LOCALDATETIME; - } - return dateType; - } - } 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 06f87834..37351900 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 @@ -80,7 +80,9 @@ public static List mapPathObjects( return pathObjects; } - private static List mapOperationObject(final JsonNode openAPI, final SpecFile specFile, final Entry path, final GlobalObject globalObject, final Path baseDir) { + private static List mapOperationObject( + final JsonNode openAPI, final SpecFile specFile, final Entry path, + final GlobalObject globalObject, final Path baseDir) { final List operationObjects = new ArrayList<>(); final List operationIdList = new ArrayList<>(); final var pathNode = path.getValue(); @@ -204,7 +206,7 @@ private static List mapRequestObject(final SpecFile specFile, fin private static List mapParameterObjects( final JsonNode openAPI, final List parameters, final SpecFile specFile, final String contentClassName, - final GlobalObject globalObject, Path baseDir) { + final GlobalObject globalObject, final Path baseDir) { final List parameterObjects = new ArrayList<>(); if (Objects.nonNull(parameters) && !parameters.isEmpty()) { for (JsonNode parameter : parameters) { @@ -222,7 +224,8 @@ private static List mapParameterObjects( return parameterObjects; } - private static ParameterObject buildParameterObject(final SpecFile specFile, final GlobalObject globalObject, final JsonNode refParameter, Path baseDir) { + private static ParameterObject buildParameterObject( + final SpecFile specFile, final GlobalObject globalObject, final JsonNode refParameter, final Path baseDir) { return ParameterObject.builder() .name(ApiTool.getName(refParameter)) .required(ApiTool.getNodeAsBoolean(refParameter, REQUIRED)) @@ -355,14 +358,14 @@ private static SchemaFieldObjectType getSchemaType( SchemaFieldObjectType type = null; if (ApiTool.hasRef(schema)) { - final String refSchemaPojoName = MapperContentUtil.getRef(schema, specFile); + final String refSchemaPojoName = MapperUtil.getRef(schema, specFile); final JsonNode refSchema = OpenApiUtil.solveRef(ApiTool.getRefValue(schema), globalObject.getSchemaMap(), baseDir.resolve(specFile.getFilePath()).getParent()); type = getSchemaType(refSchema, refSchemaPojoName, specFile, globalObject, baseDir); } else if (ApiTool.hasAdditionalProperties(schema)) { type = getMapSchemaType(schema, pojoName, specFile, globalObject, baseDir); } else if (ApiTool.isDateTime(schema)) { - type = new SchemaFieldObjectType(MapperContentUtil.getDateType(schema, specFile)); + type = new SchemaFieldObjectType(MapperUtil.getDateType(schema, specFile)); } else if (ApiTool.hasType(schema)) { type = getObjectOrType(schema, pojoName, specFile, globalObject, baseDir); } else if (ApiTool.isComposed(schema)) { 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/openapi/utils/MapperUtil.java index 280182e1..55ad86bf 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/openapi/utils/MapperUtil.java @@ -66,8 +66,6 @@ private static String processNumber(final JsonNode schema) { } else { type = TypeConstants.INTEGER; } - } else if (TypeConstants.INT_32.equalsIgnoreCase(nodeType) || TypeConstants.INT_64.equalsIgnoreCase(nodeType)) { - type = TypeConstants.INTEGER; } return type; } @@ -79,8 +77,7 @@ public static String getTypeArray(final JsonNode array, final SpecFile specFile) } else if (ApiTool.isNumber(ApiTool.getItems(array))) { typeArray = ApiTool.getNumberType(ApiTool.getItems(array)); } else if (ApiTool.hasRef(ApiTool.getItems(array))) { - final String[] pathObjectRef = ApiTool.getRefValue(ApiTool.getItems(array)).split("/"); - typeArray = getPojoName(pathObjectRef[pathObjectRef.length - 1], specFile); + typeArray = getPojoName(MapperUtil.getRefSchemaName(ApiTool.getItems(array)), specFile); } return typeArray; } @@ -90,4 +87,44 @@ public static String getPojoName(final String namePojo, final SpecFile specFile) + StringUtils.capitalize(namePojo) + (StringUtils.isNotBlank(specFile.getModelNameSuffix()) ? specFile.getModelNameSuffix() : ""); } + + public static String getRef(final JsonNode schema, final SpecFile specFile) { + final String typeObject; + typeObject = getPojoName(getRefSchemaName(schema), specFile); + return typeObject; + } + + public static String getDateType(final JsonNode schema, final SpecFile specFile) { + final String dateType; + switch (ApiTool.getFormat(schema)) { + + case "date": + switch (specFile.getUseTimeType()) { + case ZONED: + dateType = TypeConstants.ZONEDDATE; + break; + case OFFSET: + dateType = TypeConstants.OFFSETDATE; + break; + default: + dateType = TypeConstants.LOCALDATE; + } + break; + case "date-time": + switch (specFile.getUseTimeType()) { + case ZONED: + dateType = TypeConstants.ZONEDDATETIME; + break; + case OFFSET: + dateType = TypeConstants.OFFSETDATETIME; + break; + default: + dateType = TypeConstants.LOCALDATETIME; + } + break; + default: + dateType = TypeConstants.LOCALDATETIME; + } + return dateType; + } } 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 f11cd546..e186f0a7 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 @@ -40,12 +40,13 @@ public class OpenApiUtil { static final ObjectMapper PARSER = new ObjectMapper(new YAMLFactory()); static final Set REST_VERB_SET = Set.of("get", "post", "delete", "patch", "put"); + public static final String PATHS = "paths"; private OpenApiUtil() {} public static Map> mapApiGroups(final JsonNode openAPI, final boolean groupByTags) { final Map> mapApis = new HashMap<>(); - final var pathList = openAPI.findValue("paths").fields(); + final var pathList = openAPI.findValue(PATHS).fields(); if (pathList.hasNext()) { mapApis.putAll(groupByTags ? mapApiGroupsByTags(pathList) : mapApiGroupsByUrl(openAPI)); } @@ -94,11 +95,11 @@ private static MultiValuedMap> getMapMethodsByTag( private static Map> mapApiGroupsByUrl(final JsonNode openAPI) { final var mapByUrl = new HashMap>(); - for (Iterator it = openAPI.get("paths").fieldNames(); it.hasNext();) { + for (Iterator it = openAPI.get(PATHS).fieldNames(); it.hasNext();) { final var pathUrl = it.next(); final String[] pathName = pathUrl.split("/"); mapByUrl.putIfAbsent(pathName[1], new HashMap<>()); - mapByUrl.get(pathName[1]).put(pathUrl, openAPI.get("paths").get(pathUrl)); + mapByUrl.get(pathName[1]).put(pathUrl, openAPI.get(PATHS).get(pathUrl)); } return mapByUrl; @@ -132,9 +133,9 @@ private static String readFile(final Path rootFilePath, final String filePath) t } final var sb = new StringBuilder(); if (Objects.nonNull(fileURL)) { - try (BufferedReader in = new BufferedReader(new InputStreamReader(fileURL.openStream()))) { + try (BufferedReader reader = new BufferedReader(new InputStreamReader(fileURL.openStream()))) { String inputLine; - while ((inputLine = in.readLine()) != null) { + while ((inputLine = reader.readLine()) != null) { sb.append(inputLine).append(System.lineSeparator()); } } catch (final IOException e) { @@ -147,7 +148,7 @@ private static String readFile(final Path rootFilePath, final String filePath) t public static Map processBasicJsonNodes(final JsonNode openApi, final Map schemaMap) { final var basicJsonNodeMap = new HashMap<>(schemaMap); - for (final var pathElement = openApi.findValue("paths").elements(); pathElement.hasNext();) { + for (final var pathElement = openApi.findValue(PATHS).elements(); pathElement.hasNext();) { final var pathDefinition = pathElement.next(); for (Iterator it = pathDefinition.fieldNames(); it.hasNext();) { final var pathDefElement = it.next(); @@ -259,15 +260,15 @@ protected static JsonNode solveRef(final String refValue, final Map TEST_RESTRICTION_SCHEMA = List.of( + SpecFile + .builder() + .filePath("openapigenerator/testRestrictionsSchema/api-rest.yaml") + .apiPackage("com.sngular.multifileplugin.testRestrictionsSchema") + .modelPackage("com.sngular.multifileplugin.testRestrictionsSchema.model") + .clientPackage("com.sngular.multifileplugin.testRestrictionsSchema.client") + .modelNameSuffix("DTO") + .useLombokModelAnnotation(true) + .build() + ); + final static List TEST_VALIDATION_ANNOTATIONS = List.of( SpecFile .builder() @@ -1065,6 +1077,46 @@ static Function validateCoconutSchema() { return (path) -> commonTest(path, expectedTestApiFile, expectedTestApiModelFiles, DEFAULT_TARGET_API, DEFAULT_MODEL_API, expectedExceptionFiles, DEFAULT_EXCEPTION_API); } + static Function validateRestrictionsSchema() { + + final String DEFAULT_TARGET_API = "generated/com/sngular/multifileplugin/testRestrictionsSchema"; + + final String DEFAULT_MODEL_API = "generated/com/sngular/multifileplugin/testRestrictionsSchema/model"; + + final String DEFAULT_EXCEPTION_API = "generated/com/sngular/multifileplugin/testRestrictionsSchema/model/exception"; + + final String COMMON_PATH = "openapigenerator/testRestrictionsSchema/"; + + final String ASSETS_PATH = COMMON_PATH + "assets/"; + + final List expectedTestApiFile = List.of( + ASSETS_PATH + "SchemaApi.java", + ASSETS_PATH + "SchemaMasterApi.java", + ASSETS_PATH + "SchemasApi.java" + ); + + final List expectedTestApiModelFiles = List.of( + ASSETS_PATH + "model/ArrayFieldDTO.java", + ASSETS_PATH + "model/BooleanFieldDTO.java", + ASSETS_PATH + "model/DateFieldDTO.java", + ASSETS_PATH + "model/EnumFieldDTO.java", + ASSETS_PATH + "model/FieldDTO.java", + ASSETS_PATH + "model/FieldValueDTO.java", + ASSETS_PATH + "model/MapFieldDTO.java", + ASSETS_PATH + "model/NumberFieldDTO.java", + ASSETS_PATH + "model/ObjectFieldDTO.java", + ASSETS_PATH + "model/SchemaDTO.java", + ASSETS_PATH + "model/SequenceFieldDTO.java", + ASSETS_PATH + "model/StringFieldDTO.java", + ASSETS_PATH + "model/UUIDFieldDTO.java", + ASSETS_PATH + "model/UnionFieldDTO.java" + ); + + 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); + } static Function validateValidationAnnotations(int springBootVersion) { @@ -1118,7 +1170,7 @@ static Function validateValidationAnnotations(int springBootVersi ); return (path) -> commonTest(path, expectedTestApiFile, expectedTestApiModelFiles, DEFAULT_TARGET_API, DEFAULT_MODEL_API, expectedExceptionFiles, DEFAULT_EXCEPTION_API) - && customValidatorTest(path, expectedValidatorFiles, DEFAULT_CUSTOMVALIDATOR_API); + && customValidatorTest(path, expectedValidatorFiles); } static Function validateValidationAnnotationsLombok(int springBootTest) { @@ -1326,13 +1378,13 @@ private static Boolean commonTest( return result; } - private static Boolean customValidatorTest(final Path resultPath, final List expectedValidatorFiles, final String targetCustomValidator) { + private static Boolean customValidatorTest(final Path resultPath, final List expectedValidatorFiles) { Boolean result = Boolean.TRUE; try { final Path pathToTarget = Path.of(resultPath.toString(), "target"); if (!expectedValidatorFiles.isEmpty()) { - final Path pathToTargetCustomValidator = pathToTarget.resolve(targetCustomValidator); + final Path pathToTargetCustomValidator = pathToTarget.resolve("generated/com/sngular/multifileplugin/testapi/model/customvalidator"); final File targetCustomValidatorFolder = pathToTargetCustomValidator.toFile(); assertThat(targetCustomValidatorFolder).isNotEmptyDirectory(); TestUtils.validateFiles(expectedValidatorFiles, targetCustomValidatorFolder); 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 148ba270..1e71c069 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 @@ -99,7 +99,9 @@ static Stream fileSpecToProcess() { Arguments.of("testListString", OpenApiGeneratorFixtures.TEST_LIST_STRING, OpenApiGeneratorFixtures.validateListString()), Arguments.of("testReferenceFile", OpenApiGeneratorFixtures.TEST_REFERENCE_FILE, OpenApiGeneratorFixtures.validateReferenceFile()), Arguments.of("testQueryParam", OpenApiGeneratorFixtures.TEST_QUERY_PARAM, OpenApiGeneratorFixtures.validateQueryParam()), - Arguments.of("testApiWithNoComponents", OpenApiGeneratorFixtures.TEST_API_WITH_NO_COMPONENTS, OpenApiGeneratorFixtures.validateApiWithNoComponents()) + Arguments.of("testApiWithNoComponents", OpenApiGeneratorFixtures.TEST_API_WITH_NO_COMPONENTS, OpenApiGeneratorFixtures.validateApiWithNoComponents()), + Arguments.of("testRestrictionSchema", OpenApiGeneratorFixtures.TEST_RESTRICTION_SCHEMA, + OpenApiGeneratorFixtures.validateRestrictionsSchema()) ); } diff --git a/multiapi-engine/src/test/java/com/sngular/api/generator/test/utils/TestUtils.java b/multiapi-engine/src/test/java/com/sngular/api/generator/test/utils/TestUtils.java index eac02ed5..de2a43d5 100644 --- a/multiapi-engine/src/test/java/com/sngular/api/generator/test/utils/TestUtils.java +++ b/multiapi-engine/src/test/java/com/sngular/api/generator/test/utils/TestUtils.java @@ -26,12 +26,15 @@ public static void validateFiles(final List expectedFiles, final File ta List outputFiles = new ArrayList<>(List.of(Objects.requireNonNull(targetDirectory.listFiles()))); outputFiles.removeIf(File::isDirectory); outputFiles.sort(Comparator.comparing(File::getPath)); - assertThat(outputFiles).hasSize(expectedFiles.size()); + assertThat(outputFiles) + .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)); final String sourceName = expectedFiles.get(i); reader2 = TestUtils.resourceAsFile(sourceName); - assertThat(reader1).as(() -> "Unexpected content for file " + sourceName).hasSameContentAs(reader2); + int finalI = i; + assertThat(reader1).as(() -> "Unexpected content for file " + outputFiles.get(finalI)).hasSameContentAs(reader2); } } 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 ee27a312..c3220017 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testAdditionalPropertiesWithSchema/assets/TestDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testAdditionalPropertiesWithSchema/assets/TestDTO.java @@ -3,7 +3,6 @@ import com.fasterxml.jackson.annotation.JsonProperty; import java.util.Map; import java.util.HashMap; -import com.sngular.multifileplugin.testadditionalpropertiesWithSchema.model.SubtestDTO; import lombok.Builder; import lombok.Data; import lombok.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 d4d2b18b..30e113a3 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testAdditionalPropertiesWithUnnamedObject/assets/SecondTestDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testAdditionalPropertiesWithUnnamedObject/assets/SecondTestDTO.java @@ -3,7 +3,6 @@ import com.fasterxml.jackson.annotation.JsonProperty; import java.util.Map; import java.util.HashMap; -import com.sngular.multifileplugin.testadditionalpropertiesWithUnnamedObject.model.EnumSchemaDTO; import lombok.Builder; import lombok.Data; import lombok.NonNull; diff --git a/multiapi-engine/src/test/resources/openapigenerator/testCoconutSchema/api-test.yml b/multiapi-engine/src/test/resources/openapigenerator/testCoconutSchema/api-test.yml index 35c60c42..e2b03d8c 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testCoconutSchema/api-test.yml +++ b/multiapi-engine/src/test/resources/openapigenerator/testCoconutSchema/api-test.yml @@ -159,7 +159,6 @@ paths: description: Bad Request '500': description: Server Error - /schema_master/{schemaType}: post: tags: 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 47eb02ad..b48823f7 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 @@ -5,7 +5,6 @@ import java.util.ArrayList; import java.util.Map; import java.util.HashMap; -import com.sngular.multifileplugin.testCoconutSchema.model.FieldDTO; import lombok.Builder; import lombok.Data; import lombok.NonNull; 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 013736f2..7f6512cc 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testComplexAnyOf/assets/ApiArrayFieldDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testComplexAnyOf/assets/ApiArrayFieldDTO.java @@ -6,7 +6,6 @@ import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder; import com.fasterxml.jackson.annotation.JsonProperty; import io.swagger.v3.oas.annotations.media.Schema; -import com.sngular.multifileplugin.testcomplexanyof.model.ApiTypeArrayDTO; import java.util.List; import java.util.ArrayList; 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 5f22f962..5c6e8fa0 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testComplexAnyOf/assets/ApiDefaultItemDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testComplexAnyOf/assets/ApiDefaultItemDTO.java @@ -5,59 +5,190 @@ import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder; import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; import io.swagger.v3.oas.annotations.media.Schema; +import java.util.List; +import java.util.ArrayList; import com.sngular.multifileplugin.testcomplexanyof.model.exception.ModelClassException; @JsonDeserialize(builder = ApiDefaultItemDTO.ApiDefaultItemDTOBuilder.class) public class ApiDefaultItemDTO { - @JsonProperty(value ="stringField") - private ApiStringFieldDTO stringField; - @JsonProperty(value ="sequenceField") - private ApiSequenceFieldDTO sequenceField; - @JsonProperty(value ="dateField") - private ApiDateFieldDTO dateField; - @JsonProperty(value ="enumField") - private ApiEnumFieldDTO enumField; - @JsonProperty(value ="booleanField") - private ApiBooleanFieldDTO booleanField; - @JsonProperty(value ="arrayField") - private ApiArrayFieldDTO arrayField; - @JsonProperty(value ="numberField") - private ApiNumberFieldDTO numberField; - @JsonProperty(value ="objectField") - private ApiObjectFieldDTO objectField; - @JsonProperty(value ="mapField") - private ApiMapFieldDTO mapField; - @JsonProperty(value ="unionField") - private ApiUnionFieldDTO unionField; - - private ApiDefaultItemDTO(ApiStringFieldDTO stringField, ApiSequenceFieldDTO sequenceField, ApiDateFieldDTO dateField, ApiEnumFieldDTO enumField, ApiBooleanFieldDTO booleanField, ApiArrayFieldDTO arrayField, ApiNumberFieldDTO numberField, ApiObjectFieldDTO objectField, ApiMapFieldDTO mapField, ApiUnionFieldDTO unionField) { - this.stringField = stringField; - this.sequenceField = sequenceField; - this.dateField = dateField; - this.enumField = enumField; - this.booleanField = booleanField; - this.arrayField = arrayField; - this.numberField = numberField; - this.objectField = objectField; - this.mapField = mapField; - this.unionField = unionField; + @JsonProperty(value ="precision") + private Integer precision; + @JsonProperty(value ="maximum") + private Integer maximum; + @JsonProperty(value ="type") + private String type; + @JsonProperty(value ="scale") + private Integer scale; + @JsonProperty(value ="minLength") + private Integer minLength; + @JsonProperty(value ="increment") + private Integer increment; + @JsonProperty(value ="keyType") + private String keyType; + @JsonProperty(value ="requiredValues") + private List requiredValues = new ArrayList(); + @JsonProperty(value ="initialValue") + private String initialValue; + @JsonProperty(value ="flagExclusiveMinimum") + private Boolean flagExclusiveMinimum; + @JsonProperty(value ="flagExclusiveMaximum") + private Boolean flagExclusiveMaximum; + @JsonProperty(value ="defaultValue") + private Boolean defaultValue; + @JsonProperty(value ="enumValues") + private List enumValues = new ArrayList(); + @JsonProperty(value ="properties") + private List properties = new ArrayList(); + @JsonProperty(value ="defaultValues") + private List defaultValues = new ArrayList(); + @JsonProperty(value ="seqEnum") + private SeqEnum seqEnum; + public enum SeqEnum { + MONTH("MONTH"), + YEAR("YEAR"), + HOUR("HOUR"), + MINUTE("MINUTE"), + SECOND("SECOND"), + DAY("DAY"); + + private String value; + + SeqEnum(String value) { + this.value = value; + } + + @JsonValue + public String getValue() { + return value; + } + + @Override + public String toString() { + return String.valueOf(value); + } + } + @JsonProperty(value ="arraySize") + private Integer arraySize; + @JsonProperty(value ="multipleOf") + private Integer multipleOf; + @JsonProperty(value ="mapSize") + private Integer mapSize; + @JsonProperty(value ="mapTypes") + private List mapTypes = new ArrayList(); + @JsonProperty(value ="format") + private Integer format; + @JsonProperty(value ="maxLength") + private Integer maxLength; + @JsonProperty(value ="uniqueItems") + private Boolean uniqueItems; + @JsonProperty(value ="elements") + private Integer elements; + @JsonProperty(value ="name") + private String name; + @JsonProperty(value ="regex") + private String regex; + @JsonProperty(value ="minItems") + private Integer minItems; + @JsonProperty(value ="values") + private List values = new ArrayList(); + @JsonProperty(value ="minimum") + private Integer minimum; + @JsonProperty(value ="numberEnum") + private NumberEnum numberEnum; + public enum NumberEnum { + FLOAT("float"), + INTEGER("integer"); + + private String value; + + NumberEnum(String value) { + this.value = value; + } + + @JsonValue + public String getValue() { + return value; + } + + @Override + public String toString() { + return String.valueOf(value); + } + } + @JsonProperty(value ="valueLength") + private Integer valueLength; + + private ApiDefaultItemDTO(Integer precision, Integer maximum, String type, Integer scale, Integer minLength, Integer increment, String keyType, List requiredValues, String initialValue, Boolean flagExclusiveMinimum, Boolean flagExclusiveMaximum, Boolean defaultValue, List enumValues, List properties, List defaultValues, SeqEnum seqEnum, Integer arraySize, Integer multipleOf, Integer mapSize, List mapTypes, Integer format, Integer maxLength, Boolean uniqueItems, Integer elements, String name, String regex, Integer minItems, List values, Integer minimum, NumberEnum numberEnum, Integer valueLength) { + this.precision = precision; + this.maximum = maximum; + this.type = type; + this.scale = scale; + this.minLength = minLength; + this.increment = increment; + this.keyType = keyType; + this.requiredValues = requiredValues; + this.initialValue = initialValue; + this.flagExclusiveMinimum = flagExclusiveMinimum; + this.flagExclusiveMaximum = flagExclusiveMaximum; + this.defaultValue = defaultValue; + this.enumValues = enumValues; + this.properties = properties; + this.defaultValues = defaultValues; + this.seqEnum = seqEnum; + this.arraySize = arraySize; + this.multipleOf = multipleOf; + this.mapSize = mapSize; + this.mapTypes = mapTypes; + this.format = format; + 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.stringField = builder.stringField; - this.sequenceField = builder.sequenceField; - this.dateField = builder.dateField; - this.enumField = builder.enumField; - this.booleanField = builder.booleanField; - this.arrayField = builder.arrayField; - this.numberField = builder.numberField; - this.objectField = builder.objectField; - this.mapField = builder.mapField; - this.unionField = builder.unionField; + this.precision = builder.precision; + this.maximum = builder.maximum; + this.type = builder.type; + this.scale = builder.scale; + this.minLength = builder.minLength; + this.increment = builder.increment; + this.keyType = builder.keyType; + this.requiredValues = builder.requiredValues; + this.initialValue = builder.initialValue; + this.flagExclusiveMinimum = builder.flagExclusiveMinimum; + this.flagExclusiveMaximum = builder.flagExclusiveMaximum; + this.defaultValue = builder.defaultValue; + this.enumValues = builder.enumValues; + this.properties = builder.properties; + this.defaultValues = builder.defaultValues; + 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.maxLength = builder.maxLength; + this.uniqueItems = builder.uniqueItems; + this.elements = builder.elements; + this.name = builder.name; + this.regex = builder.regex; + this.minItems = builder.minItems; + this.values = builder.values; + this.minimum = builder.minimum; + this.numberEnum = builder.numberEnum; + this.valueLength = builder.valueLength; validatePartialCombinations(); } @@ -69,54 +200,236 @@ public static ApiDefaultItemDTO.ApiDefaultItemDTOBuilder builder() { @JsonPOJOBuilder(buildMethodName = "build", withPrefix = "") public static class ApiDefaultItemDTOBuilder { - private ApiStringFieldDTO stringField; - private ApiSequenceFieldDTO sequenceField; - private ApiDateFieldDTO dateField; - private ApiEnumFieldDTO enumField; - private ApiBooleanFieldDTO booleanField; - private ApiArrayFieldDTO arrayField; - private ApiNumberFieldDTO numberField; - private ApiObjectFieldDTO objectField; - private ApiMapFieldDTO mapField; - private ApiUnionFieldDTO unionField; - public ApiDefaultItemDTO.ApiDefaultItemDTOBuilder stringField(ApiStringFieldDTO stringField) { - this.stringField = stringField; + private Integer precision; + private Integer maximum; + private String type; + private Integer scale; + private Integer minLength; + private Integer increment; + private String keyType; + private List requiredValues = new ArrayList(); + private String initialValue; + private Boolean flagExclusiveMinimum; + private Boolean flagExclusiveMaximum; + private Boolean defaultValue; + private List enumValues = new ArrayList(); + private List properties = new ArrayList(); + private List defaultValues = new ArrayList(); + private SeqEnum seqEnum; + private Integer arraySize; + private Integer multipleOf; + private Integer mapSize; + private List mapTypes = new ArrayList(); + private Integer format; + private Integer maxLength; + private Boolean uniqueItems; + private Integer elements; + private String name; + private String regex; + private Integer minItems; + private List values = new ArrayList(); + private Integer minimum; + private NumberEnum numberEnum; + private Integer valueLength; + + public ApiDefaultItemDTO.ApiDefaultItemDTOBuilder precision(Integer precision) { + this.precision = precision; + return this; + } + + public ApiDefaultItemDTO.ApiDefaultItemDTOBuilder maximum(Integer maximum) { + this.maximum = maximum; + return this; + } + + public ApiDefaultItemDTO.ApiDefaultItemDTOBuilder type(String type) { + this.type = type; + return this; + } + + public ApiDefaultItemDTO.ApiDefaultItemDTOBuilder scale(Integer scale) { + this.scale = scale; + return this; + } + + public ApiDefaultItemDTO.ApiDefaultItemDTOBuilder minLength(Integer minLength) { + this.minLength = minLength; + return this; + } + + public ApiDefaultItemDTO.ApiDefaultItemDTOBuilder increment(Integer increment) { + this.increment = increment; + return this; + } + + public ApiDefaultItemDTO.ApiDefaultItemDTOBuilder keyType(String keyType) { + this.keyType = keyType; + return this; + } + public ApiDefaultItemDTO.ApiDefaultItemDTOBuilder requiredValues(List requiredValues) { + if (!requiredValues.isEmpty()) { + this.requiredValues.addAll(requiredValues); + } + return this; + } + + public ApiDefaultItemDTO.ApiDefaultItemDTOBuilder requiredValues(String requiredValues) { + if (requiredValues != null) { + this.requiredValues.add(requiredValues); + } + return this; + } + + public ApiDefaultItemDTO.ApiDefaultItemDTOBuilder initialValue(String initialValue) { + this.initialValue = initialValue; + return this; + } + + public ApiDefaultItemDTO.ApiDefaultItemDTOBuilder flagExclusiveMinimum(Boolean flagExclusiveMinimum) { + this.flagExclusiveMinimum = flagExclusiveMinimum; + return this; + } + + public ApiDefaultItemDTO.ApiDefaultItemDTOBuilder flagExclusiveMaximum(Boolean flagExclusiveMaximum) { + this.flagExclusiveMaximum = flagExclusiveMaximum; + return this; + } + + public ApiDefaultItemDTO.ApiDefaultItemDTOBuilder defaultValue(Boolean defaultValue) { + this.defaultValue = defaultValue; + return this; + } + public ApiDefaultItemDTO.ApiDefaultItemDTOBuilder enumValues(List enumValues) { + if (!enumValues.isEmpty()) { + this.enumValues.addAll(enumValues); + } + return this; + } + + public ApiDefaultItemDTO.ApiDefaultItemDTOBuilder enumValues(String enumValues) { + if (enumValues != null) { + this.enumValues.add(enumValues); + } + return this; + } + public ApiDefaultItemDTO.ApiDefaultItemDTOBuilder properties(List properties) { + if (!properties.isEmpty()) { + this.properties.addAll(properties); + } + return this; + } + + public ApiDefaultItemDTO.ApiDefaultItemDTOBuilder properties(String properties) { + if (properties != null) { + this.properties.add(properties); + } + return this; + } + public ApiDefaultItemDTO.ApiDefaultItemDTOBuilder defaultValues(List defaultValues) { + if (!defaultValues.isEmpty()) { + this.defaultValues.addAll(defaultValues); + } + return this; + } + + public ApiDefaultItemDTO.ApiDefaultItemDTOBuilder defaultValues(String defaultValues) { + if (defaultValues != null) { + this.defaultValues.add(defaultValues); + } + return this; + } + public ApiDefaultItemDTO.ApiDefaultItemDTOBuilder seqEnum(SeqEnum seqEnum) { + this.seqEnum = seqEnum; + return this; + } + + public ApiDefaultItemDTO.ApiDefaultItemDTOBuilder arraySize(Integer arraySize) { + this.arraySize = arraySize; + return this; + } + + public ApiDefaultItemDTO.ApiDefaultItemDTOBuilder multipleOf(Integer multipleOf) { + this.multipleOf = multipleOf; + return this; + } + + public ApiDefaultItemDTO.ApiDefaultItemDTOBuilder mapSize(Integer mapSize) { + this.mapSize = mapSize; + return this; + } + public ApiDefaultItemDTO.ApiDefaultItemDTOBuilder mapTypes(List mapTypes) { + if (!mapTypes.isEmpty()) { + this.mapTypes.addAll(mapTypes); + } + return this; + } + + public ApiDefaultItemDTO.ApiDefaultItemDTOBuilder mapTypes(ApiTypeArrayDTO mapTypes) { + if (mapTypes != null) { + this.mapTypes.add(mapTypes); + } + return this; + } + + public ApiDefaultItemDTO.ApiDefaultItemDTOBuilder format(Integer format) { + this.format = format; + return this; + } + + public ApiDefaultItemDTO.ApiDefaultItemDTOBuilder maxLength(Integer maxLength) { + this.maxLength = maxLength; + return this; + } + + public ApiDefaultItemDTO.ApiDefaultItemDTOBuilder uniqueItems(Boolean uniqueItems) { + this.uniqueItems = uniqueItems; return this; } - public ApiDefaultItemDTO.ApiDefaultItemDTOBuilder sequenceField(ApiSequenceFieldDTO sequenceField) { - this.sequenceField = sequenceField; + + public ApiDefaultItemDTO.ApiDefaultItemDTOBuilder elements(Integer elements) { + this.elements = elements; return this; } - public ApiDefaultItemDTO.ApiDefaultItemDTOBuilder dateField(ApiDateFieldDTO dateField) { - this.dateField = dateField; + + public ApiDefaultItemDTO.ApiDefaultItemDTOBuilder name(String name) { + this.name = name; return this; } - public ApiDefaultItemDTO.ApiDefaultItemDTOBuilder enumField(ApiEnumFieldDTO enumField) { - this.enumField = enumField; + + public ApiDefaultItemDTO.ApiDefaultItemDTOBuilder regex(String regex) { + this.regex = regex; return this; } - public ApiDefaultItemDTO.ApiDefaultItemDTOBuilder booleanField(ApiBooleanFieldDTO booleanField) { - this.booleanField = booleanField; + + public ApiDefaultItemDTO.ApiDefaultItemDTOBuilder minItems(Integer minItems) { + this.minItems = minItems; return this; } - public ApiDefaultItemDTO.ApiDefaultItemDTOBuilder arrayField(ApiArrayFieldDTO arrayField) { - this.arrayField = arrayField; + public ApiDefaultItemDTO.ApiDefaultItemDTOBuilder values(List values) { + if (!values.isEmpty()) { + this.values.addAll(values); + } return this; } - public ApiDefaultItemDTO.ApiDefaultItemDTOBuilder numberField(ApiNumberFieldDTO numberField) { - this.numberField = numberField; + + public ApiDefaultItemDTO.ApiDefaultItemDTOBuilder values(ApiTypeArrayDTO values) { + if (values != null) { + this.values.add(values); + } return this; } - public ApiDefaultItemDTO.ApiDefaultItemDTOBuilder objectField(ApiObjectFieldDTO objectField) { - this.objectField = objectField; + + public ApiDefaultItemDTO.ApiDefaultItemDTOBuilder minimum(Integer minimum) { + this.minimum = minimum; return this; } - public ApiDefaultItemDTO.ApiDefaultItemDTOBuilder mapField(ApiMapFieldDTO mapField) { - this.mapField = mapField; + public ApiDefaultItemDTO.ApiDefaultItemDTOBuilder numberEnum(NumberEnum numberEnum) { + this.numberEnum = numberEnum; return this; } - public ApiDefaultItemDTO.ApiDefaultItemDTOBuilder unionField(ApiUnionFieldDTO unionField) { - this.unionField = unionField; + + public ApiDefaultItemDTO.ApiDefaultItemDTOBuilder valueLength(Integer valueLength) { + this.valueLength = valueLength; return this; } @@ -126,84 +439,252 @@ public ApiDefaultItemDTO build() { } } - @Schema(name = "stringField", required = false) - public ApiStringFieldDTO getStringField() { - return stringField; + @Schema(name = "precision", required = false) + public Integer getPrecision() { + return precision; + } + public void setPrecision(Integer precision) { + this.precision = precision; + } + + @Schema(name = "maximum", required = false) + public Integer getMaximum() { + return maximum; + } + public void setMaximum(Integer maximum) { + this.maximum = maximum; + } + + @Schema(name = "type", required = false) + public String getType() { + return type; + } + public void setType(String type) { + this.type = type; + } + + @Schema(name = "scale", required = false) + public Integer getScale() { + return scale; + } + public void setScale(Integer scale) { + this.scale = scale; + } + + @Schema(name = "minLength", required = false) + public Integer getMinLength() { + return minLength; + } + public void setMinLength(Integer minLength) { + this.minLength = minLength; + } + + @Schema(name = "increment", required = false) + public Integer getIncrement() { + return increment; + } + public void setIncrement(Integer increment) { + this.increment = increment; + } + + @Schema(name = "keyType", required = false) + public String getKeyType() { + return keyType; + } + public void setKeyType(String keyType) { + this.keyType = keyType; + } + + @Schema(name = "requiredValues", required = false) + public List getRequiredValues() { + return requiredValues; + } + public void setRequiredValues(List requiredValues) { + this.requiredValues = requiredValues; + } + + @Schema(name = "initialValue", required = false) + public String getInitialValue() { + return initialValue; + } + public void setInitialValue(String initialValue) { + this.initialValue = initialValue; + } + + @Schema(name = "flagExclusiveMinimum", required = false) + public Boolean getFlagExclusiveMinimum() { + return flagExclusiveMinimum; + } + public void setFlagExclusiveMinimum(Boolean flagExclusiveMinimum) { + this.flagExclusiveMinimum = flagExclusiveMinimum; + } + + @Schema(name = "flagExclusiveMaximum", required = false) + public Boolean getFlagExclusiveMaximum() { + return flagExclusiveMaximum; + } + public void setFlagExclusiveMaximum(Boolean flagExclusiveMaximum) { + this.flagExclusiveMaximum = flagExclusiveMaximum; + } + + @Schema(name = "defaultValue", required = false) + public Boolean getDefaultValue() { + return defaultValue; + } + public void setDefaultValue(Boolean defaultValue) { + this.defaultValue = defaultValue; + } + + @Schema(name = "enumValues", required = false) + public List getEnumValues() { + return enumValues; + } + public void setEnumValues(List enumValues) { + this.enumValues = enumValues; + } + + @Schema(name = "properties", required = false) + public List getProperties() { + return properties; + } + public void setProperties(List properties) { + this.properties = properties; + } + + @Schema(name = "defaultValues", required = false) + public List getDefaultValues() { + return defaultValues; + } + public void setDefaultValues(List defaultValues) { + this.defaultValues = defaultValues; + } + + @Schema(name = "seqEnum", required = false) + public SeqEnum getSeqEnum() { + return seqEnum; + } + public void setSeqEnum(SeqEnum seqEnum) { + this.seqEnum = seqEnum; + } + + @Schema(name = "arraySize", required = false) + public Integer getArraySize() { + return arraySize; + } + public void setArraySize(Integer arraySize) { + this.arraySize = arraySize; + } + + @Schema(name = "multipleOf", required = false) + public Integer getMultipleOf() { + return multipleOf; + } + public void setMultipleOf(Integer multipleOf) { + this.multipleOf = multipleOf; + } + + @Schema(name = "mapSize", required = false) + public Integer getMapSize() { + return mapSize; + } + public void setMapSize(Integer mapSize) { + this.mapSize = mapSize; + } + + @Schema(name = "mapTypes", required = false) + public List getMapTypes() { + return mapTypes; + } + public void setMapTypes(List mapTypes) { + this.mapTypes = mapTypes; + } + + @Schema(name = "format", required = false) + public Integer getFormat() { + return format; + } + public void setFormat(Integer format) { + this.format = format; + } + + @Schema(name = "maxLength", required = false) + public Integer getMaxLength() { + return maxLength; } - public void setStringField(ApiStringFieldDTO stringField) { - this.stringField = stringField; + public void setMaxLength(Integer maxLength) { + this.maxLength = maxLength; } - @Schema(name = "sequenceField", required = false) - public ApiSequenceFieldDTO getSequenceField() { - return sequenceField; + @Schema(name = "uniqueItems", required = false) + public Boolean getUniqueItems() { + return uniqueItems; } - public void setSequenceField(ApiSequenceFieldDTO sequenceField) { - this.sequenceField = sequenceField; + public void setUniqueItems(Boolean uniqueItems) { + this.uniqueItems = uniqueItems; } - @Schema(name = "dateField", required = false) - public ApiDateFieldDTO getDateField() { - return dateField; + @Schema(name = "elements", required = false) + public Integer getElements() { + return elements; } - public void setDateField(ApiDateFieldDTO dateField) { - this.dateField = dateField; + public void setElements(Integer elements) { + this.elements = elements; } - @Schema(name = "enumField", required = false) - public ApiEnumFieldDTO getEnumField() { - return enumField; + @Schema(name = "name", required = false) + public String getName() { + return name; } - public void setEnumField(ApiEnumFieldDTO enumField) { - this.enumField = enumField; + public void setName(String name) { + this.name = name; } - @Schema(name = "booleanField", required = false) - public ApiBooleanFieldDTO getBooleanField() { - return booleanField; + @Schema(name = "regex", required = false) + public String getRegex() { + return regex; } - public void setBooleanField(ApiBooleanFieldDTO booleanField) { - this.booleanField = booleanField; + public void setRegex(String regex) { + this.regex = regex; } - @Schema(name = "arrayField", required = false) - public ApiArrayFieldDTO getArrayField() { - return arrayField; + @Schema(name = "minItems", required = false) + public Integer getMinItems() { + return minItems; } - public void setArrayField(ApiArrayFieldDTO arrayField) { - this.arrayField = arrayField; + public void setMinItems(Integer minItems) { + this.minItems = minItems; } - @Schema(name = "numberField", required = false) - public ApiNumberFieldDTO getNumberField() { - return numberField; + @Schema(name = "values", required = false) + public List getValues() { + return values; } - public void setNumberField(ApiNumberFieldDTO numberField) { - this.numberField = numberField; + public void setValues(List values) { + this.values = values; } - @Schema(name = "objectField", required = false) - public ApiObjectFieldDTO getObjectField() { - return objectField; + @Schema(name = "minimum", required = false) + public Integer getMinimum() { + return minimum; } - public void setObjectField(ApiObjectFieldDTO objectField) { - this.objectField = objectField; + public void setMinimum(Integer minimum) { + this.minimum = minimum; } - @Schema(name = "mapField", required = false) - public ApiMapFieldDTO getMapField() { - return mapField; + @Schema(name = "numberEnum", required = false) + public NumberEnum getNumberEnum() { + return numberEnum; } - public void setMapField(ApiMapFieldDTO mapField) { - this.mapField = mapField; + public void setNumberEnum(NumberEnum numberEnum) { + this.numberEnum = numberEnum; } - @Schema(name = "unionField", required = false) - public ApiUnionFieldDTO getUnionField() { - return unionField; + @Schema(name = "valueLength", required = false) + public Integer getValueLength() { + return valueLength; } - public void setUnionField(ApiUnionFieldDTO unionField) { - this.unionField = unionField; + public void setValueLength(Integer valueLength) { + this.valueLength = valueLength; } @Override @@ -215,28 +696,49 @@ public boolean equals(Object o) { return false; } ApiDefaultItemDTO apiDefaultItemDTO = (ApiDefaultItemDTO) o; - return Objects.equals(this.stringField, apiDefaultItemDTO.stringField) && Objects.equals(this.sequenceField, apiDefaultItemDTO.sequenceField) && Objects.equals(this.dateField, apiDefaultItemDTO.dateField) && Objects.equals(this.enumField, apiDefaultItemDTO.enumField) && Objects.equals(this.booleanField, apiDefaultItemDTO.booleanField) && Objects.equals(this.arrayField, apiDefaultItemDTO.arrayField) && Objects.equals(this.numberField, apiDefaultItemDTO.numberField) && Objects.equals(this.objectField, apiDefaultItemDTO.objectField) && Objects.equals(this.mapField, apiDefaultItemDTO.mapField) && Objects.equals(this.unionField, apiDefaultItemDTO.unionField); + 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.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(stringField, sequenceField, dateField, enumField, booleanField, arrayField, numberField, objectField, mapField, unionField); + return Objects.hash(precision, maximum, type, scale, minLength, increment, 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 public String toString() { StringBuilder sb = new StringBuilder(); sb.append("class ApiDefaultItemDTO {\n"); - sb.append(" stringField: ").append(toIndentedString(stringField)).append("\n"); - sb.append(" sequenceField: ").append(toIndentedString(sequenceField)).append("\n"); - sb.append(" dateField: ").append(toIndentedString(dateField)).append("\n"); - sb.append(" enumField: ").append(toIndentedString(enumField)).append("\n"); - sb.append(" booleanField: ").append(toIndentedString(booleanField)).append("\n"); - sb.append(" arrayField: ").append(toIndentedString(arrayField)).append("\n"); - sb.append(" numberField: ").append(toIndentedString(numberField)).append("\n"); - sb.append(" objectField: ").append(toIndentedString(objectField)).append("\n"); - sb.append(" mapField: ").append(toIndentedString(mapField)).append("\n"); - sb.append(" unionField: ").append(toIndentedString(unionField)).append("\n"); + sb.append(" precision: ").append(toIndentedString(precision)).append("\n"); + sb.append(" maximum: ").append(toIndentedString(maximum)).append("\n"); + sb.append(" type: ").append(toIndentedString(type)).append("\n"); + sb.append(" scale: ").append(toIndentedString(scale)).append("\n"); + sb.append(" minLength: ").append(toIndentedString(minLength)).append("\n"); + sb.append(" increment: ").append(toIndentedString(increment)).append("\n"); + sb.append(" keyType: ").append(toIndentedString(keyType)).append("\n"); + sb.append(" requiredValues: ").append(toIndentedString(requiredValues)).append("\n"); + sb.append(" initialValue: ").append(toIndentedString(initialValue)).append("\n"); + sb.append(" flagExclusiveMinimum: ").append(toIndentedString(flagExclusiveMinimum)).append("\n"); + sb.append(" flagExclusiveMaximum: ").append(toIndentedString(flagExclusiveMaximum)).append("\n"); + sb.append(" defaultValue: ").append(toIndentedString(defaultValue)).append("\n"); + sb.append(" enumValues: ").append(toIndentedString(enumValues)).append("\n"); + sb.append(" properties: ").append(toIndentedString(properties)).append("\n"); + sb.append(" defaultValues: ").append(toIndentedString(defaultValues)).append("\n"); + sb.append(" seqEnum: ").append(toIndentedString(seqEnum)).append("\n"); + sb.append(" arraySize: ").append(toIndentedString(arraySize)).append("\n"); + sb.append(" multipleOf: ").append(toIndentedString(multipleOf)).append("\n"); + sb.append(" mapSize: ").append(toIndentedString(mapSize)).append("\n"); + sb.append(" mapTypes: ").append(toIndentedString(mapTypes)).append("\n"); + sb.append(" format: ").append(toIndentedString(format)).append("\n"); + sb.append(" maxLength: ").append(toIndentedString(maxLength)).append("\n"); + sb.append(" uniqueItems: ").append(toIndentedString(uniqueItems)).append("\n"); + sb.append(" elements: ").append(toIndentedString(elements)).append("\n"); + sb.append(" name: ").append(toIndentedString(name)).append("\n"); + sb.append(" regex: ").append(toIndentedString(regex)).append("\n"); + sb.append(" minItems: ").append(toIndentedString(minItems)).append("\n"); + sb.append(" values: ").append(toIndentedString(values)).append("\n"); + sb.append(" minimum: ").append(toIndentedString(minimum)).append("\n"); + sb.append(" numberEnum: ").append(toIndentedString(numberEnum)).append("\n"); + sb.append(" valueLength: ").append(toIndentedString(valueLength)).append("\n"); sb.append("}"); return sb.toString(); } @@ -251,25 +753,67 @@ private String toIndentedString(Object o) { private void validatePartialCombinations() { boolean satisfiedCondition = false; - if (Objects.nonNull(this.stringField)) { + if (Objects.nonNull(this.precision)) { + 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.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.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.maxLength)) { satisfiedCondition = true; - } else if (Objects.nonNull(this.sequenceField)) { + } else if (Objects.nonNull(this.uniqueItems)) { satisfiedCondition = true; - } else if (Objects.nonNull(this.dateField)) { + } else if (Objects.nonNull(this.elements)) { satisfiedCondition = true; - } else if (Objects.nonNull(this.enumField)) { + } else if (Objects.nonNull(this.name)) { satisfiedCondition = true; - } else if (Objects.nonNull(this.booleanField)) { + } else if (Objects.nonNull(this.regex)) { satisfiedCondition = true; - } else if (Objects.nonNull(this.arrayField)) { + } else if (Objects.nonNull(this.minItems)) { satisfiedCondition = true; - } else if (Objects.nonNull(this.numberField)) { + } else if (Objects.nonNull(this.values)) { satisfiedCondition = true; - } else if (Objects.nonNull(this.objectField)) { + } else if (Objects.nonNull(this.minimum)) { satisfiedCondition = true; - } else if (Objects.nonNull(this.mapField)) { + } else if (Objects.nonNull(this.numberEnum)) { satisfiedCondition = true; - } else if (Objects.nonNull(this.unionField)) { + } else if (Objects.nonNull(this.valueLength)) { satisfiedCondition = true; } @@ -278,4 +822,4 @@ private void validatePartialCombinations() { } } -} \ No newline at end of file +} 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 c3482470..14717c1e 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testComplexAnyOf/assets/ApiMapFieldDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testComplexAnyOf/assets/ApiMapFieldDTO.java @@ -6,7 +6,6 @@ import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder; import com.fasterxml.jackson.annotation.JsonProperty; import io.swagger.v3.oas.annotations.media.Schema; -import com.sngular.multifileplugin.testcomplexanyof.model.ApiTypeArrayDTO; import java.util.List; import java.util.ArrayList; 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 d2f7ea49..1865e98e 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testComplexAnyOf/assets/ApiObjectFieldDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testComplexAnyOf/assets/ApiObjectFieldDTO.java @@ -6,7 +6,6 @@ import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder; import com.fasterxml.jackson.annotation.JsonProperty; import io.swagger.v3.oas.annotations.media.Schema; -import com.sngular.multifileplugin.testcomplexanyof.model.ApiTypeArrayDTO; import java.util.List; import java.util.ArrayList; 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 0841aff1..5861d61b 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testComplexAnyOf/assets/ApiSequenceFieldDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testComplexAnyOf/assets/ApiSequenceFieldDTO.java @@ -7,7 +7,6 @@ import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonValue; import io.swagger.v3.oas.annotations.media.Schema; -import com.sngular.multifileplugin.testcomplexanyof.model.ApiTypeArrayDTO; import java.util.List; import java.util.ArrayList; 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 b58ead3a..f22078a3 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testComplexAnyOf/assets/ApiTypeArrayDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testComplexAnyOf/assets/ApiTypeArrayDTO.java @@ -26,14 +26,16 @@ public class ApiTypeArrayDTO { private Integer scale; @JsonProperty(value ="minLength") private Integer minLength; - @JsonProperty(value ="sequenceField") - private ApiSequenceFieldDTO sequenceField; + @JsonProperty(value ="increment") + private Integer increment; @JsonProperty(value ="keyType") private String keyType; @JsonProperty(value ="requiredValues") private List requiredValues = new ArrayList(); @JsonProperty(value ="optionalUnion") private Boolean optionalUnion; + @JsonProperty(value ="initialValue") + private String initialValue; @JsonProperty(value ="flagExclusiveMinimum") private Boolean flagExclusiveMinimum; @JsonProperty(value ="flagExclusiveMaximum") @@ -69,6 +71,32 @@ public String toString() { return String.valueOf(value); } } + @JsonProperty(value ="seqEnum") + private SeqEnum seqEnum; + public enum SeqEnum { + MONTH("MONTH"), + YEAR("YEAR"), + HOUR("HOUR"), + MINUTE("MINUTE"), + SECOND("SECOND"), + DAY("DAY"); + + private String value; + + SeqEnum(String value) { + this.value = value; + } + + @JsonValue + public String getValue() { + return value; + } + + @Override + public String toString() { + return String.valueOf(value); + } + } @JsonProperty(value ="arraySize") private Integer arraySize; @JsonProperty(value ="multipleOf") @@ -85,6 +113,8 @@ public String toString() { private Integer maxLength; @JsonProperty(value ="uniqueItems") private Boolean uniqueItems; + @JsonProperty(value ="elements") + private Integer elements; @JsonProperty(value ="name") private String name; @JsonProperty(value ="regex") @@ -120,17 +150,18 @@ public String toString() { @JsonProperty(value ="valueLength") private Integer valueLength; - private ApiTypeArrayDTO(Integer precision, ApiDefaultItemDTO defaultItem, Integer maximum, String type, Integer scale, Integer minLength, ApiSequenceFieldDTO sequenceField, String keyType, List requiredValues, Boolean optionalUnion, Boolean flagExclusiveMinimum, Boolean flagExclusiveMaximum, Boolean defaultValue, List enumValues, List properties, List defaultValues, UnionEnum unionEnum, Integer arraySize, Integer multipleOf, Integer mapSize, List mapTypes, Integer format, Boolean generatedFlag, Integer maxLength, Boolean uniqueItems, String name, String regex, Integer minItems, List values, Integer minimum, NumberEnum numberEnum, 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.sequenceField = sequenceField; + this.increment = increment; this.keyType = keyType; this.requiredValues = requiredValues; this.optionalUnion = optionalUnion; + this.initialValue = initialValue; this.flagExclusiveMinimum = flagExclusiveMinimum; this.flagExclusiveMaximum = flagExclusiveMaximum; this.defaultValue = defaultValue; @@ -138,6 +169,7 @@ private ApiTypeArrayDTO(Integer precision, ApiDefaultItemDTO defaultItem, Intege this.properties = properties; this.defaultValues = defaultValues; this.unionEnum = unionEnum; + this.seqEnum = seqEnum; this.arraySize = arraySize; this.multipleOf = multipleOf; this.mapSize = mapSize; @@ -146,6 +178,7 @@ private ApiTypeArrayDTO(Integer precision, ApiDefaultItemDTO defaultItem, Intege this.generatedFlag = generatedFlag; this.maxLength = maxLength; this.uniqueItems = uniqueItems; + this.elements = elements; this.name = name; this.regex = regex; this.minItems = minItems; @@ -164,10 +197,11 @@ private ApiTypeArrayDTO(ApiTypeArrayDTOBuilder builder) { this.type = builder.type; this.scale = builder.scale; this.minLength = builder.minLength; - this.sequenceField = builder.sequenceField; + this.increment = builder.increment; this.keyType = builder.keyType; this.requiredValues = builder.requiredValues; this.optionalUnion = builder.optionalUnion; + this.initialValue = builder.initialValue; this.flagExclusiveMinimum = builder.flagExclusiveMinimum; this.flagExclusiveMaximum = builder.flagExclusiveMaximum; this.defaultValue = builder.defaultValue; @@ -175,6 +209,7 @@ private ApiTypeArrayDTO(ApiTypeArrayDTOBuilder builder) { 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; @@ -183,6 +218,7 @@ private ApiTypeArrayDTO(ApiTypeArrayDTOBuilder builder) { this.generatedFlag = builder.generatedFlag; this.maxLength = builder.maxLength; this.uniqueItems = builder.uniqueItems; + this.elements = builder.elements; this.name = builder.name; this.regex = builder.regex; this.minItems = builder.minItems; @@ -207,10 +243,11 @@ public static class ApiTypeArrayDTOBuilder { private String type; private Integer scale; private Integer minLength; - private ApiSequenceFieldDTO sequenceField; + private Integer increment; private String keyType; private List requiredValues = new ArrayList(); private Boolean optionalUnion; + private String initialValue; private Boolean flagExclusiveMinimum; private Boolean flagExclusiveMaximum; private Boolean defaultValue; @@ -218,6 +255,7 @@ public static class ApiTypeArrayDTOBuilder { 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; @@ -226,6 +264,7 @@ public static class ApiTypeArrayDTOBuilder { private Boolean generatedFlag; private Integer maxLength; private Boolean uniqueItems; + private Integer elements; private String name; private String regex; private Integer minItems; @@ -263,8 +302,9 @@ public ApiTypeArrayDTO.ApiTypeArrayDTOBuilder minLength(Integer minLength) { this.minLength = minLength; return this; } - public ApiTypeArrayDTO.ApiTypeArrayDTOBuilder sequenceField(ApiSequenceFieldDTO sequenceField) { - this.sequenceField = sequenceField; + + public ApiTypeArrayDTO.ApiTypeArrayDTOBuilder increment(Integer increment) { + this.increment = increment; return this; } @@ -291,6 +331,11 @@ public ApiTypeArrayDTO.ApiTypeArrayDTOBuilder optionalUnion(Boolean optionalUnio return this; } + public ApiTypeArrayDTO.ApiTypeArrayDTOBuilder initialValue(String initialValue) { + this.initialValue = initialValue; + return this; + } + public ApiTypeArrayDTO.ApiTypeArrayDTOBuilder flagExclusiveMinimum(Boolean flagExclusiveMinimum) { this.flagExclusiveMinimum = flagExclusiveMinimum; return this; @@ -348,6 +393,10 @@ public ApiTypeArrayDTO.ApiTypeArrayDTOBuilder unionEnum(UnionEnum unionEnum) { this.unionEnum = unionEnum; return this; } + public ApiTypeArrayDTO.ApiTypeArrayDTOBuilder seqEnum(SeqEnum seqEnum) { + this.seqEnum = seqEnum; + return this; + } public ApiTypeArrayDTO.ApiTypeArrayDTOBuilder arraySize(Integer arraySize) { this.arraySize = arraySize; @@ -397,6 +446,11 @@ public ApiTypeArrayDTO.ApiTypeArrayDTOBuilder uniqueItems(Boolean uniqueItems) { return this; } + public ApiTypeArrayDTO.ApiTypeArrayDTOBuilder elements(Integer elements) { + this.elements = elements; + return this; + } + public ApiTypeArrayDTO.ApiTypeArrayDTOBuilder name(String name) { this.name = name; return this; @@ -493,12 +547,12 @@ public void setMinLength(Integer minLength) { this.minLength = minLength; } - @Schema(name = "sequenceField", required = false) - public ApiSequenceFieldDTO getSequenceField() { - return sequenceField; + @Schema(name = "increment", required = false) + public Integer getIncrement() { + return increment; } - public void setSequenceField(ApiSequenceFieldDTO sequenceField) { - this.sequenceField = sequenceField; + public void setIncrement(Integer increment) { + this.increment = increment; } @Schema(name = "keyType", required = false) @@ -525,6 +579,14 @@ public void setOptionalUnion(Boolean optionalUnion) { this.optionalUnion = optionalUnion; } + @Schema(name = "initialValue", required = false) + public String getInitialValue() { + return initialValue; + } + public void setInitialValue(String initialValue) { + this.initialValue = initialValue; + } + @Schema(name = "flagExclusiveMinimum", required = false) public Boolean getFlagExclusiveMinimum() { return flagExclusiveMinimum; @@ -581,6 +643,14 @@ public void setUnionEnum(UnionEnum unionEnum) { this.unionEnum = unionEnum; } + @Schema(name = "seqEnum", required = false) + public SeqEnum getSeqEnum() { + return seqEnum; + } + public void setSeqEnum(SeqEnum seqEnum) { + this.seqEnum = seqEnum; + } + @Schema(name = "arraySize", required = false) public Integer getArraySize() { return arraySize; @@ -645,6 +715,14 @@ public void setUniqueItems(Boolean uniqueItems) { this.uniqueItems = uniqueItems; } + @Schema(name = "elements", required = false) + public Integer getElements() { + return elements; + } + public void setElements(Integer elements) { + this.elements = elements; + } + @Schema(name = "name", required = false) public String getName() { return name; @@ -710,12 +788,12 @@ public boolean equals(Object o) { return false; } ApiTypeArrayDTO apiTypeArrayDTO = (ApiTypeArrayDTO) o; - return Objects.equals(this.precision, apiTypeArrayDTO.precision) && Objects.equals(this.defaultItem, apiTypeArrayDTO.defaultItem) && Objects.equals(this.maximum, apiTypeArrayDTO.maximum) && Objects.equals(this.type, apiTypeArrayDTO.type) && Objects.equals(this.scale, apiTypeArrayDTO.scale) && Objects.equals(this.minLength, apiTypeArrayDTO.minLength) && Objects.equals(this.sequenceField, apiTypeArrayDTO.sequenceField) && Objects.equals(this.keyType, apiTypeArrayDTO.keyType) && Objects.equals(this.requiredValues, apiTypeArrayDTO.requiredValues) && Objects.equals(this.optionalUnion, apiTypeArrayDTO.optionalUnion) && Objects.equals(this.flagExclusiveMinimum, apiTypeArrayDTO.flagExclusiveMinimum) && Objects.equals(this.flagExclusiveMaximum, apiTypeArrayDTO.flagExclusiveMaximum) && Objects.equals(this.defaultValue, apiTypeArrayDTO.defaultValue) && Objects.equals(this.enumValues, apiTypeArrayDTO.enumValues) && Objects.equals(this.properties, apiTypeArrayDTO.properties) && Objects.equals(this.defaultValues, apiTypeArrayDTO.defaultValues) && Objects.equals(this.unionEnum, apiTypeArrayDTO.unionEnum) && Objects.equals(this.arraySize, apiTypeArrayDTO.arraySize) && Objects.equals(this.multipleOf, apiTypeArrayDTO.multipleOf) && Objects.equals(this.mapSize, apiTypeArrayDTO.mapSize) && Objects.equals(this.mapTypes, apiTypeArrayDTO.mapTypes) && Objects.equals(this.format, apiTypeArrayDTO.format) && Objects.equals(this.generatedFlag, apiTypeArrayDTO.generatedFlag) && Objects.equals(this.maxLength, apiTypeArrayDTO.maxLength) && Objects.equals(this.uniqueItems, apiTypeArrayDTO.uniqueItems) && Objects.equals(this.name, apiTypeArrayDTO.name) && Objects.equals(this.regex, apiTypeArrayDTO.regex) && Objects.equals(this.minItems, apiTypeArrayDTO.minItems) && Objects.equals(this.values, apiTypeArrayDTO.values) && Objects.equals(this.minimum, apiTypeArrayDTO.minimum) && Objects.equals(this.numberEnum, apiTypeArrayDTO.numberEnum) && Objects.equals(this.valueLength, apiTypeArrayDTO.valueLength); + return Objects.equals(this.precision, apiTypeArrayDTO.precision) && Objects.equals(this.defaultItem, apiTypeArrayDTO.defaultItem) && Objects.equals(this.maximum, apiTypeArrayDTO.maximum) && Objects.equals(this.type, apiTypeArrayDTO.type) && Objects.equals(this.scale, apiTypeArrayDTO.scale) && Objects.equals(this.minLength, apiTypeArrayDTO.minLength) && Objects.equals(this.increment, apiTypeArrayDTO.increment) && Objects.equals(this.keyType, apiTypeArrayDTO.keyType) && Objects.equals(this.requiredValues, apiTypeArrayDTO.requiredValues) && Objects.equals(this.optionalUnion, apiTypeArrayDTO.optionalUnion) && Objects.equals(this.initialValue, apiTypeArrayDTO.initialValue) && Objects.equals(this.flagExclusiveMinimum, apiTypeArrayDTO.flagExclusiveMinimum) && Objects.equals(this.flagExclusiveMaximum, apiTypeArrayDTO.flagExclusiveMaximum) && Objects.equals(this.defaultValue, apiTypeArrayDTO.defaultValue) && Objects.equals(this.enumValues, apiTypeArrayDTO.enumValues) && Objects.equals(this.properties, apiTypeArrayDTO.properties) && Objects.equals(this.defaultValues, apiTypeArrayDTO.defaultValues) && Objects.equals(this.unionEnum, apiTypeArrayDTO.unionEnum) && Objects.equals(this.seqEnum, apiTypeArrayDTO.seqEnum) && Objects.equals(this.arraySize, apiTypeArrayDTO.arraySize) && Objects.equals(this.multipleOf, apiTypeArrayDTO.multipleOf) && Objects.equals(this.mapSize, apiTypeArrayDTO.mapSize) && Objects.equals(this.mapTypes, apiTypeArrayDTO.mapTypes) && Objects.equals(this.format, apiTypeArrayDTO.format) && Objects.equals(this.generatedFlag, apiTypeArrayDTO.generatedFlag) && Objects.equals(this.maxLength, apiTypeArrayDTO.maxLength) && Objects.equals(this.uniqueItems, apiTypeArrayDTO.uniqueItems) && Objects.equals(this.elements, apiTypeArrayDTO.elements) && Objects.equals(this.name, apiTypeArrayDTO.name) && Objects.equals(this.regex, apiTypeArrayDTO.regex) && Objects.equals(this.minItems, apiTypeArrayDTO.minItems) && Objects.equals(this.values, apiTypeArrayDTO.values) && Objects.equals(this.minimum, apiTypeArrayDTO.minimum) && Objects.equals(this.numberEnum, apiTypeArrayDTO.numberEnum) && Objects.equals(this.valueLength, apiTypeArrayDTO.valueLength); } @Override public int hashCode() { - return Objects.hash(precision, defaultItem, maximum, type, scale, minLength, sequenceField, keyType, requiredValues, optionalUnion, flagExclusiveMinimum, flagExclusiveMaximum, defaultValue, enumValues, properties, defaultValues, unionEnum, arraySize, multipleOf, mapSize, mapTypes, format, generatedFlag, maxLength, uniqueItems, name, regex, minItems, values, minimum, numberEnum, valueLength); + 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); } @Override @@ -728,10 +806,11 @@ public String toString() { sb.append(" type: ").append(toIndentedString(type)).append("\n"); sb.append(" scale: ").append(toIndentedString(scale)).append("\n"); sb.append(" minLength: ").append(toIndentedString(minLength)).append("\n"); - sb.append(" sequenceField: ").append(toIndentedString(sequenceField)).append("\n"); + sb.append(" increment: ").append(toIndentedString(increment)).append("\n"); sb.append(" keyType: ").append(toIndentedString(keyType)).append("\n"); sb.append(" requiredValues: ").append(toIndentedString(requiredValues)).append("\n"); sb.append(" optionalUnion: ").append(toIndentedString(optionalUnion)).append("\n"); + sb.append(" initialValue: ").append(toIndentedString(initialValue)).append("\n"); sb.append(" flagExclusiveMinimum: ").append(toIndentedString(flagExclusiveMinimum)).append("\n"); sb.append(" flagExclusiveMaximum: ").append(toIndentedString(flagExclusiveMaximum)).append("\n"); sb.append(" defaultValue: ").append(toIndentedString(defaultValue)).append("\n"); @@ -739,6 +818,7 @@ public String toString() { sb.append(" properties: ").append(toIndentedString(properties)).append("\n"); sb.append(" defaultValues: ").append(toIndentedString(defaultValues)).append("\n"); sb.append(" unionEnum: ").append(toIndentedString(unionEnum)).append("\n"); + sb.append(" seqEnum: ").append(toIndentedString(seqEnum)).append("\n"); sb.append(" arraySize: ").append(toIndentedString(arraySize)).append("\n"); sb.append(" multipleOf: ").append(toIndentedString(multipleOf)).append("\n"); sb.append(" mapSize: ").append(toIndentedString(mapSize)).append("\n"); @@ -747,6 +827,7 @@ public String toString() { sb.append(" generatedFlag: ").append(toIndentedString(generatedFlag)).append("\n"); sb.append(" maxLength: ").append(toIndentedString(maxLength)).append("\n"); sb.append(" uniqueItems: ").append(toIndentedString(uniqueItems)).append("\n"); + sb.append(" elements: ").append(toIndentedString(elements)).append("\n"); sb.append(" name: ").append(toIndentedString(name)).append("\n"); sb.append(" regex: ").append(toIndentedString(regex)).append("\n"); sb.append(" minItems: ").append(toIndentedString(minItems)).append("\n"); @@ -780,7 +861,7 @@ private void validatePartialCombinations() { satisfiedCondition = true; } else if (Objects.nonNull(this.minLength)) { satisfiedCondition = true; - } else if (Objects.nonNull(this.sequenceField)) { + } else if (Objects.nonNull(this.increment)) { satisfiedCondition = true; } else if (Objects.nonNull(this.keyType)) { satisfiedCondition = true; @@ -788,6 +869,8 @@ private void validatePartialCombinations() { 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)) { @@ -802,6 +885,8 @@ private void validatePartialCombinations() { 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)) { @@ -818,6 +903,8 @@ private void validatePartialCombinations() { 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)) { 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 2f5b4164..1265f35b 100644 --- a/multiapi-engine/src/test/resources/openapigenerator/testComplexAnyOf/assets/ApiUnionFieldDTO.java +++ b/multiapi-engine/src/test/resources/openapigenerator/testComplexAnyOf/assets/ApiUnionFieldDTO.java @@ -7,7 +7,6 @@ import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonValue; import io.swagger.v3.oas.annotations.media.Schema; -import com.sngular.multifileplugin.testcomplexanyof.model.ApiTypeArrayDTO; import java.util.List; import java.util.ArrayList; diff --git a/multiapi-engine/src/test/resources/openapigenerator/testRestrictionsSchema/api-rest.yaml b/multiapi-engine/src/test/resources/openapigenerator/testRestrictionsSchema/api-rest.yaml new file mode 100644 index 00000000..ce0063f5 --- /dev/null +++ b/multiapi-engine/src/test/resources/openapigenerator/testRestrictionsSchema/api-rest.yaml @@ -0,0 +1,208 @@ +openapi: 3.0.2 +info: + title: Schema Restriction Management + version: 2.0.0 +servers: + - url: https://localhost/v1 +paths: + /schema: + post: + tags: + - SchemaRestriction + operationId: createSchemaRestriction + requestBody: + required: true + content: + application/json: + schema: + $ref: 'schema-restriction/components.yml#/components/schemas/Schema' + responses: + '200': + description: OK + content: + application/json: + schema: + $ref: 'schema-restriction/components.yml#/components/schemas/Schema' + '400': + description: Bad Request + '500': + description: Server Error + /schema/{name}: + get: + tags: + - SchemaRestriction + operationId: getSchemaRestrictionByName + parameters: + - name: name + in: path + description: Schema name to get + required: true + schema: + type: string + responses: + '200': + description: OK + content: + application/json: + schema: + $ref: 'schema-restriction/components.yml#/components/schemas/Schema' + '400': + description: Bad Request + '404': + description: Not Found + '500': + description: Server Error + put: + tags: + - SchemaRestriction + operationId: updateSchemaRestrictionByName + parameters: + - name: name + in: path + description: Schema name to update + required: true + schema: + type: string + requestBody: + required: true + content: + application/json: + schema: + $ref: 'schema-restriction/components.yml#/components/schemas/Schema' + responses: + '200': + description: OK + content: + application/json: + schema: + $ref: 'schema-restriction/components.yml#/components/schemas/Schema' + '400': + description: Bad Request + '404': + description: Not Found + '500': + description: Server Error + /schema/{id}: + delete: + tags: + - SchemaRestriction + operationId: deleteSchemaRestrictionById + parameters: + - name: id + in: path + description: Subject name to delete + required: true + schema: + type: string + responses: + '200': + description: OK + '400': + description: Bad Request + '404': + description: Not Found + '500': + description: Server Error + /schemas: + get: + tags: + - SchemasRestrictions + operationId: getAllSchemaRestriction + responses: + '200': + description: OK + content: + application/json: + schema: + type: array + items: + $ref: 'schema-restriction/components.yml#/components/schemas/Schema' + '400': + description: Bad Request + '404': + description: Not Found + '500': + description: Server Error + delete: + tags: + - SchemasRestrictions + operationId: deleteAllSchemaRestriction + responses: + '200': + description: OK + '400': + description: Bad Request + '404': + description: Not Found + '500': + description: Server Error + /schema-master/{subject}: + get: + tags: + - SchemaMaster + operationId: getSchemaMaster + parameters: + - name: subject + in: path + description: Retrieve the schema of the Schema Registry, not the Schema Restriction + required: true + schema: + type: string + responses: + '200': + description: OK + content: + application/json: + schema: + $ref: 'schema-restriction/components.yml#/components/schemas/Schema' + '400': + description: Bad Request + '500': + description: Server Error + /schema-master/{schemaType}: + post: + tags: + - SchemaMaster + operationId: createSchemaMaster + parameters: + - name: schemaType + in: path + description: The schema which you need create in the schema registry + required: true + schema: + type: string + requestBody: + required: true + content: + application/json: + schema: + $ref: 'schema-restriction/components.yml#/components/schemas/Schema' + responses: + '200': + description: OK + content: + application/json: + schema: + $ref: 'schema-restriction/components.yml#/components/schemas/Schema' + '400': + description: Bad Request + '500': + description: Server Error + /schemas/names: + get: + tags: + - SchemaMaster + operationId: getAllSchemaNames + responses: + '200': + description: OK + content: + application/json: + schema: + $ref: 'schema-restriction/components.yml#/components/schemas/arrayNames' + '400': + description: Bad Request + '404': + description: Not Found + '500': + description: Server Error diff --git a/multiapi-engine/src/test/resources/openapigenerator/testRestrictionsSchema/assets/SchemaApi.java b/multiapi-engine/src/test/resources/openapigenerator/testRestrictionsSchema/assets/SchemaApi.java new file mode 100644 index 00000000..548b67f3 --- /dev/null +++ b/multiapi-engine/src/test/resources/openapigenerator/testRestrictionsSchema/assets/SchemaApi.java @@ -0,0 +1,124 @@ +package com.sngular.multifileplugin.testRestrictionsSchema; + +import java.util.Optional; +import java.util.List; +import java.util.Map; +import javax.validation.Valid; + +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.media.Schema; +import io.swagger.v3.oas.annotations.responses.ApiResponse; +import org.springframework.http.MediaType; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.*; +import org.springframework.web.context.request.NativeWebRequest; + +import com.sngular.multifileplugin.testRestrictionsSchema.model.SchemaDTO; + +public interface SchemaApi { + + /** + * GET /schema/{name} + * @param name Schema name to get true + * @return OK; (status code 200) Bad Request; (status code 400) Not Found; (status code 404) Server Error; (status code 500) + */ + + @Operation( + operationId = "getSchemaRestrictionByName", + tags = {"SchemaRestriction"}, + responses = { + @ApiResponse(responseCode = "200", description = "OK", content = @Content(mediaType = "application/json", schema = @Schema(implementation = SchemaDTO.class))), + @ApiResponse(responseCode = "400", description = "Bad Request"), + @ApiResponse(responseCode = "404", description = "Not Found"), + @ApiResponse(responseCode = "500", description = "Server Error") + } + ) + @RequestMapping( + method = RequestMethod.GET, + value = "/schema/{name}", + produces = {"application/json"} + ) + + default ResponseEntity getSchemaRestrictionByName(@Parameter(name = "name", description = "Schema name to get", required = true, schema = @Schema(description = "")) @PathVariable("name") String name) { + return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); + } + /** + * PUT /schema/{name} + * @param name Schema name to update true + * @param schemaDTO (required) + * @return OK; (status code 200) Bad Request; (status code 400) Not Found; (status code 404) Server Error; (status code 500) + */ + + @Operation( + operationId = "updateSchemaRestrictionByName", + tags = {"SchemaRestriction"}, + responses = { + @ApiResponse(responseCode = "200", description = "OK", content = @Content(mediaType = "application/json", schema = @Schema(implementation = SchemaDTO.class))), + @ApiResponse(responseCode = "400", description = "Bad Request"), + @ApiResponse(responseCode = "404", description = "Not Found"), + @ApiResponse(responseCode = "500", description = "Server Error") + } + ) + @RequestMapping( + method = RequestMethod.PUT, + value = "/schema/{name}", + produces = {"application/json"} + ) + + default ResponseEntity updateSchemaRestrictionByName(@Parameter(name = "name", description = "Schema name to update", required = true, schema = @Schema(description = "")) @PathVariable("name") String name , @Parameter(name = "schemaDTO", description = "", required = true, schema = @Schema(description = "")) @Valid @RequestBody SchemaDTO schemaDTO) { + return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); + } + /** + * POST /schema + * @param schemaDTO (required) + * @return OK; (status code 200) Bad Request; (status code 400) Server Error; (status code 500) + */ + + @Operation( + operationId = "createSchemaRestriction", + tags = {"SchemaRestriction"}, + responses = { + @ApiResponse(responseCode = "200", description = "OK", content = @Content(mediaType = "application/json", schema = @Schema(implementation = SchemaDTO.class))), + @ApiResponse(responseCode = "400", description = "Bad Request"), + @ApiResponse(responseCode = "500", description = "Server Error") + } + ) + @RequestMapping( + method = RequestMethod.POST, + value = "/schema", + produces = {"application/json"} + ) + + default ResponseEntity createSchemaRestriction(@Parameter(name = "schemaDTO", description = "", required = true, schema = @Schema(description = "")) @Valid @RequestBody SchemaDTO schemaDTO) { + return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); + } + /** + * DELETE /schema/{id} + * @param id Subject name to delete true + * @return OK; (status code 200) Bad Request; (status code 400) Not Found; (status code 404) Server Error; (status code 500) + */ + + @Operation( + operationId = "deleteSchemaRestrictionById", + tags = {"SchemaRestriction"}, + responses = { + @ApiResponse(responseCode = "200", description = "OK"), + @ApiResponse(responseCode = "400", description = "Bad Request"), + @ApiResponse(responseCode = "404", description = "Not Found"), + @ApiResponse(responseCode = "500", description = "Server Error") + } + ) + @RequestMapping( + method = RequestMethod.DELETE, + value = "/schema/{id}", + produces = {"application/json"} + ) + + default ResponseEntity deleteSchemaRestrictionById(@Parameter(name = "id", description = "Subject name to delete", required = true, schema = @Schema(description = "")) @PathVariable("id") String id) { + return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); + } + +} diff --git a/multiapi-engine/src/test/resources/openapigenerator/testRestrictionsSchema/assets/SchemaMasterApi.java b/multiapi-engine/src/test/resources/openapigenerator/testRestrictionsSchema/assets/SchemaMasterApi.java new file mode 100644 index 00000000..3f92fd06 --- /dev/null +++ b/multiapi-engine/src/test/resources/openapigenerator/testRestrictionsSchema/assets/SchemaMasterApi.java @@ -0,0 +1,73 @@ +package com.sngular.multifileplugin.testRestrictionsSchema; + +import java.util.Optional; +import java.util.List; +import java.util.Map; +import javax.validation.Valid; + +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.media.Schema; +import io.swagger.v3.oas.annotations.responses.ApiResponse; +import org.springframework.http.MediaType; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.*; +import org.springframework.web.context.request.NativeWebRequest; + +import com.sngular.multifileplugin.testRestrictionsSchema.model.SchemaDTO; + +public interface SchemaMasterApi { + + /** + * GET /schema-master/{subject} + * @param subject Retrieve the schema of the Schema Registry, not the Schema Restriction true + * @return OK; (status code 200) Bad Request; (status code 400) Server Error; (status code 500) + */ + + @Operation( + operationId = "getSchemaMaster", + tags = {"SchemaMaster"}, + responses = { + @ApiResponse(responseCode = "200", description = "OK", content = @Content(mediaType = "application/json", schema = @Schema(implementation = SchemaDTO.class))), + @ApiResponse(responseCode = "400", description = "Bad Request"), + @ApiResponse(responseCode = "500", description = "Server Error") + } + ) + @RequestMapping( + method = RequestMethod.GET, + value = "/schema-master/{subject}", + produces = {"application/json"} + ) + + default ResponseEntity getSchemaMaster(@Parameter(name = "subject", description = "Retrieve the schema of the Schema Registry, not the Schema Restriction", required = true, schema = @Schema(description = "")) @PathVariable("subject") String subject) { + return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); + } + /** + * POST /schema-master/{schemaType} + * @param schemaType The schema which you need create in the schema registry true + * @param schemaDTO (required) + * @return OK; (status code 200) Bad Request; (status code 400) Server Error; (status code 500) + */ + + @Operation( + operationId = "createSchemaMaster", + tags = {"SchemaMaster"}, + responses = { + @ApiResponse(responseCode = "200", description = "OK", content = @Content(mediaType = "application/json", schema = @Schema(implementation = SchemaDTO.class))), + @ApiResponse(responseCode = "400", description = "Bad Request"), + @ApiResponse(responseCode = "500", description = "Server Error") + } + ) + @RequestMapping( + method = RequestMethod.POST, + value = "/schema-master/{schemaType}", + produces = {"application/json"} + ) + + default ResponseEntity createSchemaMaster(@Parameter(name = "schemaType", description = "The schema which you need create in the schema registry", required = true, schema = @Schema(description = "")) @PathVariable("schemaType") String schemaType , @Parameter(name = "schemaDTO", description = "", required = true, schema = @Schema(description = "")) @Valid @RequestBody SchemaDTO schemaDTO) { + return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); + } + +} diff --git a/multiapi-engine/src/test/resources/openapigenerator/testRestrictionsSchema/assets/SchemasApi.java b/multiapi-engine/src/test/resources/openapigenerator/testRestrictionsSchema/assets/SchemasApi.java new file mode 100644 index 00000000..db523553 --- /dev/null +++ b/multiapi-engine/src/test/resources/openapigenerator/testRestrictionsSchema/assets/SchemasApi.java @@ -0,0 +1,96 @@ +package com.sngular.multifileplugin.testRestrictionsSchema; + +import java.util.Optional; +import java.util.List; +import java.util.Map; +import javax.validation.Valid; + +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.media.Schema; +import io.swagger.v3.oas.annotations.responses.ApiResponse; +import org.springframework.http.MediaType; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.*; +import org.springframework.web.context.request.NativeWebRequest; + +import com.sngular.multifileplugin.testRestrictionsSchema.model.SchemaDTO; + +public interface SchemasApi { + + /** + * GET /schemas/names + * @return OK; (status code 200) Bad Request; (status code 400) Not Found; (status code 404) Server Error; (status code 500) + */ + + @Operation( + operationId = "getAllSchemaNames", + tags = {"SchemaMaster"}, + responses = { + @ApiResponse(responseCode = "200", description = "OK", content = @Content(mediaType = "application/json", schema = @Schema(implementation = List.class))), + @ApiResponse(responseCode = "400", description = "Bad Request"), + @ApiResponse(responseCode = "404", description = "Not Found"), + @ApiResponse(responseCode = "500", description = "Server Error") + } + ) + @RequestMapping( + method = RequestMethod.GET, + value = "/schemas/names", + produces = {"application/json"} + ) + + default ResponseEntity> getAllSchemaNames() { + return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); + } + /** + * GET /schemas + * @return OK; (status code 200) Bad Request; (status code 400) Not Found; (status code 404) Server Error; (status code 500) + */ + + @Operation( + operationId = "getAllSchemaRestriction", + tags = {"SchemasRestrictions"}, + responses = { + @ApiResponse(responseCode = "200", description = "OK", content = @Content(mediaType = "application/json", schema = @Schema(implementation = List.class))), + @ApiResponse(responseCode = "400", description = "Bad Request"), + @ApiResponse(responseCode = "404", description = "Not Found"), + @ApiResponse(responseCode = "500", description = "Server Error") + } + ) + @RequestMapping( + method = RequestMethod.GET, + value = "/schemas", + produces = {"application/json"} + ) + + default ResponseEntity> getAllSchemaRestriction() { + return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); + } + /** + * DELETE /schemas + * @return OK; (status code 200) Bad Request; (status code 400) Not Found; (status code 404) Server Error; (status code 500) + */ + + @Operation( + operationId = "deleteAllSchemaRestriction", + tags = {"SchemasRestrictions"}, + responses = { + @ApiResponse(responseCode = "200", description = "OK"), + @ApiResponse(responseCode = "400", description = "Bad Request"), + @ApiResponse(responseCode = "404", description = "Not Found"), + @ApiResponse(responseCode = "500", description = "Server Error") + } + ) + @RequestMapping( + method = RequestMethod.DELETE, + value = "/schemas", + produces = {"application/json"} + ) + + default ResponseEntity deleteAllSchemaRestriction() { + return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); + } + +} diff --git a/multiapi-engine/src/test/resources/openapigenerator/testRestrictionsSchema/assets/exception/ModelClassException.java b/multiapi-engine/src/test/resources/openapigenerator/testRestrictionsSchema/assets/exception/ModelClassException.java new file mode 100644 index 00000000..a34be121 --- /dev/null +++ b/multiapi-engine/src/test/resources/openapigenerator/testRestrictionsSchema/assets/exception/ModelClassException.java @@ -0,0 +1,10 @@ +package com.sngular.multifileplugin.testRestrictionsSchema.model.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/test/resources/openapigenerator/testRestrictionsSchema/assets/model/ArrayFieldDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testRestrictionsSchema/assets/model/ArrayFieldDTO.java new file mode 100644 index 00000000..87dd58a7 --- /dev/null +++ b/multiapi-engine/src/test/resources/openapigenerator/testRestrictionsSchema/assets/model/ArrayFieldDTO.java @@ -0,0 +1,56 @@ +package com.sngular.multifileplugin.testRestrictionsSchema.model; + +import com.fasterxml.jackson.annotation.JsonProperty; +import java.util.List; +import java.util.ArrayList; +import lombok.Builder; +import lombok.Data; +import lombok.extern.jackson.Jacksonized; + +@Data +public class ArrayFieldDTO { + + @JsonProperty(value ="mandatory") + private Boolean mandatory; + + @JsonProperty(value ="uniqueItems") + private Boolean uniqueItems; + + @JsonProperty(value ="type") + private String type; + + @JsonProperty(value ="name") + private String name; + + @JsonProperty(value ="arraySize") + private Integer arraySize; + + @JsonProperty(value ="regex") + private String regex; + + @JsonProperty(value ="minItems") + private Integer minItems; + + @JsonProperty(value ="values") + private List values = new ArrayList(); + + @JsonProperty(value ="defaultValue") + private List defaultValue = new ArrayList(); + + + @Builder + @Jacksonized + private ArrayFieldDTO(Boolean mandatory, Boolean uniqueItems, String type, String name, Integer arraySize, String regex, Integer minItems, List values, List defaultValue) { + this.mandatory = mandatory; + this.uniqueItems = uniqueItems; + this.type = type; + this.name = name; + this.arraySize = arraySize; + this.regex = regex; + this.minItems = minItems; + this.values = values; + this.defaultValue = defaultValue; + + } + +} 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 new file mode 100644 index 00000000..b90e0d6a --- /dev/null +++ b/multiapi-engine/src/test/resources/openapigenerator/testRestrictionsSchema/assets/model/BooleanFieldDTO.java @@ -0,0 +1,34 @@ +package com.sngular.multifileplugin.testRestrictionsSchema.model; + +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.Builder; +import lombok.Data; +import lombok.extern.jackson.Jacksonized; + +@Data +public class BooleanFieldDTO { + + @JsonProperty(value ="mandatory") + private Boolean mandatory; + + @JsonProperty(value ="type") + private String type; + + @JsonProperty(value ="name") + private String name; + + @JsonProperty(value ="defaultValue") + private Boolean defaultValue; + + + @Builder + @Jacksonized + private BooleanFieldDTO(Boolean mandatory, String type, String name, Boolean defaultValue) { + this.mandatory = mandatory; + this.type = type; + this.name = name; + this.defaultValue = defaultValue; + + } + +} 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 new file mode 100644 index 00000000..feae2e9a --- /dev/null +++ b/multiapi-engine/src/test/resources/openapigenerator/testRestrictionsSchema/assets/model/DateFieldDTO.java @@ -0,0 +1,38 @@ +package com.sngular.multifileplugin.testRestrictionsSchema.model; + +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.Builder; +import lombok.Data; +import lombok.extern.jackson.Jacksonized; + +@Data +public class DateFieldDTO { + + @JsonProperty(value ="mandatory") + private Boolean mandatory; + + @JsonProperty(value ="type") + private String type; + + @JsonProperty(value ="name") + private String name; + + @JsonProperty(value ="defaultValue") + private String defaultValue; + + @JsonProperty(value ="format") + private String format; + + + @Builder + @Jacksonized + private DateFieldDTO(Boolean mandatory, String type, String name, String defaultValue, String format) { + this.mandatory = mandatory; + this.type = type; + this.name = name; + this.defaultValue = defaultValue; + this.format = format; + + } + +} 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 new file mode 100644 index 00000000..677520e4 --- /dev/null +++ b/multiapi-engine/src/test/resources/openapigenerator/testRestrictionsSchema/assets/model/EnumFieldDTO.java @@ -0,0 +1,40 @@ +package com.sngular.multifileplugin.testRestrictionsSchema.model; + +import com.fasterxml.jackson.annotation.JsonProperty; +import java.util.List; +import java.util.ArrayList; +import lombok.Builder; +import lombok.Data; +import lombok.extern.jackson.Jacksonized; + +@Data +public class EnumFieldDTO { + + @JsonProperty(value ="mandatory") + private Boolean mandatory; + + @JsonProperty(value ="enumValues") + private List enumValues = new ArrayList(); + + @JsonProperty(value ="type") + private String type; + + @JsonProperty(value ="name") + private String name; + + @JsonProperty(value ="defaultValue") + private String defaultValue; + + + @Builder + @Jacksonized + private EnumFieldDTO(Boolean mandatory, List enumValues, String type, String name, String defaultValue) { + this.mandatory = mandatory; + this.enumValues = enumValues; + this.type = type; + this.name = name; + this.defaultValue = defaultValue; + + } + +} 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 new file mode 100644 index 00000000..42117e85 --- /dev/null +++ b/multiapi-engine/src/test/resources/openapigenerator/testRestrictionsSchema/assets/model/FieldDTO.java @@ -0,0 +1,57 @@ +package com.sngular.multifileplugin.testRestrictionsSchema.model; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; +import lombok.Builder; +import lombok.Data; +import lombok.extern.jackson.Jacksonized; + +@Data +public class FieldDTO { + + @JsonProperty(value ="typeField") + private TypeField typeField; + + public enum TypeField { + MAPFIELD("MapField"), + STRINGFIELD("StringField"), + ARRAYFIELD("ArrayField"), + BOOLEANFIELD("BooleanField"), + UUIDFIELD("UUIDField"), + ENUMFIELD("EnumField"), + NUMBERFIELD("NumberField"), + OBJECTFIELD("ObjectField"), + DATEFIELD("DateField"), + SEQUENCEFIELD("SequenceField"), + UNIONFIELD("UnionField"); + + private String value; + + TypeField(String value) { + this.value = value; + } + + @JsonValue + public String getValue() { + return value; + } + + @Override + public String toString() { + return String.valueOf(value); + } + } + + @JsonProperty(value ="fieldValue") + private FieldValueDTO fieldValue; + + + @Builder + @Jacksonized + private FieldDTO(TypeField typeField, FieldValueDTO fieldValue) { + this.typeField = typeField; + this.fieldValue = fieldValue; + + } + +} 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 new file mode 100644 index 00000000..b8ace51c --- /dev/null +++ b/multiapi-engine/src/test/resources/openapigenerator/testRestrictionsSchema/assets/model/FieldValueDTO.java @@ -0,0 +1,321 @@ +package com.sngular.multifileplugin.testRestrictionsSchema.model; + +import java.util.Objects; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; +import java.util.List; +import java.util.ArrayList; +import lombok.Builder; +import lombok.Data; +import lombok.extern.jackson.Jacksonized; +import com.sngular.multifileplugin.testRestrictionsSchema.model.exception.ModelClassException; + +@Data +public class FieldValueDTO { + + @JsonProperty(value ="mandatory") + private Boolean mandatory; + + @JsonProperty(value ="precision") + private Integer precision; + + @JsonProperty(value ="defaultItem") + private FieldDTO defaultItem; + + @JsonProperty(value ="maximum") + private Integer maximum; + + @JsonProperty(value ="type") + private String type; + + @JsonProperty(value ="scale") + private Integer scale; + + @JsonProperty(value ="minLength") + private Integer minLength; + + @JsonProperty(value ="increment") + private Integer increment; + + @JsonProperty(value ="keyType") + private String keyType; + + @JsonProperty(value ="requiredValues") + private List requiredValues = new ArrayList(); + + @JsonProperty(value ="optionalUnion") + private Boolean optionalUnion; + + @JsonProperty(value ="initialValue") + private FieldDTO initialValue; + + @JsonProperty(value ="flagExclusiveMinimum") + private Boolean flagExclusiveMinimum; + + @JsonProperty(value ="flagExclusiveMaximum") + private Boolean flagExclusiveMaximum; + + @JsonProperty(value ="defaultValue") + private String defaultValue; + + @JsonProperty(value ="property") + private FieldDTO property; + + @JsonProperty(value ="enumValues") + private List enumValues = new ArrayList(); + + @JsonProperty(value ="properties") + private List properties = new ArrayList(); + + @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 { + MONTH("MONTH"), + YEAR("YEAR"), + HOUR("HOUR"), + MINUTE("MINUTE"), + SECOND("SECOND"), + DAY("DAY"); + + private String value; + + SeqEnum(String value) { + this.value = value; + } + + @JsonValue + public String getValue() { + return value; + } + + @Override + public String toString() { + return String.valueOf(value); + } + } + + @JsonProperty(value ="arraySize") + private Integer arraySize; + + @JsonProperty(value ="multipleOf") + private Integer multipleOf; + + @JsonProperty(value ="mapSize") + private Integer mapSize; + + @JsonProperty(value ="mapTypes") + private List mapTypes = new ArrayList(); + + @JsonProperty(value ="format") + private String format; + + @JsonProperty(value ="generatedFlag") + private Boolean generatedFlag; + + @JsonProperty(value ="maxLength") + private Integer maxLength; + + @JsonProperty(value ="uniqueItems") + private Boolean uniqueItems; + + @JsonProperty(value ="elements") + private Integer elements; + + @JsonProperty(value ="name") + private String name; + + @JsonProperty(value ="regex") + private String regex; + + @JsonProperty(value ="minItems") + private Integer minItems; + + @JsonProperty(value ="values") + private List values = new ArrayList(); + + @JsonProperty(value ="minimum") + private Integer minimum; + + @JsonProperty(value ="numberEnum") + private NumberEnum numberEnum; + + public enum NumberEnum { + BYTES("bytes"), + FLOAT("float"), + FIXED("fixed"), + DECIMAL("decimal"), + INTEGER("integer"), + LONG("long"); + + private String value; + + NumberEnum(String value) { + this.value = value; + } + + @JsonValue + public String getValue() { + return value; + } + + @Override + public String toString() { + return String.valueOf(value); + } + } + + @JsonProperty(value ="valueLength") + private Integer valueLength; + + + @Builder + @Jacksonized + private FieldValueDTO(Boolean mandatory, Integer precision, FieldDTO defaultItem, Integer maximum, String type, Integer scale, Integer minLength, Integer increment, String keyType, List requiredValues, Boolean optionalUnion, FieldDTO initialValue, Boolean flagExclusiveMinimum, Boolean flagExclusiveMaximum, String defaultValue, FieldDTO property, List enumValues, List properties, UnionEnum unionEnum, SeqEnum seqEnum, Integer arraySize, Integer multipleOf, Integer mapSize, List mapTypes, String format, Boolean generatedFlag, Integer maxLength, Boolean uniqueItems, Integer elements, String name, String regex, Integer minItems, List values, Integer minimum, NumberEnum numberEnum, Integer valueLength) { + this.mandatory = mandatory; + 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.property = property; + this.enumValues = enumValues; + this.properties = properties; + 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 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 (!satisfiedCondition) { + 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 new file mode 100644 index 00000000..6f73023c --- /dev/null +++ b/multiapi-engine/src/test/resources/openapigenerator/testRestrictionsSchema/assets/model/MapFieldDTO.java @@ -0,0 +1,48 @@ +package com.sngular.multifileplugin.testRestrictionsSchema.model; + +import com.fasterxml.jackson.annotation.JsonProperty; +import java.util.List; +import java.util.ArrayList; +import lombok.Builder; +import lombok.Data; +import lombok.extern.jackson.Jacksonized; + +@Data +public class MapFieldDTO { + + @JsonProperty(value ="mandatory") + private Boolean mandatory; + + @JsonProperty(value ="keyType") + private String keyType; + + @JsonProperty(value ="type") + private String type; + + @JsonProperty(value ="name") + private String name; + + @JsonProperty(value ="mapSize") + private Integer mapSize; + + @JsonProperty(value ="mapTypes") + private List mapTypes = new ArrayList(); + + @JsonProperty(value ="defaultValue") + private List defaultValue = new ArrayList(); + + + @Builder + @Jacksonized + private MapFieldDTO(Boolean mandatory, String keyType, String type, String name, Integer mapSize, List mapTypes, List defaultValue) { + this.mandatory = mandatory; + this.keyType = keyType; + this.type = type; + this.name = name; + this.mapSize = mapSize; + this.mapTypes = mapTypes; + this.defaultValue = defaultValue; + + } + +} 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 new file mode 100644 index 00000000..586cbaca --- /dev/null +++ b/multiapi-engine/src/test/resources/openapigenerator/testRestrictionsSchema/assets/model/NumberFieldDTO.java @@ -0,0 +1,92 @@ +package com.sngular.multifileplugin.testRestrictionsSchema.model; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; +import lombok.Builder; +import lombok.Data; +import lombok.extern.jackson.Jacksonized; + +@Data +public class NumberFieldDTO { + + @JsonProperty(value ="mandatory") + private Boolean mandatory; + + @JsonProperty(value ="precision") + private Integer precision; + + @JsonProperty(value ="maximum") + private Integer maximum; + + @JsonProperty(value ="type") + private String type; + + @JsonProperty(value ="name") + private String name; + + @JsonProperty(value ="multipleOf") + private Integer multipleOf; + + @JsonProperty(value ="scale") + private Integer scale; + + @JsonProperty(value ="minimum") + private Integer minimum; + + @JsonProperty(value ="flagExclusiveMinimum") + private Boolean flagExclusiveMinimum; + + @JsonProperty(value ="flagExclusiveMaximum") + private Boolean flagExclusiveMaximum; + + @JsonProperty(value ="numberEnum") + private NumberEnum numberEnum; + + public enum NumberEnum { + BYTES("bytes"), + FLOAT("float"), + FIXED("fixed"), + DECIMAL("decimal"), + INTEGER("integer"), + LONG("long"); + + private String value; + + NumberEnum(String value) { + this.value = value; + } + + @JsonValue + public String getValue() { + return value; + } + + @Override + public String toString() { + return String.valueOf(value); + } + } + + @JsonProperty(value ="defaultValue") + private Integer defaultValue; + + + @Builder + @Jacksonized + private NumberFieldDTO(Boolean mandatory, Integer precision, Integer maximum, String type, String name, Integer multipleOf, Integer scale, Integer minimum, Boolean flagExclusiveMinimum, Boolean flagExclusiveMaximum, NumberEnum numberEnum, Integer defaultValue) { + this.mandatory = mandatory; + this.precision = precision; + this.maximum = maximum; + this.type = type; + this.name = name; + this.multipleOf = multipleOf; + this.scale = scale; + this.minimum = minimum; + this.flagExclusiveMinimum = flagExclusiveMinimum; + this.flagExclusiveMaximum = flagExclusiveMaximum; + this.numberEnum = numberEnum; + this.defaultValue = defaultValue; + + } + +} 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 new file mode 100644 index 00000000..790cb2d9 --- /dev/null +++ b/multiapi-engine/src/test/resources/openapigenerator/testRestrictionsSchema/assets/model/ObjectFieldDTO.java @@ -0,0 +1,44 @@ +package com.sngular.multifileplugin.testRestrictionsSchema.model; + +import com.fasterxml.jackson.annotation.JsonProperty; +import java.util.List; +import java.util.ArrayList; +import lombok.Builder; +import lombok.Data; +import lombok.extern.jackson.Jacksonized; + +@Data +public class ObjectFieldDTO { + + @JsonProperty(value ="mandatory") + private Boolean mandatory; + + @JsonProperty(value ="requiredValues") + private List requiredValues = new ArrayList(); + + @JsonProperty(value ="type") + private String type; + + @JsonProperty(value ="properties") + private List properties = new ArrayList(); + + @JsonProperty(value ="name") + private String name; + + @JsonProperty(value ="defaultValue") + private List defaultValue = new ArrayList(); + + + @Builder + @Jacksonized + private ObjectFieldDTO(Boolean mandatory, List requiredValues, String type, List properties, String name, List defaultValue) { + this.mandatory = mandatory; + this.requiredValues = requiredValues; + this.type = type; + this.properties = properties; + this.name = name; + this.defaultValue = defaultValue; + + } + +} 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 new file mode 100644 index 00000000..f2dbcc7a --- /dev/null +++ b/multiapi-engine/src/test/resources/openapigenerator/testRestrictionsSchema/assets/model/SchemaDTO.java @@ -0,0 +1,48 @@ +package com.sngular.multifileplugin.testRestrictionsSchema.model; + +import com.fasterxml.jackson.annotation.JsonProperty; +import java.util.List; +import java.util.ArrayList; +import lombok.Builder; +import lombok.Data; +import lombok.NonNull; +import lombok.extern.jackson.Jacksonized; + +@Data +public class SchemaDTO { + + @JsonProperty(value ="properties") + private List properties = new ArrayList(); + + @JsonProperty(value ="type") + @NonNull + private String type; + + @JsonProperty(value ="name") + @NonNull + private String name; + + @JsonProperty(value ="id") + private String id; + + @JsonProperty(value ="subjectName") + @NonNull + private String subjectName; + + @JsonProperty(value ="original") + private Boolean original; + + + @Builder + @Jacksonized + private SchemaDTO(List properties, @NonNull String type, @NonNull String name, String id, @NonNull String subjectName, Boolean original) { + this.properties = properties; + this.type = type; + this.name = name; + this.id = id; + this.subjectName = subjectName; + this.original = original; + + } + +} 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 new file mode 100644 index 00000000..3deff992 --- /dev/null +++ b/multiapi-engine/src/test/resources/openapigenerator/testRestrictionsSchema/assets/model/SequenceFieldDTO.java @@ -0,0 +1,76 @@ +package com.sngular.multifileplugin.testRestrictionsSchema.model; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; +import lombok.Builder; +import lombok.Data; +import lombok.extern.jackson.Jacksonized; + +@Data +public class SequenceFieldDTO { + + @JsonProperty(value ="mandatory") + private Boolean mandatory; + + @JsonProperty(value ="elements") + private Integer elements; + + @JsonProperty(value ="type") + private String type; + + @JsonProperty(value ="seqEnum") + private SeqEnum seqEnum; + + public enum SeqEnum { + MONTH("MONTH"), + YEAR("YEAR"), + HOUR("HOUR"), + MINUTE("MINUTE"), + SECOND("SECOND"), + DAY("DAY"); + + private String value; + + SeqEnum(String value) { + this.value = value; + } + + @JsonValue + public String getValue() { + return value; + } + + @Override + public String toString() { + return String.valueOf(value); + } + } + + @JsonProperty(value ="name") + private String name; + + @JsonProperty(value ="initialValue") + private FieldDTO initialValue; + + @JsonProperty(value ="increment") + private Integer increment; + + @JsonProperty(value ="property") + private FieldDTO property; + + + @Builder + @Jacksonized + private SequenceFieldDTO(Boolean mandatory, Integer elements, String type, SeqEnum seqEnum, String name, FieldDTO initialValue, Integer increment, FieldDTO property) { + this.mandatory = mandatory; + this.elements = elements; + this.type = type; + this.seqEnum = seqEnum; + this.name = name; + this.initialValue = initialValue; + this.increment = increment; + this.property = property; + + } + +} 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 new file mode 100644 index 00000000..d7cfc435 --- /dev/null +++ b/multiapi-engine/src/test/resources/openapigenerator/testRestrictionsSchema/assets/model/StringFieldDTO.java @@ -0,0 +1,60 @@ +package com.sngular.multifileplugin.testRestrictionsSchema.model; + +import com.fasterxml.jackson.annotation.JsonProperty; +import java.util.List; +import java.util.ArrayList; +import lombok.Builder; +import lombok.Data; +import lombok.extern.jackson.Jacksonized; + +@Data +public class StringFieldDTO { + + @JsonProperty(value ="mandatory") + private Boolean mandatory; + + @JsonProperty(value ="maxLength") + private Integer maxLength; + + @JsonProperty(value ="type") + private String type; + + @JsonProperty(value ="properties") + private List properties = new ArrayList(); + + @JsonProperty(value ="name") + private String name; + + @JsonProperty(value ="regex") + private String regex; + + @JsonProperty(value ="minLength") + private Integer minLength; + + @JsonProperty(value ="defaultValue") + private String defaultValue; + + @JsonProperty(value ="format") + private String format; + + @JsonProperty(value ="valueLength") + private Integer valueLength; + + + @Builder + @Jacksonized + private StringFieldDTO(Boolean mandatory, Integer maxLength, String type, List properties, String name, String regex, Integer minLength, String defaultValue, String format, Integer valueLength) { + this.mandatory = mandatory; + this.maxLength = maxLength; + this.type = type; + this.properties = properties; + this.name = name; + this.regex = regex; + this.minLength = minLength; + this.defaultValue = defaultValue; + this.format = format; + this.valueLength = valueLength; + + } + +} 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 new file mode 100644 index 00000000..64273dfa --- /dev/null +++ b/multiapi-engine/src/test/resources/openapigenerator/testRestrictionsSchema/assets/model/UUIDFieldDTO.java @@ -0,0 +1,42 @@ +package com.sngular.multifileplugin.testRestrictionsSchema.model; + +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.Builder; +import lombok.Data; +import lombok.extern.jackson.Jacksonized; + +@Data +public class UUIDFieldDTO { + + @JsonProperty(value ="mandatory") + private Boolean mandatory; + + @JsonProperty(value ="type") + private String type; + + @JsonProperty(value ="name") + private String name; + + @JsonProperty(value ="regex") + private String regex; + + @JsonProperty(value ="defaultValue") + private String defaultValue; + + @JsonProperty(value ="format") + private String format; + + + @Builder + @Jacksonized + private UUIDFieldDTO(Boolean mandatory, String type, String name, String regex, String defaultValue, String format) { + this.mandatory = mandatory; + this.type = type; + this.name = name; + this.regex = regex; + this.defaultValue = defaultValue; + this.format = format; + + } + +} 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 new file mode 100644 index 00000000..b127d733 --- /dev/null +++ b/multiapi-engine/src/test/resources/openapigenerator/testRestrictionsSchema/assets/model/UnionFieldDTO.java @@ -0,0 +1,75 @@ +package com.sngular.multifileplugin.testRestrictionsSchema.model; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; +import java.util.List; +import java.util.ArrayList; +import lombok.Builder; +import lombok.Data; +import lombok.extern.jackson.Jacksonized; + +@Data +public class UnionFieldDTO { + + @JsonProperty(value ="mandatory") + private Boolean mandatory; + + @JsonProperty(value ="defaultItem") + private FieldDTO defaultItem; + + @JsonProperty(value ="generatedFlag") + private Boolean generatedFlag; + + @JsonProperty(value ="type") + private String type; + + @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 ="name") + private String name; + + @JsonProperty(value ="optionalUnion") + private Boolean optionalUnion; + + @JsonProperty(value ="values") + private List values = new ArrayList(); + + + @Builder + @Jacksonized + private UnionFieldDTO(Boolean mandatory, FieldDTO defaultItem, Boolean generatedFlag, String type, UnionEnum unionEnum, String name, Boolean optionalUnion, List values) { + this.mandatory = mandatory; + this.defaultItem = defaultItem; + this.generatedFlag = generatedFlag; + this.type = type; + this.unionEnum = unionEnum; + this.name = name; + this.optionalUnion = optionalUnion; + this.values = values; + + } + +} diff --git a/multiapi-engine/src/test/resources/openapigenerator/testRestrictionsSchema/components.yml b/multiapi-engine/src/test/resources/openapigenerator/testRestrictionsSchema/components.yml new file mode 100644 index 00000000..eb145379 --- /dev/null +++ b/multiapi-engine/src/test/resources/openapigenerator/testRestrictionsSchema/components.yml @@ -0,0 +1,304 @@ +components: + schemas: + arrayNames: + type: array + items: + type: string + Schema: + type: object + required: + - subjectName + - name + - type + - properties + properties: + id: + type: string + subjectName: + type: string + name: + type: string + original: + type: boolean + properties: + type: array + items: + $ref: '#/components/schemas/Field' + type: + type: string + StringField: + type: object + properties: + name: + type: string + type: + type: string + mandatory: + type: boolean + defaultValue: + type: string + regex: + type: string + minLength: + type: integer + format: int32 + maxLength: + type: integer + format: int32 + format: + type: string + valueLength: + type: integer + format: int32 + properties: + type: array + items: + type: string + ArrayField: + type: object + properties: + name: + type: string + type: + type: string + mandatory: + type: boolean + defaultValue: + type: array + items: + $ref: '#/components/schemas/Field' + values: + type: array + items: + $ref: '#/components/schemas/Field' + regex: + type: string + minItems: + type: integer + format: int32 + arraySize: + type: integer + format: int32 + uniqueItems: + type: boolean + BooleanField: + type: object + properties: + name: + type: string + type: + type: string + mandatory: + type: boolean + defaultValue: + type: boolean + DateField: + type: object + properties: + name: + type: string + type: + type: string + mandatory: + type: boolean + defaultValue: + type: string + format: + type: string + EnumField: + type: object + properties: + name: + type: string + type: + type: string + mandatory: + type: boolean + defaultValue: + type: string + enumValues: + type: array + items: + type: string + MapField: + type: object + properties: + name: + type: string + type: + type: string + mandatory: + type: boolean + defaultValue: + type: array + items: + type: object + mapTypes: + type: array + items: + $ref: '#/components/schemas/Field' + keyType: + type: string + mapSize: + type: integer + format: int32 + NumberField: + type: object + properties: + name: + type: string + type: + type: string + mandatory: + type: boolean + defaultValue: + type: integer + format: int32 + minimum: + type: integer + format: int32 + maximum: + type: integer + format: int32 + flagExclusiveMinimum: + type: boolean + flagExclusiveMaximum: + type: boolean + multipleOf: + type: integer + format: int32 + numberEnum: + type: string + enum: + - integer + - float + - long + - decimal + - bytes + - fixed + precision: + type: integer + format: int32 + scale: + type: integer + format: int32 + ObjectField: + type: object + properties: + name: + type: string + type: + type: string + mandatory: + type: boolean + defaultValue: + type: array + items: + type: object + properties: + type: array + items: + $ref: '#/components/schemas/Field' + requiredValues: + type: array + items: + type: string + UnionField: + type: object + properties: + name: + type: string + type: + type: string + mandatory: + type: boolean + values: + type: array + items: + $ref: '#/components/schemas/Field' + defaultItem: + $ref: '#/components/schemas/Field' + unionEnum: + type: string + enum: + - oneof + - anyof + - allof + generatedFlag: + type: boolean + optionalUnion: + type: boolean + UUIDField: + type: object + properties: + name: + type: string + type: + type: string + mandatory: + type: boolean + defaultValue: + type: string + format: uuid + regex: + type: string + format: + type: string + SequenceField: + type: object + properties: + name: + type: string + type: + type: string + mandatory: + type: boolean + initialValue: + $ref: '#/components/schemas/Field' + property: + $ref: '#/components/schemas/Field' + elements: + type: integer + format: int32 + increment: + type: integer + format: int32 + seqEnum: + type: string + enum: + - YEAR + - MONTH + - DAY + - HOUR + - MINUTE + - SECOND + Field: + type: object + properties: + typeField: + type: string + enum: + - StringField + - ArrayField + - BooleanField + - DateField + - EnumField + - MapField + - NumberField + - ObjectField + - UnionField + - UUIDField + - SequenceField + fieldValue: + oneOf: + - $ref: '#/components/schemas/StringField' + - $ref: '#/components/schemas/ArrayField' + - $ref: '#/components/schemas/BooleanField' + - $ref: '#/components/schemas/DateField' + - $ref: '#/components/schemas/EnumField' + - $ref: '#/components/schemas/MapField' + - $ref: '#/components/schemas/NumberField' + - $ref: '#/components/schemas/ObjectField' + - $ref: '#/components/schemas/UnionField' + - $ref: '#/components/schemas/SequenceField' + - $ref: '#/components/schemas/UUIDField' diff --git a/multiapi-engine/src/test/resources/openapigenerator/testRestrictionsSchema/schema-restriction/components.yml b/multiapi-engine/src/test/resources/openapigenerator/testRestrictionsSchema/schema-restriction/components.yml new file mode 100644 index 00000000..eb145379 --- /dev/null +++ b/multiapi-engine/src/test/resources/openapigenerator/testRestrictionsSchema/schema-restriction/components.yml @@ -0,0 +1,304 @@ +components: + schemas: + arrayNames: + type: array + items: + type: string + Schema: + type: object + required: + - subjectName + - name + - type + - properties + properties: + id: + type: string + subjectName: + type: string + name: + type: string + original: + type: boolean + properties: + type: array + items: + $ref: '#/components/schemas/Field' + type: + type: string + StringField: + type: object + properties: + name: + type: string + type: + type: string + mandatory: + type: boolean + defaultValue: + type: string + regex: + type: string + minLength: + type: integer + format: int32 + maxLength: + type: integer + format: int32 + format: + type: string + valueLength: + type: integer + format: int32 + properties: + type: array + items: + type: string + ArrayField: + type: object + properties: + name: + type: string + type: + type: string + mandatory: + type: boolean + defaultValue: + type: array + items: + $ref: '#/components/schemas/Field' + values: + type: array + items: + $ref: '#/components/schemas/Field' + regex: + type: string + minItems: + type: integer + format: int32 + arraySize: + type: integer + format: int32 + uniqueItems: + type: boolean + BooleanField: + type: object + properties: + name: + type: string + type: + type: string + mandatory: + type: boolean + defaultValue: + type: boolean + DateField: + type: object + properties: + name: + type: string + type: + type: string + mandatory: + type: boolean + defaultValue: + type: string + format: + type: string + EnumField: + type: object + properties: + name: + type: string + type: + type: string + mandatory: + type: boolean + defaultValue: + type: string + enumValues: + type: array + items: + type: string + MapField: + type: object + properties: + name: + type: string + type: + type: string + mandatory: + type: boolean + defaultValue: + type: array + items: + type: object + mapTypes: + type: array + items: + $ref: '#/components/schemas/Field' + keyType: + type: string + mapSize: + type: integer + format: int32 + NumberField: + type: object + properties: + name: + type: string + type: + type: string + mandatory: + type: boolean + defaultValue: + type: integer + format: int32 + minimum: + type: integer + format: int32 + maximum: + type: integer + format: int32 + flagExclusiveMinimum: + type: boolean + flagExclusiveMaximum: + type: boolean + multipleOf: + type: integer + format: int32 + numberEnum: + type: string + enum: + - integer + - float + - long + - decimal + - bytes + - fixed + precision: + type: integer + format: int32 + scale: + type: integer + format: int32 + ObjectField: + type: object + properties: + name: + type: string + type: + type: string + mandatory: + type: boolean + defaultValue: + type: array + items: + type: object + properties: + type: array + items: + $ref: '#/components/schemas/Field' + requiredValues: + type: array + items: + type: string + UnionField: + type: object + properties: + name: + type: string + type: + type: string + mandatory: + type: boolean + values: + type: array + items: + $ref: '#/components/schemas/Field' + defaultItem: + $ref: '#/components/schemas/Field' + unionEnum: + type: string + enum: + - oneof + - anyof + - allof + generatedFlag: + type: boolean + optionalUnion: + type: boolean + UUIDField: + type: object + properties: + name: + type: string + type: + type: string + mandatory: + type: boolean + defaultValue: + type: string + format: uuid + regex: + type: string + format: + type: string + SequenceField: + type: object + properties: + name: + type: string + type: + type: string + mandatory: + type: boolean + initialValue: + $ref: '#/components/schemas/Field' + property: + $ref: '#/components/schemas/Field' + elements: + type: integer + format: int32 + increment: + type: integer + format: int32 + seqEnum: + type: string + enum: + - YEAR + - MONTH + - DAY + - HOUR + - MINUTE + - SECOND + Field: + type: object + properties: + typeField: + type: string + enum: + - StringField + - ArrayField + - BooleanField + - DateField + - EnumField + - MapField + - NumberField + - ObjectField + - UnionField + - UUIDField + - SequenceField + fieldValue: + oneOf: + - $ref: '#/components/schemas/StringField' + - $ref: '#/components/schemas/ArrayField' + - $ref: '#/components/schemas/BooleanField' + - $ref: '#/components/schemas/DateField' + - $ref: '#/components/schemas/EnumField' + - $ref: '#/components/schemas/MapField' + - $ref: '#/components/schemas/NumberField' + - $ref: '#/components/schemas/ObjectField' + - $ref: '#/components/schemas/UnionField' + - $ref: '#/components/schemas/SequenceField' + - $ref: '#/components/schemas/UUIDField'