You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by mb...@apache.org on 2021/12/01 17:01:24 UTC

[ofbiz-plugins] branch trunk updated: Fixed: REST-API Plugin: Remove errors and warnings in generated openapi documentation (OFBIZ-12426)

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

mbrohl 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 421e0e7  Fixed: REST-API Plugin: Remove errors and warnings in generated openapi documentation (OFBIZ-12426)
421e0e7 is described below

commit 421e0e7994ad5e69e6a60cb75a3c8715f0891c26
Author: Michael Brohl <mi...@ecomify.de>
AuthorDate: Wed Dec 1 17:42:05 2021 +0100

    Fixed: REST-API Plugin: Remove errors and warnings in generated openapi
    documentation (OFBIZ-12426)
    
    This fixes the following errors and warnings which are displayed by the
    Swagger Editor (editor.swagger.io) when reading the generated openapi
    documentation:
    
    Errors fixed
    * "Header parameters named "Authorization" are ignored. Use the
    `securitySchemes` and `security` sections instead to define
    authorization."
    * "Structural error at paths./....parameters.0 should have either a
    `schema` or `content` property"
    the generated parameters from the service definition now have schema
    entries generated
    * the same applies to the WWW-Authenticate header in the responses
    
    Warnings fixed
    
    * "Header parameters named "Accept" are ignored. The values for the
    "Accept" header are defined by `responses.<code>.content.<media-type>`."
---
 .../java/org/apache/ofbiz/ws/rs/openapi/OFBizOpenApiReader.java   | 4 ++--
 .../src/main/java/org/apache/ofbiz/ws/rs/util/OpenApiUtil.java    | 8 +++++---
 2 files changed, 7 insertions(+), 5 deletions(-)

diff --git a/rest-api/src/main/java/org/apache/ofbiz/ws/rs/openapi/OFBizOpenApiReader.java b/rest-api/src/main/java/org/apache/ofbiz/ws/rs/openapi/OFBizOpenApiReader.java
index 86f0269..df77b94 100644
--- a/rest-api/src/main/java/org/apache/ofbiz/ws/rs/openapi/OFBizOpenApiReader.java
+++ b/rest-api/src/main/java/org/apache/ofbiz/ws/rs/openapi/OFBizOpenApiReader.java
@@ -141,7 +141,6 @@ public final class OFBizOpenApiReader extends Reader implements OpenApiReader {
                         serviceInParam.content(new Content().addMediaType(javax.ws.rs.core.MediaType.APPLICATION_JSON,
                                 new MediaType().schema(refSchema)));
                         operation.addParametersItem(serviceInParam);
-                        operation.addParametersItem(HEADER_ACCEPT_JSON);
                     } else if (verb.matches(HttpMethod.POST + "|" + HttpMethod.PUT + "|" + HttpMethod.PATCH)) {
                         RequestBody request = new RequestBody()
                                 .description("Request Body for operation " + op.getDescription())
@@ -158,7 +157,8 @@ public final class OFBizOpenApiReader extends Reader implements OpenApiReader {
                                 .findFirst().orElse(null);
                         final PathParameter pathParameter = (PathParameter) new PathParameter().required(true)
                                 .description(mdParam != null ? mdParam.getShortDisplayDescription() : "")
-                                .name(pathParam);
+                                .name(pathParam)
+                                .schema(OpenApiUtil.getAttributeSchema(service, mdParam));
                         operation.addParametersItem(pathParameter);
                     }
                     addServiceOutSchema(service);
diff --git a/rest-api/src/main/java/org/apache/ofbiz/ws/rs/util/OpenApiUtil.java b/rest-api/src/main/java/org/apache/ofbiz/ws/rs/util/OpenApiUtil.java
index a486786..96d7d3c 100644
--- a/rest-api/src/main/java/org/apache/ofbiz/ws/rs/util/OpenApiUtil.java
+++ b/rest-api/src/main/java/org/apache/ofbiz/ws/rs/util/OpenApiUtil.java
@@ -160,7 +160,7 @@ public final class OpenApiUtil {
     private static void buildApiResponseSchemas() {
         Schema<?> genericErrorSchema = new MapSchema().addProperties("statusCode", new IntegerSchema().description("HTTP Status Code"))
                  .addProperties("statusDescription", new StringSchema().description("HTTP Status Code Description"))
-                 .addProperties("errorTyoe", new StringSchema().description("Error Type for the error"))
+                 .addProperties("errorType", new StringSchema().description("Error Type for the error"))
                  .addProperties("errorMessage", new StringSchema().description("Error Message"));
         SCHEMAS.put("api.response.unauthorized.noheader", genericErrorSchema);
         SCHEMAS.put("api.response.unauthorized.invalidtoken", genericErrorSchema);
@@ -203,7 +203,7 @@ public final class OpenApiUtil {
                 "errorMessage", "HTTP POST is not allowed on service 'demoDoGetService'.");
 
         final ApiResponse unauthorizedNoHeader = new ApiResponse().addHeaderObject(HttpHeaders.WWW_AUTHENTICATE, new Header()
-                .example(HttpHeaders.WWW_AUTHENTICATE + ": "
+                .schema(new Schema<>().type("string").format("string")).example(HttpHeaders.WWW_AUTHENTICATE + ": "
                  + AuthenticationScheme.BEARER.getScheme() + " realm=\"" + AuthenticationScheme.REALM + "\""))
                 .description("Unauthorized: Access is denied due to invalid or absent Authorization header.")
                 .content(new Content()
@@ -221,6 +221,7 @@ public final class OpenApiUtil {
                                 .example(unauthorizedInvalidTokenExample)));
 
         final ApiResponse forbidden = new ApiResponse().addHeaderObject(HttpHeaders.WWW_AUTHENTICATE, new Header()
+                .schema(new Schema<>().type("string"))
                 .example(HttpHeaders.WWW_AUTHENTICATE + ": "
                 + AuthenticationScheme.BEARER.getScheme() + " realm=\"" + AuthenticationScheme.REALM + "\""))
                 .description("Forbidden: Insufficient rights to perform this API call.")
@@ -244,6 +245,7 @@ public final class OpenApiUtil {
                                 .schema(new Schema<>()
                                         .$ref("#/components/schemas/" + "api.response.service.unprocessableentity"))
                                 .example(unprocessableEntExample)));
+        
         final ApiResponse methodNotAllowed = new ApiResponse()
                 .description("Method Not Allowed: Service called with HTTP method other than the declared one.")
                 .content(new Content()
@@ -287,7 +289,7 @@ public final class OpenApiUtil {
         return parentSchema;
     }
 
-    private static Schema<?> getAttributeSchema(ModelService service, ModelParam param) {
+    public static Schema<?> getAttributeSchema(ModelService service, ModelParam param) {
         Schema<?> schema = null;
         Class<?> schemaClass = getOpenApiTypeForAttributeType(param.getType());
         if (schemaClass == null) {