You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by gr...@apache.org on 2020/10/14 15:30:26 UTC

[ofbiz-plugins] branch trunk updated: Improved: extract path parameters from declared path in rest.xml and add path parameters to OpenAPI(OFBIZ-11328)

This is an automated email from the ASF dual-hosted git repository.

grv pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/ofbiz-plugins.git


The following commit(s) were added to refs/heads/trunk by this push:
     new dd27ea5  Improved: extract path parameters from declared path in rest.xml and add path parameters to OpenAPI(OFBIZ-11328)
dd27ea5 is described below

commit dd27ea556c659a54974aca42591088d814a14f27
Author: Girish Vasmatkar <gi...@hotwaxsystems.com>
AuthorDate: Wed Oct 14 21:00:03 2020 +0530

    Improved: extract path parameters from declared path in rest.xml and add path parameters to OpenAPI(OFBIZ-11328)
---
 .../org/apache/ofbiz/ws/rs/openapi/OFBizOpenApiReader.java  | 13 +++++++++++++
 .../main/java/org/apache/ofbiz/ws/rs/util/RestApiUtil.java  |  2 +-
 2 files changed, 14 insertions(+), 1 deletion(-)

diff --git a/ofbiz-rest-impl/src/main/java/org/apache/ofbiz/ws/rs/openapi/OFBizOpenApiReader.java b/ofbiz-rest-impl/src/main/java/org/apache/ofbiz/ws/rs/openapi/OFBizOpenApiReader.java
index a993fb1..86f0269 100644
--- a/ofbiz-rest-impl/src/main/java/org/apache/ofbiz/ws/rs/openapi/OFBizOpenApiReader.java
+++ b/ofbiz-rest-impl/src/main/java/org/apache/ofbiz/ws/rs/openapi/OFBizOpenApiReader.java
@@ -33,6 +33,7 @@ import org.apache.ofbiz.base.util.UtilValidate;
 import org.apache.ofbiz.service.DispatchContext;
 import org.apache.ofbiz.service.GenericServiceException;
 import org.apache.ofbiz.service.LocalDispatcher;
+import org.apache.ofbiz.service.ModelParam;
 import org.apache.ofbiz.service.ModelService;
 import org.apache.ofbiz.webapp.WebAppUtil;
 import org.apache.ofbiz.ws.rs.core.OFBizApiConfig;
@@ -41,6 +42,7 @@ import org.apache.ofbiz.ws.rs.model.ModelApi;
 import org.apache.ofbiz.ws.rs.model.ModelOperation;
 import org.apache.ofbiz.ws.rs.model.ModelResource;
 import org.apache.ofbiz.ws.rs.util.OpenApiUtil;
+import org.apache.ofbiz.ws.rs.util.RestApiUtil;
 
 import io.swagger.v3.jaxrs2.Reader;
 import io.swagger.v3.oas.integration.api.OpenAPIConfiguration;
@@ -56,6 +58,7 @@ import io.swagger.v3.oas.models.media.Schema;
 import io.swagger.v3.oas.models.media.StringSchema;
 import io.swagger.v3.oas.models.parameters.HeaderParameter;
 import io.swagger.v3.oas.models.parameters.Parameter;
+import io.swagger.v3.oas.models.parameters.PathParameter;
 import io.swagger.v3.oas.models.parameters.QueryParameter;
 import io.swagger.v3.oas.models.parameters.RequestBody;
 import io.swagger.v3.oas.models.responses.ApiResponse;
@@ -148,6 +151,16 @@ public final class OFBizOpenApiReader extends Reader implements OpenApiReader {
                         operation.setRequestBody(request);
                         operation.addParametersItem(HEADER_CONTENT_TYPE_JSON);
                     }
+                    List<String> pathParams = RestApiUtil.getPathParameters(uri);
+                    for (String pathParam : pathParams) {
+                        ModelParam mdParam = service.getInModelParamList().stream()
+                                .filter(param -> (!param.getInternal() && pathParam.equals(param.getName())))
+                                .findFirst().orElse(null);
+                        final PathParameter pathParameter = (PathParameter) new PathParameter().required(true)
+                                .description(mdParam != null ? mdParam.getShortDisplayDescription() : "")
+                                .name(pathParam);
+                        operation.addParametersItem(pathParameter);
+                    }
                     addServiceOutSchema(service);
                     addServiceInSchema(service);
                     addServiceOperationApiResponses(service, operation);
diff --git a/ofbiz-rest-impl/src/main/java/org/apache/ofbiz/ws/rs/util/RestApiUtil.java b/ofbiz-rest-impl/src/main/java/org/apache/ofbiz/ws/rs/util/RestApiUtil.java
index 3cce43c..fb7edba 100644
--- a/ofbiz-rest-impl/src/main/java/org/apache/ofbiz/ws/rs/util/RestApiUtil.java
+++ b/ofbiz-rest-impl/src/main/java/org/apache/ofbiz/ws/rs/util/RestApiUtil.java
@@ -84,7 +84,7 @@ public final class RestApiUtil {
         String[] pathParts = pathInfo.split("/");
         for (String pathSegement : pathParts) {
             if (pathSegement.startsWith("{") && pathSegement.endsWith("}")) {
-                pathParams.add(pathSegement);
+                pathParams.add(pathSegement.substring(1, pathSegement.length() - 1));
             }
         }
         return pathParams;