You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@syncope.apache.org by il...@apache.org on 2019/10/31 15:00:49 UTC

[syncope] branch 2_1_X updated: Fixing error sample payload with OpenAPI

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

ilgrosso pushed a commit to branch 2_1_X
in repository https://gitbox.apache.org/repos/asf/syncope.git


The following commit(s) were added to refs/heads/2_1_X by this push:
     new e824fca  Fixing error sample payload with OpenAPI
e824fca is described below

commit e824fca0552948a3de8b1f1ca8a7a7e0907b9aa8
Author: Francesco Chicchiriccò <il...@apache.org>
AuthorDate: Thu Oct 31 15:59:32 2019 +0100

    Fixing error sample payload with OpenAPI
---
 .../syncope/core/rest/cxf/SyncopeOpenApiCustomizer.java   | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/core/rest-cxf/src/main/java/org/apache/syncope/core/rest/cxf/SyncopeOpenApiCustomizer.java b/core/rest-cxf/src/main/java/org/apache/syncope/core/rest/cxf/SyncopeOpenApiCustomizer.java
index 2676521..bf37246 100644
--- a/core/rest-cxf/src/main/java/org/apache/syncope/core/rest/cxf/SyncopeOpenApiCustomizer.java
+++ b/core/rest-cxf/src/main/java/org/apache/syncope/core/rest/cxf/SyncopeOpenApiCustomizer.java
@@ -36,6 +36,7 @@ import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.Optional;
+import javax.ws.rs.core.Response;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.cxf.jaxrs.ext.MessageContext;
 import org.apache.cxf.jaxrs.model.OperationResourceInfo;
@@ -44,6 +45,7 @@ import org.apache.cxf.jaxrs.openapi.OpenApiCustomizer;
 import org.apache.cxf.jaxrs.utils.JAXRSUtils;
 import org.apache.syncope.common.lib.SyncopeConstants;
 import org.apache.syncope.common.lib.to.ErrorTO;
+import org.apache.syncope.common.lib.types.ClientExceptionType;
 import org.apache.syncope.common.rest.api.RESTHeaders;
 import org.apache.syncope.core.persistence.api.DomainsHolder;
 import org.apache.syncope.core.spring.ApplicationContextProvider;
@@ -127,13 +129,20 @@ public class SyncopeOpenApiCustomizer extends OpenApiCustomizer {
                 RESTHeaders.ERROR_INFO,
                 new Header().schema(new Schema<>().type("string")).description("Error message"));
 
+        ErrorTO sampleError = new ErrorTO();
+        sampleError.setStatus(Response.Status.BAD_REQUEST.getStatusCode());
+        sampleError.setType(ClientExceptionType.InvalidEntity);
+        sampleError.getElements().add("additional information");
         Content content = new Content();
         content.addMediaType(
-                javax.ws.rs.core.MediaType.APPLICATION_JSON, new MediaType().schema(new Schema<ErrorTO>()));
+                javax.ws.rs.core.MediaType.APPLICATION_JSON,
+                new MediaType().schema(new Schema<ErrorTO>().example(sampleError)));
         content.addMediaType(
-                RESTHeaders.APPLICATION_YAML, new MediaType().schema(new Schema<ErrorTO>()));
+                RESTHeaders.APPLICATION_YAML,
+                new MediaType().schema(new Schema<ErrorTO>().example(sampleError)));
         content.addMediaType(
-                javax.ws.rs.core.MediaType.APPLICATION_XML, new MediaType().schema(new Schema<ErrorTO>()));
+                javax.ws.rs.core.MediaType.APPLICATION_XML,
+                new MediaType().schema(new Schema<ErrorTO>().example(sampleError)));
 
         responses.addApiResponse("400", new ApiResponse().
                 description("An error occurred; HTTP status code can vary depending on the actual error: "