cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From r...@apache.org
Subject [cxf] branch master updated: CXF-8046: Resource Listing in CXF 3.3.x does not recognize OpenAPI endpoints
Date Wed, 22 May 2019 21:17:40 GMT
This is an automated email from the ASF dual-hosted git repository.

reta pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/cxf.git


The following commit(s) were added to refs/heads/master by this push:
     new 85b7563  CXF-8046: Resource Listing in CXF 3.3.x does not recognize OpenAPI endpoints
85b7563 is described below

commit 85b75632f62ea5cabdb4909f2ec4844b6bd4389c
Author: reta <drreta@gmail.com>
AuthorDate: Wed May 22 17:17:15 2019 -0400

    CXF-8046: Resource Listing in CXF 3.3.x does not recognize OpenAPI endpoints
---
 .../apache/cxf/jaxrs/openapi/OpenApiFeature.java   |  2 +
 .../servicelist/FormattedServiceListWriter.java    | 53 +++++++++++++++-------
 .../servicelist/UnformattedServiceListWriter.java  |  6 ++-
 3 files changed, 43 insertions(+), 18 deletions(-)

diff --git a/rt/rs/description-openapi-v3/src/main/java/org/apache/cxf/jaxrs/openapi/OpenApiFeature.java
b/rt/rs/description-openapi-v3/src/main/java/org/apache/cxf/jaxrs/openapi/OpenApiFeature.java
index c774b40..2d8f606 100644
--- a/rt/rs/description-openapi-v3/src/main/java/org/apache/cxf/jaxrs/openapi/OpenApiFeature.java
+++ b/rt/rs/description-openapi-v3/src/main/java/org/apache/cxf/jaxrs/openapi/OpenApiFeature.java
@@ -182,6 +182,8 @@ public class OpenApiFeature extends AbstractFeature implements SwaggerUiSupport,
             if (customizer != null) {
                 customizer.setApplicationInfo(factory.getApplicationProvider());
             }
+            
+            bus.setProperty("openapi.service.description.available", "true");
         } catch (OpenApiConfigurationException ex) {
             throw new RuntimeException("Unable to initialize OpenAPI context", ex);
         }
diff --git a/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/servicelist/FormattedServiceListWriter.java
b/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/servicelist/FormattedServiceListWriter.java
index 04fe879..efadf8b 100644
--- a/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/servicelist/FormattedServiceListWriter.java
+++ b/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/servicelist/FormattedServiceListWriter.java
@@ -179,30 +179,49 @@ public class FormattedServiceListWriter implements ServiceListWriter
{
             sb = ((AbstractHTTPDestination)sd).getBus();
         }        
         
+        addWadlIfNeeded(absoluteURL, sb, writer);
+        addOpenApiIfNeeded(absoluteURL, sb, writer);
+        addSwaggerIfNeeded(absoluteURL, sb, writer);
+        addAtomLinkIfNeeded(absoluteURL, atomMap, writer);
+        writer.write("</td></tr>");
+    }
+
+    private static void addWadlIfNeeded(String absoluteURL, Bus sb, PrintWriter writer) {
         if (sb != null && PropertyUtils.isTrue(sb.getProperty("wadl.service.description.available")))
{
             writer.write("<br/><span class=\"field\">WADL :</span> " +
"<a href=\"" + absoluteURL
                      + "?_wadl\">" + absoluteURL + "?_wadl" + "</a>");
         }
+    }
+
+    private static void addSwaggerIfNeeded(String absoluteURL, Bus sb, PrintWriter writer)
{
         if (sb != null && PropertyUtils.isTrue(sb.getProperty("swagger.service.description.available")))
{
-            String swaggerPath = "swagger.json";
-            if (PropertyUtils.isTrue(sb.getProperty("swagger.service.ui.available"))) {
-                URI uri = URI.create(absoluteURL);
-                String schemePath = uri.getScheme() + "://" + uri.getHost()
-                    + (uri.getPort() == -1 ? "" : ":" + uri.getPort());
-                String relPath = absoluteURL.substring(schemePath.length());
-                if (!relPath.endsWith("/")) {
-                    relPath += "/";
-                }
-                swaggerPath = "api-docs?url=" + relPath + swaggerPath;
-            }
-            if (!absoluteURL.endsWith("/")) {
-                swaggerPath = "/" + swaggerPath;
+            writeApiSpec(absoluteURL, sb, writer, "swagger.json", "Swagger");
+        }
+    }
+
+    private static void addOpenApiIfNeeded(String absoluteURL, Bus sb, PrintWriter writer)
{
+        if (sb != null && PropertyUtils.isTrue(sb.getProperty("openapi.service.description.available")))
{
+            writeApiSpec(absoluteURL, sb, writer, "openapi.json", "OpenAPI");
+        }
+    }
+
+    private static void writeApiSpec(String absoluteURL, Bus sb, PrintWriter writer, 
+            String specPath, String specName) {
+        if (PropertyUtils.isTrue(sb.getProperty("swagger.service.ui.available"))) {
+            URI uri = URI.create(absoluteURL);
+            String schemePath = uri.getScheme() + "://" + uri.getHost()
+                + (uri.getPort() == -1 ? "" : ":" + uri.getPort());
+            String relPath = absoluteURL.substring(schemePath.length());
+            if (!relPath.endsWith("/")) {
+                relPath += "/";
             }
-            writer.write("<br/><span class=\"field\">Swagger :</span> "
+ "<a href=\"" + absoluteURL
-                     + swaggerPath + "\">" + absoluteURL + swaggerPath + "</a>");
+            specPath = "api-docs?url=" + relPath + specPath;
         }
-        addAtomLinkIfNeeded(absoluteURL, atomMap, writer);
-        writer.write("</td></tr>");
+        if (!absoluteURL.endsWith("/")) {
+            specPath = "/" + specPath;
+        }
+        writer.write("<br/><span class=\"field\">" + specName + " :</span>
" + "<a href=\"" + absoluteURL
+                 + specPath + "\">" + absoluteURL + specPath + "</a>");
     }
 
     private static void addAtomLinkIfNeeded(String address, Map<String, String> extMap,
PrintWriter pw) {
diff --git a/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/servicelist/UnformattedServiceListWriter.java
b/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/servicelist/UnformattedServiceListWriter.java
index 49929de..b5aea51 100644
--- a/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/servicelist/UnformattedServiceListWriter.java
+++ b/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/servicelist/UnformattedServiceListWriter.java
@@ -78,6 +78,8 @@ public class UnformattedServiceListWriter implements ServiceListWriter {
                 && PropertyUtils.isTrue(bus.getProperty("wadl.service.descrition.available"));
             boolean swaggerAvailable = bus != null
                 && PropertyUtils.isTrue(bus.getProperty("swagger.service.descrition.available"));
+            boolean openApiAvailable = bus != null
+                && PropertyUtils.isTrue(bus.getProperty("openapi.service.descrition.available"));
             if (!wadlAvailable && !swaggerAvailable) {
                 writer.write(address + "\n");
                 return;
@@ -88,7 +90,9 @@ public class UnformattedServiceListWriter implements ServiceListWriter {
             if (swaggerAvailable) {
                 writer.write(address + "/swagger.json\n");
             }
-
+            if (openApiAvailable) {
+                writer.write(address + "/openapi.json\n");
+            }
         }
     }
 


Mime
View raw message