[ofbiz-plugins] branch trunk updated: Improved: Structural changes in the OpenAPI reader to allow for reading resources defined in XML schema(OFBIZ-11995)

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

[ofbiz-plugins] branch trunk updated: Improved: Structural changes in the OpenAPI reader to allow for reading resources defined in XML schema(OFBIZ-11995)

grv-2
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 dabca1e  Improved: Structural changes in the OpenAPI reader to allow for reading resources defined in XML schema(OFBIZ-11995)
dabca1e is described below

commit dabca1e416cb129d51e76cc90f0847674547f5f9
Author: Girish Vasmatkar <[hidden email]>
AuthorDate: Tue Sep 15 16:58:55 2020 +0530

    Improved: Structural changes in the OpenAPI reader to allow for reading resources defined in XML schema(OFBIZ-11995)
---
 .../ofbiz/ws/rs/openapi/OFBizOpenApiReader.java    | 68 +++++++++++++---------
 1 file changed, 39 insertions(+), 29 deletions(-)

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 afb9b15..95a50bf 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
@@ -63,6 +63,7 @@ public final class OFBizOpenApiReader extends Reader implements OpenApiReader {
     @SuppressWarnings("rawtypes")
     private Map<String, Schema> schemas;
     private OpenAPI openApi;
+    private DispatchContext context;
 
     public OFBizOpenApiReader() {
         openApiTags = new LinkedHashSet<>();
@@ -76,34 +77,24 @@ public final class OFBizOpenApiReader extends Reader implements OpenApiReader {
     @Override
     public OpenAPI read(Set<Class<?>> classes, Map<String, Object> resources) {
         openApi = super.read(classes, resources);
-        if (openApi.getTags() != null) {
-            openApiTags.addAll(openApi.getTags());
-        }
-
-        Tag serviceResourceTag = new Tag().name("Exported Services")
-                .description("OFBiz services that are exposed via REST interface with export attribute set to true");
-        openApiTags.add(serviceResourceTag);
-        openApi.setTags(new ArrayList<Tag>(openApiTags));
-        components = openApi.getComponents();
-
-        if (components == null) {
-            components = new Components();
-        }
-        schemas = components.getSchemas();
-        if (schemas == null) {
-            schemas = new HashMap<>();
-            components.schemas(schemas);
-        }
-        paths = openApi.getPaths();
-        if (paths == null) {
-            paths = new Paths();
-        }
-        addPredefinedSchemas();
         ServletContext servletContext = ApiContextListener.getApplicationCntx();
         LocalDispatcher dispatcher = WebAppUtil.getDispatcher(servletContext);
-        DispatchContext context = dispatcher.getDispatchContext();
-        Set<String> serviceNames = context.getAllServiceNames();
+        context = dispatcher.getDispatchContext();
+        initializeStdOpenApiComponents();
+        addPredefinedSchemas();
+        addExportableServices();
+        addApiResources();
+        openApi.setPaths(paths);
+        openApi.setComponents(components);
+        return openApi;
+    }
 
+    //TODO - Add method contents
+    private void addApiResources() {
+    }
+
+    private void addExportableServices() {
+        Set<String> serviceNames = context.getAllServiceNames();
         for (String serviceName : serviceNames) {
             ModelService service = null;
             try {
@@ -139,13 +130,32 @@ public final class OFBizOpenApiReader extends Reader implements OpenApiReader {
                 addServiceOperationApiResponses(service, operation);
                 setPathItemOperation(pathItemObject, service.getAction().toUpperCase(), operation);
                 paths.addPathItem("/services/" + service.getName(), pathItemObject);
-
             }
         }
+    }
+    private void initializeStdOpenApiComponents() {
+        if (openApi.getTags() != null) {
+            openApiTags.addAll(openApi.getTags());
+        }
 
-        openApi.setPaths(paths);
-        openApi.setComponents(components);
-        return openApi;
+        Tag serviceResourceTag = new Tag().name("Exported Services")
+                .description("OFBiz services that are exposed via REST interface with export attribute set to true");
+        openApiTags.add(serviceResourceTag);
+        openApi.setTags(new ArrayList<Tag>(openApiTags));
+        components = openApi.getComponents();
+
+        if (components == null) {
+            components = new Components();
+        }
+        schemas = components.getSchemas();
+        if (schemas == null) {
+            schemas = new HashMap<>();
+            components.schemas(schemas);
+        }
+        paths = openApi.getPaths();
+        if (paths == null) {
+            paths = new Paths();
+        }
     }
 
     private void setPathItemOperation(PathItem pathItemObject, String method, Operation operation) {