diff --git a/pom.xml b/pom.xml
index aee415d..410a1b2 100644
--- a/pom.xml
+++ b/pom.xml
@@ -6,7 +6,7 @@
net.coru
scc-multiapi-converter
- 2.6.2
+ 2.7.0
SCC-MultiApi-Converter
Generates Spring Cloud Contracts based on an OpenApi and AsyncApi document
https://github.com/corunet/scc-multiapi-converter
@@ -35,7 +35,7 @@
jegarcia
Jose Enrique Garcia Maciñeiras
- jegarcia@corunet.com
+ joseenrique.garcia@sngular.com
Corunet
https://corunet.github.io/
@@ -47,7 +47,7 @@
cmunozgomez
Cesar Munoz Gomez
- cmunoz@corunet.com
+ cesar.munoz@sngular.com
Corunet
https://corunet.github.io/
@@ -58,7 +58,7 @@
Rivarsal
Pablo José López Rivadulla
- plopez@corunet.com
+ pablo.lopezr@sngular.com
Corunet
https://corunet.github.io/
@@ -69,7 +69,7 @@
fcampostato
Fernando Campos Tato
- fcampos@corunet.com
+ fernando.campos@sngular.com
Corunet
https://corunet.github.io/
@@ -80,7 +80,7 @@
jmejutovazquez
Javier Mejuto Vázquez
- jmejuto@corunet.com
+ javier.mejuto@sngular.com
Corunet
https://corunet.github.io/
@@ -91,7 +91,7 @@
mcabezasp
Miguel Cabezas Puerto
- mcabezas@corunet.com
+ miguel.cabezas@sngular.com
Corunet
https://corunet.github.io/
@@ -192,7 +192,43 @@
+
+
+
+ org.apache.maven.plugins
+ maven-checkstyle-plugin
+ 3.1.2
+
+
+ com.puppycrawl.tools
+ checkstyle
+ 10.2
+
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-checkstyle-plugin
+
+ styles/checkstyle/OSS_checkstyle.xml
+ UTF-8
+ true
+ true
+ false
+
+
+
+ validate
+
+ check
+
+ validate
+
+
+
org.apache.maven.plugins
maven-plugin-plugin
@@ -287,4 +323,16 @@
+
+
+
+
+ org.apache.maven.plugins
+ maven-checkstyle-plugin
+
+ styles/checkstyle/OSS_checkstyle.xml
+
+
+
+
diff --git a/src/main/java/net/coru/multiapi/converter/MultiApiContractConverter.java b/src/main/java/net/coru/multiapi/converter/MultiApiContractConverter.java
index a15648c..3664a83 100644
--- a/src/main/java/net/coru/multiapi/converter/MultiApiContractConverter.java
+++ b/src/main/java/net/coru/multiapi/converter/MultiApiContractConverter.java
@@ -21,7 +21,7 @@
import org.springframework.cloud.contract.spec.ContractConverter;
@Slf4j
-public class MultiApiContractConverter implements ContractConverter> {
+public final class MultiApiContractConverter implements ContractConverter> {
private static final OpenApiContractConverter OPEN_API_CONTRACT_CONVERTER = new OpenApiContractConverter();
@@ -35,8 +35,8 @@ public boolean isAccepted(final File file) {
try {
final JsonNode node;
node = BasicTypeConstants.OBJECT_MAPPER.readTree(file);
- isAccepted = (node != null && node.size() > 0 && (Objects.nonNull(node.get(BasicTypeConstants.ASYNCAPI)) || Objects.nonNull(node.get(BasicTypeConstants.OPENAPI))));
- } catch (IOException e) {
+ isAccepted = node != null && node.size() > 0 && (Objects.nonNull(node.get(BasicTypeConstants.ASYNCAPI)) || Objects.nonNull(node.get(BasicTypeConstants.OPENAPI)));
+ } catch (final IOException e) {
isAccepted = false;
}
}
@@ -47,7 +47,7 @@ public boolean isAccepted(final File file) {
public Collection convertFrom(final File file) {
Collection contracts = null;
- JsonNode node;
+ final JsonNode node;
if (isAccepted(file)) {
try {
node = BasicTypeConstants.OBJECT_MAPPER.readTree(file);
@@ -60,7 +60,7 @@ public Collection convertFrom(final File file) {
} else {
throw new MultiApiContractConverterException("Yaml file is not correct");
}
- } catch (IOException e) {
+ } catch (final IOException e) {
throw new MultiApiContractConverterException(e);
}
}
@@ -68,5 +68,7 @@ public Collection convertFrom(final File file) {
}
@Override
- public Collection convertTo(final Collection contract) {return contract;}
+ public Collection convertTo(final Collection contract) {
+ return contract;
+ }
}
diff --git a/src/main/java/net/coru/multiapi/converter/asyncapi/AsyncApiContractConverter.java b/src/main/java/net/coru/multiapi/converter/asyncapi/AsyncApiContractConverter.java
index 0de8f89..16f7456 100644
--- a/src/main/java/net/coru/multiapi/converter/asyncapi/AsyncApiContractConverter.java
+++ b/src/main/java/net/coru/multiapi/converter/asyncapi/AsyncApiContractConverter.java
@@ -34,72 +34,76 @@
import org.springframework.cloud.contract.spec.internal.ResponseBodyMatchers;
@Slf4j
-public class AsyncApiContractConverter {
+public final class AsyncApiContractConverter {
+
+ private File basePath;
public Collection convertFrom(final File file) {
+ basePath = file;
final Collection sccContracts = new ArrayList<>();
try {
- final var fileContent = BasicTypeConstants.OBJECT_MAPPER.readTree(file);
+ final var fileContent = BasicTypeConstants.OBJECT_MAPPER.readTree(basePath);
final var channelsNode = fileContent.get(BasicTypeConstants.CHANNELS);
- Iterator it = channelsNode.elements();
- Iterator topicIterator = channelsNode.fieldNames();
+ final Iterator it = channelsNode.elements();
+ final Iterator topicIterator = channelsNode.fieldNames();
while (it.hasNext()) {
final Contract contract = new Contract();
- final JsonNode operationContent;
- final String operationType;
- final Map bodyProcessed;
-
- JsonNode channel = it.next();
- operationType = channel.fieldNames().next();
- operationContent = subscribeOrPublishOperation(channel);
- String operationId = operationContent.get("operationId").asText();
+
+ final JsonNode channel = it.next();
+ final String operationType = channel.fieldNames().next();
+ final JsonNode operationContent = AsyncApiContractConverterUtils.subscribeOrPublishOperation(channel);
+ final String operationId = operationContent.get("operationId").asText();
contract.setName(operationId);
- ResponseBodyMatchers responseBodyMatchers = new ResponseBodyMatchers();
- bodyProcessed = processMessage(responseBodyMatchers, operationContent, fileContent, operationType, file);
+ final ResponseBodyMatchers responseBodyMatchers = new ResponseBodyMatchers();
+ final Map bodyProcessed = processMessage(responseBodyMatchers, operationContent, fileContent, operationType);
contract.label(operationId);
- String topicName = topicIterator.next();
+ final String topicName = topicIterator.next();
if (operationType.equals(BasicTypeConstants.SUBSCRIBE)) {
- Input input = new Input();
- input.messageFrom(topicName);
- input.messageBody(bodyProcessed);
- input.messageHeaders(headers -> headers.accept("application/json"));
- contract.setInput(input);
-
- OutputMessage outputMessage = new OutputMessage();
- outputMessage.headers(headers -> headers.accept("application/json"));
- outputMessage.sentTo(topicName);
- outputMessage.body(bodyProcessed);
- contract.setOutputMessage(outputMessage);
-
+ processSubscribeOperation(contract, bodyProcessed, topicName);
} else if (operationType.equals(BasicTypeConstants.PUBLISH)) {
- Input input = new Input();
- input.triggeredBy(operationId + "()");
- contract.setInput(input);
-
- OutputMessage outputMessage = new OutputMessage();
- outputMessage.sentTo(topicName);
-
- outputMessage.body(bodyProcessed);
- outputMessage.setBodyMatchers(responseBodyMatchers);
- contract.setOutputMessage(outputMessage);
+ processPublishOperation(contract, operationId, responseBodyMatchers, bodyProcessed, topicName);
}
-
sccContracts.add(contract);
}
-
-
- } catch (Exception e) {
+ } catch (final IOException e) {
log.error("Error", e);
}
return sccContracts;
}
+ private void processPublishOperation(
+ final Contract contract, final String operationId, final ResponseBodyMatchers responseBodyMatchers, final Map bodyProcessed, final String topicName) {
+ final Input input = new Input();
+ input.triggeredBy(operationId + "()");
+ contract.setInput(input);
+
+ final OutputMessage outputMessage = new OutputMessage();
+ outputMessage.sentTo(topicName);
+
+ outputMessage.body(bodyProcessed);
+ outputMessage.setBodyMatchers(responseBodyMatchers);
+ contract.setOutputMessage(outputMessage);
+ }
+
+ private void processSubscribeOperation(final Contract contract, final Map bodyProcessed, final String topicName) {
+ final Input input = new Input();
+ input.messageFrom(topicName);
+ input.messageBody(bodyProcessed);
+ input.messageHeaders(headers -> headers.accept("application/json"));
+ contract.setInput(input);
+
+ final OutputMessage outputMessage = new OutputMessage();
+ outputMessage.headers(headers -> headers.accept("application/json"));
+ outputMessage.sentTo(topicName);
+ outputMessage.body(bodyProcessed);
+ contract.setOutputMessage(outputMessage);
+ }
+
private Map processMessage(
- final ResponseBodyMatchers responseBodyMatchers, final JsonNode operationContent, final JsonNode fileContent, final String operationType,
- final File basePath)
+ final ResponseBodyMatchers responseBodyMatchers, final JsonNode operationContent, final JsonNode fileContent, final String operationType)
throws IOException {
final JsonNode message;
JsonNode propertiesJson;
@@ -107,16 +111,16 @@ private Map processMessage(
final Map messageBody = new HashMap<>();
message = operationContent.get("message");
- checkIfReferenceWithProperties(message);
+ AsyncApiContractConverterUtils.checkIfReferenceWithProperties(message);
- if (message.get(BasicTypeConstants.REF) != null && message.get(BasicTypeConstants.REF).asText().startsWith("#")) {
+ if (Objects.nonNull(message.get(BasicTypeConstants.REF)) && message.get(BasicTypeConstants.REF).asText().startsWith("#")) {
final String[] pathToRef = message.get(BasicTypeConstants.REF).asText().split("/");
ref = pathToRef[pathToRef.length - 1];
final var payload = fileContent.findPath(ref);
- messageBody.putAll(processSchemas(responseBodyMatchers, operationType, payload.fieldNames().next(), payload, basePath, fileContent, ""));
+ messageBody.putAll(processSchemas(responseBodyMatchers, operationType, payload.fieldNames().next(), payload, fileContent, ""));
- } else if (message.get(BasicTypeConstants.REF) != null) {
+ } else if (Objects.nonNull(message.get(BasicTypeConstants.REF))) {
final var fillProperties = processAvro(responseBodyMatchers, message);
messageBody.putAll(fillProperties.getValue());
} else {
@@ -127,12 +131,12 @@ private Map processMessage(
final var length = pathToRef.length;
ref = pathToRef[length - 1];
propertiesJson = fileContent.findPath(ref).get(BasicTypeConstants.PROPERTIES);
- messageBody.putAll(fillObjectProperties(responseBodyMatchers, propertiesJson, "", operationType, basePath, fileContent));
- } else if (propertiesJson.get(BasicTypeConstants.REF) != null && propertiesJson.get(BasicTypeConstants.REF).asText().contains(".yml")) {
+ messageBody.putAll(fillObjectProperties(responseBodyMatchers, propertiesJson, "", operationType, fileContent));
+ } else if (Objects.nonNull(propertiesJson.get(BasicTypeConstants.REF)) && propertiesJson.get(BasicTypeConstants.REF).asText().contains(".yml")) {
final String[] pathToRef = propertiesJson.get(BasicTypeConstants.REF).asText().split("#");
- messageBody.putAll(processExternalFile(pathToRef[0], pathToRef[1], responseBodyMatchers, operationType, basePath, ""));
+ messageBody.putAll(processExternalFile(pathToRef[0], pathToRef[1], responseBodyMatchers, operationType, ""));
} else {
- messageBody.putAll(fillObjectProperties(responseBodyMatchers, propertiesJson, "", operationType, basePath, fileContent));
+ messageBody.putAll(fillObjectProperties(responseBodyMatchers, propertiesJson, "", operationType, fileContent));
}
}
@@ -140,31 +144,31 @@ private Map processMessage(
}
private Map processSchemas(
- final ResponseBodyMatchers responseBodyMatchers, final String operationType, String fieldName,
- final JsonNode payload, final File basePath, final JsonNode fileContent, final String bodyMatcherPath) throws IOException {
+ final ResponseBodyMatchers responseBodyMatchers, final String operationType, final String fieldName,
+ final JsonNode payload, final JsonNode fileContent, final String bodyMatcherPath) throws IOException {
final JsonNode properties;
final String ref;
final Map messageBody = new HashMap<>();
- checkIfReferenceWithProperties(payload.get(fieldName));
+ AsyncApiContractConverterUtils.checkIfReferenceWithProperties(payload.get(fieldName));
if (Objects.nonNull(payload.get(fieldName).get(BasicTypeConstants.REF)) && payload.get(fieldName).get(BasicTypeConstants.REF).asText().startsWith("#")) {
final String[] pathToRef = payload.get(fieldName).get(BasicTypeConstants.REF).asText().split("/");
final var length = pathToRef.length;
ref = pathToRef[length - 1];
properties = fileContent.findPath(ref).get(BasicTypeConstants.PROPERTIES);
- messageBody.putAll(processProperties(responseBodyMatchers, operationType, basePath, fileContent, bodyMatcherPath, properties));
+ messageBody.putAll(processProperties(responseBodyMatchers, operationType, fileContent, bodyMatcherPath, properties));
} else if (Objects.nonNull(payload.get(fieldName).get(BasicTypeConstants.REF)) && payload.get(fieldName).get(BasicTypeConstants.REF).asText().contains(".yml")) {
final String[] pathToRef = payload.get(fieldName).get(BasicTypeConstants.REF).asText().split("#");
- messageBody.putAll(processExternalFile(pathToRef[0], pathToRef[1], responseBodyMatchers, operationType, basePath, bodyMatcherPath));
- } else if (payload.get(fieldName).get(BasicTypeConstants.REF) != null) {
+ messageBody.putAll(processExternalFile(pathToRef[0], pathToRef[1], responseBodyMatchers, operationType, bodyMatcherPath));
+ } else if (Objects.nonNull(payload.get(fieldName).get(BasicTypeConstants.REF))) {
final var fillProperties = processAvro(responseBodyMatchers, payload);
messageBody.putAll(fillProperties.getValue());
} else {
if (Objects.nonNull(payload.get(BasicTypeConstants.PAYLOAD).get(BasicTypeConstants.PROPERTIES))) {
properties = payload.get(BasicTypeConstants.PAYLOAD).get(BasicTypeConstants.PROPERTIES);
- messageBody.putAll(processProperties(responseBodyMatchers, operationType, basePath, fileContent, bodyMatcherPath, properties));
+ messageBody.putAll(processProperties(responseBodyMatchers, operationType, fileContent, bodyMatcherPath, properties));
} else {
if (Objects.nonNull(payload.get(BasicTypeConstants.PAYLOAD))) {
@@ -172,7 +176,7 @@ private Map processSchemas(
} else {
properties = payload;
}
- messageBody.putAll(fillObjectProperties(responseBodyMatchers, properties, bodyMatcherPath, operationType, basePath, fileContent));
+ messageBody.putAll(fillObjectProperties(responseBodyMatchers, properties, bodyMatcherPath, operationType, fileContent));
}
}
@@ -180,67 +184,61 @@ private Map processSchemas(
}
private Map processProperties(
- final ResponseBodyMatchers responseBodyMatchers, final String operationType, final File basePath, final JsonNode fileContent, final String bodyMatcherPath,
+ final ResponseBodyMatchers responseBodyMatchers, final String operationType, final JsonNode fileContent, final String bodyMatcherPath,
final JsonNode properties) throws IOException {
- var propertiesName = properties.fieldNames();
+ final var propertiesName = properties.fieldNames();
final Map messageBody = new HashMap<>();
while (propertiesName.hasNext()) {
- var propertyName = propertiesName.next();
+ final var propertyName = propertiesName.next();
if (Objects.nonNull(properties.get(propertyName).get(BasicTypeConstants.REF))) {
- messageBody.put(propertyName, processSchemas(responseBodyMatchers, operationType, propertyName, properties, basePath, fileContent, propertyName + "."));
+ messageBody.put(propertyName, processSchemas(responseBodyMatchers, operationType, propertyName, properties, fileContent, propertyName + "."));
} else {
final ObjectNode propertiesToFill = BasicTypeConstants.OBJECT_MAPPER.createObjectNode();
propertiesToFill.set(propertyName, properties.get(propertyName));
- messageBody.putAll(fillObjectProperties(responseBodyMatchers, propertiesToFill, bodyMatcherPath, operationType, basePath, fileContent));
+ messageBody.putAll(fillObjectProperties(responseBodyMatchers, propertiesToFill, bodyMatcherPath, operationType, fileContent));
}
}
return messageBody;
}
private Map processExternalFile(
- final String externalFilePath, final String schemaPath, final ResponseBodyMatchers responseBodyMatchers, final String operationType, final File basePath,
- String bodyMatcherPath)
+ final String externalFilePath, final String schemaPath, final ResponseBodyMatchers responseBodyMatchers, final String operationType,
+ final String bodyMatcherPath)
throws IOException {
final Map messageBody = new HashMap<>();
final JsonNode schema;
final Path externalFile = composePath(basePath.toPath(), externalFilePath);
- var externalFileContent = BasicTypeConstants.OBJECT_MAPPER.readTree(externalFile.toFile());
+ final var externalFileContent = BasicTypeConstants.OBJECT_MAPPER.readTree(externalFile.toFile());
final String[] splitSchemaPath = schemaPath.split("/");
final var length = splitSchemaPath.length;
final String ref = splitSchemaPath[length - 1];
schema = externalFileContent.findPath(ref).get(BasicTypeConstants.PROPERTIES);
- var fieldNames = schema.fieldNames();
+ final var fieldNames = schema.fieldNames();
while (fieldNames.hasNext()) {
- var fieldName = fieldNames.next();
+ final var fieldName = fieldNames.next();
if (Objects.nonNull(schema.get(BasicTypeConstants.REF)) && schema.get(BasicTypeConstants.REF).asText().contains(".yml")) {
final String[] pathToRef = schema.get(BasicTypeConstants.REF).asText().split("#");
- messageBody.putAll(processExternalFile(pathToRef[0], pathToRef[1], responseBodyMatchers, operationType, basePath, bodyMatcherPath));
+ messageBody.putAll(processExternalFile(pathToRef[0], pathToRef[1], responseBodyMatchers, operationType, bodyMatcherPath));
} else if (Objects.nonNull(schema.get(fieldName).get(BasicTypeConstants.REF))) {
- var bodyMatcherPathObject = bodyMatcherPath + fieldName + ".";
- messageBody.put(fieldName, processSchemas(responseBodyMatchers, operationType, fieldName, schema, basePath, externalFileContent, bodyMatcherPathObject));
+ final var bodyMatcherPathObject = bodyMatcherPath + fieldName + ".";
+ messageBody.put(fieldName, processSchemas(responseBodyMatchers, operationType, fieldName, schema, externalFileContent, bodyMatcherPathObject));
} else {
final ObjectNode propertiesToFill = BasicTypeConstants.OBJECT_MAPPER.createObjectNode();
propertiesToFill.set(fieldName, schema.get(fieldName));
- messageBody.putAll(fillObjectProperties(responseBodyMatchers, propertiesToFill, bodyMatcherPath, operationType, basePath, externalFileContent));
+ messageBody.putAll(fillObjectProperties(responseBodyMatchers, propertiesToFill, bodyMatcherPath, operationType, externalFileContent));
}
}
return messageBody;
}
- private void checkIfReferenceWithProperties(final JsonNode jsonNode) {
- if (jsonNode.size() > 1 && Objects.nonNull(jsonNode.get(BasicTypeConstants.REF))) {
- throw new MultiApiContractConverterException("If reference exists no other additional properties are allowed");
- }
- }
-
private Path composePath(final Path basePath, final String uriComponent) {
Path finalFilePath = null;
if (uriComponent.startsWith(".")) {
@@ -255,112 +253,30 @@ private Path composePath(final Path basePath, final String uriComponent) {
return finalFilePath;
}
- private JsonNode subscribeOrPublishOperation(final JsonNode rootNode) {
- final JsonNode result;
-
- if (rootNode.has(BasicTypeConstants.SUBSCRIBE)) {
- result = rootNode.get(BasicTypeConstants.SUBSCRIBE);
- } else {
- result = rootNode.get(BasicTypeConstants.PUBLISH);
- }
- return result;
- }
-
private Map fillObjectProperties(
final ResponseBodyMatchers responseBodyMatchers, final JsonNode properties, final String rootProperty, final String operationType,
- final File basePath, final JsonNode fileContent)
- throws IOException {
- Iterator fieldNames = properties.fieldNames();
+ final JsonNode fileContent) throws IOException {
+
+ final Iterator fieldNames = properties.fieldNames();
final Map messageBody = new HashMap<>();
while (fieldNames.hasNext()) {
- var property = fieldNames.next();
- var path = rootProperty + property;
-
- if (!Objects.nonNull(properties.get(property).get(BasicTypeConstants.PROPERTIES)) ||
- !Objects.nonNull(properties.get(property).get(BasicTypeConstants.PROPERTIES).get(BasicTypeConstants.REF))) {
- String enumType = "";
- var type = getType(properties.get(property));
-
- if (isEnum(properties.get(property))) {
- enumType = type;
- type = BasicTypeConstants.ENUM;
- }
-
- switch (type) {
- case BasicTypeConstants.STRING:
- if (operationType.equals(BasicTypeConstants.SUBSCRIBE)) {
- messageBody.put(property, properties.get(property).get(BasicTypeConstants.EXAMPLE).asText());
- } else {
- responseBodyMatchers.jsonPath(path, responseBodyMatchers.byRegex(BasicTypeConstants.STRING_REGEX));
- messageBody.put(property, RandomStringUtils.random(5, true, false));
- }
- break;
- case BasicTypeConstants.INT_32:
- case BasicTypeConstants.NUMBER:
- if (operationType.equals(BasicTypeConstants.SUBSCRIBE)) {
- messageBody.put(property, properties.get(property).get(BasicTypeConstants.EXAMPLE).asInt());
- } else {
- responseBodyMatchers.jsonPath(path, responseBodyMatchers.byRegex(BasicTypeConstants.INT_REGEX));
- messageBody.put(property, BasicTypeConstants.RANDOM.nextInt());
- }
- break;
- case BasicTypeConstants.INT_64:
- case BasicTypeConstants.FLOAT:
- if (operationType.equals(BasicTypeConstants.SUBSCRIBE)) {
- messageBody.put(property, properties.get(property).get(BasicTypeConstants.EXAMPLE).asDouble());
- } else {
- responseBodyMatchers.jsonPath(path, responseBodyMatchers.byRegex(BasicTypeConstants.DECIMAL_REGEX));
- messageBody.put(property, Math.abs(BasicTypeConstants.RANDOM.nextFloat()));
- }
- break;
- case BasicTypeConstants.DOUBLE:
- if (operationType.equals(BasicTypeConstants.SUBSCRIBE)) {
- messageBody.put(property, properties.get(property).get(BasicTypeConstants.EXAMPLE).asDouble());
- } else {
- responseBodyMatchers.jsonPath(path, responseBodyMatchers.byRegex(BasicTypeConstants.DECIMAL_REGEX));
- messageBody.put(property, BasicTypeConstants.RANDOM.nextDouble());
- }
- break;
- case BasicTypeConstants.BOOLEAN:
- if (operationType.equals(BasicTypeConstants.SUBSCRIBE)) {
- messageBody.put(property, properties.get(property).get(BasicTypeConstants.EXAMPLE).asBoolean());
- } else {
- responseBodyMatchers.jsonPath(path, responseBodyMatchers.byRegex(BasicTypeConstants.BOOLEAN_REGEX));
- messageBody.put(property, BasicTypeConstants.RANDOM.nextBoolean());
- }
- break;
- case BasicTypeConstants.ENUM:
- if (operationType.equals(BasicTypeConstants.SUBSCRIBE)) {
- messageBody.put(property, processEnumTypes(properties.get(property).get(BasicTypeConstants.EXAMPLE), enumType));
- } else {
- var enumList = properties.get(property).get(BasicTypeConstants.ENUM);
- responseBodyMatchers.jsonPath(path, responseBodyMatchers.byRegex(getEnumRegex(enumType, properties, property)));
- messageBody.put(property, processEnumTypes(enumList.get(BasicTypeConstants.RANDOM.nextInt(enumList.size())), enumType));
- }
- break;
- case BasicTypeConstants.OBJECT:
- messageBody.put(property, fillObjectProperties(responseBodyMatchers, properties.get(property).get(BasicTypeConstants.PROPERTIES), path + ".", operationType,
- basePath, fileContent));
- break;
- case BasicTypeConstants.ARRAY:
- messageBody.put(property,
- processArray(responseBodyMatchers, property, properties.get(property).get("items"), path, operationType, fileContent, basePath));
- break;
- default:
- throw new ElementNotFoundException(BasicTypeConstants.TYPE);
- }
+ final var property = fieldNames.next();
+ final var path = rootProperty + property;
+ if (!Objects.nonNull(properties.get(property).get(BasicTypeConstants.PROPERTIES))
+ || !Objects.nonNull(properties.get(property).get(BasicTypeConstants.PROPERTIES).get(BasicTypeConstants.REF))) {
+ messageBody.putAll(processObjectProperties(responseBodyMatchers, properties, operationType, fileContent, property, path));
} else {
final var subProperties = properties.get(property).get(BasicTypeConstants.PROPERTIES);
if (subProperties.get(BasicTypeConstants.REF).asText().contains(".yml")) {
final String[] pathToRef = subProperties.get(BasicTypeConstants.REF).asText().split("#");
- messageBody.putAll(processExternalFile(pathToRef[0], pathToRef[1], responseBodyMatchers, operationType, basePath, path));
+ messageBody.putAll(processExternalFile(pathToRef[0], pathToRef[1], responseBodyMatchers, operationType, path));
} else {
final String[] pathToObject = subProperties.get(BasicTypeConstants.REF).asText().split("/");
final var body = pathToObject[pathToObject.length - 1];
final var schema = fileContent.findPath(body).get(BasicTypeConstants.PROPERTIES);
- messageBody.put(property, fillObjectProperties(responseBodyMatchers, schema, path + ".", operationType, basePath, fileContent));
+ messageBody.put(property, fillObjectProperties(responseBodyMatchers, schema, path + ".", operationType, fileContent));
}
}
}
@@ -368,262 +284,163 @@ private Map fillObjectProperties(
return messageBody;
}
- private List