diff --git a/multiapi-engine/pom.xml b/multiapi-engine/pom.xml
index 402bc19f..b1527a26 100644
--- a/multiapi-engine/pom.xml
+++ b/multiapi-engine/pom.xml
@@ -4,23 +4,28 @@
com.sngular
multiapi-engine
- 5.4.3
+ 6.0.0
jar
11
11
2.1.12
- 3.12.0
- 2.11.0
+ 3.13.0
+ 2.13.0
4.4
- 2.15.0
+ 2.15.3
2.3.32
3.24.2
- 5.9.2
+ 5.10.1
2.2.9
3.0.0
+ 1.12.0
+ 1.18.30
+ 2.0.11
+ 1.16.0
+ 3.9.1
@@ -32,7 +37,7 @@
org.apache.commons
commons-text
- 1.10.0
+ ${commons-text.version}
commons-io
@@ -63,18 +68,18 @@
org.projectlombok
lombok
- 1.18.30
+ ${lombok.version}
org.slf4j
slf4j-api
- 1.7.28
+ ${slf4j-api.version}
commons-codec
commons-codec
- 1.15
+ ${commons-codec.version}
io.swagger.parser.v3
@@ -143,7 +148,7 @@
org.apache.maven
maven-artifact
- 3.9.1
+ ${maven-artifact.version}
provided
diff --git a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/asyncapi/AsyncApiGenerator.java b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/asyncapi/AsyncApiGenerator.java
index e64d4777..2a57a28c 100644
--- a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/asyncapi/AsyncApiGenerator.java
+++ b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/asyncapi/AsyncApiGenerator.java
@@ -9,7 +9,6 @@
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
-import java.io.FilenameFilter;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Path;
@@ -23,29 +22,34 @@
import java.util.Map.Entry;
import java.util.Objects;
import java.util.regex.Pattern;
-
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
import com.sngular.api.generator.plugin.PluginConstants;
-import com.sngular.api.generator.plugin.asyncapi.exception.*;
+import com.sngular.api.generator.plugin.asyncapi.exception.ChannelNameException;
+import com.sngular.api.generator.plugin.asyncapi.exception.DuplicateClassException;
+import com.sngular.api.generator.plugin.asyncapi.exception.DuplicatedOperationException;
+import com.sngular.api.generator.plugin.asyncapi.exception.ExternalRefComponentNotFoundException;
+import com.sngular.api.generator.plugin.asyncapi.exception.FileSystemException;
+import com.sngular.api.generator.plugin.asyncapi.exception.InvalidAsyncAPIException;
+import com.sngular.api.generator.plugin.asyncapi.exception.InvalidAvroException;
import com.sngular.api.generator.plugin.asyncapi.model.ProcessBindingsResult;
import com.sngular.api.generator.plugin.asyncapi.model.ProcessBindingsResult.ProcessBindingsResultBuilder;
import com.sngular.api.generator.plugin.asyncapi.model.ProcessMethodResult;
-import com.sngular.api.generator.plugin.asyncapi.model.SchemaObject;
import com.sngular.api.generator.plugin.asyncapi.parameter.OperationParameterObject;
import com.sngular.api.generator.plugin.asyncapi.parameter.SpecFile;
import com.sngular.api.generator.plugin.asyncapi.template.TemplateFactory;
import com.sngular.api.generator.plugin.asyncapi.util.BindingTypeEnum;
import com.sngular.api.generator.plugin.asyncapi.util.FactoryTypeEnum;
-import com.sngular.api.generator.plugin.asyncapi.util.MapperContentUtil;
-import com.sngular.api.generator.plugin.asyncapi.util.MapperUtil;
import com.sngular.api.generator.plugin.asyncapi.util.ReferenceProcessor;
import com.sngular.api.generator.plugin.common.files.ClasspathFileLocation;
import com.sngular.api.generator.plugin.common.files.DirectoryFileLocation;
import com.sngular.api.generator.plugin.common.files.FileLocation;
-import com.sngular.api.generator.plugin.common.model.TimeType;
+import com.sngular.api.generator.plugin.common.model.CommonSpecFile;
+import com.sngular.api.generator.plugin.common.model.SchemaObject;
import com.sngular.api.generator.plugin.common.tools.ApiTool;
+import com.sngular.api.generator.plugin.common.tools.MapperContentUtil;
+import com.sngular.api.generator.plugin.common.tools.MapperUtil;
import com.sngular.api.generator.plugin.exception.InvalidAPIException;
import freemarker.template.TemplateException;
import lombok.extern.slf4j.Slf4j;
@@ -57,8 +61,12 @@
@Slf4j
public class AsyncApiGenerator {
+ private static final String PACKAGE_SEPARATOR_STR = ".";
+
private static final String SLASH = "/";
+ public static final Pattern PACKAGE_SEPARATOR = Pattern.compile(PACKAGE_SEPARATOR_STR);
+
private static final String DEFAULT_ASYNCAPI_API_PACKAGE = PluginConstants.DEFAULT_API_PACKAGE + ".asyncapi";
private static final String DEFAULT_ASYNCAPI_MODEL_PACKAGE = DEFAULT_ASYNCAPI_API_PACKAGE + ".model";
@@ -72,13 +80,8 @@ public class AsyncApiGenerator {
private static final String SUBSCRIBE = "subscribe";
private static final String PUBLISH = "publish";
-
private static final String OPERATION_ID = "operationId";
- private static final String PACKAGE_SEPARATOR_STR = ".";
-
- public static final Pattern PACKAGE_SEPARATOR = Pattern.compile(PACKAGE_SEPARATOR_STR);
-
private static final String AVSC = "avsc";
private static final String PAYLOAD = "payload";
@@ -107,33 +110,27 @@ public class AsyncApiGenerator {
private final List processedApiPackages = new ArrayList<>();
- private final File targetFolder;
-
- private final File baseDir;
-
- private final FilenameFilter targetFileFilter;
+ private final Path baseDir;
private final TemplateFactory templateFactory;
- private final String processedGeneratedSourcesFolder;
-
private final String groupId;
private final Integer springBootVersion;
- private boolean generateExceptionTemplate;
-
- public AsyncApiGenerator(final Integer springBootVersion, final File targetFolder, final String processedGeneratedSourcesFolder, final String groupId, final File baseDir) {
+ public AsyncApiGenerator(final Integer springBootVersion,
+ boolean overwriteModel,
+ final File targetFolder,
+ final String processedGeneratedSourcesFolder,
+ final String groupId,
+ final File baseDir) {
this.groupId = groupId;
- this.processedGeneratedSourcesFolder = processedGeneratedSourcesFolder;
- this.targetFolder = targetFolder;
- this.baseDir = baseDir;
- this.templateFactory = new TemplateFactory();
- this.targetFileFilter = (dir, name) -> name.toLowerCase().contains(targetFolder.toPath().getFileName().toString());
+ this.baseDir = baseDir.toPath().toAbsolutePath();
+ this.templateFactory = new TemplateFactory(overwriteModel, targetFolder, processedGeneratedSourcesFolder, baseDir);
this.springBootVersion = springBootVersion;
}
- public static Pair resolveYmlLocation(final String ymlFilePath) throws FileNotFoundException {
+ private static Pair resolveYmlLocation(final String ymlFilePath) throws FileNotFoundException {
final InputStream classPathInput = AsyncApiGenerator.class.getClassLoader().getResourceAsStream(ymlFilePath);
final InputStream ymlFile;
@@ -153,8 +150,8 @@ public static Pair resolveYmlLocation(final String ym
public final void processFileSpec(final List specsListFile) {
final ObjectMapper om = new ObjectMapper(new YAMLFactory());
processedOperationIds.clear();
- generateExceptionTemplate = false;
- for (final SpecFile fileParameter : specsListFile) {
+ templateFactory.setNotGenerateTemplate();
+ for (final SpecFile fileParameter : specsListFile) {
final Pair ymlFileAndPath;
try {
ymlFileAndPath = resolveYmlLocation(fileParameter.getFilePath());
@@ -166,13 +163,13 @@ public final void processFileSpec(final List specsListFile) {
try {
final JsonNode openApi = om.readTree(ymlFile);
- final JsonNode internalNode = openApi.get(CHANNELS);
+ final JsonNode channelList = openApi.get(CHANNELS);
final Map totalSchemas = getAllSchemas(ymlParent, openApi);
- final Iterator> iter = internalNode.fields();
+ final Iterator> channelListIt = channelList.fields();
setUpTemplate(fileParameter, springBootVersion);
- while (iter.hasNext()) {
+ while (channelListIt.hasNext()) {
- final Map.Entry entry = iter.next();
+ final Map.Entry entry = channelListIt.next();
final JsonNode channel = entry.getValue();
@@ -182,27 +179,11 @@ public final void processFileSpec(final List specsListFile) {
processOperation(fileParameter, ymlParent, entry, channel, operationId, channelPayload, totalSchemas);
}
- templateFactory.fillTemplates(generateExceptionTemplate);
- templateFactory.clearData();
+ templateFactory.fillTemplates();
} catch (final TemplateException | IOException e) {
throw new FileSystemException(e);
}
- }
- }
-
- private void checkRequiredOrCombinatorExists(final SchemaObject schema, final boolean useLombok) {
- if ("anyOf".equals(schema.getSchemaCombinator()) || "oneOf".equals(schema.getSchemaCombinator())) {
- generateExceptionTemplate = true;
- } else if (Objects.nonNull(schema.getFieldObjectList()) && !useLombok) {
- final var fieldListIt = schema.getFieldObjectList().listIterator();
- if (fieldListIt.hasNext()) {
- do {
- final var field = fieldListIt.next();
- if (field.isRequired()) {
- generateExceptionTemplate = true;
- }
- } while (fieldListIt.hasNext() && !generateExceptionTemplate);
- }
+ templateFactory.clearData();
}
}
@@ -216,7 +197,7 @@ private Map getAllSchemas(final FileLocation ymlParent, final
});
ApiTool.getComponent(node, SCHEMAS).forEachRemaining(
- schema -> totalSchemas.putIfAbsent((SCHEMAS + SLASH + schema.getKey()).toUpperCase(), schema.getValue())
+ schema -> totalSchemas.putIfAbsent(SCHEMAS.toUpperCase() + SLASH + MapperUtil.getSchemaKey(schema.getKey()), schema.getValue())
);
ApiTool.getComponent(node, MESSAGES).forEachRemaining(
@@ -239,7 +220,7 @@ private void getMessageSchemas(
if (ApiTool.hasNode(message, PAYLOAD)) {
final JsonNode payload = message.get(PAYLOAD);
if (!payload.has(REF)) {
- final String key = (EVENT + SLASH + calculateMessageName(messageName, message)).toUpperCase();
+ final String key = EVENT.toUpperCase() + SLASH + MapperUtil.getSchemaKey(calculateMessageName(messageName, message));
totalSchemas.putIfAbsent(key, payload);
}
} else if (ApiTool.hasRef(message)) {
@@ -249,14 +230,23 @@ private void getMessageSchemas(
}
private String calculateMessageName(final String messageName, final JsonNode message) {
- return StringUtils.defaultString(ApiTool.getName(message), messageName);
+ final String finalMessageName;
+ if (ApiTool.hasNode(message, "messageId")) {
+ finalMessageName = ApiTool.getNodeAsString(message, "messageId");
+ } else if (ApiTool.hasName(message)) {
+ finalMessageName = ApiTool.getName(message);
+ } else {
+ finalMessageName = messageName;
+ }
+ return StringUtils.capitalize(finalMessageName);
}
private void getChannelSchemas(final JsonNode channel, final Map totalSchemas, final FileLocation ymlParent) {
final List options = List.of(PUBLISH, SUBSCRIBE);
options.forEach(option -> {
- if (channel.has(option) && channel.get(option).has(MESSAGE)) {
- getMessageSchemas(null, channel.get(option).get(MESSAGE), ymlParent, totalSchemas);
+ if (ApiTool.hasNode(channel, option) && ApiTool.hasNode(ApiTool.getNode(channel, option), MESSAGE)) {
+ final var optionNode = ApiTool.getNode(channel, option);
+ getMessageSchemas(ApiTool.getNodeAsString(optionNode, OPERATION_ID), ApiTool.getNode(optionNode, MESSAGE), ymlParent, totalSchemas);
}
});
}
@@ -266,16 +256,19 @@ private void processOperation(
final String operationId, final JsonNode channelPayload, final Map totalSchemas) throws IOException, TemplateException {
if (isValidOperation(fileParameter.getConsumer(), operationId, channel, SUBSCRIBE, true)) {
final var operationObject = fileParameter.getConsumer();
+ operationObject.setFilePath(fileParameter.getFilePath());
checkClassPackageDuplicate(operationObject.getClassNamePostfix(), operationObject.getApiPackage());
processSubscribeMethod(channelPayload, operationObject, ymlParent, totalSchemas);
addProcessedClassesAndPackagesToGlobalVariables(operationObject.getClassNamePostfix(), operationObject.getApiPackage(), CONSUMER_CLASS_NAME);
} else if (isValidOperation(fileParameter.getSupplier(), operationId, channel, PUBLISH, Objects.isNull(fileParameter.getStreamBridge()))) {
final var operationObject = fileParameter.getSupplier();
+ operationObject.setFilePath(fileParameter.getFilePath());
checkClassPackageDuplicate(operationObject.getClassNamePostfix(), operationObject.getApiPackage());
processSupplierMethod(channelPayload, operationObject, ymlParent, totalSchemas);
addProcessedClassesAndPackagesToGlobalVariables(operationObject.getClassNamePostfix(), operationObject.getApiPackage(), SUPPLIER_CLASS_NAME);
} else if (isValidOperation(fileParameter.getStreamBridge(), operationId, channel, PUBLISH, Objects.isNull(fileParameter.getSupplier()))) {
final var operationObject = fileParameter.getStreamBridge();
+ operationObject.setFilePath(fileParameter.getFilePath());
checkClassPackageDuplicate(operationObject.getClassNamePostfix(), operationObject.getApiPackage());
processStreamBridgeMethod(channelPayload, operationObject, ymlParent, entry.getKey(), totalSchemas);
addProcessedClassesAndPackagesToGlobalVariables(operationObject.getClassNamePostfix(), operationObject.getApiPackage(), STREAM_BRIDGE_CLASS_NAME);
@@ -321,26 +314,13 @@ private String getOperationId(final JsonNode channel) {
private void setUpTemplate(final SpecFile fileParameter, final Integer springBootVersion) {
processPackage(fileParameter);
- processFilePaths(fileParameter);
+ templateFactory.processFilePaths(fileParameter, DEFAULT_ASYNCAPI_API_PACKAGE);
processClassNames(fileParameter);
processEntitiesSuffix(fileParameter);
processJavaEEPackage(springBootVersion);
}
- private void processFilePaths(final SpecFile fileParameter) {
- var pathToCreate = convertPackageToTargetPath(fileParameter.getSupplier());
- if (Objects.nonNull(pathToCreate)) {
- templateFactory.setSupplierFilePath(processPath(pathToCreate));
- }
- pathToCreate = convertPackageToTargetPath(fileParameter.getStreamBridge());
- if (Objects.nonNull(pathToCreate)) {
- templateFactory.setStreamBridgeFilePath(processPath(pathToCreate));
- }
- pathToCreate = convertPackageToTargetPath(fileParameter.getConsumer());
- if (Objects.nonNull(pathToCreate)) {
- templateFactory.setSubscribeFilePath(processPath(pathToCreate));
- }
- }
+
private void processEntitiesSuffix(final SpecFile fileParameter) {
templateFactory.setSupplierEntitiesSuffix(fileParameter.getSupplier() != null && fileParameter.getSupplier().getModelNameSuffix() != null
@@ -373,40 +353,6 @@ private void processClassNames(final SpecFile fileParameter) {
? fileParameter.getConsumer().getClassNamePostfix() : CONSUMER_CLASS_NAME);
}
- private Path processPath(final String packagePath) {
- Path path;
- final File[] pathList = Objects.requireNonNull(baseDir.listFiles(targetFileFilter));
- if (pathList.length > 0) {
- path = pathList[0].toPath().resolve(packagePath);
- } else {
- path = targetFolder.toPath();
- if (!path.toFile().exists() && !path.toFile().mkdirs()) {
- throw new FileSystemException(path.toFile().getName());
- }
- path = path.resolve(packagePath);
- }
- if (!path.toFile().isDirectory() && !path.toFile().mkdirs()) {
- throw new FileSystemException(path.toFile().getName());
- }
- return path;
- }
-
- private String convertPackageToTargetPath(final OperationParameterObject operationParameter) {
- String path = null;
- if (Objects.nonNull(operationParameter)) {
- if (Objects.nonNull(operationParameter.getApiPackage())) {
- path = getPath(operationParameter.getApiPackage());
- } else {
- path = getPath(DEFAULT_ASYNCAPI_API_PACKAGE);
- }
- }
- return path;
- }
-
- private String getPath(final String pathName) {
- return processedGeneratedSourcesFolder + pathName.replace(PACKAGE_SEPARATOR_STR, SLASH);
- }
-
private void processJavaEEPackage(final Integer springBootVersion) {
templateFactory.calculateJavaEEPackage(springBootVersion);
}
@@ -461,7 +407,7 @@ private void processSubscribeMethod(
private void fillTemplateFactory(
final ProcessMethodResult processedMethod, final Map totalSchemas, final OperationParameterObject operationObject)
- throws TemplateException, IOException {
+ throws IOException {
final String classFullName = processedMethod.getNamespace();
final String keyClassFullName = processedMethod.getBindings();
final String modelPackage = classFullName.substring(0, classFullName.lastIndexOf("."));
@@ -471,21 +417,15 @@ private void fillTemplateFactory(
final JsonNode schemaToBuild = processedMethod.getPayload();
if (shouldBuild(schemaToBuild)) {
final var schemaObjectIt =
- MapperContentUtil.mapComponentToSchemaObject(totalSchemas, className, schemaToBuild, null, operationObject.getModelNameSuffix(), parentPackage, modelPackage,
- operationObject.getFormats(), operationObject.getUseTimeType()).iterator();
+ MapperContentUtil.mapComponentToSchemaObject(totalSchemas, className, schemaToBuild, parentPackage, operationObject, this.baseDir).iterator();
if (schemaObjectIt.hasNext()) {
- final var filePath = writeSchemaObject(operationObject.isUseLombokModelAnnotation(), operationObject.getModelPackage(), keyClassName, schemaObjectIt.next());
+ writeSchemaObject(operationObject.isUseLombokModelAnnotation(), operationObject.getModelPackage(), keyClassName, schemaObjectIt.next());
if (Objects.nonNull(keyClassName)) {
templateFactory.setWrapperPackageName(operationObject.getApiPackage());
- templateFactory.fillTemplateWrapper(processPath(getPath(operationObject.getApiPackage())),
- operationObject.getApiPackage(), classFullName, className, keyClassFullName, keyClassName);
+ templateFactory.fillTemplateWrapper(operationObject.getApiPackage(), classFullName, className, keyClassFullName, keyClassName);
}
schemaObjectIt.forEachRemaining(schemaObj -> writeSchemaObject(operationObject.isUseLombokModelAnnotation(), operationObject.getModelPackage(), null, schemaObj));
-
- if (Boolean.TRUE.equals(generateExceptionTemplate)) {
- templateFactory.fillTemplateModelClassException(filePath, modelPackage);
- }
}
}
}
@@ -502,28 +442,26 @@ private boolean shouldBuild(final JsonNode schemaToBuild) {
return result;
}
- private Path writeSchemaObject(final boolean usingLombok, final String modelPackageReceived, final String keyClassName, final SchemaObject schemaObject) {
- final var filePath = processPath(getPath(StringUtils.defaultIfEmpty(modelPackageReceived, DEFAULT_ASYNCAPI_API_PACKAGE + SLASH + schemaObject.getParentPackage())));
- final var propertiesPath = processPath(getPath(modelPackageReceived));
- templateFactory.addSchemaObject(modelPackageReceived, keyClassName, schemaObject, filePath, propertiesPath);
- checkRequiredOrCombinatorExists(schemaObject, usingLombok);
- return filePath;
+ private void writeSchemaObject(final boolean usingLombok, final String modelPackageReceived, final String keyClassName, final SchemaObject schemaObject) {
+ final var destinationPackage = StringUtils.defaultIfEmpty(modelPackageReceived, DEFAULT_ASYNCAPI_API_PACKAGE + SLASH + schemaObject.getParentPackage());
+ templateFactory.addSchemaObject(modelPackageReceived, keyClassName, schemaObject, destinationPackage, usingLombok);
+ templateFactory.checkRequiredOrCombinatorExists(schemaObject, usingLombok);
}
private ProcessMethodResult processMethod(
final JsonNode channel, final OperationParameterObject operationObject, final FileLocation ymlParent, final Map totalSchemas)
throws IOException {
- final JsonNode message = channel.get(MESSAGE);
- final String operationId = channel.get(OPERATION_ID).asText();
+ final JsonNode message = ApiTool.getNode(channel, MESSAGE);
+ final String operationId = ApiTool.getNodeAsString(channel, OPERATION_ID);
final Pair payloadInfo;
final var processBindingsResultBuilder = ProcessBindingsResult.builder();
if (message.has(REF)) {
payloadInfo = processMethodRef(processBindingsResultBuilder, ApiTool.getRefValue(message), operationObject, ymlParent, totalSchemas,
message);
} else if (message.has(PAYLOAD)) {
- payloadInfo = processPayload(operationObject, ApiTool.getName(message), ApiTool.getNode(message, PAYLOAD), ymlParent);
+ payloadInfo = processPayload(operationObject, calculateMessageName(operationId, message), ApiTool.getNode(message, PAYLOAD), ymlParent);
if (ApiTool.hasNode(message, BINDINGS)) {
- processBindings(processBindingsResultBuilder, operationObject.getClassNamePostfix(), operationObject.getModelNameSuffix(), message, operationObject.getUseTimeType());
+ processBindings(processBindingsResultBuilder, message, operationObject);
}
} else {
throw new InvalidAsyncAPIException(operationId);
@@ -554,9 +492,9 @@ private Pair processMethodRef(
final ProcessBindingsResultBuilder bindingsResult, final String messageRef, final OperationParameterObject operationObject,
final FileLocation ymlParent, final Map totalSchemas, final JsonNode method) throws IOException {
- final var message = totalSchemas.get(MapperUtil.buildKey(MapperUtil.splitName(messageRef)));
+ final var message = totalSchemas.get(MapperUtil.getRefSchemaKey(messageRef));
if (ApiTool.hasNode(message, BINDINGS)) {
- processBindings(bindingsResult, operationObject.getClassNamePostfix(), operationObject.getModelNameSuffix(), message, operationObject.getUseTimeType());
+ processBindings(bindingsResult, message, operationObject);
}
return processPayload(operationObject, MapperUtil.getRefClass(method), ApiTool.getNode(message, PAYLOAD), ymlParent);
}
@@ -569,18 +507,18 @@ private String processMessageRef(final JsonNode messageBody, final String modelP
} else if (messageContent.contains("#")) {
namespace = processExternalRef(modelPackage, ymlParent, messageBody);
} else {
- namespace = processExternalAvro(modelPackage, ymlParent, messageContent);
+ namespace = processExternalAvro(ymlParent, messageContent);
}
return namespace;
}
- private String processExternalAvro(final String modelPackage, final FileLocation ymlParent, final String messageContent) {
+ private String processExternalAvro(final FileLocation ymlParent, final String messageContent) {
String avroFilePath = messageContent;
final String namespace;
if (messageContent.startsWith(SLASH)) {
avroFilePath = avroFilePath.replaceFirst(SLASH, "");
} else if (messageContent.startsWith(".")) {
- avroFilePath = baseDir.getAbsolutePath() + avroFilePath.replaceFirst("\\.", "");
+ avroFilePath = baseDir.toAbsolutePath() + avroFilePath.replaceFirst("\\.", "");
}
final InputStream avroFile = ymlParent.getFileAtLocation(avroFilePath);
final ObjectMapper mapper = new ObjectMapper();
@@ -590,7 +528,7 @@ private String processExternalAvro(final String modelPackage, final FileLocation
if (avroNamespace == null) throw new InvalidAvroException(avroFilePath);
- namespace = avroNamespace.asText() + PACKAGE_SEPARATOR + fileTree.get("name").asText();;//processModelPackage(fullNamespace, avroPackage);
+ namespace = avroNamespace.asText() + PACKAGE_SEPARATOR + fileTree.get("name").asText();
} catch (final IOException e) {
throw new FileSystemException(e);
}
@@ -613,22 +551,21 @@ private String processExternalRef(final String modelPackage, final FileLocation
}
}
- private void processBindings(final ProcessBindingsResultBuilder bindingsResult, final String prefix, final String suffix, final JsonNode message,
- final TimeType useTimeType) {
+ private void processBindings(final ProcessBindingsResultBuilder bindingsResult, final JsonNode message,
+ final CommonSpecFile commonSpecFile) {
if (message.has(BINDINGS)) {
final var bindingsNode = message.get(BINDINGS);
if (bindingsNode.has(KAFKA)) {
- processKafkaBindings(bindingsResult, prefix, suffix, bindingsNode.get(KAFKA), useTimeType);
+ processKafkaBindings(bindingsResult, bindingsNode.get(KAFKA), commonSpecFile);
} else {
bindingsResult.bindingType(BindingTypeEnum.NONBINDING.getValue());
}
}
}
- private void processKafkaBindings(final ProcessBindingsResultBuilder bindingsResult, final String prefix, final String suffix, final JsonNode kafkaBindings,
- final TimeType useTimeType) {
+ private void processKafkaBindings(final ProcessBindingsResultBuilder bindingsResult, final JsonNode kafkaBindings, final CommonSpecFile specFile) {
if (kafkaBindings.has(KEY)) {
- bindingsResult.bindings(MapperUtil.getSimpleType(ApiTool.getNode(kafkaBindings, "key"), prefix, suffix, useTimeType))
+ bindingsResult.bindings(MapperUtil.getSimpleType(ApiTool.getNode(kafkaBindings, "key"), specFile))
.bindingType(BindingTypeEnum.KAFKA.getValue());
}
}
diff --git a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/asyncapi/model/MethodObject.java b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/asyncapi/model/MethodObject.java
index 83baddfe..6b2d2ae5 100644
--- a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/asyncapi/model/MethodObject.java
+++ b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/asyncapi/model/MethodObject.java
@@ -7,8 +7,8 @@
package com.sngular.api.generator.plugin.asyncapi.model;
import java.util.Objects;
-
import com.sngular.api.generator.plugin.asyncapi.util.BindingTypeEnum;
+import com.sngular.api.generator.plugin.common.model.SchemaObject;
import lombok.Builder;
import lombok.Value;
import org.apache.commons.lang3.StringUtils;
diff --git a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/asyncapi/model/SchemaFieldObject.java b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/asyncapi/model/SchemaFieldObject.java
deleted file mode 100644
index b3eb12c6..00000000
--- a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/asyncapi/model/SchemaFieldObject.java
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * This Source Code Form is subject to the terms of the Mozilla Public
- * * License, v. 2.0. If a copy of the MPL was not distributed with this
- * * file, You can obtain one at https://mozilla.org/MPL/2.0/.
- */
-
-package com.sngular.api.generator.plugin.asyncapi.model;
-
-import java.util.List;
-
-import lombok.AllArgsConstructor;
-import lombok.Builder;
-import lombok.Builder.Default;
-import lombok.Data;
-import lombok.NoArgsConstructor;
-
-@Data
-@Builder
-@NoArgsConstructor
-@AllArgsConstructor
-public class SchemaFieldObject {
-
- private String baseName;
-
- private String dataTypeSimple;
-
- @Default
- private SchemaFieldObjectProperties restrictions = new SchemaFieldObjectProperties();
-
- private String dataType;
-
- private String importClass;
-
- private boolean required;
-
- private List enumValues;
-
- private Object constValue;
-
-}
diff --git a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/asyncapi/model/SchemaObject.java b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/asyncapi/model/SchemaObject.java
deleted file mode 100644
index ed66182f..00000000
--- a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/asyncapi/model/SchemaObject.java
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
- * This Source Code Form is subject to the terms of the Mozilla Public
- * * License, v. 2.0. If a copy of the MPL was not distributed with this
- * * file, You can obtain one at https://mozilla.org/MPL/2.0/.
- */
-
-package com.sngular.api.generator.plugin.asyncapi.model;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import lombok.AllArgsConstructor;
-import lombok.Builder;
-import lombok.Data;
-import lombok.NoArgsConstructor;
-
-@Data
-@Builder
-@NoArgsConstructor
-@AllArgsConstructor
-public class SchemaObject {
-
- private String schemaName;
-
- private String className;
-
- private List importList;
-
- private List fieldObjectList;
-
- private String schemaCombinator;
-
- private String parentPackage;
-
- public static final class SchemaObjectBuilder {
-
- private final List importList = new ArrayList<>();
-
- private final List fieldObjectList = new ArrayList<>();
-
- public SchemaObjectBuilder importList(final List importList) {
- this.importList.addAll(importList);
- return this;
- }
-
- public SchemaObjectBuilder importItem(final String importItem) {
- this.importList.add(importItem);
- return this;
- }
-
- public SchemaObjectBuilder fieldObjectList(final List fieldObjectList) {
- this.fieldObjectList.addAll(fieldObjectList);
- return this;
- }
-
- public SchemaObjectBuilder fieldObject(final SchemaFieldObject fieldObject) {
- this.fieldObjectList.add(fieldObject);
- return this;
- }
- }
-}
diff --git a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/asyncapi/parameter/OperationParameterObject.java b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/asyncapi/parameter/OperationParameterObject.java
index f831c476..f332414c 100644
--- a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/asyncapi/parameter/OperationParameterObject.java
+++ b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/asyncapi/parameter/OperationParameterObject.java
@@ -12,54 +12,31 @@
package com.sngular.api.generator.plugin.asyncapi.parameter;
-
import java.util.List;
-import java.util.Map;
-
-import com.sngular.api.generator.plugin.common.model.TimeType;
+import com.sngular.api.generator.plugin.common.model.CommonSpecFile;
import lombok.AllArgsConstructor;
-import lombok.Builder;
-import lombok.Builder.Default;
import lombok.Data;
+import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
+import lombok.experimental.SuperBuilder;
import org.apache.commons.lang3.StringUtils;
@Data
-@Builder
+@SuperBuilder
@NoArgsConstructor
@AllArgsConstructor
-public final class OperationParameterObject {
+@EqualsAndHashCode(callSuper = true)
+public final class OperationParameterObject extends CommonSpecFile {
private String ids;
- private String apiPackage;
-
- private String modelPackage;
-
- private String modelNameSuffix;
-
private String classNamePostfix;
- private boolean useLombokModelAnnotation;
-
- @Builder.Default
- private String dateTimeFormat = "yyyy-MM-dd'T'HH:mm:ss";
-
- @Builder.Default
- private String dateFormat = "yyyy-MM-dd";
-
- @Default
- private TimeType useTimeType = TimeType.LOCAL;
-
@SuppressWarnings("unused")
private List operationIds;
public List getOperationIds() {
return StringUtils.isEmpty(ids) ? List.of() : List.of(ids.replace(" ", "").split(","));
}
-
- public Map getFormats() {
- return Map.of("DATE_TIME", dateTimeFormat, "DATE", dateFormat);
- }
}
diff --git a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/asyncapi/template/ClassTemplate.java b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/asyncapi/template/ClassTemplate.java
index 073f257c..30a8ce46 100644
--- a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/asyncapi/template/ClassTemplate.java
+++ b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/asyncapi/template/ClassTemplate.java
@@ -7,8 +7,7 @@
package com.sngular.api.generator.plugin.asyncapi.template;
import java.nio.file.Path;
-
-import com.sngular.api.generator.plugin.asyncapi.model.SchemaObject;
+import com.sngular.api.generator.plugin.common.model.SchemaObject;
import lombok.Builder;
import lombok.Value;
@@ -28,4 +27,6 @@ public class ClassTemplate {
SchemaObject classSchema;
+ boolean useLombok;
+
}
diff --git a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/asyncapi/template/ClasspathTemplateLoader.java b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/asyncapi/template/ClasspathTemplateLoader.java
index 7da369b3..0310bfec 100644
--- a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/asyncapi/template/ClasspathTemplateLoader.java
+++ b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/asyncapi/template/ClasspathTemplateLoader.java
@@ -6,74 +6,36 @@
package com.sngular.api.generator.plugin.asyncapi.template;
+import com.sngular.api.generator.plugin.common.template.CommonTemplateLoader;
+import com.sngular.api.generator.plugin.exception.GeneratorTemplateException;
+
import java.io.IOException;
import java.io.InputStream;
-import java.io.Reader;
-import java.io.StringReader;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
-import com.sngular.api.generator.plugin.exception.GeneratorTemplateException;
-import freemarker.cache.TemplateLoader;
+public class ClasspathTemplateLoader extends CommonTemplateLoader {
-public class ClasspathTemplateLoader implements TemplateLoader {
private static final List TEMPLATE_FILES = List.of("templateSuppliers.ftlh", "interfaceConsumer.ftlh", "templateConsumers.ftlh",
- "interfaceSupplier.ftlh", "templateStreamBridge.ftlh", "templateSchema.ftlh",
- "templateSchemaWithLombok.ftlh", "templateModelClassException.ftlh",
- "interfaceSupplierWithKafkaBindings.ftlh", "templateSuppliersWithKafkaBindings.ftlh",
+ "interfaceSupplier.ftlh", "templateStreamBridge.ftlh",
+ "interfaceSupplierWithKafkaBindings.ftlh", "templateSuppliersWithKafkaBindings.ftlh",
"interfaceConsumerWithKafkaBindings.ftlh", "templateConsumersWithKafkaBindings.ftlh",
"templateStreamBridgeWithKafkaBindings.ftlh", "templateMessageWrapper.ftlh");
-
- private static final List TEMPLATE_ANNOTATION_FILES = List.of(TemplateIndexConstants.TEMPLATE_NOT_NULL_ANNOTATION,
- TemplateIndexConstants.TEMPLATE_NOT_NULL_VALIDATOR_ANNOTATION,
- TemplateIndexConstants.TEMPLATE_MAX_ANNOTATION, TemplateIndexConstants.TEMPLATE_MAX_VALIDATOR_ANNOTATION,
- TemplateIndexConstants.TEMPLATE_MIN_ANNOTATION, TemplateIndexConstants.TEMPLATE_MIN_VALIDATOR_ANNOTATION,
- TemplateIndexConstants.TEMPLATE_SIZE_ANNOTATION, TemplateIndexConstants.TEMPLATE_SIZE_VALIDATOR_ANNOTATION,
- TemplateIndexConstants.TEMPLATE_PATTERN_ANNOTATION,
- TemplateIndexConstants.TEMPLATE_PATTERN_VALIDATOR_ANNOTATION,
- TemplateIndexConstants.TEMPLATE_MULTIPLEOF_ANNOTATION,
- TemplateIndexConstants.TEMPLATE_MULTIPLEOF_VALIDATOR_ANNOTATION,
- TemplateIndexConstants.TEMPLATE_MAX_ITEMS_ANNOTATION,
- TemplateIndexConstants.TEMPLATE_MAX_ITEMS_VALIDATOR_ANNOTATION,
- TemplateIndexConstants.TEMPLATE_MIN_ITEMS_ANNOTATION,
- TemplateIndexConstants.TEMPLATE_MIN_ITEMS_VALIDATOR_ANNOTATION,
- TemplateIndexConstants.TEMPLATE_UNIQUE_ITEMS_ANNOTATION,
- TemplateIndexConstants.TEMPLATE_UNIQUE_ITEMS_VALIDATOR_ANNOTATION);
-
- private static final ClassLoader LOADER = ClasspathTemplateLoader.class.getClassLoader();
-
- private final Map templatesMap = new HashMap<>();
-
public ClasspathTemplateLoader() {
- templatesMap.putAll(getResourceFolderFiles());
- }
-
- @Override
- public final Object findTemplateSource(final String templateName) {
- return templatesMap.get(templateName);
- }
-
- @Override
- public final long getLastModified(final Object o) {
- return 0;
- }
-
- @Override
- public final Reader getReader(final Object template, final String charSet) {
- return new StringReader(template.toString());
- }
-
- @Override
- public void closeTemplateSource(final Object o) {
- // Not required to implement
+ super();
+ init(getResourceFolderFiles());
}
private Map getResourceFolderFiles() {
final Map templates = new HashMap<>();
try {
+ for (var templateFile : TEMPLATE_MODEL_FILES) {
+ templates.put(templateFile,
+ readFile((InputStream) Objects.requireNonNull(LOADER.getResource("templates/model/" + templateFile)).getContent()));
+ }
for (var templateFile : TEMPLATE_FILES) {
templates.put(templateFile,
readFile((InputStream) Objects.requireNonNull(LOADER.getResource("templates/asyncapi/" + templateFile)).getContent()));
@@ -88,8 +50,4 @@ private Map getResourceFolderFiles() {
return templates;
}
-
- private String readFile(final InputStream file) throws IOException {
- return new String(file.readAllBytes());
- }
}
diff --git a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/asyncapi/template/TemplateFactory.java b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/asyncapi/template/TemplateFactory.java
index 7ced27b3..f2da5871 100644
--- a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/asyncapi/template/TemplateFactory.java
+++ b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/asyncapi/template/TemplateFactory.java
@@ -7,55 +7,34 @@
package com.sngular.api.generator.plugin.asyncapi.template;
import java.io.File;
-import java.io.FileWriter;
import java.io.IOException;
import java.nio.file.Path;
-import java.nio.file.Paths;
import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Objects;
-import java.util.Set;
-
-import com.sngular.api.generator.plugin.asyncapi.exception.FileSystemException;
import com.sngular.api.generator.plugin.asyncapi.exception.NonSupportedBindingException;
import com.sngular.api.generator.plugin.asyncapi.model.MethodObject;
-import com.sngular.api.generator.plugin.asyncapi.model.SchemaFieldObject;
-import com.sngular.api.generator.plugin.asyncapi.model.SchemaObject;
+import com.sngular.api.generator.plugin.asyncapi.parameter.SpecFile;
import com.sngular.api.generator.plugin.asyncapi.util.BindingTypeEnum;
-import com.sngular.api.generator.plugin.asyncapi.util.MapperUtil;
-import com.sngular.api.generator.plugin.exception.GeneratorTemplateException;
-import freemarker.template.Configuration;
-import freemarker.template.Template;
-import freemarker.template.TemplateException;
-import freemarker.template.TemplateExceptionHandler;
-
-public class TemplateFactory {
-
- public static final String SUBSCRIBE_PACKAGE = "subscribePackage";
-
- public static final String WRAPPER_PACKAGE = "wrapperPackage";
+import com.sngular.api.generator.plugin.common.template.CommonTemplateFactory;
+import com.sngular.api.generator.plugin.common.tools.MapperUtil;
- public static final String SUPPLIER_PACKAGE = "supplierPackage";
+public class TemplateFactory extends CommonTemplateFactory {
- public static final String STREAM_BRIDGE_PACKAGE = "streamBridgePackage";
+ private static final String SUBSCRIBE_PACKAGE = "subscribePackage";
- public static final String SUPPLIER_ENTITIES_SUFFIX = "supplierEntitiesSuffix";
+ private static final String WRAPPER_PACKAGE = "wrapperPackage";
- public static final String STREAM_BRIDGE_ENTITIES_SUFFIX = "streamBridgeEntitiesSuffix";
+ private static final String SUPPLIER_PACKAGE = "supplierPackage";
- public static final String SUBSCRIBE_ENTITIES_SUFFIX = "subscribeEntitiesSuffix";
+ private static final String STREAM_BRIDGE_PACKAGE = "streamBridgePackage";
- public static final String FILE_TYPE_JAVA = ".java";
+ private static final String SUPPLIER_ENTITIES_SUFFIX = "supplierEntitiesSuffix";
- public static final String EXCEPTION_PACKAGE = "exceptionPackage";
+ private static final String STREAM_BRIDGE_ENTITIES_SUFFIX = "streamBridgeEntitiesSuffix";
- private final Configuration cfg = new Configuration(Configuration.VERSION_2_3_32);
-
- private final Map root = new HashMap<>();
+ private static final String SUBSCRIBE_ENTITIES_SUFFIX = "subscribeEntitiesSuffix";
private final List publishMethods = new ArrayList<>();
@@ -63,8 +42,6 @@ public class TemplateFactory {
private final List streamBridgeMethods = new ArrayList<>();
- private final List schemaObjectMap = new LinkedList<>();
-
private String subscribeFilePath = null;
private String supplierFilePath = null;
@@ -77,205 +54,63 @@ public class TemplateFactory {
private String subscribeClassName = null;
- public TemplateFactory() {
- cfg.setTemplateLoader(new ClasspathTemplateLoader());
- cfg.setDefaultEncoding("UTF-8");
- cfg.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
- cfg.setLogTemplateExceptions(true);
+ public TemplateFactory(boolean enableOverwrite,
+ final File targetFolder,
+ final String processedGeneratedSourcesFolder,
+ final File baseDir) {
+ super(enableOverwrite, targetFolder, processedGeneratedSourcesFolder, baseDir, new ClasspathTemplateLoader());
}
- private void fillTemplate(final String filePathToSave, final String className, final String templateName, final Map root) throws IOException, TemplateException {
- final File fileToSave = Paths.get(filePathToSave).normalize().toFile();
- fileToSave.mkdirs();
- final String pathToSaveMainClass = fileToSave.toPath().resolve(className + FILE_TYPE_JAVA).toString();
- fillTemplate(pathToSaveMainClass, templateName, root);
- }
-
- private void fillTemplate(final String pathToSaveMainClass, final String templateName, final Map root) throws IOException, TemplateException {
- writeTemplateToFile(templateName, root, pathToSaveMainClass);
- }
-
- public final void fillTemplates(final boolean generateExceptionTemplate) throws IOException, TemplateException {
- root.put("publishMethods", publishMethods);
- root.put("subscribeMethods", subscribeMethods);
- root.put("streamBridgeMethods", streamBridgeMethods);
+ public final void fillTemplates() throws IOException {
+ addToRoot("publishMethods", publishMethods);
+ addToRoot("subscribeMethods", subscribeMethods);
+ addToRoot("streamBridgeMethods", streamBridgeMethods);
for (final var method : publishMethods) {
- fillTemplate(supplierFilePath, supplierClassName, checkTemplate(method.getBindingType(), TemplateIndexConstants.TEMPLATE_API_SUPPLIERS), root);
+ fillTemplate(supplierFilePath, supplierClassName, checkTemplate(method.getBindingType(), TemplateIndexConstants.TEMPLATE_API_SUPPLIERS));
}
for (final var method : subscribeMethods) {
- fillTemplate(subscribeFilePath, subscribeClassName, checkTemplate(method.getBindingType(), TemplateIndexConstants.TEMPLATE_API_CONSUMERS), root);
+ fillTemplate(subscribeFilePath, subscribeClassName, checkTemplate(method.getBindingType(), TemplateIndexConstants.TEMPLATE_API_CONSUMERS));
}
for (final var method : streamBridgeMethods) {
- fillTemplate(streamBridgeFilePath, streamBridgeClassName, checkTemplate(method.getBindingType(), TemplateIndexConstants.TEMPLATE_API_STREAM_BRIDGE), root);
- }
-
- final String exceptionPackage;
- if (Boolean.TRUE.equals(generateExceptionTemplate)) {
- exceptionPackage = getClassTemplate().getModelPackage();
- } else {
- exceptionPackage = null;
+ fillTemplate(streamBridgeFilePath, streamBridgeClassName, checkTemplate(method.getBindingType(), TemplateIndexConstants.TEMPLATE_API_STREAM_BRIDGE));
}
- final HashSet propertiesSet = new HashSet<>();
- schemaObjectMap.forEach(classTemplate -> {
- try {
- propertiesSet.addAll(fillTemplateSchema(classTemplate, false, exceptionPackage));
- } catch (final IOException | TemplateException exception) {
- throw new FileSystemException(exception);
- }
- });
+ generateTemplates();
- if (!schemaObjectMap.isEmpty()) {
- try {
- fillTemplates(schemaObjectMap.get(0).getPropertiesPath(), schemaObjectMap.get(0).getModelPackage(), propertiesSet);
- } catch (IOException | TemplateException e) {
- throw new GeneratorTemplateException("Generation Error", e);
- }
- }
this.generateInterfaces();
}
- @SuppressWarnings("checkstyle:CyclomaticComplexity")
- private void fillTemplates(final Path filePathToSave, final String modelPackage, final Set fieldProperties) throws TemplateException, IOException {
- for (final String current : fieldProperties) {
- switch (current) {
- case "Size":
- fillTemplateCustom(filePathToSave, modelPackage, "Size.java", TemplateIndexConstants.TEMPLATE_SIZE_ANNOTATION, "SizeValidator.java",
- TemplateIndexConstants.TEMPLATE_SIZE_VALIDATOR_ANNOTATION);
- break;
- case "Pattern":
- fillTemplateCustom(filePathToSave, modelPackage, "Pattern.java", TemplateIndexConstants.TEMPLATE_PATTERN_ANNOTATION,
- "PatternValidator.java", TemplateIndexConstants.TEMPLATE_PATTERN_VALIDATOR_ANNOTATION);
- break;
- case "MultipleOf":
- fillTemplateCustom(filePathToSave, modelPackage, "MultipleOf.java", TemplateIndexConstants.TEMPLATE_MULTIPLEOF_ANNOTATION,
- "MultipleOfValidator.java", TemplateIndexConstants.TEMPLATE_MULTIPLEOF_VALIDATOR_ANNOTATION);
- break;
- case "Maximum":
- fillTemplateCustom(filePathToSave, modelPackage, "Max.java", TemplateIndexConstants.TEMPLATE_MAX_ANNOTATION,
- "MaxValidator.java", TemplateIndexConstants.TEMPLATE_MAX_VALIDATOR_ANNOTATION);
- break;
- case "Minimum":
- fillTemplateCustom(filePathToSave, modelPackage, "Min.java", TemplateIndexConstants.TEMPLATE_MIN_ANNOTATION,
- "MinValidator.java", TemplateIndexConstants.TEMPLATE_MIN_VALIDATOR_ANNOTATION);
- break;
- case "MaxItems":
- fillTemplateCustom(filePathToSave, modelPackage, "MaxItems.java", TemplateIndexConstants.TEMPLATE_MAX_ITEMS_ANNOTATION,
- "MaxItemsValidator.java", TemplateIndexConstants.TEMPLATE_MAX_ITEMS_VALIDATOR_ANNOTATION);
- break;
- case "MinItems":
- fillTemplateCustom(filePathToSave, modelPackage, "MinItems.java", TemplateIndexConstants.TEMPLATE_MIN_ITEMS_ANNOTATION,
- "MinItemsValidator.java", TemplateIndexConstants.TEMPLATE_MIN_ITEMS_VALIDATOR_ANNOTATION);
- break;
- case "NotNull":
- fillTemplateCustom(filePathToSave, modelPackage, "NotNull.java", TemplateIndexConstants.TEMPLATE_NOT_NULL_ANNOTATION,
- "NotNullValidator.java", TemplateIndexConstants.TEMPLATE_NOT_NULL_VALIDATOR_ANNOTATION);
- break;
- case "UniqueItems":
- fillTemplateCustom(filePathToSave, modelPackage, "UniqueItems.java", TemplateIndexConstants.TEMPLATE_UNIQUE_ITEMS_ANNOTATION,
- "UniqueItemsValidator.java", TemplateIndexConstants.TEMPLATE_UNIQUE_ITEMS_VALIDATOR_ANNOTATION);
- break;
- default:
- break;
- }
- }
- }
-
- private ClassTemplate getClassTemplate() {
- ClassTemplate ourClassTemplate = null;
- for (ClassTemplate classTemplate : schemaObjectMap) {
- if (classTemplate.getFilePath().endsWith("schemas")) {
- ourClassTemplate = classTemplate;
- break;
- }
- }
- if (ourClassTemplate == null) {
- ourClassTemplate = schemaObjectMap.get(0);
- }
-
- return ourClassTemplate;
- }
-
- public final void fillTemplateModelClassException(final Path filePathToSave, final String modelPackage) throws IOException, TemplateException {
- final Path pathToExceptionPackage = filePathToSave.resolve("exception");
- pathToExceptionPackage.toFile().mkdirs();
- root.put(EXCEPTION_PACKAGE, modelPackage);
- final String pathToSaveMainClass = pathToExceptionPackage.resolve("ModelClassException.java").toString();
- writeTemplateToFile(TemplateIndexConstants.TEMPLATE_MODEL_EXCEPTION, root, pathToSaveMainClass);
- }
-
- public final void fillTemplateCustom(
- final Path filePathToSave, final String modelPackage, final String fileNameAnnotation, final String templateAnnotation,
- final String fileNameValidator, final String templateValidator) throws TemplateException, IOException {
- final Path pathToCustomValidatorPackage = filePathToSave.resolve("customvalidator");
- pathToCustomValidatorPackage.toFile().mkdirs();
- root.put("packageModel", modelPackage);
- final String pathToSaveAnnotationClass = pathToCustomValidatorPackage.resolve(fileNameAnnotation).toString();
- writeTemplateToFile(templateAnnotation, root, pathToSaveAnnotationClass);
- final String pathToSaveValidatorClass = pathToCustomValidatorPackage.resolve(fileNameValidator).toString();
- writeTemplateToFile(templateValidator, root, pathToSaveValidatorClass);
- }
-
- @SuppressWarnings("checkstyle:CyclomaticComplexity")
- private Set fillTemplateSchema(final ClassTemplate classTemplate, final Boolean useLombok, final String exceptionPackage)
- throws IOException, TemplateException {
- final var propertiesSet = new HashSet();
- final var schemaObject = classTemplate.getClassSchema();
- final var filePath = classTemplate.getFilePath();
- if (Objects.nonNull(schemaObject) && Objects.nonNull(schemaObject.getFieldObjectList()) && !schemaObject.getFieldObjectList().isEmpty()) {
- final Map rootSchema = new HashMap<>();
- rootSchema.put("schema", schemaObject);
- root.put("schema", schemaObject);
- final String templateName = null != useLombok && useLombok ? TemplateIndexConstants.TEMPLATE_CONTENT_SCHEMA_LOMBOK : TemplateIndexConstants.TEMPLATE_CONTENT_SCHEMA;
- if (Objects.nonNull(classTemplate.getModelPackage())) {
- rootSchema.put("packageModel", classTemplate.getModelPackage());
- }
- if (Objects.nonNull(exceptionPackage)) {
- rootSchema.put(EXCEPTION_PACKAGE, exceptionPackage);
- root.put(EXCEPTION_PACKAGE, exceptionPackage);
- }
- fillTemplate(filePath.toString(), schemaObject.getClassName(), templateName, rootSchema);
- for (SchemaFieldObject fieldObject : schemaObject.getFieldObjectList()) {
- propertiesSet.addAll(fieldObject.getRestrictions().getProperties());
- if (fieldObject.isRequired() && Boolean.FALSE.equals(useLombok)) {
- propertiesSet.add("NotNull");
- }
- }
- }
- return propertiesSet;
- }
-
public final void setSubscribePackageName(final String packageName) {
- root.put(SUBSCRIBE_PACKAGE, packageName);
+ addToRoot(SUBSCRIBE_PACKAGE, packageName);
}
public final void setWrapperPackageName(final String packageName) {
- root.put(WRAPPER_PACKAGE, packageName);
+ addToRoot(WRAPPER_PACKAGE, packageName);
}
public final void setSupplierPackageName(final String packageName) {
- root.put(SUPPLIER_PACKAGE, packageName);
+ addToRoot(SUPPLIER_PACKAGE, packageName);
}
public final void setStreamBridgePackageName(final String packageName) {
- root.put(STREAM_BRIDGE_PACKAGE, packageName);
+ addToRoot(STREAM_BRIDGE_PACKAGE, packageName);
}
public final void setSubscribeClassName(final String className) {
- root.put("subscribeClassName", className);
+ addToRoot("subscribeClassName", className);
this.subscribeClassName = className;
}
public final void setSupplierClassName(final String className) {
- root.put("supplierClassName", className);
+ addToRoot("supplierClassName", className);
this.supplierClassName = className;
}
public final void setStreamBridgeClassName(final String className) {
- root.put("streamBridgeClassName", className);
+ addToRoot("streamBridgeClassName", className);
this.streamBridgeClassName = className;
}
@@ -325,96 +160,89 @@ public final void addSubscribeMethod(final String operationId, final String clas
.build());
}
- public final void addSchemaObject(final String modelPackage, final String keyClassName, final SchemaObject schemaObject, final Path filePath, final Path propertiesPath) {
- final var builder = ClassTemplate.builder().filePath(filePath).modelPackage(modelPackage).className(schemaObject.getClassName()).classSchema(schemaObject)
- .propertiesPath(propertiesPath);
- if (Objects.nonNull(keyClassName)) {
- builder.keyClassName(keyClassName);
- }
- schemaObjectMap.add(builder.build());
- }
-
public final void setSupplierEntitiesSuffix(final String suffix) {
- root.put(SUPPLIER_ENTITIES_SUFFIX, suffix);
+ addToRoot(SUPPLIER_ENTITIES_SUFFIX, suffix);
}
public final void setStreamBridgeEntitiesSuffix(final String suffix) {
- root.put(STREAM_BRIDGE_ENTITIES_SUFFIX, suffix);
+ addToRoot(STREAM_BRIDGE_ENTITIES_SUFFIX, suffix);
}
public final void setSubscribeEntitiesSuffix(final String suffix) {
- root.put(SUBSCRIBE_ENTITIES_SUFFIX, suffix);
+ addToRoot(SUBSCRIBE_ENTITIES_SUFFIX, suffix);
}
public final void calculateJavaEEPackage(final Integer springBootVersion) {
if (3 <= springBootVersion) {
- root.put("javaEEPackage", "jakarta");
+ addToRoot("javaEEPackage", "jakarta");
} else {
- root.put("javaEEPackage", "javax");
+ addToRoot("javaEEPackage", "javax");
}
}
public final void clearData() {
- root.clear();
+ cleanData();
publishMethods.clear();
subscribeMethods.clear();
- schemaObjectMap.clear();
streamBridgeMethods.clear();
- subscribeFilePath = null;
- supplierFilePath = null;
- streamBridgeFilePath = null;
- supplierClassName = null;
- subscribeClassName = null;
- streamBridgeClassName = null;
+ }
+
+ @Override
+ protected void clearRoot() {
+ delFromRoot("classNamespace");
+ delFromRoot("className");
+ delFromRoot("keyNamespace");
+ delFromRoot("publishMethods");
+ delFromRoot("subscribeMethods");
+ delFromRoot("streamBridgeMethods");
}
public final void fillTemplateWrapper(
- final Path filePath,
final String modelPackage,
final String classFullName,
final String className,
final String keyClassFullName,
final String keyClassName
- ) throws TemplateException, IOException {
- final Map context = Map.of(WRAPPER_PACKAGE, modelPackage,
- "classNamespace", classFullName,
- "className", className,
- "keyNamespace", keyClassFullName,
- "keyClassName", keyClassName);
-
- writeTemplateToFile(TemplateIndexConstants.TEMPLATE_MESSAGE_WRAPPER, context, filePath.resolve("MessageWrapper.java").toAbsolutePath().toString());
+ ) throws IOException {
+ final var filePath = processPath(getPath(modelPackage));
+ addToRoot(Map.of(WRAPPER_PACKAGE, modelPackage,
+ "classNamespace", classFullName,
+ "className", className,
+ "keyNamespace", keyClassFullName,
+ "keyClassName", keyClassName));
+ writeTemplateToFile(TemplateIndexConstants.TEMPLATE_MESSAGE_WRAPPER, filePath, "MessageWrapper");
+ }
+
+ public void processFilePaths(final SpecFile fileParameter, final String defaultApiPackage) {
+ var pathToCreate = convertPackageToTargetPath(fileParameter.getSupplier(), defaultApiPackage);
+ if (Objects.nonNull(pathToCreate)) {
+ setSupplierFilePath(processPath(pathToCreate));
+ }
+ pathToCreate = convertPackageToTargetPath(fileParameter.getStreamBridge(), defaultApiPackage);
+ if (Objects.nonNull(pathToCreate)) {
+ setStreamBridgeFilePath(processPath(pathToCreate));
+ }
+ pathToCreate = convertPackageToTargetPath(fileParameter.getConsumer(), defaultApiPackage);
+ if (Objects.nonNull(pathToCreate)) {
+ setSubscribeFilePath(processPath(pathToCreate));
+ }
}
-
- private void generateInterfaces() throws IOException, TemplateException {
+ private void generateInterfaces() throws IOException {
final ArrayList allMethods = new ArrayList<>(subscribeMethods);
allMethods.addAll(publishMethods);
- final Map interfaceRoot = new HashMap<>();
- interfaceRoot.put(SUBSCRIBE_PACKAGE, root.get(SUBSCRIBE_PACKAGE));
- interfaceRoot.put(SUPPLIER_PACKAGE, root.get(SUPPLIER_PACKAGE));
-
- interfaceRoot.put(SUPPLIER_ENTITIES_SUFFIX, root.get(SUPPLIER_ENTITIES_SUFFIX));
- interfaceRoot.put(SUBSCRIBE_ENTITIES_SUFFIX, root.get(SUBSCRIBE_ENTITIES_SUFFIX));
-
for (MethodObject method : allMethods) {
- interfaceRoot.put("method", method);
+ addToRoot("method", method);
if (Objects.equals(method.getType(), "publish")) {
fillTemplate(supplierFilePath, "I" + method.getOperationId().substring(0, 1).toUpperCase() + method.getOperationId().substring(1),
- checkTemplate(method.getBindingType(), TemplateIndexConstants.TEMPLATE_INTERFACE_SUPPLIERS), interfaceRoot);
+ checkTemplate(method.getBindingType(), TemplateIndexConstants.TEMPLATE_INTERFACE_SUPPLIERS));
} else if (Objects.equals(method.getType(), "subscribe")) {
fillTemplate(subscribeFilePath, "I" + method.getOperationId().substring(0, 1).toUpperCase() + method.getOperationId().substring(1),
- checkTemplate(method.getBindingType(), TemplateIndexConstants.TEMPLATE_INTERFACE_CONSUMERS), interfaceRoot);
+ checkTemplate(method.getBindingType(), TemplateIndexConstants.TEMPLATE_INTERFACE_CONSUMERS));
}
}
- }
-
- private void writeTemplateToFile(final String templateName, final Map root, final String path) throws IOException, TemplateException {
- final Template template = cfg.getTemplate(templateName);
-
- final FileWriter writer = new FileWriter(path);
- template.process(root, writer);
- writer.close();
+ cleanData();
}
private String checkTemplate(final String bindingType, final String defaultTemplate) {
diff --git a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/asyncapi/template/TemplateIndexConstants.java b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/asyncapi/template/TemplateIndexConstants.java
index fe83b7e3..0eb92c5b 100644
--- a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/asyncapi/template/TemplateIndexConstants.java
+++ b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/asyncapi/template/TemplateIndexConstants.java
@@ -6,70 +6,20 @@
package com.sngular.api.generator.plugin.asyncapi.template;
-public class TemplateIndexConstants {
+import com.sngular.api.generator.plugin.common.template.CommonTemplateIndexConstants;
- public static final String TEMPLATE_CONTENT_SCHEMA = "templateSchema.ftlh";
-
- public static final String TEMPLATE_CONTENT_SCHEMA_LOMBOK = "templateSchemaWithLombok.ftlh";
-
- public static final String TEMPLATE_MODEL_EXCEPTION = "templateModelClassException.ftlh";
+public class TemplateIndexConstants extends CommonTemplateIndexConstants {
public static final String TEMPLATE_API_SUPPLIERS = "templateSuppliers.ftlh";
- public static final String TEMPLATE_API_SUPPLIERS_WITH_KAFKA_BINDINGS = "templateSuppliersWithKafkaBindings.ftlh";
-
public static final String TEMPLATE_API_CONSUMERS = "templateConsumers.ftlh";
- public static final String TEMPLATE_API_CONSUMERS_WITH_KAFKA_BINDINGS = "templateConsumersWithKafkaBindings.ftlh";
-
public static final String TEMPLATE_API_STREAM_BRIDGE = "templateStreamBridge.ftlh";
- public static final String TEMPLATE_API_STREAM_BRIDGE_WITH_KAFKA_BINDINGS = "templateStreamBridgeWithKafkaBindings.ftlh";
-
public static final String TEMPLATE_INTERFACE_SUPPLIERS = "interfaceSupplier.ftlh";
- public static final String TEMPLATE_INTERFACE_SUPPLIERS_WITH_KAFKA_BINDINGS = "interfaceSupplierWithKafkaBindings.ftlh";
-
public static final String TEMPLATE_INTERFACE_CONSUMERS = "interfaceConsumer.ftlh";
- public static final String TEMPLATE_INTERFACE_CONSUMERS_WITH_KAFKA_BINDINGS = "interfaceConsumerWithKafkaBindings.ftlh";
-
- public static final String TEMPLATE_NOT_NULL_ANNOTATION = "templateNotNull.ftlh";
-
- public static final String TEMPLATE_NOT_NULL_VALIDATOR_ANNOTATION = "templateNotNullValidator.ftlh";
-
- public static final String TEMPLATE_MIN_ANNOTATION = "templateMin.ftlh";
-
- public static final String TEMPLATE_MIN_VALIDATOR_ANNOTATION = "templateMinValidatorAsync.ftlh";
-
- public static final String TEMPLATE_MAX_ANNOTATION = "templateMax.ftlh";
-
- public static final String TEMPLATE_MAX_VALIDATOR_ANNOTATION = "templateMaxValidatorAsync.ftlh";
-
- public static final String TEMPLATE_SIZE_ANNOTATION = "templateSize.ftlh";
-
- public static final String TEMPLATE_SIZE_VALIDATOR_ANNOTATION = "templateSizeValidator.ftlh";
-
- public static final String TEMPLATE_PATTERN_ANNOTATION = "templatePattern.ftlh";
-
- public static final String TEMPLATE_PATTERN_VALIDATOR_ANNOTATION = "templatePatternValidator.ftlh";
-
- public static final String TEMPLATE_MULTIPLEOF_ANNOTATION = "templateMultipleOf.ftlh";
-
- public static final String TEMPLATE_MULTIPLEOF_VALIDATOR_ANNOTATION = "templateMultipleOfValidatorAsync.ftlh";
-
- public static final String TEMPLATE_MAX_ITEMS_ANNOTATION = "templateMaxItems.ftlh";
-
- public static final String TEMPLATE_MAX_ITEMS_VALIDATOR_ANNOTATION = "templateMaxItemsValidator.ftlh";
-
- public static final String TEMPLATE_MIN_ITEMS_ANNOTATION = "templateMinItems.ftlh";
-
- public static final String TEMPLATE_MIN_ITEMS_VALIDATOR_ANNOTATION = "templateMinItemsValidator.ftlh";
-
- public static final String TEMPLATE_UNIQUE_ITEMS_ANNOTATION = "templateUniqueItems.ftlh";
-
- public static final String TEMPLATE_UNIQUE_ITEMS_VALIDATOR_ANNOTATION = "templateUniqueItemsValidator.ftlh";
-
public static final String TEMPLATE_MESSAGE_WRAPPER = "templateMessageWrapper.ftlh";
public static final String KAFKA_BINDINGS_FTLH = "WithKafkaBindings.ftlh";
diff --git a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/asyncapi/util/MapperContentUtil.java b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/asyncapi/util/MapperContentUtil.java
deleted file mode 100644
index 1533b615..00000000
--- a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/asyncapi/util/MapperContentUtil.java
+++ /dev/null
@@ -1,486 +0,0 @@
-/*
- * This Source Code Form is subject to the terms of the Mozilla Public
- * * License, v. 2.0. If a copy of the MPL was not distributed with this
- * * file, You can obtain one at https://mozilla.org/MPL/2.0/.
- */
-
-package com.sngular.api.generator.plugin.asyncapi.util;
-
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.Objects;
-import java.util.Queue;
-import java.util.Set;
-import java.util.concurrent.ConcurrentLinkedQueue;
-
-import com.fasterxml.jackson.databind.JsonNode;
-import com.sngular.api.generator.plugin.asyncapi.exception.BadDefinedEnumException;
-import com.sngular.api.generator.plugin.asyncapi.exception.NonSupportedSchemaException;
-import com.sngular.api.generator.plugin.asyncapi.model.SchemaFieldObject;
-import com.sngular.api.generator.plugin.asyncapi.model.SchemaFieldObjectProperties;
-import com.sngular.api.generator.plugin.asyncapi.model.SchemaObject;
-import com.sngular.api.generator.plugin.common.model.TimeType;
-import com.sngular.api.generator.plugin.common.tools.ApiTool;
-import org.apache.commons.lang3.StringUtils;
-import org.apache.commons.text.WordUtils;
-
-public class MapperContentUtil {
-
- public static final String OBJECT = "object";
-
- public static final String ONE_OF = "oneOf";
-
- public static final String PROPERTIES = "properties";
-
- public static final String REF = "$ref";
-
- public static final String TYPE = "type";
-
- public static final String ALL_OF = "allOf";
-
- public static final String ANY_OF = "anyOf";
-
- private static final String ARRAY = "array";
-
- private static final String BIG_DECIMAL = "BigDecimal";
-
- private static final String LOCAL_DATE = "LocalDate";
-
- private static final String LOCAL_DATE_TIME = "LocalDateTime";
-
- private static final String ZONED_DATE_TIME = "ZonedDateTime";
-
- private static final String MAP = "map";
-
- private static String schemaCombinatorType;
-
- private MapperContentUtil() {}
-
- public static List mapComponentToSchemaObject(
- final Map totalSchemas, final String component, final JsonNode model,
- final String prefix, final String suffix, final String parentPackage,
- final String modelPackage, final Map formats, final TimeType useTimeType) {
- final List schemasList = new ArrayList<>();
- if (Objects.nonNull(model)) {
- final Queue modelToBuildList = new ConcurrentLinkedQueue<>();
- final List alreadyBuilt = new ArrayList<>();
- schemasList.add(buildSchemaObject(totalSchemas, component, model, prefix, suffix, modelToBuildList, parentPackage, modelPackage, formats, useTimeType));
- while (!modelToBuildList.isEmpty()) {
-
- final var modelToBuild = modelToBuildList.remove();
- if (!alreadyBuilt.contains(modelToBuild)) {
- final var path = MapperUtil.splitName(modelToBuild);
- final var nexElement = buildSchemaObject(totalSchemas, modelToBuild, totalSchemas.get(getComponent(path)),
- prefix, suffix, modelToBuildList, getParentName(path), modelPackage, formats, useTimeType);
- if (schemasList.contains(nexElement)) {
- modelToBuildList.poll();
- } else {
- schemasList.add(nexElement);
- }
- alreadyBuilt.add(modelToBuild);
- }
- }
- }
- return schemasList;
- }
-
- private static String getParentName(final String[] path) {
- final String parenName;
- if (path.length > 1) {
- parenName = String.join(".", Arrays.copyOf(path, path.length - 1));
- } else {
- parenName = "";
- }
- return parenName;
- }
-
- private static String getComponent(final String[] path) {
- final String componentName;
- if (path.length > 1) {
- componentName = String.join(".", Arrays.copyOf(path, path.length - 1)) + "/" + path[path.length - 1];
- } else {
- componentName = path[0];
- }
- return componentName.toUpperCase();
- }
-
- private static String getSchema(final String[] path) {
- final String componentName;
- if (path.length > 1) {
- componentName = path[path.length - 2] + "/" + path[path.length - 1];
- } else {
- componentName = path[0];
- }
- return componentName.toUpperCase();
- }
-
- private static SchemaObject buildSchemaObject(
- final Map totalSchemas, final String component, final JsonNode model,
- final String prefix, final String suffix, final Collection modelToBuildList, final String parentPackage,
- final String modelPackage, final Map formats, final TimeType useTimeType) {
-
- final var listSchema = getFields(totalSchemas, model, true, prefix, suffix, modelToBuildList, modelPackage, formats, useTimeType);
- final var splitPackage = MapperUtil.splitName(component);
- final String className = splitPackage[splitPackage.length - 1];
- return SchemaObject.builder()
- .schemaName(WordUtils.capitalizeFully(className))
- .className(MapperUtil.getPojoName(className, prefix, suffix))
- .importList(getImportList(listSchema))
- .schemaCombinator(StringUtils.isNotBlank(schemaCombinatorType) ? schemaCombinatorType : "")
- .fieldObjectList(listSchema)
- .parentPackage(parentPackage.toLowerCase())
- .build();
- }
-
- private static List getImportList(final List schemaListToImport) {
- final var importList = new HashSet();
-
- for (final SchemaFieldObject fieldObject : schemaListToImport) {
- importList.addAll(getTypeImports(fieldObject));
- }
- return new ArrayList<>(importList);
- }
-
- private static List getTypeImports(final SchemaFieldObject fieldObject) {
- final List importList = new ArrayList<>();
- if (Objects.nonNull(fieldObject.getDataTypeSimple())) {
- if (fieldObject.getDataTypeSimple().equals(ARRAY)) {
- importList.addAll(List.of("java.util.List", "java.util.ArrayList"));
- if (Objects.nonNull(fieldObject.getDataType())) {
- if (Objects.equals(fieldObject.getDataType(), LOCAL_DATE)) {
- importList.add("java.time.LocalDate");
- } else if (Objects.equals(fieldObject.getDataType(), LOCAL_DATE_TIME)) {
- importList.add("java.time.LocalDateTime");
- } else if (Objects.equals(fieldObject.getDataType(), ZONED_DATE_TIME)) {
- importList.add("java.time.ZonedDateTime");
- }
- }
- } else if (Objects.equals(fieldObject.getDataTypeSimple(), MAP)) {
- importList.addAll(List.of("java.util.Map", "java.util.HashMap"));
- } else if (fieldObject.getDataTypeSimple().equals(BIG_DECIMAL)
- || Objects.nonNull(fieldObject.getDataType()) && fieldObject.getDataType().equals(BIG_DECIMAL)) {
- importList.add("java.math.BigDecimal");
- } else if (Objects.equals(fieldObject.getDataTypeSimple(), LOCAL_DATE)) {
- importList.add("java.time.LocalDate");
- } else if (Objects.equals(fieldObject.getDataTypeSimple(), LOCAL_DATE_TIME)) {
- importList.add("java.time.LocalDateTime");
- } else if (Objects.equals(fieldObject.getDataTypeSimple(), ZONED_DATE_TIME)) {
- importList.add("java.time.ZonedDateTime");
- }
- }
- return importList;
- }
-
- private static List getFields(
- final Map totalSchemas, final JsonNode model, final boolean required, final String prefix,
- final String suffix, final Collection modelToBuildList,
- final String modelPackage, final Map formats, final TimeType useTimeType) {
- final var fieldObjectArrayList = new ArrayList();
- schemaCombinatorType = null;
- if (ApiTool.hasType(model)) {
- if (OBJECT.equalsIgnoreCase(model.get(TYPE).textValue())) {
- fieldObjectArrayList.addAll(processFieldObject(totalSchemas, model, prefix, suffix, modelToBuildList, modelPackage, formats, useTimeType));
- } else if (ARRAY.equalsIgnoreCase(model.get(TYPE).textValue())) {
- fieldObjectArrayList.add(processFieldObjectList(totalSchemas, "", model, required, prefix, suffix, modelToBuildList, modelPackage, null, formats, useTimeType));
- } else if ("enum".equalsIgnoreCase(model.get(TYPE).textValue())) {
- fieldObjectArrayList.add(processFieldObjectList(totalSchemas, "", model, required, prefix, suffix, modelToBuildList, modelPackage, null, formats, useTimeType));
- }
- } else if (ApiTool.hasRef(model)) {
- final var splitName = MapperUtil.splitName(ApiTool.getRefValue(model));
- fieldObjectArrayList.addAll(processFieldObject(totalSchemas, totalSchemas.get(MapperUtil.buildKey(splitName)), prefix, suffix,
- modelToBuildList, modelPackage, formats, useTimeType));
- } else if (model.elements().hasNext()) {
- fieldObjectArrayList.addAll(processFieldObject(totalSchemas, model, prefix, suffix, modelToBuildList, modelPackage, formats, useTimeType));
- }
- return fieldObjectArrayList;
- }
-
- private static List processFieldObject(
- final Map totalSchemas, final JsonNode model, final String prefix, final String suffix, final Collection modelToBuildList,
- final String modelPackage, final Map formats, final TimeType useTimeType) {
- final Set requiredSet = new HashSet<>();
- final var fieldObjectArrayList = new ArrayList();
- if (model.has("required")) {
- final JsonNode arrayNode = model.get("required");
- final Iterator fields = arrayNode.iterator();
- fields.forEachRemaining(field -> requiredSet.add(field.textValue()));
- }
- final var properties = model.get(PROPERTIES);
- if (!(properties.has(ANY_OF) || properties.has(ALL_OF) || properties.has(ONE_OF))) {
- final var propertiesIt = model.get(PROPERTIES).fieldNames();
- while (propertiesIt.hasNext()) {
- final var property = propertiesIt.next();
- fieldObjectArrayList.add(processFieldObjectList(totalSchemas, property, model.get(PROPERTIES).path(property), requiredSet.contains(property), prefix, suffix,
- modelToBuildList, modelPackage, null, formats, useTimeType));
- if (model.get(PROPERTIES).path(property).has(REF) && !totalSchemas.containsKey(createKey(modelPackage, property.toUpperCase(), "/"))) {
- modelToBuildList.add(MapperUtil.getLongRefClass(model.get(PROPERTIES).path(property)));
- }
- }
- } else if (properties.has(ALL_OF)) {
- fieldObjectArrayList.addAll(processAllOfAnyOfOneOf(totalSchemas, properties.get(ALL_OF), true, prefix, suffix, modelToBuildList, formats, useTimeType));
- schemaCombinatorType = ALL_OF;
- } else if (properties.has(ANY_OF)) {
- fieldObjectArrayList.addAll(processAllOfAnyOfOneOf(totalSchemas, properties.get(ANY_OF), false, prefix, suffix, modelToBuildList, formats, useTimeType));
- schemaCombinatorType = ANY_OF;
- } else if (properties.has(ONE_OF)) {
- fieldObjectArrayList.addAll(processAllOfAnyOfOneOf(totalSchemas, properties.get(ONE_OF), false, prefix, suffix, modelToBuildList, formats, useTimeType));
- schemaCombinatorType = ONE_OF;
- }
- return fieldObjectArrayList;
- }
-
- private static List processAllOfAnyOfOneOf(
- final Map totalSchemas, final JsonNode schemaList, final boolean required, final String prefix, final String suffix,
- final Collection modelToBuildList, final Map formats, final TimeType useTimeType) {
- final var fieldObjectArrayList = new ArrayList();
- final var allOfIterator = schemaList.elements();
-
- allOfIterator.forEachRemaining(element -> fieldObjectArrayList.add(solveElement(totalSchemas, required, prefix, suffix, element,
- modelToBuildList, formats, useTimeType)));
- return fieldObjectArrayList;
- }
-
- private static SchemaFieldObject solveElement(
- final Map totalSchemas, final boolean required, final String prefix, final String suffix,
- final JsonNode element, final Collection modelToBuildList, final Map formats, final TimeType useTimeType) {
- final SchemaFieldObject result;
- if (element.has(REF)) {
- final String schemaName = MapperUtil.getLongRefClass(element);
- final var schemaToProcess = totalSchemas.get(schemaName.toUpperCase());
- result = processFieldObjectList(totalSchemas, schemaName, schemaToProcess, required, prefix, suffix, modelToBuildList, null, null, formats, useTimeType);
- result.setRequired(false);
- } else {
- result = processFieldObjectList(totalSchemas, "", element, required, prefix, suffix, modelToBuildList, null, null, formats, useTimeType);
- }
- return result;
- }
-
- private static SchemaFieldObject processFieldObjectList(
- final Map totalSchemas, final String propertyName, final JsonNode schema, final boolean required,
- final String prefix, final String suffix, final Collection modelToBuildList, final String modelPackage, final String className,
- final Map formats, final TimeType useTimeType) {
- final SchemaFieldObject fieldObject;
- final var name = schema.has("name") ? schema.get("name").textValue() : propertyName;
- if (ApiTool.hasType(schema)) {
- final var type = ApiTool.getType(schema);
- if (OBJECT.equalsIgnoreCase(type)) {
- fieldObject =
- SchemaFieldObject
- .builder()
- .baseName(name)
- .restrictions(new SchemaFieldObjectProperties())
- .dataType(MapperUtil.getSimpleType(schema, prefix, suffix, useTimeType))
- .build();
- setFieldType(fieldObject, schema, required, prefix, suffix, className, formats, useTimeType);
- final var schemaName = StringUtils.defaultString(className, propertyName);
- if (StringUtils.isNotEmpty(schemaName) && !totalSchemas.containsKey(createKey(modelPackage, schemaName.toUpperCase(), "/"))) {
- totalSchemas.put(createKey(modelPackage, schemaName.toUpperCase(), "/"), schema);
- modelToBuildList.add(createKey(modelPackage.toLowerCase(), schemaName, "."));
- }
- } else if (ApiTool.hasItems(schema)) {
- final var items = ApiTool.getItems(schema);
- final var arrayType = MapperUtil.getSimpleType(items, prefix, suffix, useTimeType);
- if (items.has(REF)) {
- final var longType = MapperUtil.getLongRefClass(items);
- modelToBuildList.add(longType);
- }
- fieldObject =
- SchemaFieldObject
- .builder()
- .baseName(name)
- .restrictions(new SchemaFieldObjectProperties())
- .dataType(arrayType)
- .dataTypeSimple(type)
- .importClass(getImportClass(arrayType))
- .build();
- setFormatProperies(fieldObject, arrayType, formats);
- handleItems(schema, modelToBuildList, fieldObject, required, items);
- } else if (ApiTool.isEnum(schema)) {
- fieldObject = processEnumField(name, required, schema, prefix, suffix, useTimeType);
- } else {
- final String simpleType = MapperUtil.getSimpleType(schema, prefix, suffix, useTimeType);
- fieldObject = SchemaFieldObject
- .builder()
- .baseName(name)
- .restrictions(new SchemaFieldObjectProperties())
- .dataType(simpleType)
- .dataTypeSimple(simpleType)
- .constValue(MapperUtil.getConstValue(schema))
- .build();
- setFieldProperties(fieldObject, schema);
- setFormatProperies(fieldObject, simpleType, formats);
- fieldObject.setRequired(required);
- }
- } else if (ApiTool.hasRef(schema)) {
- final var splitName = MapperUtil.splitName(ApiTool.getRefValue(schema));
- final var solvedRef = totalSchemas.get(getSchema(splitName));
- fieldObject = processFieldObjectList(totalSchemas, name, solvedRef, required, prefix, suffix, modelToBuildList, modelPackage,
- splitName[splitName.length - 1], formats, useTimeType);
- } else {
- final String simpleType = MapperUtil.getSimpleType(schema, prefix, suffix, useTimeType);
- fieldObject = SchemaFieldObject
- .builder()
- .baseName(name)
- .dataType(simpleType)
- .dataTypeSimple(simpleType)
- .restrictions(new SchemaFieldObjectProperties())
- .constValue(MapperUtil.getConstValue(schema))
- .build();
- }
- return fieldObject;
- }
-
- private static String createKey(final String modelPackage, final String className, final String separator) {
- return Objects.nonNull(modelPackage) ? modelPackage.toUpperCase() + separator + className : className;
- }
-
- private static void handleItems(
- final JsonNode schema, final Collection modelToBuildList, final SchemaFieldObject fieldObject, final boolean required,
- final JsonNode items) {
- if (ApiTool.hasRef(items)) {
- modelToBuildList.add(MapperUtil.getLongRefClass(items));
- }
- final Iterator> iterator = schema.fields();
- Entry current;
- while (iterator.hasNext()) {
- current = iterator.next();
- switch (current.getKey()) {
- case "maxItems":
- fieldObject.getRestrictions().setMaxItems(current.getValue().intValue());
- break;
- case "minItems":
- fieldObject.getRestrictions().setMinItems(current.getValue().intValue());
- break;
- case "uniqueItems":
- fieldObject.getRestrictions().setUniqueItems(current.getValue().booleanValue());
- break;
- default:
- break;
- }
- }
- fieldObject.setRequired(required);
- }
-
- @SuppressWarnings("checkstyle:CyclomaticComplexity")
- private static void setFieldProperties(final SchemaFieldObject fieldObject, final JsonNode schema) {
- final Iterator> iterator = schema.fields();
- Entry current;
- final SchemaFieldObjectProperties props = fieldObject.getRestrictions();
- while (iterator.hasNext()) {
- current = iterator.next();
- switch (current.getKey()) {
- case "minimum":
- props.setMinimum(current.getValue().asText());
- break;
- case "maximum":
- props.setMaximum(current.getValue().asText());
- break;
- case "exclusiveMinimum":
- props.setExclusiveMinimum(current.getValue().booleanValue());
- break;
- case "exclusiveMaximum":
- props.setExclusiveMaximum(current.getValue().booleanValue());
- break;
- case "maxItems":
- props.setMaxItems(current.getValue().intValue());
- break;
- case "maxLength":
- props.setMaxLength(current.getValue().intValue());
- break;
- case "minItems":
- props.setMinItems(current.getValue().intValue());
- break;
- case "minLength":
- props.setMinLength(current.getValue().intValue());
- break;
- case "pattern":
- props.setPattern(current.getValue().toString().replace("\"", ""));
- break;
- case "uniqueItems":
- props.setUniqueItems(current.getValue().booleanValue());
- break;
- case "multipleOf":
- props.setMultipleOf(current.getValue().asText());
- break;
- default:
- break;
- }
- }
- }
-
- private static void setFormatProperies(final SchemaFieldObject fieldObject, final String dataType, final Map formats) {
- if (Objects.equals(dataType, LOCAL_DATE)) {
- fieldObject.getRestrictions().setFormat(formats.get("DATE"));
- } else if (Objects.equals(dataType, LOCAL_DATE_TIME)) {
- fieldObject.getRestrictions().setFormat(formats.get("DATE_TIME"));
- }
- }
-
- private static void setFieldType(final SchemaFieldObject field, final JsonNode value, final boolean required, final String prefix, final String suffix, final String className,
- final Map formats, final TimeType useTimeType) {
- field.setRequired(required);
- if (ApiTool.hasType(value)) {
- if (ARRAY.equalsIgnoreCase(ApiTool.getType(value))) {
- final var typeArray = MapperUtil.getTypeArray(value, prefix, suffix, useTimeType);
- field.setDataType(typeArray);
- field.setImportClass(getImportClass(typeArray));
- setFormatProperies(field, typeArray, formats);
- } else if (ApiTool.getType(value).equalsIgnoreCase(OBJECT)) {
- if (value.has("additionalProperties")) {
- final var typeMap = MapperUtil.getTypeMap(value, prefix, suffix, useTimeType);
- field.setDataTypeSimple(MAP);
- field.setDataType(typeMap);
- field.setImportClass(getImportClass(typeMap));
- } else {
- var typeObject = "";
- if (ApiTool.hasRef(value)) {
- typeObject = MapperUtil.getRef(value, prefix, suffix);
- } else {
- if (StringUtils.isEmpty(className)) {
- typeObject = MapperUtil.getPojoName(field.getBaseName(), prefix, suffix);
- } else {
- typeObject = MapperUtil.getPojoName(className, prefix, suffix);
- }
- }
- field.setImportClass(getImportClass(typeObject));
- field.setDataType(typeObject);
- field.setDataTypeSimple(typeObject);
- }
- } else {
- throw new NonSupportedSchemaException(value.toPrettyString());
- }
- }
- }
-
- private static SchemaFieldObject processEnumField(final String name, final boolean required, final JsonNode value, final String prefix,
- final String suffix, final TimeType useTimeType) {
- final List enumValues = new ArrayList<>();
- value.get("enum").elements().forEachRemaining(enumValue -> enumValues.add(enumValue.textValue()));
-
- if (enumValues.isEmpty()) {
- throw new BadDefinedEnumException(name);
- }
-
- return SchemaFieldObject
- .builder()
- .baseName(name)
- .dataTypeSimple("enum")
- .dataType(MapperUtil.getSimpleType(value, prefix, suffix, useTimeType))
- .required(required)
- .enumValues(enumValues)
- .restrictions(new SchemaFieldObjectProperties())
- .build();
- }
-
- private static String getImportClass(final String type) {
- return StringUtils.isNotBlank(type) && !"String".equals(type) && !"Integer".equals(type) ? type : "";
- }
-
-}
diff --git a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/asyncapi/util/MapperUtil.java b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/asyncapi/util/MapperUtil.java
deleted file mode 100644
index cf536e62..00000000
--- a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/asyncapi/util/MapperUtil.java
+++ /dev/null
@@ -1,174 +0,0 @@
-/*
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at https://mozilla.org/MPL/2.0/.
- */
-
-package com.sngular.api.generator.plugin.asyncapi.util;
-
-import java.util.Objects;
-
-import com.fasterxml.jackson.databind.JsonNode;
-import com.sngular.api.generator.plugin.common.model.TimeType;
-import com.sngular.api.generator.plugin.common.tools.ApiTool;
-import org.apache.commons.lang3.ArrayUtils;
-import org.apache.commons.lang3.StringUtils;
-
-public class MapperUtil {
-
- public static final String INTEGER = "integer";
-
- public static final String DOUBLE = "double";
-
- public static final String FLOAT = "float";
-
- public static final String NUMBER = "number";
-
- public static final String INT_64 = "int64";
-
- public static final String LONG = "long";
-
- public static final String DATE = "date";
-
- public static final String DATE_TIME = "date-time";
-
- public static final String BIG_DECIMAL = "BigDecimal";
-
- public static final String LOCAL_DATE = "LocalDate";
-
- public static final String LOCAL_DATE_TIME = "LocalDateTime";
-
- public static final String ZONED_DATE_TIME = "ZonedDateTime";
-
- public static final String REF = "$ref";
-
- private static final String DIVISOR = "([./])";
-
- private static final String SLASH = "/";
-
- private MapperUtil() {}
-
- public static String getSimpleType(final JsonNode schema, final String prefix, final String suffix,
- final TimeType useTimeType) {
- String type = schema.textValue();
- if (schema.has("type")) {
- type = schema.get("type").textValue();
- String format = null;
- if ("string".equalsIgnoreCase(type)) {
- type = "String";
- }
- if (schema.has("format")) {
- format = schema.get("format").textValue();
- }
- if ("string".equalsIgnoreCase(type)) {
- type = formatTypeOfString(format, useTimeType);
- } else if (NUMBER.equalsIgnoreCase(type)) {
- if (FLOAT.equalsIgnoreCase(format)) {
- type = StringUtils.capitalize(FLOAT);
- } else if (DOUBLE.equalsIgnoreCase(format)) {
- type = StringUtils.capitalize(DOUBLE);
- } else {
- type = StringUtils.capitalize(BIG_DECIMAL);
- }
- } else if (INTEGER.equalsIgnoreCase(type)) {
- if (INT_64.equalsIgnoreCase(format)) {
- type = StringUtils.capitalize(LONG);
- } else {
- type = StringUtils.capitalize(INTEGER);
- }
- }
- } else if (schema.has(REF)) {
- type = getRef(schema, prefix, suffix);
- }
- return type;
- }
-
- public static String formatTypeOfString(final String format, final TimeType useTimeType) {
- String type = "String";
- if (format != null) {
- if (DATE_TIME.equalsIgnoreCase(format)) {
- if (Objects.requireNonNull(useTimeType) == TimeType.ZONED) {
- type = ZONED_DATE_TIME;
- } else {
- type = LOCAL_DATE_TIME;
- }
-
- } else if (DATE.equalsIgnoreCase(format)) {
- type = LOCAL_DATE;
- }
- }
- return type;
- }
-
- public static String getRef(final JsonNode schema, final String prefix, final String suffix) {
- return getPojoName(getRefClass(schema), prefix, suffix);
- }
-
- public static String getLongRefClass(final JsonNode schema) {
- final String[] pathObjectRef = getStrings(schema);
- return pathObjectRef[pathObjectRef.length - 2] + "/" + pathObjectRef[pathObjectRef.length - 1];
- }
-
- private static String[] getStrings(final JsonNode schema) {
- return splitName(schema.get(REF).textValue());
- }
-
- public static String getRefClass(final JsonNode schema) {
- final String[] pathObjectRef = getStrings(schema);
- return pathObjectRef[pathObjectRef.length - 1];
- }
-
- public static String getTypeMap(final JsonNode mapSchema, final String prefix, final String suffix, final TimeType useTimeType) {
- var typeMap = "";
- final var mapNode = mapSchema.get("additionalProperties");
- final var mapValueType = mapNode.findPath("type");
- typeMap = getCollectionType(mapNode, mapValueType, prefix, suffix, useTimeType);
- return typeMap;
- }
-
- public static String getTypeArray(final JsonNode array, final String prefix, final String suffix, final TimeType useTimeType) {
- var typeArray = "";
- final var arrayNode = array.get("items");
- final JsonNode mapValueType;
- if (arrayNode.has("type")) {
- mapValueType = arrayNode.get("type");
- } else {
- mapValueType = arrayNode.get(REF);
- }
- typeArray = getCollectionType(arrayNode, mapValueType, prefix, suffix, useTimeType);
- return typeArray;
- }
-
- private static String getCollectionType(final JsonNode mapNode, final JsonNode mapValueType, final String prefix,
- final String suffix, final TimeType useTimeType) {
- var typeMap = mapValueType.textValue();
- if (!typeMap.contains("#")) {
- typeMap = getSimpleType(mapNode, prefix, suffix, useTimeType);
- } else {
- final var valueSchema = mapNode.findPath(REF);
- if (Objects.nonNull(valueSchema)) {
- getRef(valueSchema, prefix, suffix);
- }
- }
- return typeMap;
- }
-
- public static String getPojoName(final String namePojo, final String prefix, final String suffix) {
- return StringUtils.defaultIfBlank(prefix, "")
- + StringUtils.capitalize(namePojo)
- + StringUtils.defaultIfBlank(suffix, "");
- }
-
- public static String[] splitName(final String name) {
- return ArrayUtils.removeAllOccurrences(name.split(DIVISOR), "");
- }
-
- public static String buildKey(final String[] pathList) {
- final var arrayLength = pathList.length;
- return (arrayLength > 2 ? pathList[arrayLength - 2] + SLASH + pathList[arrayLength - 1] : pathList[0]).toUpperCase();
- }
-
- protected static Object getConstValue(final JsonNode schema) {
- return ApiTool.hasNode(schema, "const") ? ApiTool.getNodeAsObject(schema, "const") : null;
- }
-}
diff --git a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/asyncapi/util/ReferenceProcessor.java b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/asyncapi/util/ReferenceProcessor.java
index 29d831f0..8e22b9a7 100644
--- a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/asyncapi/util/ReferenceProcessor.java
+++ b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/asyncapi/util/ReferenceProcessor.java
@@ -5,12 +5,12 @@
import java.util.List;
import java.util.Map;
import java.util.Objects;
-
import com.fasterxml.jackson.databind.JsonNode;
import com.sngular.api.generator.plugin.asyncapi.exception.FileSystemException;
import com.sngular.api.generator.plugin.asyncapi.exception.NonSupportedSchemaException;
import com.sngular.api.generator.plugin.common.files.FileLocation;
import com.sngular.api.generator.plugin.common.tools.ApiTool;
+import com.sngular.api.generator.plugin.common.tools.MapperUtil;
import lombok.Builder;
public final class ReferenceProcessor {
@@ -46,7 +46,7 @@ public void processReference(
}
final String[] path = MapperUtil.splitName(referenceLink);
final JsonNode component;
- final var calculatedKey = calculateKey(path);
+ final var calculatedKey = MapperUtil.getRefSchemaKey(referenceLink);
if (!totalSchemas.containsKey(calculatedKey) && !alreadyProcessed.contains(calculatedKey)) {
alreadyProcessed.add(calculatedKey);
try {
@@ -71,10 +71,6 @@ public void processReference(
}
}
- private String calculateKey(final String[] path) {
- return (path[path.length - 2] + SLASH + path[path.length - 1]).toUpperCase();
- }
-
private JsonNode solveRef(final FileLocation ymlParent, final String[] path, final String reference, final Map totalSchemas) throws IOException {
final String[] pathToFile = reference.split("#");
final String filePath = pathToFile[0];
diff --git a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/files/DirectoryFileLocation.java b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/files/DirectoryFileLocation.java
index 7fa976e1..119879a1 100644
--- a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/files/DirectoryFileLocation.java
+++ b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/files/DirectoryFileLocation.java
@@ -10,7 +10,6 @@
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Path;
-
import com.sngular.api.generator.plugin.asyncapi.exception.FileSystemException;
public class DirectoryFileLocation implements FileLocation {
diff --git a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/model/CommonSpecFile.java b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/model/CommonSpecFile.java
new file mode 100644
index 00000000..19361ff7
--- /dev/null
+++ b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/model/CommonSpecFile.java
@@ -0,0 +1,42 @@
+package com.sngular.api.generator.plugin.common.model;
+
+import java.util.Map;
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+import lombok.experimental.SuperBuilder;
+
+@Data
+@SuperBuilder(toBuilder = true)
+@NoArgsConstructor
+@AllArgsConstructor
+public class CommonSpecFile {
+
+ private String filePath;
+
+ private String apiPackage;
+
+ private String modelPackage;
+
+ private String modelNamePrefix;
+
+ private String modelNameSuffix;
+
+ private String classNamePostfix;
+
+ private boolean useLombokModelAnnotation;
+
+ @Builder.Default
+ private String dateTimeFormat = "yyyy-MM-dd'T'HH:mm:ss";
+
+ @Builder.Default
+ private String dateFormat = "yyyy-MM-dd";
+
+ @Builder.Default
+ private TypeConstants.TimeType useTimeType = TypeConstants.TimeType.LOCAL;
+
+ public Map getFormats() {
+ return Map.of("DATE_TIME", dateTimeFormat, "DATE", dateFormat);
+ }
+}
diff --git a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/model/SchemaFieldObject.java b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/model/SchemaFieldObject.java
new file mode 100644
index 00000000..601b17ba
--- /dev/null
+++ b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/model/SchemaFieldObject.java
@@ -0,0 +1,30 @@
+package com.sngular.api.generator.plugin.common.model;
+
+import java.util.Map;
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+
+@Data
+@Builder
+@AllArgsConstructor
+@EqualsAndHashCode(of = "baseName")
+public class SchemaFieldObject {
+
+ private String baseName;
+
+ @Builder.Default
+ private SchemaFieldObjectType dataType = new SchemaFieldObjectType(TypeConstants.OBJECT);
+
+ @Builder.Default
+ private SchemaFieldObjectProperties restrictions = new SchemaFieldObjectProperties();
+
+ private String importClass;
+
+ private boolean required;
+
+ private Map enumValues;
+
+ private Object constValue;
+}
diff --git a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/asyncapi/model/SchemaFieldObjectProperties.java b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/model/SchemaFieldObjectProperties.java
similarity index 97%
rename from multiapi-engine/src/main/java/com/sngular/api/generator/plugin/asyncapi/model/SchemaFieldObjectProperties.java
rename to multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/model/SchemaFieldObjectProperties.java
index 7c01695e..e644f6f3 100644
--- a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/asyncapi/model/SchemaFieldObjectProperties.java
+++ b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/model/SchemaFieldObjectProperties.java
@@ -1,9 +1,8 @@
-package com.sngular.api.generator.plugin.asyncapi.model;
+package com.sngular.api.generator.plugin.common.model;
import java.util.HashSet;
import java.util.Objects;
import java.util.Set;
-
import lombok.Data;
@Data
diff --git a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/openapi/model/SchemaFieldObjectType.java b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/model/SchemaFieldObjectType.java
similarity index 87%
rename from multiapi-engine/src/main/java/com/sngular/api/generator/plugin/openapi/model/SchemaFieldObjectType.java
rename to multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/model/SchemaFieldObjectType.java
index 5b8de712..42144d46 100644
--- a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/openapi/model/SchemaFieldObjectType.java
+++ b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/model/SchemaFieldObjectType.java
@@ -4,12 +4,11 @@
* * file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
-package com.sngular.api.generator.plugin.openapi.model;
+package com.sngular.api.generator.plugin.common.model;
import java.util.AbstractMap.SimpleImmutableEntry;
import java.util.Map;
import java.util.Objects;
-
import com.sngular.api.generator.plugin.openapi.exception.CodeGenerationException;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;
@@ -17,6 +16,8 @@
@Data
public class SchemaFieldObjectType {
+ public static final String ZONED_DATE_TIME = "ZonedDateTime";
+ public static final String OFFSET_DATE_TIME = "OffsetDateTime";
private static final Map TYPE_MAPPINGS = Map.ofEntries(
new SimpleImmutableEntry<>(TypeConstants.OBJECT, "Object"),
new SimpleImmutableEntry<>(TypeConstants.ARRAY, "List>"),
@@ -30,10 +31,10 @@ public class SchemaFieldObjectType {
new SimpleImmutableEntry<>(TypeConstants.ENUM, "Enum"),
new SimpleImmutableEntry<>(TypeConstants.LOCALDATE, "LocalDate"),
new SimpleImmutableEntry<>(TypeConstants.LOCALDATETIME, "LocalDateTime"),
- new SimpleImmutableEntry<>(TypeConstants.ZONEDDATE, "ZonedDateTime"),
- new SimpleImmutableEntry<>(TypeConstants.ZONEDDATETIME, "ZonedDateTime"),
- new SimpleImmutableEntry<>(TypeConstants.OFFSETDATE, "OffsetDateTime"),
- new SimpleImmutableEntry<>(TypeConstants.OFFSETDATETIME, "OffsetDateTime")
+ new SimpleImmutableEntry<>(TypeConstants.ZONEDDATE, ZONED_DATE_TIME),
+ new SimpleImmutableEntry<>(TypeConstants.ZONEDDATETIME, ZONED_DATE_TIME),
+ new SimpleImmutableEntry<>(TypeConstants.OFFSETDATE, OFFSET_DATE_TIME),
+ new SimpleImmutableEntry<>(TypeConstants.OFFSETDATETIME, OFFSET_DATE_TIME)
);
private static final Map IMPL_TYPE_MAPPINGS = Map.ofEntries(
@@ -49,10 +50,10 @@ public class SchemaFieldObjectType {
new SimpleImmutableEntry<>(TypeConstants.ENUM, "Enum"),
new SimpleImmutableEntry<>(TypeConstants.LOCALDATE, "LocalDate"),
new SimpleImmutableEntry<>(TypeConstants.LOCALDATETIME, "LocalDateTime"),
- new SimpleImmutableEntry<>(TypeConstants.ZONEDDATE, "ZonedDateTime"),
- new SimpleImmutableEntry<>(TypeConstants.ZONEDDATETIME, "ZonedDateTime"),
- new SimpleImmutableEntry<>(TypeConstants.OFFSETDATE, "OffsetDateTime"),
- new SimpleImmutableEntry<>(TypeConstants.OFFSETDATETIME, "OffsetDateTime")
+ new SimpleImmutableEntry<>(TypeConstants.ZONEDDATE, ZONED_DATE_TIME),
+ new SimpleImmutableEntry<>(TypeConstants.ZONEDDATETIME, ZONED_DATE_TIME),
+ new SimpleImmutableEntry<>(TypeConstants.OFFSETDATE, OFFSET_DATE_TIME),
+ new SimpleImmutableEntry<>(TypeConstants.OFFSETDATETIME, OFFSET_DATE_TIME)
);
private SchemaFieldObjectType innerType;
diff --git a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/model/SchemaObject.java b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/model/SchemaObject.java
new file mode 100644
index 00000000..a3ddc3f2
--- /dev/null
+++ b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/model/SchemaObject.java
@@ -0,0 +1,60 @@
+package com.sngular.api.generator.plugin.common.model;
+
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+import lombok.NoArgsConstructor;
+
+@Data
+@Builder(toBuilder = true)
+@NoArgsConstructor
+@AllArgsConstructor
+@EqualsAndHashCode(of = {"schemaName", "className"})
+public class SchemaObject {
+
+ private boolean isEnum;
+
+ private String schemaName;
+
+ private String className;
+
+ private List importList;
+
+ private Set fieldObjectList;
+
+ private String schemaCombinator;
+
+ private String parentPackage;
+
+ public static final class SchemaObjectBuilder {
+
+ private final List importList = new ArrayList<>();
+
+ private final Set fieldObjectList = new HashSet<>();
+
+ public SchemaObjectBuilder importList(final List importList) {
+ this.importList.addAll(importList);
+ return this;
+ }
+
+ public SchemaObjectBuilder importItem(final String importItem) {
+ this.importList.add(importItem);
+ return this;
+ }
+
+ public SchemaObjectBuilder fieldObjectList(final Set fieldObjectList) {
+ this.fieldObjectList.addAll(fieldObjectList);
+ return this;
+ }
+
+ public SchemaObjectBuilder fieldObject(final SchemaFieldObject fieldObject) {
+ this.fieldObjectList.add(fieldObject);
+ return this;
+ }
+ }
+}
diff --git a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/model/TimeType.java b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/model/TimeType.java
deleted file mode 100644
index baada72c..00000000
--- a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/model/TimeType.java
+++ /dev/null
@@ -1,6 +0,0 @@
-package com.sngular.api.generator.plugin.common.model;
-
-public enum TimeType {
- LOCAL,
- ZONED
-}
diff --git a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/openapi/model/TypeConstants.java b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/model/TypeConstants.java
similarity index 98%
rename from multiapi-engine/src/main/java/com/sngular/api/generator/plugin/openapi/model/TypeConstants.java
rename to multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/model/TypeConstants.java
index 24ba8e09..da239494 100644
--- a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/openapi/model/TypeConstants.java
+++ b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/model/TypeConstants.java
@@ -4,7 +4,7 @@
* * file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
-package com.sngular.api.generator.plugin.openapi.model;
+package com.sngular.api.generator.plugin.common.model;
import java.util.Set;
diff --git a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/template/CommonTemplateFactory.java b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/template/CommonTemplateFactory.java
new file mode 100644
index 00000000..8b35d71d
--- /dev/null
+++ b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/template/CommonTemplateFactory.java
@@ -0,0 +1,351 @@
+package com.sngular.api.generator.plugin.common.template;
+
+import java.io.File;
+import java.io.FileWriter;
+import java.io.FilenameFilter;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Set;
+import com.sngular.api.generator.plugin.asyncapi.exception.FileSystemException;
+import com.sngular.api.generator.plugin.asyncapi.parameter.OperationParameterObject;
+import com.sngular.api.generator.plugin.asyncapi.template.ClassTemplate;
+import com.sngular.api.generator.plugin.common.model.SchemaFieldObject;
+import com.sngular.api.generator.plugin.common.model.SchemaObject;
+import com.sngular.api.generator.plugin.common.tools.MapperUtil;
+import com.sngular.api.generator.plugin.exception.GeneratorTemplateException;
+import com.sngular.api.generator.plugin.openapi.exception.OverwritingApiFilesException;
+import freemarker.template.Configuration;
+import freemarker.template.Template;
+import freemarker.template.TemplateException;
+import freemarker.template.TemplateExceptionHandler;
+
+public abstract class CommonTemplateFactory {
+
+ private static final List BASIC_DATA_TYPES = List.of("Integer", "Long", "Float", "Double", "Boolean", "String", "Char", "Byte", "Short");
+
+ private static final String EXCEPTION_PACKAGE = "exceptionPackage";
+
+ private static final String SLASH = "/";
+
+ private static final String PACKAGE_SEPARATOR_STR = ".";
+
+ private static final String FILE_TYPE_JAVA = ".java";
+
+ private final Configuration cfg = new Configuration(Configuration.VERSION_2_3_32);
+
+ private final Map root = new HashMap<>();
+
+ private final List classTemplateList = new LinkedList<>();
+
+ private final boolean checkOverwrite;
+
+ private final File targetFolder;
+
+ private final String processedGeneratedSourcesFolder;
+
+ private final FilenameFilter targetFileFilter;
+
+ private final File baseDir;
+
+ protected boolean generateExceptionTemplate;
+
+ protected CommonTemplateFactory(boolean checkOverwrite,
+ final File targetFolder,
+ final String processedGeneratedSourcesFolder,
+ final File baseDir,
+ final CommonTemplateLoader classpathTemplateLoader) {
+ this.checkOverwrite = checkOverwrite;
+ cfg.setTemplateLoader(classpathTemplateLoader);
+ cfg.setDefaultEncoding("UTF-8");
+ cfg.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
+ cfg.setLogTemplateExceptions(true);
+ cfg.setAPIBuiltinEnabled(true);
+ addToRoot("checkBasicTypes", BASIC_DATA_TYPES);
+ this.targetFolder = targetFolder;
+ this.targetFileFilter = (dir, name) -> name.toLowerCase().contains(targetFolder.toPath().getFileName().toString());
+ this.processedGeneratedSourcesFolder = processedGeneratedSourcesFolder;
+ this.baseDir = baseDir;
+ }
+
+ private static String getTemplateName(ClassTemplate classTemplate) {
+ String templateName;
+ if (classTemplate.getClassSchema().isEnum()) {
+ templateName = CommonTemplateIndexConstants.TEMPLATE_CONTENT_ENUM;
+ } else {
+ templateName = classTemplate.isUseLombok() ? CommonTemplateIndexConstants.TEMPLATE_CONTENT_SCHEMA_LOMBOK : CommonTemplateIndexConstants.TEMPLATE_CONTENT_SCHEMA;
+ }
+ return templateName;
+ }
+
+ private ClassTemplate getClassTemplate() {
+ ClassTemplate ourClassTemplate = null;
+ final var classTemplateListIt = classTemplateList.iterator();
+ while (Objects.isNull(ourClassTemplate) && classTemplateListIt.hasNext()) {
+ final var classTemplate = classTemplateListIt.next();
+ if (classTemplate.getFilePath().endsWith("schemas")) {
+ ourClassTemplate = classTemplate;
+ }
+ }
+ if (ourClassTemplate == null) {
+ ourClassTemplate = classTemplateList.get(0);
+ }
+
+ return ourClassTemplate;
+ }
+
+ protected void generateTemplates() {
+
+ final String exceptionPackage;
+ if (Boolean.TRUE.equals(generateExceptionTemplate)) {
+ exceptionPackage = getClassTemplate().getModelPackage();
+ } else {
+ exceptionPackage = null;
+ }
+
+ classTemplateList.forEach(classTemplate -> {
+ try {
+ fillTemplates(classTemplate.getPropertiesPath(), classTemplate.getModelPackage(),
+ fillTemplateSchema(classTemplate, exceptionPackage));
+ if (generateExceptionTemplate) {
+ fillTemplateModelClassException(classTemplate.getModelPackage());
+ }
+ } catch (final IOException exception) {
+ throw new FileSystemException(exception);
+ }
+ });
+ }
+
+ protected void fillTemplate(final String filePathToSave, final String className, final String templateName) throws IOException {
+ final var fileToSave = Paths.get(filePathToSave);
+ fileToSave.toFile().mkdirs();
+ writeTemplateToFile(templateName, fileToSave, className);
+ }
+
+ @SuppressWarnings("checkstyle:CyclomaticComplexity")
+ protected void fillTemplates(final Path filePathToSave, final String modelPackage, final Set fieldProperties) throws IOException {
+ for (final String current : fieldProperties) {
+ switch (current) {
+ case "Size":
+ fillTemplateCustom(filePathToSave, modelPackage, "Size", CommonTemplateIndexConstants.TEMPLATE_SIZE_ANNOTATION, "SizeValidator",
+ CommonTemplateIndexConstants.TEMPLATE_SIZE_VALIDATOR_ANNOTATION);
+ break;
+ case "Pattern":
+ fillTemplateCustom(filePathToSave, modelPackage, "Pattern", CommonTemplateIndexConstants.TEMPLATE_PATTERN_ANNOTATION,
+ "PatternValidator", CommonTemplateIndexConstants.TEMPLATE_PATTERN_VALIDATOR_ANNOTATION);
+ break;
+ case "MultipleOf":
+ fillTemplateCustom(filePathToSave, modelPackage, "MultipleOf", CommonTemplateIndexConstants.TEMPLATE_MULTIPLEOF_ANNOTATION,
+ "MultipleOfValidator", CommonTemplateIndexConstants.TEMPLATE_MULTIPLEOF_VALIDATOR_ANNOTATION);
+ break;
+ case "Maximum":
+ fillTemplateCustom(filePathToSave, modelPackage, "MaxInteger", CommonTemplateIndexConstants.TEMPLATE_MAX_INTEGER_ANNOTATION,
+ "MaxIntegerValidator", CommonTemplateIndexConstants.TEMPLATE_MAX_INTEGER_VALIDATOR_ANNOTATION);
+ fillTemplateCustom(filePathToSave, modelPackage, "MaxBigDecimal", CommonTemplateIndexConstants.TEMPLATE_MAX_BIG_DECIMAL_ANNOTATION,
+ "MaxBigDecimalValidator", CommonTemplateIndexConstants.TEMPLATE_MAX_BIG_DECIMAL_VALIDATOR_ANNOTATION);
+ fillTemplateCustom(filePathToSave, modelPackage, "MaxDouble", CommonTemplateIndexConstants.TEMPLATE_MAX_DOUBLE_ANNOTATION,
+ "MaxDoubleValidator", CommonTemplateIndexConstants.TEMPLATE_MAX_DOUBLE_VALIDATOR_ANNOTATION);
+ fillTemplateCustom(filePathToSave, modelPackage, "MaxFloat", CommonTemplateIndexConstants.TEMPLATE_MAX_FLOAT_ANNOTATION,
+ "MaxFloatValidator", CommonTemplateIndexConstants.TEMPLATE_MAX_FLOAT_VALIDATOR_ANNOTATION);
+ break;
+ case "Minimum":
+ fillTemplateCustom(filePathToSave, modelPackage, "MinInteger", CommonTemplateIndexConstants.TEMPLATE_MIN_INTEGER_ANNOTATION,
+ "MinIntegerValidator", CommonTemplateIndexConstants.TEMPLATE_MIN_INTEGER_VALIDATOR_ANNOTATION);
+ fillTemplateCustom(filePathToSave, modelPackage, "MinDouble", CommonTemplateIndexConstants.TEMPLATE_MIN_DOUBLE_ANNOTATION,
+ "MinDoubleValidator", CommonTemplateIndexConstants.TEMPLATE_MIN_DOUBLE_VALIDATOR_ANNOTATION);
+ fillTemplateCustom(filePathToSave, modelPackage, "MinFloat", CommonTemplateIndexConstants.TEMPLATE_MIN_FLOAT_ANNOTATION,
+ "MinFloatValidator", CommonTemplateIndexConstants.TEMPLATE_MIN_FLOAT_VALIDATOR_ANNOTATION);
+ fillTemplateCustom(filePathToSave, modelPackage, "MinBigDecimal", CommonTemplateIndexConstants.TEMPLATE_MIN_BIG_DECIMAL_ANNOTATION,
+ "MinBigDecimalValidator", CommonTemplateIndexConstants.TEMPLATE_MIN_BIG_DECIMAL_VALIDATOR_ANNOTATION);
+ break;
+ case "MaxItems":
+ fillTemplateCustom(filePathToSave, modelPackage, "MaxItems", CommonTemplateIndexConstants.TEMPLATE_MAX_ITEMS_ANNOTATION,
+ "MaxItemsValidator", CommonTemplateIndexConstants.TEMPLATE_MAX_ITEMS_VALIDATOR_ANNOTATION);
+ break;
+ case "MinItems":
+ fillTemplateCustom(filePathToSave, modelPackage, "MinItems", CommonTemplateIndexConstants.TEMPLATE_MIN_ITEMS_ANNOTATION,
+ "MinItemsValidator", CommonTemplateIndexConstants.TEMPLATE_MIN_ITEMS_VALIDATOR_ANNOTATION);
+ break;
+ case "NotNull":
+ fillTemplateCustom(filePathToSave, modelPackage, "NotNull", CommonTemplateIndexConstants.TEMPLATE_NOT_NULL_ANNOTATION,
+ "NotNullValidator", CommonTemplateIndexConstants.TEMPLATE_NOT_NULL_VALIDATOR_ANNOTATION);
+ break;
+ case "UniqueItems":
+ fillTemplateCustom(filePathToSave, modelPackage, "UniqueItems", CommonTemplateIndexConstants.TEMPLATE_UNIQUE_ITEMS_ANNOTATION,
+ "UniqueItemsValidator", CommonTemplateIndexConstants.TEMPLATE_UNIQUE_ITEMS_VALIDATOR_ANNOTATION);
+ break;
+ default:
+ break;
+ }
+ }
+ }
+
+ @SuppressWarnings("checkstyle:CyclomaticComplexity")
+ private Set fillTemplateSchema(final ClassTemplate classTemplate, final String exceptionPackage)
+ throws IOException {
+ final var propertiesSet = new HashSet();
+ final var schemaObject = classTemplate.getClassSchema();
+ final var filePath = classTemplate.getFilePath();
+ if (Objects.nonNull(schemaObject) && Objects.nonNull(schemaObject.getFieldObjectList()) && !schemaObject.getFieldObjectList().isEmpty()) {
+ addToRoot("schema", schemaObject);
+ final String templateName = getTemplateName(classTemplate);
+ if (Objects.nonNull(classTemplate.getModelPackage())) {
+ addToRoot("packageModel", classTemplate.getModelPackage());
+ }
+ if (Objects.nonNull(exceptionPackage)) {
+ addToRoot(EXCEPTION_PACKAGE, exceptionPackage);
+ }
+ fillTemplate(filePath.toString(), schemaObject.getClassName(), templateName);
+ for (SchemaFieldObject fieldObject : schemaObject.getFieldObjectList()) {
+ propertiesSet.addAll(fieldObject.getRestrictions().getProperties());
+ if (fieldObject.isRequired() && Boolean.FALSE.equals(classTemplate.isUseLombok())) {
+ propertiesSet.add("NotNull");
+ }
+ }
+ }
+ return propertiesSet;
+ }
+
+ public final void fillTemplateModelClassException(final String modelPackage) throws IOException {
+ addToRoot(EXCEPTION_PACKAGE, modelPackage);
+ writeTemplateToFile(CommonTemplateIndexConstants.TEMPLATE_MODEL_EXCEPTION, MapperUtil.packageToFolder(modelPackage) + SLASH + "exception", "ModelClassException");
+ }
+
+ public void setNotGenerateTemplate() {
+ this.generateExceptionTemplate = false;
+ }
+
+ private void fillTemplateCustom(
+ final Path filePathToSave, final String modelPackage, final String fileNameAnnotation, final String templateAnnotation,
+ final String fileNameValidator, final String templateValidator) throws IOException {
+ final Path pathToCustomValidatorPackage = filePathToSave.resolve("customvalidator");
+ if (!pathToCustomValidatorPackage.toFile().exists() && !pathToCustomValidatorPackage.toFile().mkdirs()) {
+ throw new IOException("Can't create custom validator directory");
+ }
+ root.put("packageModel", modelPackage);
+ writeTemplateToFile(templateAnnotation, pathToCustomValidatorPackage, fileNameAnnotation);
+ writeTemplateToFile(templateValidator, pathToCustomValidatorPackage, fileNameValidator);
+ }
+
+ protected void addToRoot(final String key, final Object value) {
+ root.put(key, value);
+ }
+
+ protected void delFromRoot(final String key) {
+ root.remove(key);
+ }
+
+ protected void addToRoot(final Map propertiesSet) {
+ root.putAll(propertiesSet);
+ }
+
+ protected void cleanData() {
+ clearRoot();
+ addToRoot("checkBasicTypes", BASIC_DATA_TYPES);
+ classTemplateList.clear();
+ generateExceptionTemplate = false;
+ }
+
+ protected abstract void clearRoot();
+
+ public final void addSchemaObject(final String modelPackage,
+ final String keyClassName,
+ final SchemaObject schemaObject,
+ final String destinationPackage,
+ final boolean useLombok) {
+ final var filePath = processPath(getPath(destinationPackage));
+ final var propertiesPath = processPath(getPath(modelPackage));
+ final var builder = ClassTemplate
+ .builder()
+ .filePath(filePath)
+ .modelPackage(modelPackage)
+ .className(schemaObject.getClassName())
+ .classSchema(schemaObject)
+ .propertiesPath(propertiesPath)
+ .useLombok(useLombok);
+ if (Objects.nonNull(keyClassName)) {
+ builder.keyClassName(keyClassName);
+ }
+ classTemplateList.add(builder.build());
+ }
+
+ protected void writeTemplateToFile(final String templateName, final String apiPackage, final String partialPath) throws IOException {
+ writeTemplateToFile(templateName, processPath(getPath(apiPackage)), partialPath);
+ }
+
+ protected void writeTemplateToFile(final String templateName, final Path filePathToSave, final String partialPath) throws IOException {
+ if (!filePathToSave.toFile().exists() && !filePathToSave.toFile().mkdirs()) {
+ throw new IOException("Could not create directory: " + filePathToSave.toFile().getAbsolutePath());
+ }
+ final String path = filePathToSave.resolve(partialPath + FILE_TYPE_JAVA).toString();
+ final Template template = cfg.getTemplate(templateName);
+
+ if (!Files.exists(Path.of(path)) || checkOverwrite) {
+ try (FileWriter writer = new FileWriter(path)) {
+ template.process(root, writer);
+ } catch (IOException | TemplateException exception) {
+ final var schema = root.get("schema");
+ throw new GeneratorTemplateException(String.format(" Error processing template %s with object %s", templateName, ((SchemaObject) schema).getClassName()), exception);
+ }
+ } else {
+ throw new OverwritingApiFilesException();
+ }
+ }
+
+ public Path processPath(final String packagePath) {
+ Path path;
+ final File[] pathList = Objects.requireNonNull(baseDir.listFiles(targetFileFilter));
+ if (pathList.length > 0) {
+ path = pathList[0].toPath().resolve(packagePath);
+ } else {
+ path = targetFolder.toPath();
+ if (!path.toFile().exists() && !path.toFile().mkdirs()) {
+ throw new FileSystemException(path.toFile().getName());
+ }
+ path = path.resolve(packagePath);
+ }
+ if (!path.toFile().isDirectory() && !path.toFile().mkdirs()) {
+ throw new FileSystemException(path.toFile().getName());
+ }
+ return path;
+ }
+
+ protected String convertPackageToTargetPath(final OperationParameterObject operationParameter, final String defaultApiPackage) {
+ String path = null;
+ if (Objects.nonNull(operationParameter)) {
+ if (Objects.nonNull(operationParameter.getApiPackage())) {
+ path = getPath(operationParameter.getApiPackage());
+ } else {
+ path = getPath(defaultApiPackage);
+ }
+ }
+ return path;
+ }
+
+ protected String getPath(final String pathName) {
+ return processedGeneratedSourcesFolder + SLASH + pathName.replace(PACKAGE_SEPARATOR_STR, SLASH);
+ }
+
+ public void checkRequiredOrCombinatorExists(final SchemaObject schema, final boolean useLombok) {
+ if ("anyOf".equals(schema.getSchemaCombinator()) || "oneOf".equals(schema.getSchemaCombinator())) {
+ generateExceptionTemplate = true;
+ } else if (Objects.nonNull(schema.getFieldObjectList()) && !useLombok) {
+ final var fieldListIt = schema.getFieldObjectList().iterator();
+ if (fieldListIt.hasNext()) {
+ do {
+ final var field = fieldListIt.next();
+ if (field.isRequired()) {
+ generateExceptionTemplate = true;
+ }
+ } while (fieldListIt.hasNext() && !generateExceptionTemplate);
+ }
+ }
+ }
+}
diff --git a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/template/CommonTemplateIndexConstants.java b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/template/CommonTemplateIndexConstants.java
new file mode 100644
index 00000000..3ffd08f4
--- /dev/null
+++ b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/template/CommonTemplateIndexConstants.java
@@ -0,0 +1,75 @@
+package com.sngular.api.generator.plugin.common.template;
+
+public abstract class CommonTemplateIndexConstants {
+
+ public static final String TEMPLATE_CONTENT_SCHEMA = "templateSchema.ftlh";
+
+ public static final String TEMPLATE_CONTENT_ENUM = "templateContentEnum.ftlh";
+
+ public static final String TEMPLATE_CONTENT_SCHEMA_LOMBOK = "templateSchemaWithLombok.ftlh";
+
+ public static final String TEMPLATE_MODEL_EXCEPTION = "templateModelClassException.ftlh";
+
+ public static final String TEMPLATE_NOT_NULL_ANNOTATION = "templateNotNull.ftlh";
+
+ public static final String TEMPLATE_NOT_NULL_VALIDATOR_ANNOTATION = "templateNotNullValidator.ftlh";
+
+ public static final String TEMPLATE_MIN_INTEGER_ANNOTATION = "templateMinInteger.ftlh";
+
+ public static final String TEMPLATE_MIN_INTEGER_VALIDATOR_ANNOTATION = "templateMinIntegerValidator.ftlh";
+
+ public static final String TEMPLATE_MIN_BIG_DECIMAL_ANNOTATION = "templateMinBigDecimal.ftlh";
+
+ public static final String TEMPLATE_MIN_BIG_DECIMAL_VALIDATOR_ANNOTATION = "templateMinBigDecimalValidator.ftlh";
+
+ public static final String TEMPLATE_MIN_DOUBLE_ANNOTATION = "templateMinDouble.ftlh";
+
+ public static final String TEMPLATE_MIN_DOUBLE_VALIDATOR_ANNOTATION = "templateMinDoubleValidator.ftlh";
+
+ public static final String TEMPLATE_MIN_FLOAT_ANNOTATION = "templateMinFloat.ftlh";
+
+ public static final String TEMPLATE_MIN_FLOAT_VALIDATOR_ANNOTATION = "templateMinFloatValidator.ftlh";
+
+ public static final String TEMPLATE_MAX_INTEGER_ANNOTATION = "templateMaxInteger.ftlh";
+
+ public static final String TEMPLATE_MAX_INTEGER_VALIDATOR_ANNOTATION = "templateMaxIntegerValidator.ftlh";
+
+ public static final String TEMPLATE_MAX_BIG_DECIMAL_ANNOTATION = "templateMaxBigDecimal.ftlh";
+
+ public static final String TEMPLATE_MAX_BIG_DECIMAL_VALIDATOR_ANNOTATION = "templateMaxBigDecimalValidator.ftlh";
+
+ public static final String TEMPLATE_MAX_DOUBLE_ANNOTATION = "templateMaxDouble.ftlh";
+
+ public static final String TEMPLATE_MAX_DOUBLE_VALIDATOR_ANNOTATION = "templateMaxDoubleValidator.ftlh";
+
+ public static final String TEMPLATE_MAX_FLOAT_ANNOTATION = "templateMaxFloat.ftlh";
+
+ public static final String TEMPLATE_MAX_FLOAT_VALIDATOR_ANNOTATION = "templateMaxFloatValidator.ftlh";
+
+ public static final String TEMPLATE_SIZE_ANNOTATION = "templateSize.ftlh";
+
+ public static final String TEMPLATE_SIZE_VALIDATOR_ANNOTATION = "templateSizeValidator.ftlh";
+
+ public static final String TEMPLATE_PATTERN_ANNOTATION = "templatePattern.ftlh";
+
+ public static final String TEMPLATE_PATTERN_VALIDATOR_ANNOTATION = "templatePatternValidator.ftlh";
+
+ public static final String TEMPLATE_MULTIPLEOF_ANNOTATION = "templateMultipleOf.ftlh";
+
+ public static final String TEMPLATE_MULTIPLEOF_VALIDATOR_ANNOTATION = "templateMultipleOfValidator.ftlh";
+
+ public static final String TEMPLATE_MAX_ITEMS_ANNOTATION = "templateMaxItems.ftlh";
+
+ public static final String TEMPLATE_MAX_ITEMS_VALIDATOR_ANNOTATION = "templateMaxItemsValidator.ftlh";
+
+ public static final String TEMPLATE_MIN_ITEMS_ANNOTATION = "templateMinItems.ftlh";
+
+ public static final String TEMPLATE_MIN_ITEMS_VALIDATOR_ANNOTATION = "templateMinItemsValidator.ftlh";
+
+ public static final String TEMPLATE_UNIQUE_ITEMS_ANNOTATION = "templateUniqueItems.ftlh";
+
+ public static final String TEMPLATE_UNIQUE_ITEMS_VALIDATOR_ANNOTATION = "templateUniqueItemsValidator.ftlh";
+
+ protected CommonTemplateIndexConstants() {
+ }
+}
diff --git a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/template/CommonTemplateLoader.java b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/template/CommonTemplateLoader.java
new file mode 100644
index 00000000..c92b96c5
--- /dev/null
+++ b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/template/CommonTemplateLoader.java
@@ -0,0 +1,79 @@
+package com.sngular.api.generator.plugin.common.template;
+
+import com.sngular.api.generator.plugin.openapi.template.ClasspathTemplateLoader;
+import freemarker.cache.TemplateLoader;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.Reader;
+import java.io.StringReader;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+
+public abstract class CommonTemplateLoader implements TemplateLoader {
+
+ private final Map templatesMap = new HashMap<>();
+
+ protected static final ClassLoader LOADER = ClasspathTemplateLoader.class.getClassLoader();
+
+ protected static final List TEMPLATE_MODEL_FILES = List.of(CommonTemplateIndexConstants.TEMPLATE_CONTENT_SCHEMA,
+ CommonTemplateIndexConstants.TEMPLATE_CONTENT_ENUM, CommonTemplateIndexConstants.TEMPLATE_CONTENT_SCHEMA_LOMBOK, CommonTemplateIndexConstants.TEMPLATE_MODEL_EXCEPTION);
+
+ protected static final List TEMPLATE_ANNOTATION_FILES = List.of(CommonTemplateIndexConstants.TEMPLATE_NOT_NULL_ANNOTATION,
+ CommonTemplateIndexConstants.TEMPLATE_NOT_NULL_VALIDATOR_ANNOTATION,
+ CommonTemplateIndexConstants.TEMPLATE_MAX_INTEGER_ANNOTATION, CommonTemplateIndexConstants.TEMPLATE_MAX_INTEGER_VALIDATOR_ANNOTATION,
+ CommonTemplateIndexConstants.TEMPLATE_MAX_BIG_DECIMAL_ANNOTATION, CommonTemplateIndexConstants.TEMPLATE_MAX_BIG_DECIMAL_VALIDATOR_ANNOTATION,
+ CommonTemplateIndexConstants.TEMPLATE_MAX_DOUBLE_ANNOTATION, CommonTemplateIndexConstants.TEMPLATE_MAX_DOUBLE_VALIDATOR_ANNOTATION,
+ CommonTemplateIndexConstants.TEMPLATE_MAX_FLOAT_ANNOTATION, CommonTemplateIndexConstants.TEMPLATE_MAX_FLOAT_VALIDATOR_ANNOTATION,
+ CommonTemplateIndexConstants.TEMPLATE_MIN_INTEGER_ANNOTATION, CommonTemplateIndexConstants.TEMPLATE_MIN_INTEGER_VALIDATOR_ANNOTATION,
+ CommonTemplateIndexConstants.TEMPLATE_MIN_DOUBLE_ANNOTATION, CommonTemplateIndexConstants.TEMPLATE_MIN_DOUBLE_VALIDATOR_ANNOTATION,
+ CommonTemplateIndexConstants.TEMPLATE_MIN_FLOAT_ANNOTATION, CommonTemplateIndexConstants.TEMPLATE_MIN_FLOAT_VALIDATOR_ANNOTATION,
+ CommonTemplateIndexConstants.TEMPLATE_MIN_BIG_DECIMAL_ANNOTATION, CommonTemplateIndexConstants.TEMPLATE_MIN_BIG_DECIMAL_VALIDATOR_ANNOTATION,
+ CommonTemplateIndexConstants.TEMPLATE_SIZE_ANNOTATION, CommonTemplateIndexConstants.TEMPLATE_SIZE_VALIDATOR_ANNOTATION,
+ CommonTemplateIndexConstants.TEMPLATE_PATTERN_ANNOTATION,
+ CommonTemplateIndexConstants.TEMPLATE_PATTERN_VALIDATOR_ANNOTATION,
+ CommonTemplateIndexConstants.TEMPLATE_MULTIPLEOF_ANNOTATION,
+ CommonTemplateIndexConstants.TEMPLATE_MULTIPLEOF_VALIDATOR_ANNOTATION,
+ CommonTemplateIndexConstants.TEMPLATE_MAX_ITEMS_ANNOTATION,
+ CommonTemplateIndexConstants.TEMPLATE_MAX_ITEMS_VALIDATOR_ANNOTATION,
+ CommonTemplateIndexConstants.TEMPLATE_MIN_ITEMS_ANNOTATION,
+ CommonTemplateIndexConstants.TEMPLATE_MIN_ITEMS_VALIDATOR_ANNOTATION,
+ CommonTemplateIndexConstants.TEMPLATE_UNIQUE_ITEMS_ANNOTATION,
+ CommonTemplateIndexConstants.TEMPLATE_UNIQUE_ITEMS_VALIDATOR_ANNOTATION);
+
+ protected CommonTemplateLoader() {
+
+ }
+
+ protected String readFile(final InputStream file) throws IOException {
+ return new String(file.readAllBytes());
+ }
+
+ protected void init(final Map resourceFiles) {
+ templatesMap.putAll(resourceFiles);
+ }
+
+
+ @Override
+ public final Object findTemplateSource(final String templateName) {
+ return templatesMap.get(templateName);
+ }
+
+ @Override
+ public final long getLastModified(final Object o) {
+ return 0;
+ }
+
+ @Override
+ public final Reader getReader(final Object template, final String charSet) {
+ return new StringReader(template.toString());
+ }
+
+ @Override
+ public void closeTemplateSource(final Object o) {
+ // Not required to implement
+ }
+
+}
diff --git a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/tools/ApiTool.java b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/tools/ApiTool.java
index ba333417..8f15e272 100644
--- a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/tools/ApiTool.java
+++ b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/tools/ApiTool.java
@@ -14,13 +14,12 @@
import java.util.Map;
import java.util.Map.Entry;
import java.util.Objects;
-
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
import com.sngular.api.generator.plugin.asyncapi.util.FactoryTypeEnum;
import com.sngular.api.generator.plugin.common.files.FileLocation;
-import com.sngular.api.generator.plugin.openapi.model.TypeConstants;
+import com.sngular.api.generator.plugin.common.model.TypeConstants;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.collections4.IteratorUtils;
import org.apache.commons.collections4.Transformer;
@@ -35,7 +34,6 @@ public final class ApiTool {
public static final String ANY_OF = "anyOf";
public static final String ONE_OF = "oneOf";
-
public static final String COMPONENTS = "components";
public static final String SCHEMAS = "schemas";
@@ -147,7 +145,8 @@ private static Map getComponentSchemasByType(final JsonNode op
if (hasNode(components, schemaType)) {
final var schemas = getNode(components, schemaType);
final var schemasIt = schemas.fieldNames();
- schemasIt.forEachRemaining(name -> schemasMap.put(name, getNode(schemas, name)));
+ schemasIt.forEachRemaining(name -> schemasMap.put(schemaType.toUpperCase() + "/"+ StringCaseUtils.titleToSnakeCase(name),
+ getNode(schemas, name)));
}
}
@@ -204,6 +203,10 @@ public static boolean hasRequired(final JsonNode schema) {
return hasNode(schema, REQUIRED);
}
+ public static boolean hasName(JsonNode message) {
+ return hasNode(message, "name");
+ }
+
public static boolean hasType(final JsonNode schema) {
return hasNode(schema, "type");
}
@@ -303,7 +306,7 @@ private static Transformer getTextValue() {
}
public static boolean hasComponents(final JsonNode node) {
- return hasNode(node, "components");
+ return hasNode(node, COMPONENTS);
}
public static Iterator> getComponent(final JsonNode node, final String componentType) {
@@ -349,4 +352,36 @@ private static Object getNodeAsType(final JsonNode node) {
}
return result;
}
+
+ public static boolean hasConst(final JsonNode fieldBody) {
+ return hasNode(fieldBody, "const");
+ }
+
+ public static Object getConst(final JsonNode fieldBody) {
+ return getValue(getNode(fieldBody, "const"));
+ }
+
+ private static Object getValue(final JsonNode aConst) {
+ Object value = null;
+ if (Objects.nonNull(aConst)) {
+ if (aConst.isTextual()) {
+ value = aConst.textValue();
+ } else if (aConst.isNumber()) {
+ value = aConst.numberValue();
+ } else if (aConst.isBoolean()) {
+ value = aConst.booleanValue();
+ } else if (aConst.isFloat()) {
+ value = aConst.floatValue();
+ } else if (aConst.isDouble()) {
+ value = aConst.doubleValue();
+ } else if (aConst.isInt()) {
+ value = aConst.intValue();
+ } else if (aConst.isLong()) {
+ value = aConst.longValue();
+ } else if (aConst.isBigDecimal()) {
+ value = aConst.decimalValue();
+ }
+ }
+ return value;
+ }
}
diff --git a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/tools/MapperContentUtil.java b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/tools/MapperContentUtil.java
new file mode 100644
index 00000000..bf119fcc
--- /dev/null
+++ b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/tools/MapperContentUtil.java
@@ -0,0 +1,37 @@
+/*
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * * file, You can obtain one at https://mozilla.org/MPL/2.0/.
+ */
+
+package com.sngular.api.generator.plugin.common.tools;
+
+import java.nio.file.Path;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import com.fasterxml.jackson.databind.JsonNode;
+import com.sngular.api.generator.plugin.common.model.CommonSpecFile;
+import com.sngular.api.generator.plugin.common.model.SchemaObject;
+
+public class MapperContentUtil {
+
+ private MapperContentUtil() {
+ }
+
+ public static List mapComponentToSchemaObject(
+ final Map totalSchemas, final String className, final JsonNode model,
+ final String parentPackage, final CommonSpecFile specFile, final Path baseDir) {
+ final List schemasList = new ArrayList<>();
+ if (Objects.nonNull(model)) {
+ final var modelToBuildMap = new HashMap();
+ schemasList.add(ModelBuilder.buildSchemaObject(totalSchemas, className, model, new HashSet<>(), modelToBuildMap, parentPackage, specFile, baseDir));
+ schemasList.addAll(modelToBuildMap.values());
+ }
+ return schemasList;
+ }
+
+}
diff --git a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/openapi/utils/MapperUtil.java b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/tools/MapperUtil.java
similarity index 65%
rename from multiapi-engine/src/main/java/com/sngular/api/generator/plugin/openapi/utils/MapperUtil.java
rename to multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/tools/MapperUtil.java
index 55ad86bf..d2d80ed1 100644
--- a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/openapi/utils/MapperUtil.java
+++ b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/tools/MapperUtil.java
@@ -4,20 +4,26 @@
* * file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
-package com.sngular.api.generator.plugin.openapi.utils;
+package com.sngular.api.generator.plugin.common.tools;
import com.fasterxml.jackson.databind.JsonNode;
-import com.sngular.api.generator.plugin.common.tools.ApiTool;
-import com.sngular.api.generator.plugin.openapi.model.TypeConstants;
-import com.sngular.api.generator.plugin.openapi.parameter.SpecFile;
+import com.sngular.api.generator.plugin.common.model.CommonSpecFile;
+import com.sngular.api.generator.plugin.common.model.TypeConstants;
+import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
public class MapperUtil {
+ private static final String REF = "$ref";
+
+ private static final String DIVISOR = "([./])";
+
+ private static final String SLASH = "/";
+
private MapperUtil() {}
- public static String getSimpleType(final JsonNode schema, final SpecFile specFile) {
+ public static String getSimpleType(final JsonNode schema, final CommonSpecFile specFile) {
final String type;
final var nodeType = ApiTool.getType(schema);
if (checkIfNumber(nodeType)) {
@@ -32,16 +38,42 @@ public static String getSimpleType(final JsonNode schema, final SpecFile specFil
return type;
}
+ public static String[] splitName(final String name) {
+ return ArrayUtils.removeAllOccurrences(name.split(DIVISOR), "");
+ }
+
+ public static String packageToFolder(final String packageName) {
+ return StringUtils.replace(packageName, ".", SLASH);
+ }
+
public static String getRefSchemaName(final JsonNode parameter) {
final String[] pathObjectRef = ApiTool.getRefValue(parameter).split("/");
return pathObjectRef[pathObjectRef.length - 1];
}
- public static String getRefSchemaName(final String parameter) {
+ public static String getRefSchemaKey(final JsonNode parameter) {
+ final String[] pathObjectRef = ApiTool.getRefValue(parameter).split("/");
+ return StringUtils.upperCase(pathObjectRef[pathObjectRef.length - 2] + "/" + StringCaseUtils.titleToSnakeCase(pathObjectRef[pathObjectRef.length - 1]));
+ }
+
+ public static String getRefSchemaKey(final String parameter) {
final String[] pathObjectRef = parameter.split("/");
+ return StringUtils.upperCase(pathObjectRef[pathObjectRef.length - 2] + "/" + getSchemaKey(pathObjectRef[pathObjectRef.length - 1]));
+ }
+
+ public static String getKeySchemaName(final String parameter) {
+ return StringCaseUtils.toCamelCase(getKey(parameter));
+ }
+
+ public static String getKey(final String keyString) {
+ final String[] pathObjectRef = keyString.split("/");
return pathObjectRef[pathObjectRef.length - 1];
}
+ public static String getSchemaKey(final String schemaName) {
+ return StringCaseUtils.titleToSnakeCase(schemaName);
+ }
+
private static boolean checkIfNumber(final String nodeType) {
return TypeConstants.NUMBER.equalsIgnoreCase(nodeType) || TypeConstants.INTEGER.equalsIgnoreCase(nodeType)
|| TypeConstants.INT_32.equalsIgnoreCase(nodeType) || TypeConstants.INT_64.equalsIgnoreCase(nodeType);
@@ -70,7 +102,7 @@ private static String processNumber(final JsonNode schema) {
return type;
}
- public static String getTypeArray(final JsonNode array, final SpecFile specFile) {
+ public static String getTypeArray(final JsonNode array, final CommonSpecFile specFile) {
var typeArray = "";
if (ApiTool.isString(ApiTool.getItems(array))) {
typeArray = TypeConstants.STRING;
@@ -82,19 +114,19 @@ public static String getTypeArray(final JsonNode array, final SpecFile specFile)
return typeArray;
}
- public static String getPojoName(final String namePojo, final SpecFile specFile) {
+ public static String getPojoName(final String namePojo, final CommonSpecFile specFile) {
return (StringUtils.isNotBlank(specFile.getModelNamePrefix()) ? specFile.getModelNamePrefix() : "")
+ StringUtils.capitalize(namePojo)
+ (StringUtils.isNotBlank(specFile.getModelNameSuffix()) ? specFile.getModelNameSuffix() : "");
}
- public static String getRef(final JsonNode schema, final SpecFile specFile) {
+ public static String getRef(final JsonNode schema, final CommonSpecFile specFile) {
final String typeObject;
typeObject = getPojoName(getRefSchemaName(schema), specFile);
return typeObject;
}
- public static String getDateType(final JsonNode schema, final SpecFile specFile) {
+ public static String getDateType(final JsonNode schema, final CommonSpecFile specFile) {
final String dateType;
switch (ApiTool.getFormat(schema)) {
@@ -127,4 +159,18 @@ public static String getDateType(final JsonNode schema, final SpecFile specFile)
}
return dateType;
}
+
+ public static String getRefClass(final JsonNode schema) {
+ final String[] pathObjectRef = getStrings(schema);
+ return pathObjectRef[pathObjectRef.length - 1];
+ }
+
+ private static String[] getStrings(final JsonNode schema) {
+ return splitName(schema.get(REF).textValue());
+ }
+
+ public static String getLongRefClass(final JsonNode schema) {
+ final String[] pathObjectRef = getStrings(schema);
+ return pathObjectRef[pathObjectRef.length - 2] + "/" + pathObjectRef[pathObjectRef.length - 1];
+ }
}
diff --git a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/openapi/utils/MapperContentUtil.java b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/tools/ModelBuilder.java
similarity index 55%
rename from multiapi-engine/src/main/java/com/sngular/api/generator/plugin/openapi/utils/MapperContentUtil.java
rename to multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/tools/ModelBuilder.java
index d78dd7e7..86bb5d5f 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/common/tools/ModelBuilder.java
@@ -1,10 +1,4 @@
-/*
- * This Source Code Form is subject to the terms of the Mozilla Public
- * * License, v. 2.0. If a copy of the MPL was not distributed with this
- * * file, You can obtain one at https://mozilla.org/MPL/2.0/.
- */
-
-package com.sngular.api.generator.plugin.openapi.utils;
+package com.sngular.api.generator.plugin.common.tools;
import java.nio.file.Path;
import java.util.ArrayList;
@@ -16,20 +10,18 @@
import java.util.Objects;
import java.util.Set;
import java.util.function.Consumer;
-
import com.fasterxml.jackson.databind.JsonNode;
-import com.sngular.api.generator.plugin.common.tools.ApiTool;
-import com.sngular.api.generator.plugin.common.tools.SchemaUtil;
+import com.sngular.api.generator.plugin.common.model.CommonSpecFile;
+import com.sngular.api.generator.plugin.common.model.SchemaFieldObject;
+import com.sngular.api.generator.plugin.common.model.SchemaFieldObjectType;
+import com.sngular.api.generator.plugin.common.model.SchemaObject;
+import com.sngular.api.generator.plugin.common.model.TypeConstants;
import com.sngular.api.generator.plugin.openapi.exception.BadDefinedEnumException;
-import com.sngular.api.generator.plugin.openapi.model.SchemaFieldObject;
-import com.sngular.api.generator.plugin.openapi.model.SchemaFieldObjectType;
-import com.sngular.api.generator.plugin.openapi.model.SchemaObject;
-import com.sngular.api.generator.plugin.openapi.model.TypeConstants;
-import com.sngular.api.generator.plugin.openapi.parameter.SpecFile;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
+import org.apache.commons.text.WordUtils;
-public class MapperContentUtil {
+public final class ModelBuilder {
private static final String ADDITIONAL_PROPERTY_NAME = "AdditionalProperty";
@@ -41,59 +33,43 @@ public class MapperContentUtil {
private static final String ADDITIONAL_PROPERTIES = "additionalProperties";
- private MapperContentUtil() {
- }
-
- public static Map mapComponentToSchemaObject(
- final Map totalSchemas, final Map compositedSchemas, final JsonNode schema,
- final String schemaName, final SpecFile specFile, final Path baseDir) {
-
- return mapComponentToSchemaObject(totalSchemas, compositedSchemas, new HashSet<>(), schema,
- StringUtils.defaultIfEmpty(ApiTool.getName(schema), schemaName), specFile, baseDir);
- }
+ private static final Map cachedSchemas = new HashMap<>();
- private static Map mapComponentToSchemaObject(
- final Map totalSchemas, final Map compositedSchemas,
- final Set antiLoopList, final JsonNode schema, final String schemaName, final SpecFile specFile,
- final Path baseDir) {
- final var name = StringUtils.defaultIfBlank(ApiTool.getName(schema), schemaName);
- if (!compositedSchemas.containsKey(name)) {
- compositedSchemas
- .put(name, toSchemaObject(name, totalSchemas, compositedSchemas, antiLoopList, schema, schemaName, specFile, baseDir));
- }
- return compositedSchemas;
- }
+ public static SchemaObject buildSchemaObject(
+ final Map totalSchemas, final String className, final JsonNode model,
+ final Set antiLoopList, final Map compositedSchemas, final String parentPackage,
+ final CommonSpecFile specFile, final Path baseDir) {
- @SuppressWarnings("checkstyle:ParameterNumber")
- private static SchemaObject toSchemaObject(
- final String name, final Map totalSchemas, final Map compositedSchemas,
- final Set antiLoopList, final JsonNode schema, final String schemaName, final SpecFile specFile,
- final Path baseDir) {
+ antiLoopList.add(WordUtils.capitalizeFully(className));
+ final var schemaBuilder = SchemaObject.builder()
+ .schemaName(WordUtils.capitalizeFully(className))
+ .className(MapperUtil.getPojoName(className, specFile));
- antiLoopList.add(schemaName);
+ if (!ApiTool.isEnum(model)) {
+ final var listSchema = getFields(null, totalSchemas, model, specFile, compositedSchemas, antiLoopList, WordUtils.capitalizeFully(className), baseDir);
- final var listSchema = getFields(null, totalSchemas, schema, specFile, compositedSchemas, antiLoopList, schemaName, baseDir);
+ schemaBuilder.importList(getImportList(listSchema, specFile.getModelPackage()));
- String schemaCombinatorType = "";
- if (ApiTool.isAllOf(schema)) {
- schemaCombinatorType = ALL_OF_COMBINATOR;
- }
-
- if (ApiTool.isAnyOf(schema)) {
- schemaCombinatorType = ANY_OF_COMBINATOR;
- }
+ if (ApiTool.isAllOf(model)) {
+ schemaBuilder.schemaCombinator(ALL_OF_COMBINATOR);
+ } else if (ApiTool.isAnyOf(model)) {
+ schemaBuilder.schemaCombinator(ANY_OF_COMBINATOR);
+ } else if (ApiTool.isOneOf(model)) {
+ schemaBuilder.schemaCombinator(ONE_OF_COMBINATOR);
+ } else {
+ schemaBuilder.schemaCombinator("");
+ }
- if (ApiTool.isOneOf(schema)) {
- schemaCombinatorType = ONE_OF_COMBINATOR;
+ schemaBuilder
+ .fieldObjectList(listSchema)
+ .parentPackage(parentPackage.toLowerCase());
+ } else {
+ schemaBuilder
+ .isEnum(true)
+ .fieldObject(processEnumField(className, model, specFile, ApiTool.getEnumValues(model), model));
}
-
- return SchemaObject.builder()
- .schemaName(name)
- .className(MapperUtil.getPojoName(schemaName, specFile))
- .importList(getImportList(listSchema, specFile.getModelPackage()))
- .schemaCombinator(schemaCombinatorType)
- .fieldObjectList(listSchema)
- .build();
+ cachedSchemas.putAll(compositedSchemas);
+ return schemaBuilder.build();
}
private static List getImportList(final Set fieldObjectList, final String modelPackage) {
@@ -103,10 +79,10 @@ private static List getImportList(final Set fieldObje
for (final var fieldObject : fieldObjectList) {
getTypeImports(listHashMap, fieldObject);
if (StringUtils.isNotBlank(fieldObject.getImportClass())
- && !listHashMap.containsKey(fieldObject.getImportClass())
- && !fieldObject.getDataType().containsType("enum")) {
+ && !listHashMap.containsKey(fieldObject.getImportClass())
+ && !fieldObject.getDataType().containsType("enum")) {
listHashMap.put(StringUtils.capitalize(fieldObject.getImportClass()),
- List.of(modelPackage + "." + StringUtils.capitalize(fieldObject.getImportClass())));
+ List.of(modelPackage + "." + StringUtils.capitalize(fieldObject.getImportClass())));
}
}
if (!listHashMap.isEmpty()) {
@@ -116,8 +92,8 @@ private static List getImportList(final Set fieldObje
}
private static void getTypeImports(
- final HashMap> listHashMap,
- final SchemaFieldObject fieldObject) {
+ final HashMap> listHashMap,
+ final SchemaFieldObject fieldObject) {
final SchemaFieldObjectType type = fieldObject.getDataType();
if (type.containsType(TypeConstants.ARRAY)) {
listHashMap.computeIfAbsent(TypeConstants.ARRAY, key -> List.of("java.util.List", "java.util.ArrayList"));
@@ -157,26 +133,26 @@ private static void getTypeImports(
}
private static Set getFields(final String buildingSchema,
- final Map totalSchemas, final JsonNode schema, final SpecFile specFile,
- final Map compositedSchemas, final Set antiLoopList, final String nameSchema,
- final Path baseDir) {
+ final Map totalSchemas, final JsonNode schema, final CommonSpecFile specFile,
+ final Map compositedSchemas, final Set antiLoopList, final String nameSchema,
+ final Path baseDir) {
final Set fieldObjectArrayList = new HashSet<>();
if (ApiTool.hasProperties(schema)) {
if (ApiTool.hasAdditionalProperties(schema)) {
ApiTool.getProperties(schema).forEachRemaining(processProperties(buildingSchema, totalSchemas, compositedSchemas, fieldObjectArrayList, specFile, schema, antiLoopList,
- baseDir));
+ baseDir));
fieldObjectArrayList.addAll(processAdditionalProperties(ADDITIONAL_PROPERTIES, schema, specFile, totalSchemas, compositedSchemas, antiLoopList, nameSchema, baseDir));
} else {
- ApiTool.getProperties(schema).forEachRemaining(processProperties(buildingSchema, totalSchemas, compositedSchemas, fieldObjectArrayList, specFile, schema, antiLoopList,
- baseDir));
+ ApiTool.getProperties(schema).forEachRemaining(processProperties(nameSchema, totalSchemas, compositedSchemas, fieldObjectArrayList, specFile, schema, antiLoopList,
+ baseDir));
}
} else if (TypeConstants.ARRAY.equalsIgnoreCase(ApiTool.getType(schema))) {
final String itemType = ApiTool.hasRef(ApiTool.getItems(schema)) ? MapperUtil.getRef(ApiTool.getItems(schema), specFile) : ApiTool.getType(ApiTool.getItems(schema));
fieldObjectArrayList.add(SchemaFieldObject.builder()
- .baseName("items")
- .dataType(SchemaFieldObjectType.fromTypeList(TypeConstants.ARRAY, itemType))
- .build());
+ .baseName("items")
+ .dataType(SchemaFieldObjectType.fromTypeList(TypeConstants.ARRAY, itemType))
+ .build());
} else if (ApiTool.isAllOf(schema)) {
fieldObjectArrayList.addAll(processAllOf(totalSchemas, ApiTool.getAllOf(schema), specFile, compositedSchemas, antiLoopList, baseDir));
} else if (ApiTool.isAnyOf(schema)) {
@@ -186,76 +162,25 @@ private static Set getFields(final String buildingSchema,
} else if (ApiTool.isEnum(schema)) {
fieldObjectArrayList.add(processEnumField(ApiTool.getName(schema), schema, specFile, ApiTool.getEnumValues(schema), schema));
} else if (ApiTool.hasRef(schema)) {
- final var refSchema = totalSchemas.get(MapperUtil.getRefSchemaName(schema));
- ApiTool.getProperties(refSchema).forEachRemaining(processProperties(buildingSchema, totalSchemas, compositedSchemas, fieldObjectArrayList, specFile, schema, antiLoopList,
- baseDir));
+ final var refSchema = totalSchemas.get(MapperUtil.getRefSchemaKey(schema));
+ ApiTool.getProperties(refSchema).forEachRemaining(processProperties(buildingSchema, totalSchemas, compositedSchemas, fieldObjectArrayList, specFile, refSchema, antiLoopList,
+ baseDir));
} else {
fieldObjectArrayList.add(SchemaFieldObject.builder()
- .baseName(ApiTool.getName(schema))
- .dataType(new SchemaFieldObjectType(MapperUtil.getSimpleType(schema, specFile)))
- .build());
+ .baseName(ApiTool.getName(schema))
+ .dataType(new SchemaFieldObjectType(MapperUtil.getSimpleType(schema, specFile)))
+ .build());
}
return fieldObjectArrayList;
}
- private static Set processAllOf(
- final Map totalSchemas, final JsonNode schemaList, final SpecFile specFile,
- final Map compositedSchemas, final Set antiLoopList, final Path baseDir) {
- final Set fieldObjectArrayList = new HashSet<>();
-
- for (JsonNode ref : schemaList) {
- if (ApiTool.hasRef(ref)) {
- final String schemaName = MapperUtil.getRefSchemaName(ref);
- final var schemaToProcess = totalSchemas.get(schemaName);
- ApiTool.getProperties(schemaToProcess).forEachRemaining(processProperties("", totalSchemas, compositedSchemas, fieldObjectArrayList, specFile, ref, antiLoopList, baseDir));
- for (var fieldObject : fieldObjectArrayList) {
- fieldObject.setRequired(true);
- }
- }
- }
- return fieldObjectArrayList;
- }
-
- private static Set processAnyOfOneOf(final String buildingSchema,
- final Map totalSchemas, final JsonNode schemaList, final SpecFile specFile,
- final Map compositedSchemas, final Set antiLoopList, final Path baseDir) {
- final Set fieldObjectArrayList = new HashSet<>();
-
- for (JsonNode internalSchema : schemaList) {
- if (ApiTool.hasRef(internalSchema)) {
- final var schemaName = MapperUtil.getRefSchemaName(internalSchema);
- if (!antiLoopList.contains(schemaName)) {
- if (compositedSchemas.containsKey(schemaName)) {
- antiLoopList.add(schemaName);
- fieldObjectArrayList.addAll(compositedSchemas.get(schemaName).getFieldObjectList());
- } else {
- final var schemaObject = solveRef(internalSchema, totalSchemas, compositedSchemas, antiLoopList, specFile, baseDir);
- compositedSchemas.put(schemaName, schemaObject);
- antiLoopList.add(schemaName);
- fieldObjectArrayList.addAll(schemaObject.getFieldObjectList());
- }
- } else if (compositedSchemas.containsKey(schemaName)) {
- fieldObjectArrayList.addAll(compositedSchemas.get(schemaName).getFieldObjectList());
- } else if (!schemaName.equalsIgnoreCase(buildingSchema)) {
- fieldObjectArrayList.addAll(getFields(schemaName, totalSchemas, internalSchema, specFile, compositedSchemas, antiLoopList, ApiTool.getName(internalSchema), baseDir));
- }
- } else {
- fieldObjectArrayList.addAll(getFields(buildingSchema, totalSchemas, internalSchema, specFile, compositedSchemas, antiLoopList, ApiTool.getName(internalSchema), baseDir));
- for (var fieldObject : fieldObjectArrayList) {
- if (ApiTool.checkIfRequired(internalSchema, fieldObject.getBaseName())) {
- fieldObject.setRequired(true);
- }
- }
- }
- }
- return fieldObjectArrayList;
- }
@SuppressWarnings("checkstyle:CyclomaticComplexity")
private static List processFieldObjectList(final String buildingSchema,
- final String fieldName, final String className, final JsonNode schema, final SpecFile specFile, final Map totalSchemas,
- final Map compositedSchemas, final Set antiLoopList, final Path baseDir) {
+ final String fieldName, final String className, final JsonNode schema, final CommonSpecFile specFile,
+ final Map totalSchemas, final Map compositedSchemas,
+ final Set antiLoopList, final Path baseDir) {
final var fieldObjectArrayList = new ArrayList();
if (TypeConstants.ARRAY.equalsIgnoreCase(ApiTool.getType(schema))) {
@@ -267,18 +192,18 @@ private static List processFieldObjectList(final String build
processRef(fieldName, schema, new SchemaFieldObjectType(MapperUtil.getSimpleType(schema, specFile)), totalSchemas, compositedSchemas, antiLoopList, specFile, baseDir));
} else if (ApiTool.isObject(schema) && !ApiTool.hasProperties(schema)) {
fieldObjectArrayList.add(SchemaFieldObject
- .builder()
- .baseName(fieldName)
- .dataType(new SchemaFieldObjectType(TypeConstants.OBJECT))
- .build());
+ .builder()
+ .baseName(fieldName)
+ .dataType(new SchemaFieldObjectType(TypeConstants.OBJECT))
+ .build());
} else if (ApiTool.isEnum(schema)) {
fieldObjectArrayList.add(processEnumField(fieldName, schema, specFile, ApiTool.getEnumValues(schema), schema));
} else if (!ApiTool.hasProperties(schema) && !ApiTool.isComposed(schema)) {
fieldObjectArrayList.add(SchemaFieldObject
- .builder()
- .baseName(fieldName)
- .dataType(new SchemaFieldObjectType(TypeConstants.OBJECT))
- .build());
+ .builder()
+ .baseName(fieldName)
+ .dataType(new SchemaFieldObjectType(TypeConstants.OBJECT))
+ .build());
} else if (ApiTool.isObject(schema)) {
fieldObjectArrayList.addAll(processObject(fieldName, className, schema, specFile, totalSchemas, compositedSchemas, antiLoopList, baseDir));
} else {
@@ -286,56 +211,23 @@ private static List processFieldObjectList(final String build
var schemaObjectComposed = compositedSchemas.get(composedSchemaName);
if (Objects.isNull(schemaObjectComposed)) {
schemaObjectComposed = createComposedSchema(buildingSchema, StringUtils.defaultIfBlank(className, fieldName), schema, specFile,
- totalSchemas, compositedSchemas, antiLoopList, baseDir);
+ totalSchemas, compositedSchemas, antiLoopList, baseDir);
compositedSchemas.put(composedSchemaName, schemaObjectComposed);
}
fieldObjectArrayList.add(SchemaFieldObject
- .builder()
- .baseName(fieldName)
- .dataType(SchemaFieldObjectType.fromTypeList(schemaObjectComposed.getClassName(), schemaObjectComposed.getClassName()))
- .build());
+ .builder()
+ .baseName(fieldName)
+ .dataType(SchemaFieldObjectType.fromTypeList(schemaObjectComposed.getClassName(), schemaObjectComposed.getClassName()))
+ .build());
}
return fieldObjectArrayList;
}
- private static SchemaFieldObject processRef(
- final String fieldName, final JsonNode schema, final SchemaFieldObjectType dataType,
- final Map totalSchemas, final Map compositedSchemas,
- final Set antiLoopList, final SpecFile specFile, final Path baseDir) {
- final var field = SchemaFieldObject.builder()
- .baseName(fieldName)
- .dataType(dataType)
- .build();
- if (!antiLoopList.contains(MapperUtil.getRefSchemaName(schema))) {
- antiLoopList.add(MapperUtil.getRefSchemaName(schema));
- final String refSchemaName = MapperUtil.getRef(schema, specFile);
- setFieldType(field, schema, schema, specFile, refSchemaName);
-
- solveRef(schema, totalSchemas, compositedSchemas, antiLoopList, specFile, baseDir);
- }
- return field;
- }
-
- private static SchemaObject solveRef(
- final JsonNode schema, final Map totalSchemas,
- final Map compositedSchemas, final Set antiLoopList, final SpecFile specFile,
- final Path baseDir) {
-
- final var referredSchema = SchemaUtil.solveRef(ApiTool.getRefValue(schema), totalSchemas, baseDir.resolve(specFile.getFilePath()).getParent());
-
- final var schemaObject = toSchemaObject(MapperUtil.getRefSchemaName(schema), totalSchemas, compositedSchemas,
- antiLoopList, referredSchema, MapperUtil.getRefSchemaName(schema), specFile, baseDir);
- schemaObject.setEnum(ApiTool.isEnum(referredSchema));
-
- compositedSchemas.put(MapperUtil.getRefSchemaName(schema), schemaObject);
- return schemaObject;
- }
-
private static Consumer> processProperties(final String buildingSchema,
- final Map totalSchemas, final Map compositedSchemas, final Set fieldObjectArrayList, final SpecFile specFile,
- final JsonNode schema, final Set antiLoopList, final Path baseDir) {
+ final Map totalSchemas, final Map compositedSchemas, final Set fieldObjectArrayList, final CommonSpecFile specFile,
+ final JsonNode schema, final Set antiLoopList, final Path baseDir) {
return field -> {
final var nodeName = field.getKey();
final var nodeValue = field.getValue();
@@ -349,29 +241,57 @@ private static Consumer> processProperties(final Str
@SuppressWarnings({"checkstyle:CyclomaticComplexity", "checkstyle:ParameterNumber"})
private static List processObjectProperty(final String buildingSchema,
- final Map totalSchemas, final String fieldName, final JsonNode fieldBody, final Map compositedSchemas, final SpecFile specFile,
- final JsonNode schema, final Set antiLoopList, final Path baseDir) {
+ final Map totalSchemas, final String fieldName, final JsonNode fieldBody, final Map compositedSchemas, final CommonSpecFile specFile,
+ final JsonNode schema, final Set antiLoopList, final Path baseDir) {
final List fieldObjectArrayList = new LinkedList<>();
final var isRequired = ApiTool.checkIfRequired(fieldBody, fieldName);
final SchemaFieldObject field;
if (ApiTool.hasRef(fieldBody)) {
final var typeName = MapperUtil.getRefSchemaName(fieldBody);
- final var refSchema = totalSchemas.get(typeName);
- if (!antiLoopList.contains(typeName) && totalSchemas.containsKey(typeName) && ApiTool.hasType(refSchema)
- && ApiTool.hasItems(refSchema) || ApiTool.getRefValue(fieldBody).contains(fieldName)) {
+ final var refSchema = totalSchemas.get(MapperUtil.getRefSchemaKey(fieldBody));
+ if (!antiLoopList.contains(typeName) && Objects.nonNull(refSchema) && ApiTool.hasType(refSchema)
+ && ApiTool.hasItems(refSchema) || ApiTool.getRefValue(fieldBody).contains(fieldName)) {
+ if (antiLoopList.contains(typeName) && ApiTool.getRefValue(fieldBody).contains(fieldName)) {
+ fieldObjectArrayList.add(SchemaFieldObject
+ .builder()
+ .baseName(fieldName)
+ .required(ApiTool.checkIfRequired(schema, fieldName))
+ .dataType(SchemaFieldObjectType.fromTypeList(MapperUtil.getSimpleType(refSchema, specFile),
+ MapperUtil.getPojoName(typeName, specFile)))
+ .build());
+ } else {
antiLoopList.add(typeName);
- fieldObjectArrayList.addAll(processFieldObjectList(buildingSchema, fieldName, typeName, totalSchemas.get(typeName), specFile, totalSchemas, compositedSchemas,
- antiLoopList, baseDir));
+ fieldObjectArrayList.addAll(processFieldObjectList(buildingSchema, fieldName, typeName, refSchema, specFile, totalSchemas, compositedSchemas,
+ antiLoopList, baseDir));
+ }
} else if (ApiTool.isEnum(refSchema)) {
fieldObjectArrayList.add(processEnumField(fieldName, refSchema, specFile, ApiTool.getEnumValues(refSchema), schema));
- } else {
+ } else if (ApiTool.isObject(refSchema) || ApiTool.isComposed(refSchema)) {
+ compositedSchemas.put(typeName, buildSchemaObject(totalSchemas, typeName, refSchema, antiLoopList, compositedSchemas, "", specFile, baseDir ));
+ fieldObjectArrayList.add(SchemaFieldObject
+ .builder()
+ .baseName(fieldName)
+ .required(ApiTool.checkIfRequired(schema, fieldName))
+ .dataType(SchemaFieldObjectType.fromTypeList(MapperUtil.getSimpleType(refSchema, specFile),
+ MapperUtil.getPojoName(typeName, specFile)))
+ .build());
+ } else if (ApiTool.isBoolean(refSchema) || ApiTool.isString(refSchema) || ApiTool.isNumber(refSchema) || ApiTool.isDateTime(refSchema)) {
fieldObjectArrayList.add(SchemaFieldObject
- .builder()
- .baseName(fieldName)
- .required(ApiTool.checkIfRequired(schema, fieldName))
- .dataType(SchemaFieldObjectType.fromTypeList(MapperUtil.getSimpleType(refSchema, specFile),
- MapperUtil.getPojoName(typeName, specFile)))
- .build());
+ .builder()
+ .baseName(fieldName)
+ .required(ApiTool.checkIfRequired(schema, fieldName))
+ .dataType(new SchemaFieldObjectType(MapperUtil.getSimpleType(refSchema, specFile)))
+ .constValue(ApiTool.getConst(refSchema))
+ .build());
+ } else if (antiLoopList.contains(typeName) &&
+ cachedSchemas.containsKey(typeName)) {
+ fieldObjectArrayList.add(SchemaFieldObject
+ .builder()
+ .baseName(fieldName)
+ .required(ApiTool.checkIfRequired(schema, fieldName))
+ .dataType(SchemaFieldObjectType.fromTypeList(MapperUtil.getSimpleType(refSchema, specFile),
+ MapperUtil.getPojoName(typeName, specFile)))
+ .build());
}
} else if (ApiTool.isEnum(fieldBody)) {
fieldObjectArrayList.add(processEnumField(fieldName, fieldBody, specFile, ApiTool.getEnumValues(fieldBody), fieldBody));
@@ -381,11 +301,12 @@ private static List processObjectProperty(final String buildi
fieldObjectArrayList.add(field);
} else if (isBasicType(fieldBody)) {
field = SchemaFieldObject
- .builder()
- .baseName(fieldName)
- .required(isRequired)
- .dataType(new SchemaFieldObjectType(MapperUtil.getSimpleType(fieldBody, specFile)))
- .build();
+ .builder()
+ .baseName(fieldName)
+ .required(isRequired || ApiTool.hasConst(fieldBody))
+ .dataType(new SchemaFieldObjectType(MapperUtil.getSimpleType(fieldBody, specFile)))
+ .constValue(ApiTool.getConst(fieldBody))
+ .build();
addPropertiesToFieldObject(field, fieldBody);
setFieldType(field, fieldBody, schema, specFile, fieldName);
fieldObjectArrayList.add(field);
@@ -395,15 +316,20 @@ private static List processObjectProperty(final String buildi
return fieldObjectArrayList;
}
- private static SchemaFieldObject processStringProperty(final String propertyName, final JsonNode schema, final SpecFile specFile) {
+ private static Object getConst(final JsonNode fieldBody) {
+ return ApiTool.hasConst(fieldBody) ? ApiTool.getConst(fieldBody) : null;
+ }
+
+ private static SchemaFieldObject processStringProperty(final String propertyName, final JsonNode schema, final CommonSpecFile specFile) {
final String resultingType = ApiTool.isDateTime(schema) ? MapperUtil.getDateType(schema, specFile) : TypeConstants.STRING;
final SchemaFieldObject field = SchemaFieldObject
- .builder()
- .baseName(propertyName)
- .required(ApiTool.checkIfRequired(schema, propertyName))
- .dataType(new SchemaFieldObjectType(resultingType))
- .build();
+ .builder()
+ .baseName(propertyName)
+ .required(ApiTool.checkIfRequired(schema, propertyName) || ApiTool.hasConst(schema))
+ .dataType(new SchemaFieldObjectType(resultingType))
+ .constValue(ApiTool.getConst(schema))
+ .build();
addPropertiesToFieldObject(field, schema);
return field;
}
@@ -415,37 +341,37 @@ private static void addPropertiesToFieldObject(final SchemaFieldObject fieldObje
final var restriction = restrictionList.next();
switch (restriction.getKey()) {
case "pattern":
- fieldObject.getRestrictionProperties().setPattern(restriction.getValue().asText());
+ fieldObject.getRestrictions().setPattern(restriction.getValue().asText());
break;
case "maxItems":
- fieldObject.getRestrictionProperties().setMaxItems(restriction.getValue().asInt());
+ fieldObject.getRestrictions().setMaxItems(restriction.getValue().asInt());
break;
case "minItems":
- fieldObject.getRestrictionProperties().setMinItems(restriction.getValue().asInt());
+ fieldObject.getRestrictions().setMinItems(restriction.getValue().asInt());
break;
case "maxLength":
- fieldObject.getRestrictionProperties().setMaxLength(restriction.getValue().asInt());
+ fieldObject.getRestrictions().setMaxLength(restriction.getValue().asInt());
break;
case "minLength":
- fieldObject.getRestrictionProperties().setMinLength(restriction.getValue().asInt());
+ fieldObject.getRestrictions().setMinLength(restriction.getValue().asInt());
break;
case "uniqueItems":
- fieldObject.getRestrictionProperties().setUniqueItems(restriction.getValue().asBoolean());
+ fieldObject.getRestrictions().setUniqueItems(restriction.getValue().asBoolean());
break;
case "exclusiveMaximum":
- fieldObject.getRestrictionProperties().setExclusiveMaximum(restriction.getValue().asBoolean());
+ fieldObject.getRestrictions().setExclusiveMaximum(restriction.getValue().asBoolean());
break;
case "exclusiveMinimum":
- fieldObject.getRestrictionProperties().setExclusiveMinimum(restriction.getValue().asBoolean());
+ fieldObject.getRestrictions().setExclusiveMinimum(restriction.getValue().asBoolean());
break;
case "multipleOf":
- fieldObject.getRestrictionProperties().setMultipleOf(restriction.getValue().asText());
+ fieldObject.getRestrictions().setMultipleOf(restriction.getValue().asText());
break;
case "maximum":
- fieldObject.getRestrictionProperties().setMaximum(restriction.getValue().asText());
+ fieldObject.getRestrictions().setMaximum(restriction.getValue().asText());
break;
case "minimum":
- fieldObject.getRestrictionProperties().setMinimum(restriction.getValue().asText());
+ fieldObject.getRestrictions().setMinimum(restriction.getValue().asText());
break;
default:
break;
@@ -455,50 +381,51 @@ private static void addPropertiesToFieldObject(final SchemaFieldObject fieldObje
@SuppressWarnings("checkstyle:ParameterNumber")
private static List processArray(
- final String fieldName, final String className, final JsonNode schema, final SpecFile specFile, final Map totalSchemas,
- final Map compositedSchemas, final Set antiLoopList, final Path baseDir) {
+ final String fieldName, final String className, final JsonNode schema, final CommonSpecFile specFile, final Map totalSchemas,
+ final Map compositedSchemas, final Set antiLoopList, final Path baseDir) {
final List fieldObjectArrayList = new LinkedList<>();
if (!ApiTool.hasItems(schema)) {
fieldObjectArrayList.add(SchemaFieldObject
- .builder()
- .baseName(fieldName)
- .dataType(new SchemaFieldObjectType(TypeConstants.OBJECT))
- .build());
+ .builder()
+ .baseName(fieldName)
+ .dataType(new SchemaFieldObjectType(TypeConstants.OBJECT))
+ .build());
} else {
final var items = ApiTool.getItems(schema);
if (ApiTool.hasRef(items)) {
fieldObjectArrayList.add(
- processRef(fieldName, items, SchemaFieldObjectType.fromTypeList(TypeConstants.ARRAY, MapperUtil.getSimpleType(items, specFile)), totalSchemas, compositedSchemas,
- antiLoopList, specFile, baseDir));
+ processRef(fieldName, items, SchemaFieldObjectType.fromTypeList(TypeConstants.ARRAY, MapperUtil.getSimpleType(items, specFile)), totalSchemas, compositedSchemas,
+ antiLoopList, specFile, baseDir));
} else if (ApiTool.isComposed(items)) {
final String composedSchemaName = StringUtils.defaultIfBlank(className, fieldName);
SchemaObject schemaObjectComposed = compositedSchemas.get(composedSchemaName);
if (Objects.isNull(schemaObjectComposed)) {
schemaObjectComposed = createComposedSchema("", StringUtils.defaultIfBlank(className, fieldName), items, specFile,
- totalSchemas, compositedSchemas, antiLoopList, baseDir);
+ totalSchemas, compositedSchemas, antiLoopList, baseDir);
compositedSchemas.put(composedSchemaName, schemaObjectComposed);
}
fieldObjectArrayList.add(SchemaFieldObject
- .builder()
- .baseName(fieldName)
- .dataType(SchemaFieldObjectType.fromTypeList(TypeConstants.ARRAY, schemaObjectComposed.getClassName()))
- .importClass(schemaObjectComposed.getClassName())
- .build());
+ .builder()
+ .baseName(fieldName)
+ .dataType(SchemaFieldObjectType.fromTypeList(TypeConstants.ARRAY, schemaObjectComposed.getClassName()))
+ .importClass(schemaObjectComposed.getClassName())
+ .build());
} else if (ApiTool.hasProperties(items)) {
- compositedSchemas.putAll(mapComponentToSchemaObject(totalSchemas, compositedSchemas, items, fieldName, specFile, baseDir));
+ final var itemsObject = buildSchemaObject(totalSchemas, className, items, antiLoopList, compositedSchemas, "", specFile, baseDir);
+ compositedSchemas.put(className, itemsObject);
fieldObjectArrayList.add(SchemaFieldObject
- .builder()
- .baseName(fieldName)
- .dataType(SchemaFieldObjectType.fromTypeList(TypeConstants.ARRAY, MapperUtil.getPojoName(fieldName, specFile)))
- .build());
+ .builder()
+ .baseName(fieldName)
+ .dataType(SchemaFieldObjectType.fromTypeList(TypeConstants.ARRAY, MapperUtil.getPojoName(fieldName, specFile)))
+ .build());
} else {
final SchemaFieldObject field = SchemaFieldObject
- .builder()
- .baseName(fieldName)
- .dataType(SchemaFieldObjectType.fromTypeList(TypeConstants.ARRAY, MapperUtil.getSimpleType(items, specFile)))
- .build();
+ .builder()
+ .baseName(fieldName)
+ .dataType(SchemaFieldObjectType.fromTypeList(TypeConstants.ARRAY, MapperUtil.getSimpleType(items, specFile)))
+ .build();
fieldObjectArrayList.add(field);
addPropertiesToFieldObject(field, schema);
}
@@ -509,108 +436,109 @@ private static List processArray(
@SuppressWarnings("checkstyle:ParameterNumber")
private static Set processObject(
- final String fieldName, final String className, final JsonNode schema, final SpecFile specFile,
- final Map totalSchemas, final Map compositedSchemas,
- final Set antiLoopList, final Path baseDir) {
+ final String fieldName, final String className, final JsonNode schema, final CommonSpecFile specFile,
+ final Map totalSchemas, final Map compositedSchemas,
+ final Set antiLoopList, final Path baseDir) {
final Set fieldObjectArrayList = new HashSet<>();
if (ObjectUtils.allNull(className, fieldName)) {
ApiTool.getProperties(schema).forEachRemaining(
- processProperties("", totalSchemas, compositedSchemas, fieldObjectArrayList, specFile, schema, antiLoopList, baseDir));
- } else if (antiLoopList.contains(className)) {
+ processProperties("", totalSchemas, compositedSchemas, fieldObjectArrayList, specFile, schema, antiLoopList, baseDir));
+ } else if (antiLoopList.contains(className) && compositedSchemas.containsKey(className)) {
fieldObjectArrayList
- .add(SchemaFieldObject
- .builder()
- .baseName(className)
- .dataType(SchemaFieldObjectType.fromTypeList(TypeConstants.OBJECT, MapperUtil.getPojoName(className, specFile)))
- .build());
- } else if (antiLoopList.contains(fieldName)) {
+ .add(SchemaFieldObject
+ .builder()
+ .baseName(className)
+ .dataType(SchemaFieldObjectType.fromTypeList(TypeConstants.OBJECT, MapperUtil.getPojoName(className, specFile)))
+ .build());
+ } else if (antiLoopList.contains(fieldName) && compositedSchemas.containsKey(className)) {
fieldObjectArrayList
- .add(SchemaFieldObject
- .builder()
- .baseName(fieldName)
- .dataType(SchemaFieldObjectType.fromTypeList(TypeConstants.OBJECT, MapperUtil.getPojoName(fieldName, specFile)))
- .build());
+ .add(SchemaFieldObject
+ .builder()
+ .baseName(fieldName)
+ .dataType(SchemaFieldObjectType.fromTypeList(TypeConstants.OBJECT, MapperUtil.getPojoName(fieldName, specFile)))
+ .build());
} else {
final String name = StringUtils.defaultIfBlank(className, fieldName);
- compositedSchemas.putAll(
- mapComponentToSchemaObject(totalSchemas, compositedSchemas, antiLoopList, schema, name, specFile,
- baseDir));
+ final var itemsObject = buildSchemaObject(totalSchemas, className, schema, antiLoopList, compositedSchemas, "", specFile, baseDir);
+ compositedSchemas.put(className, itemsObject);
fieldObjectArrayList
- .add(SchemaFieldObject
- .builder()
- .baseName(name)
- .dataType(SchemaFieldObjectType.fromTypeList(TypeConstants.OBJECT, MapperUtil.getPojoName(name, specFile)))
- .build());
+ .add(SchemaFieldObject
+ .builder()
+ .baseName(name)
+ .dataType(SchemaFieldObjectType.fromTypeList(TypeConstants.OBJECT, MapperUtil.getPojoName(name, specFile)))
+ .build());
}
return fieldObjectArrayList;
}
private static Set processMap(
- final String fieldName, final JsonNode schema, final SpecFile specFile, final Map totalSchemas,
- final Map compositedSchemas, final Set antiLoopList, final Path baseDir) {
+ final String fieldName, final JsonNode schema, final CommonSpecFile specFile, final Map totalSchemas,
+ final Map compositedSchemas, final Set antiLoopList, final Path baseDir) {
final Set fieldObjectArrayList = new HashSet<>();
if (TypeConstants.OBJECT.equalsIgnoreCase(ApiTool.getType(schema)) && ApiTool.hasProperties(schema)) {
ApiTool.getProperties(schema).forEachRemaining(
- processProperties("", totalSchemas, compositedSchemas, fieldObjectArrayList, specFile, schema, antiLoopList, baseDir));
+ processProperties("", totalSchemas, compositedSchemas, fieldObjectArrayList, specFile, schema, antiLoopList, baseDir));
}
if (ApiTool.hasAdditionalProperties(schema)) {
fieldObjectArrayList.addAll(processAdditionalProperties(fieldName, schema, specFile, totalSchemas, compositedSchemas,
- antiLoopList, ADDITIONAL_PROPERTIES, baseDir));
+ antiLoopList, ADDITIONAL_PROPERTIES, baseDir));
}
return fieldObjectArrayList;
}
private static List processAdditionalProperties(
- final String fieldName, final JsonNode schema, final SpecFile specFile, final Map totalSchemas,
- final Map compositedSchemas, final Set antiLoopList, final String nameSchema,
- final Path baseDir) {
+ final String fieldName, final JsonNode schema, final CommonSpecFile specFile, final Map totalSchemas,
+ final Map compositedSchemas, final Set antiLoopList, final String nameSchema,
+ final Path baseDir) {
final var fieldObjectArrayList = new ArrayList();
final var addPropObj = ApiTool.getAdditionalProperties(schema);
if (TypeConstants.isBoolean(addPropObj.asText())) {
fieldObjectArrayList
- .add(SchemaFieldObject
- .builder()
- .baseName(fieldName)
- .dataType(SchemaFieldObjectType.fromTypeList(TypeConstants.MAP, TypeConstants.OBJECT))
- .build());
+ .add(SchemaFieldObject
+ .builder()
+ .baseName(fieldName)
+ .dataType(SchemaFieldObjectType.fromTypeList(TypeConstants.MAP, TypeConstants.OBJECT))
+ .build());
} else if (ApiTool.hasRef(addPropObj)) {
final String refSchemaName = MapperUtil.getRef(addPropObj, specFile);
fieldObjectArrayList.add(processRef(fieldName, addPropObj,
- SchemaFieldObjectType.fromTypeList(TypeConstants.MAP, refSchemaName), totalSchemas, compositedSchemas,
- antiLoopList, specFile, baseDir));
+ SchemaFieldObjectType.fromTypeList(TypeConstants.MAP, refSchemaName), totalSchemas, compositedSchemas,
+ antiLoopList, specFile, baseDir));
} else if (ApiTool.hasItems(addPropObj)) {
fieldObjectArrayList
- .add(SchemaFieldObject
- .builder()
- .baseName(fieldName)
- .dataType(SchemaFieldObjectType.fromTypeList(TypeConstants.MAP, TypeConstants.ARRAY,
- MapperUtil.getSimpleType(ApiTool.getItems(addPropObj), specFile)))
- .build());
+ .add(SchemaFieldObject
+ .builder()
+ .baseName(fieldName)
+ .dataType(SchemaFieldObjectType.fromTypeList(TypeConstants.MAP, TypeConstants.ARRAY,
+ MapperUtil.getSimpleType(ApiTool.getItems(addPropObj), specFile)))
+ .build());
} else if (ApiTool.isObject(addPropObj)) {
- compositedSchemas.putAll(
- mapComponentToSchemaObject(totalSchemas, compositedSchemas, antiLoopList, addPropObj, nameSchema + "Value", specFile,
- baseDir));
+ final String className = nameSchema + "Value";
+ final var itemsObject = buildSchemaObject(totalSchemas, className, addPropObj, antiLoopList, compositedSchemas, "", specFile, baseDir);
+ compositedSchemas.put(className, itemsObject);
fieldObjectArrayList
- .add(SchemaFieldObject
- .builder()
- .baseName(ADDITIONAL_PROPERTIES)
- .dataType(SchemaFieldObjectType.fromTypeList(TypeConstants.MAP, MapperUtil.getPojoName(nameSchema + "Value", specFile)))
- .build());
+ .add(SchemaFieldObject
+ .builder()
+ .baseName(ADDITIONAL_PROPERTIES)
+ .dataType(SchemaFieldObjectType.fromTypeList(TypeConstants.MAP, MapperUtil.getPojoName(className, specFile)))
+ .build());
} else {
final String type = isBasicType(addPropObj) ? MapperUtil.getSimpleType(addPropObj, specFile)
- : MapperUtil.getPojoName(ApiTool.getName(schema) + ADDITIONAL_PROPERTY_NAME, specFile);
+ : MapperUtil.getPojoName(ApiTool.getName(schema) + ADDITIONAL_PROPERTY_NAME, specFile);
fieldObjectArrayList
- .add(SchemaFieldObject
- .builder()
- .baseName(fieldName)
- .dataType(SchemaFieldObjectType.fromTypeList(TypeConstants.MAP, type))
- .build());
+ .add(SchemaFieldObject
+ .builder()
+ .baseName(fieldName)
+ .dataType(SchemaFieldObjectType.fromTypeList(TypeConstants.MAP, type))
+ .constValue(getConst(addPropObj))
+ .required(ApiTool.checkIfRequired(schema, fieldName) ||ApiTool.hasConst(addPropObj))
+ .build());
}
return fieldObjectArrayList;
@@ -618,40 +546,40 @@ private static List processAdditionalProperties(
private static boolean isBasicType(final JsonNode value) {
return !(ApiTool.isObject(value) || ApiTool.isArray(value) || ApiTool.isComposed(value)
- || ApiTool.hasAdditionalProperties(value));
+ || ApiTool.hasAdditionalProperties(value));
}
private static SchemaObject createComposedSchema(final String buildingSchema,
- final String fieldName, final JsonNode schema, final SpecFile specFile, final Map totalSchemas,
- final Map compositedSchemas, final Set antiLoopList, final Path baseDir) {
+ final String fieldName, final JsonNode schema, final CommonSpecFile specFile, final Map totalSchemas,
+ final Map compositedSchemas, final Set antiLoopList, final Path baseDir) {
final Set fieldObjectArrayList = new HashSet<>();
String schemaCombinatorType = "";
if (ApiTool.isAllOf(schema)) {
fieldObjectArrayList.addAll(
- processAllOf(totalSchemas, ApiTool.getAllOf(schema), specFile, compositedSchemas, antiLoopList, baseDir));
+ processAllOf(totalSchemas, ApiTool.getAllOf(schema), specFile, compositedSchemas, antiLoopList, baseDir));
schemaCombinatorType = ALL_OF_COMBINATOR;
} else if (ApiTool.isAnyOf(schema)) {
fieldObjectArrayList.addAll(
- processAnyOfOneOf(buildingSchema, totalSchemas, ApiTool.getAnyOf(schema), specFile, compositedSchemas, antiLoopList, baseDir));
+ processAnyOfOneOf(fieldName, totalSchemas, ApiTool.getAnyOf(schema), specFile, compositedSchemas, antiLoopList, baseDir));
schemaCombinatorType = ANY_OF_COMBINATOR;
} else if (ApiTool.isOneOf(schema)) {
fieldObjectArrayList.addAll(
- processAnyOfOneOf(buildingSchema, totalSchemas, ApiTool.getOneOf(schema), specFile, compositedSchemas, antiLoopList, baseDir));
+ processAnyOfOneOf(buildingSchema, totalSchemas, ApiTool.getOneOf(schema), specFile, compositedSchemas, antiLoopList, baseDir));
schemaCombinatorType = ONE_OF_COMBINATOR;
}
return SchemaObject.builder()
- .schemaName(fieldName)
- .className(MapperUtil.getPojoName(fieldName, specFile))
- .importList(getImportList(fieldObjectArrayList, specFile.getModelPackage()))
- .schemaCombinator(schemaCombinatorType)
- .fieldObjectList(fieldObjectArrayList)
- .build();
+ .schemaName(fieldName)
+ .className(MapperUtil.getPojoName(fieldName, specFile))
+ .importList(getImportList(fieldObjectArrayList, specFile.getModelPackage()))
+ .schemaCombinator(schemaCombinatorType)
+ .fieldObjectList(fieldObjectArrayList)
+ .build();
}
private static void setFieldType(
- final SchemaFieldObject field, final JsonNode schemaProperty, final JsonNode schema,
- final SpecFile specFile, final String key) {
+ final SchemaFieldObject field, final JsonNode schemaProperty, final JsonNode schema,
+ final CommonSpecFile specFile, final String key) {
field.setRequired(ApiTool.hasRequired(schema) && ApiTool.checkIfRequired(schema, key));
if (ApiTool.isArray(schemaProperty)) {
final String typeArray;
@@ -677,7 +605,7 @@ private static void setFieldType(
}
}
- private static String getMapTypeObject(final JsonNode schema, final SpecFile specFile) {
+ private static String getMapTypeObject(final JsonNode schema, final CommonSpecFile specFile) {
final String type;
if (ApiTool.isBoolean(ApiTool.getAdditionalProperties(schema))) {
type = TypeConstants.OBJECT;
@@ -687,10 +615,10 @@ private static String getMapTypeObject(final JsonNode schema, final SpecFile spe
type = MapperUtil.getRef(additionalProperties, specFile);
} else if (ApiTool.isObject(schema)) {
final var additionalPropertiesField = SchemaFieldObject
- .builder()
- .baseName(ApiTool.getName(additionalProperties))
- .dataType(new SchemaFieldObjectType(MapperUtil.getSimpleType(additionalProperties, specFile)))
- .build();
+ .builder()
+ .baseName(ApiTool.getName(additionalProperties))
+ .dataType(new SchemaFieldObjectType(MapperUtil.getSimpleType(additionalProperties, specFile)))
+ .build();
setFieldType(additionalPropertiesField, additionalProperties, additionalProperties, specFile, "");
type = getMapFieldType(additionalPropertiesField);
} else {
@@ -721,14 +649,102 @@ private static String getMapFieldType(final SchemaFieldObject schemaFieldObject)
return type;
}
+ private static Set processAllOf(
+ final Map totalSchemas, final JsonNode schemaList, final CommonSpecFile specFile,
+ final Map compositedSchemas, final Set antiLoopList, final Path baseDir) {
+ final Set fieldObjectArrayList = new HashSet<>();
+
+ for (JsonNode ref : schemaList) {
+ if (ApiTool.hasRef(ref)) {
+ final var schemaToProcess = totalSchemas.get(MapperUtil.getRefSchemaKey(ref));
+ ApiTool.getProperties(schemaToProcess).forEachRemaining(processProperties("", totalSchemas, compositedSchemas, fieldObjectArrayList, specFile, ref, antiLoopList, baseDir));
+ for (var fieldObject : fieldObjectArrayList) {
+ fieldObject.setRequired(true);
+ }
+ }
+ }
+ return fieldObjectArrayList;
+ }
+
+ private static Set processAnyOfOneOf(final String buildingSchema,
+ final Map totalSchemas, final JsonNode schemaList, final CommonSpecFile specFile,
+ final Map compositedSchemas, final Set antiLoopList, final Path baseDir) {
+ final Set