From 08a06136492630c24e60a8eab5661304fb773e77 Mon Sep 17 00:00:00 2001 From: lnash94 Date: Wed, 12 Jun 2024 13:34:44 +0530 Subject: [PATCH] Fix review suggestions --- .../openapi/service/mapper/InfoMapper.java | 55 ++++++++++--------- module-ballerina-openapi/CompilerPlugin.toml | 2 +- .../openapi/cmd/BallerinaToOpenAPITests.java | 3 +- .../project_openapi_info/Ballerina.toml | 2 +- .../project_openapi_info/result.yaml | 2 +- 5 files changed, 32 insertions(+), 32 deletions(-) diff --git a/ballerina-to-openapi/src/main/java/io/ballerina/openapi/service/mapper/InfoMapper.java b/ballerina-to-openapi/src/main/java/io/ballerina/openapi/service/mapper/InfoMapper.java index d20650daa..ef2b91e2f 100644 --- a/ballerina-to-openapi/src/main/java/io/ballerina/openapi/service/mapper/InfoMapper.java +++ b/ballerina-to-openapi/src/main/java/io/ballerina/openapi/service/mapper/InfoMapper.java @@ -288,33 +288,34 @@ private static OASResult updateExistingContractOpenAPI(List 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 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 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(); } diff --git a/module-ballerina-openapi/CompilerPlugin.toml b/module-ballerina-openapi/CompilerPlugin.toml index 0a8b0e59b..2241d919b 100644 --- a/module-ballerina-openapi/CompilerPlugin.toml +++ b/module-ballerina-openapi/CompilerPlugin.toml @@ -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/openapi-validator-@project.version@" groupId = "ballerina" artifactId = "openapi" version = "@project.version@" diff --git a/openapi-integration-tests/src/test/java/io/ballerina/openapi/cmd/BallerinaToOpenAPITests.java b/openapi-integration-tests/src/test/java/io/ballerina/openapi/cmd/BallerinaToOpenAPITests.java index 9ac4aa7b3..37d0e6006 100644 --- a/openapi-integration-tests/src/test/java/io/ballerina/openapi/cmd/BallerinaToOpenAPITests.java +++ b/openapi-integration-tests/src/test/java/io/ballerina/openapi/cmd/BallerinaToOpenAPITests.java @@ -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"); diff --git a/openapi-integration-tests/src/test/resources/ballerina_sources/project_openapi_info/Ballerina.toml b/openapi-integration-tests/src/test/resources/ballerina_sources/project_openapi_info/Ballerina.toml index d3cc51d4b..a50ec9b4b 100644 --- a/openapi-integration-tests/src/test/resources/ballerina_sources/project_openapi_info/Ballerina.toml +++ b/openapi-integration-tests/src/test/resources/ballerina_sources/project_openapi_info/Ballerina.toml @@ -1,4 +1,4 @@ [package] org= "ballerina" -name= "openapi" +name= "openapi_test" version= "2.0.0" diff --git a/openapi-integration-tests/src/test/resources/ballerina_sources/project_openapi_info/result.yaml b/openapi-integration-tests/src/test/resources/ballerina_sources/project_openapi_info/result.yaml index 17ba74356..d3c971c10 100644 --- a/openapi-integration-tests/src/test/resources/ballerina_sources/project_openapi_info/result.yaml +++ b/openapi-integration-tests/src/test/resources/ballerina_sources/project_openapi_info/result.yaml @@ -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