Skip to content

Commit

Permalink
Refactor updateOpenAPIInfoModel function
Browse files Browse the repository at this point in the history
  • Loading branch information
lnash94 committed Jun 12, 2024
1 parent d1287ca commit 2ad40e2
Showing 1 changed file with 27 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -288,33 +288,33 @@ private static OASResult updateExistingContractOpenAPI(List<OpenAPIMapperDiagnos

private static OpenAPIInfo updateOpenAPIInfoModel(SeparatedNodeList<MappingFieldNode> fields) {
OpenAPIInfo.OpenAPIInfoBuilder infoBuilder = new OpenAPIInfo.OpenAPIInfoBuilder();
for (MappingFieldNode field: fields) {
String fieldName = ((SpecificFieldNode) field).fieldName().toString().trim();
Optional<ExpressionNode> value = ((SpecificFieldNode) field).valueExpr();
String fieldValue;
if (value.isPresent()) {
ExpressionNode expressionNode = value.get();
if (!expressionNode.toString().trim().isBlank()) {
fieldValue = expressionNode.toString().trim().replaceAll("\"", "");
if (!fieldValue.isBlank()) {
switch (fieldName) {
case CONTRACT -> infoBuilder.contractPath(fieldValue);
case TITLE -> infoBuilder.title(fieldValue);
case VERSION -> infoBuilder.version(fieldValue);
case EMAIL -> infoBuilder.email(fieldValue);
case DESCRIPTION -> infoBuilder.description(fieldValue);
case CONTACT_NAME -> infoBuilder.contactName(fieldValue);
case CONTACT_URL -> infoBuilder.contactURL(fieldValue);
case TERMS_OF_SERVICE -> infoBuilder.termsOfService(fieldValue);
case LICENSE_NAME -> infoBuilder.licenseName(fieldValue);
case LICENSE_URL -> infoBuilder.licenseURL(fieldValue);
default -> {
}
}
}
}
}
}
fields.stream()
.filter(field -> field instanceof SpecificFieldNode)
.map(field -> (SpecificFieldNode) field)
.forEach(field -> {
String fieldName = field.fieldName().toString().trim();
Optional<ExpressionNode> valueOpt = field.valueExpr();
valueOpt.map(ExpressionNode::toString)
.map(String::trim)
.filter(fieldValue -> !fieldValue.isBlank())
.map(fieldValue -> fieldValue.replaceAll("\"", ""))
.ifPresent(fieldValue -> {
switch (fieldName) {
case CONTRACT -> infoBuilder.contractPath(fieldValue);
case TITLE -> infoBuilder.title(fieldValue);
case VERSION -> infoBuilder.version(fieldValue);
case EMAIL -> infoBuilder.email(fieldValue);
case DESCRIPTION -> infoBuilder.description(fieldValue);
case CONTACT_NAME -> infoBuilder.contactName(fieldValue);
case CONTACT_URL -> infoBuilder.contactURL(fieldValue);
case TERMS_OF_SERVICE -> infoBuilder.termsOfService(fieldValue);
case LICENSE_NAME -> infoBuilder.licenseName(fieldValue);
case LICENSE_URL -> infoBuilder.licenseURL(fieldValue);
default -> { }
}
});
});

return infoBuilder.build();
}

Expand Down

0 comments on commit 2ad40e2

Please sign in to comment.