Skip to content

Commit

Permalink
Fix review suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
lnash94 committed Jun 13, 2024
1 parent 2ad40e2 commit 08a0613
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -288,33 +288,34 @@ private static OASResult updateExistingContractOpenAPI(List<OpenAPIMapperDiagnos

private static OpenAPIInfo updateOpenAPIInfoModel(SeparatedNodeList<MappingFieldNode> fields) {
OpenAPIInfo.OpenAPIInfoBuilder infoBuilder = new OpenAPIInfo.OpenAPIInfoBuilder();
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 -> { }
}
});
});

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()) {
continue;
}
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
2 changes: 1 addition & 1 deletion module-ballerina-openapi/CompilerPlugin.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ id = "openapi-tools"
class = "io.ballerina.openapi.validator.OpenAPIValidatorPlugin"

[[dependency]]
path = "../openapi-validator/build/libs/openapi-validator-2.0.1-@project.version@"
path = "../openapi-validator/build/libs/[email protected]@"
groupId = "ballerina"
artifactId = "openapi"
version = "@project.version@"
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,7 @@ public void nonOpenAPIAnnotationWithWithoutBasePath() throws IOException, Interr
"project_non_openapi_annotation_without_base_path/result.yaml");
}

//TODO enable after resolving dependency issue
@Test(description = "Service is with openapi annotation include all oas infor section details", enabled = false)
@Test(description = "Service is with openapi annotation include all oas infor section details")
public void openAPInForSectionTest() throws IOException, InterruptedException {
executeCommand("project_openapi_info/service_file.bal", "info_openapi.yaml",
"project_openapi_info/result.yaml");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[package]
org= "ballerina"
name= "openapi"
name= "openapi_test"
version= "2.0.0"
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ info:
url: http://abc.com
version: 1.0.0
servers:
- url: "{server}:{port}/v1"
- url: "{server}:{port}/info"
variables:
server:
default: http://localhost
Expand Down

0 comments on commit 08a0613

Please sign in to comment.