cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject [cxf] branch 3.1.x-fixes updated: Updating 3.1.x SwaggerToOpenApi filter to support Swagger 1.5.17 and newer
Date Wed, 27 Dec 2017 13:17:27 GMT
This is an automated email from the ASF dual-hosted git repository.

sergeyb pushed a commit to branch 3.1.x-fixes
in repository https://gitbox.apache.org/repos/asf/cxf.git


The following commit(s) were added to refs/heads/3.1.x-fixes by this push:
     new 749c2d7  Updating 3.1.x SwaggerToOpenApi filter to support Swagger 1.5.17 and newer
749c2d7 is described below

commit 749c2d740699f19892a70b887ed8504639452f85
Author: Sergey Beryozkin <sberyozkin@gmail.com>
AuthorDate: Wed Dec 27 13:17:01 2017 +0000

    Updating 3.1.x SwaggerToOpenApi filter to support Swagger 1.5.17 and newer
---
 .../openapi/SwaggerToOpenApiConversionFilter.java  | 22 ++++++++++++++++++++--
 1 file changed, 20 insertions(+), 2 deletions(-)

diff --git a/rt/rs/description-swagger/src/main/java/org/apache/cxf/jaxrs/swagger/openapi/SwaggerToOpenApiConversionFilter.java
b/rt/rs/description-swagger/src/main/java/org/apache/cxf/jaxrs/swagger/openapi/SwaggerToOpenApiConversionFilter.java
index ccda81a..f2b1446 100644
--- a/rt/rs/description-swagger/src/main/java/org/apache/cxf/jaxrs/swagger/openapi/SwaggerToOpenApiConversionFilter.java
+++ b/rt/rs/description-swagger/src/main/java/org/apache/cxf/jaxrs/swagger/openapi/SwaggerToOpenApiConversionFilter.java
@@ -25,6 +25,8 @@ import java.net.URI;
 import javax.ws.rs.WebApplicationException;
 import javax.ws.rs.container.ContainerRequestContext;
 import javax.ws.rs.container.ContainerRequestFilter;
+import javax.ws.rs.container.ContainerResponseContext;
+import javax.ws.rs.container.ContainerResponseFilter;
 import javax.ws.rs.container.PreMatching;
 import javax.ws.rs.ext.Provider;
 import javax.ws.rs.ext.WriterInterceptor;
@@ -37,7 +39,8 @@ import org.apache.cxf.jaxrs.utils.JAXRSUtils;
 
 @Provider
 @PreMatching
-public final class SwaggerToOpenApiConversionFilter implements ContainerRequestFilter, WriterInterceptor
{
+public final class SwaggerToOpenApiConversionFilter implements ContainerRequestFilter,
+    ContainerResponseFilter, WriterInterceptor {
 
     private static final String SWAGGER_PATH = "swagger.json";
     private static final String OPEN_API_PATH = "openapi.json";
@@ -64,7 +67,7 @@ public final class SwaggerToOpenApiConversionFilter implements ContainerRequestF
 
     @Override
     public void aroundWriteTo(WriterInterceptorContext context) throws IOException, WebApplicationException
{
-        if (Boolean.TRUE == JAXRSUtils.getCurrentMessage().getExchange().get(OPEN_API_PROPERTY))
{
+        if (isOpenApiRequested() && !(context.getEntity() instanceof String)) {
             OutputStream os = context.getOutputStream();
             CachedOutputStream cos = new CachedOutputStream();
             context.setOutputStream(cos);
@@ -76,4 +79,19 @@ public final class SwaggerToOpenApiConversionFilter implements ContainerRequestF
             
         }
     }
+
+    private boolean isOpenApiRequested() {
+        return Boolean.TRUE == JAXRSUtils.getCurrentMessage().getExchange().get(OPEN_API_PROPERTY);
+    }
+
+    @Override
+    public void filter(ContainerRequestContext requestContext, ContainerResponseContext responseContext)
+        throws IOException {
+        if (isOpenApiRequested() && responseContext.getEntity() instanceof String)
{
+            String swaggerJson = (String)responseContext.getEntity();
+            String openApiJson = SwaggerToOpenApiConversionUtils.getOpenApiFromSwaggerJson(swaggerJson,
openApiConfig);
+            responseContext.setEntity(openApiJson);
+        }
+        
+    }
 }

-- 
To stop receiving notification emails like this one, please contact
['"commits@cxf.apache.org" <commits@cxf.apache.org>'].

Mime
View raw message