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 c092a57 Improved: Service required parameters now show as required in OpenAPI schema as required (OFBIZ-11328) c092a57 is described below commit c092a5714fc32c6cdf94be5206318cf9e6be6ea0 Author: Girish Vasmatkar <[hidden email]> AuthorDate: Mon Oct 12 12:25:54 2020 +0530 Improved: Service required parameters now show as required in OpenAPI schema as required (OFBIZ-11328) --- .../org/apache/ofbiz/ws/rs/openapi/OFBizOpenApiReader.java | 2 +- .../main/java/org/apache/ofbiz/ws/rs/util/OpenApiUtil.java | 14 ++++++++++++-- 2 files changed, 13 insertions(+), 3 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 bec8286..0287645 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 @@ -175,7 +175,7 @@ public final class OFBizOpenApiReader extends Reader implements OpenApiReader { PathItem pathItemObject = new PathItem(); if (service.getAction().equalsIgnoreCase(HttpMethod.GET)) { final QueryParameter serviceInParam = (QueryParameter) new QueryParameter() - .required(UtilValidate.isNotEmpty(service.getInParamNamesMap()) ? true: false) + .required(UtilValidate.isNotEmpty(service.getInParamNamesMap()) ? true : false) .description("Service In Parameters in JSON").name("inParams"); Schema<?> refSchema = new Schema<>(); refSchema.$ref("#/components/schemas/" + "api.request." + service.getName()); diff --git a/ofbiz-rest-impl/src/main/java/org/apache/ofbiz/ws/rs/util/OpenApiUtil.java b/ofbiz-rest-impl/src/main/java/org/apache/ofbiz/ws/rs/util/OpenApiUtil.java index ebf50b0..a486786 100644 --- a/ofbiz-rest-impl/src/main/java/org/apache/ofbiz/ws/rs/util/OpenApiUtil.java +++ b/ofbiz-rest-impl/src/main/java/org/apache/ofbiz/ws/rs/util/OpenApiUtil.java @@ -272,12 +272,18 @@ public final class OpenApiUtil { Schema<Object> parentSchema = new Schema<Object>(); parentSchema.setDescription("In Schema for service: " + service.getName() + " request"); parentSchema.setType("object"); + List<String> required = UtilMisc.toList(); service.getInParamNamesMap().forEach((name, type) -> { - Schema<?> attrSchema = getAttributeSchema(service, service.getParam(name)); + ModelParam param = service.getParam(name); + if (!param.isOptional()) { + required.add(name); + } + Schema<?> attrSchema = getAttributeSchema(service, param); if (attrSchema != null) { parentSchema.addProperties(name, getAttributeSchema(service, service.getParam(name))); } }); + parentSchema.setRequired(required); return parentSchema; } @@ -318,10 +324,14 @@ public final class OpenApiUtil { MODULE); return null; } else { + List<String> required = UtilMisc.toList(); for (ModelParam childParam : children) { + if (!param.isOptional()) { + required.add(childParam.getName()); + } schema.addProperties(childParam.getName(), getAttributeSchema(service, childParam)); } - + schema.setRequired(required); } } |
Free forum by Nabble | Edit this page |