cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject cxf git commit: [CXF-7353] Initial support for custom Swagger UI coordinates
Date Fri, 28 Apr 2017 16:07:39 GMT
Repository: cxf
Updated Branches:
  refs/heads/master 99f6eb63f -> dd3cb8eb8


[CXF-7353] Initial support for custom Swagger UI coordinates


Project: http://git-wip-us.apache.org/repos/asf/cxf/repo
Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/dd3cb8eb
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/dd3cb8eb
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/dd3cb8eb

Branch: refs/heads/master
Commit: dd3cb8eb84f1f17ebadb4104873faa4f17377a96
Parents: 99f6eb6
Author: Sergey Beryozkin <sberyozkin@gmail.com>
Authored: Fri Apr 28 17:07:22 2017 +0100
Committer: Sergey Beryozkin <sberyozkin@gmail.com>
Committed: Fri Apr 28 17:07:22 2017 +0100

----------------------------------------------------------------------
 .../cxf/jaxrs/swagger/OsgiSwaggerUiResolver.java    | 16 +++++++++++-----
 .../apache/cxf/jaxrs/swagger/Swagger2Feature.java   | 13 ++++++++++++-
 .../apache/cxf/jaxrs/swagger/SwaggerUiResolver.java | 12 ++++++++----
 3 files changed, 31 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/dd3cb8eb/rt/rs/description-swagger/src/main/java/org/apache/cxf/jaxrs/swagger/OsgiSwaggerUiResolver.java
----------------------------------------------------------------------
diff --git a/rt/rs/description-swagger/src/main/java/org/apache/cxf/jaxrs/swagger/OsgiSwaggerUiResolver.java
b/rt/rs/description-swagger/src/main/java/org/apache/cxf/jaxrs/swagger/OsgiSwaggerUiResolver.java
index 1350fcd..32493a1 100644
--- a/rt/rs/description-swagger/src/main/java/org/apache/cxf/jaxrs/swagger/OsgiSwaggerUiResolver.java
+++ b/rt/rs/description-swagger/src/main/java/org/apache/cxf/jaxrs/swagger/OsgiSwaggerUiResolver.java
@@ -26,25 +26,31 @@ import org.osgi.framework.FrameworkUtil;
 import io.swagger.annotations.Api;
 
 public class OsgiSwaggerUiResolver extends SwaggerUiResolver {
-    private static final String LOCATIONS[] = {
-        "mvn:org.webjars/swagger-ui/",
-        "wrap:mvn:org.webjars/swagger-ui/"
+    private static final String DEFAULT_COORDINATES = "org.webjars/swagger-ui";
+    private static final String DEFAULT_LOCATIONS[] = {
+        "mvn:" + DEFAULT_COORDINATES + "/",
+        "wrap:mvn:" + DEFAULT_COORDINATES + "/"
     };
 
     OsgiSwaggerUiResolver() throws Exception {
         Class.forName("org.osgi.framework.FrameworkUtil");
     }
 
-    protected String findSwaggerUiRootInternal(String swaggerUiVersion) {
+    @Override
+    protected String findSwaggerUiRootInternal(String swaggerUiMavenGroupAndArtifact,
+                                               String swaggerUiVersion) {
         try {
             Bundle bundle = FrameworkUtil.getBundle(Api.class);
             if (bundle == null) {
                 return null;
             }
+            String[] locations = swaggerUiMavenGroupAndArtifact == null ? DEFAULT_LOCATIONS
+                : new String[]{"mvn:" + DEFAULT_COORDINATES + "/",
+                               "wrap:mvn:" + swaggerUiMavenGroupAndArtifact + "/"};
             for (Bundle b : bundle.getBundleContext().getBundles()) {
                 String location = b.getLocation();
 
-                for (String pattern: LOCATIONS) {
+                for (String pattern: locations) {
                     if (swaggerUiVersion != null) {
                         if (location.equals(pattern + swaggerUiVersion)) {
                             return getSwaggerUiRoot(b, swaggerUiVersion);

http://git-wip-us.apache.org/repos/asf/cxf/blob/dd3cb8eb/rt/rs/description-swagger/src/main/java/org/apache/cxf/jaxrs/swagger/Swagger2Feature.java
----------------------------------------------------------------------
diff --git a/rt/rs/description-swagger/src/main/java/org/apache/cxf/jaxrs/swagger/Swagger2Feature.java
b/rt/rs/description-swagger/src/main/java/org/apache/cxf/jaxrs/swagger/Swagger2Feature.java
index fd57b64..5696c94 100644
--- a/rt/rs/description-swagger/src/main/java/org/apache/cxf/jaxrs/swagger/Swagger2Feature.java
+++ b/rt/rs/description-swagger/src/main/java/org/apache/cxf/jaxrs/swagger/Swagger2Feature.java
@@ -89,6 +89,8 @@ public class Swagger2Feature extends AbstractSwaggerFeature {
     private boolean supportSwaggerUi = true;
 
     private String swaggerUiVersion;
+    
+    private String swaggerUiMavenGroupAndArtifact;
 
     private Map<String, String> swaggerUiMediaTypes;
 
@@ -134,7 +136,8 @@ public class Swagger2Feature extends AbstractSwaggerFeature {
         }
 
         if (supportSwaggerUi) {
-            String swaggerUiRoot = SwaggerUiResolver.findSwaggerUiRoot(swaggerUiVersion);
+            String swaggerUiRoot = SwaggerUiResolver.findSwaggerUiRoot(swaggerUiMavenGroupAndArtifact,

+                                                                       swaggerUiVersion);
             if (swaggerUiRoot != null) {
                 SwaggerUIService swaggerUiService = new SwaggerUIService(swaggerUiRoot, swaggerUiMediaTypes);
                 if (!runAsFilter) {
@@ -267,6 +270,14 @@ public class Swagger2Feature extends AbstractSwaggerFeature {
         }
     }
 
+    /**
+     * Set SwaggerUI Maven group and artifact using the "groupId/artifactId" format. 
+     * @param swaggerUiMavenGroupAndArtifact
+     */
+    public void setSwaggerUiMavenGroupAndArtifact(String swaggerUiMavenGroupAndArtifact)
{
+        this.swaggerUiMavenGroupAndArtifact = swaggerUiMavenGroupAndArtifact;
+    }
+    
     public void setSwaggerUiVersion(String swaggerUiVersion) {
         this.swaggerUiVersion = swaggerUiVersion;
     }

http://git-wip-us.apache.org/repos/asf/cxf/blob/dd3cb8eb/rt/rs/description-swagger/src/main/java/org/apache/cxf/jaxrs/swagger/SwaggerUiResolver.java
----------------------------------------------------------------------
diff --git a/rt/rs/description-swagger/src/main/java/org/apache/cxf/jaxrs/swagger/SwaggerUiResolver.java
b/rt/rs/description-swagger/src/main/java/org/apache/cxf/jaxrs/swagger/SwaggerUiResolver.java
index f38ad2b..314e8b3 100644
--- a/rt/rs/description-swagger/src/main/java/org/apache/cxf/jaxrs/swagger/SwaggerUiResolver.java
+++ b/rt/rs/description-swagger/src/main/java/org/apache/cxf/jaxrs/swagger/SwaggerUiResolver.java
@@ -37,7 +37,8 @@ public class SwaggerUiResolver {
     protected SwaggerUiResolver() {
     }
 
-    protected String findSwaggerUiRootInternal(String swaggerUiVersion) {
+    protected String findSwaggerUiRootInternal(String swaggerUiMavenGroupAndArtifact,
+                                               String swaggerUiVersion) {
         try {
             ClassLoader cl = AbstractSwaggerFeature.class.getClassLoader();
             if (cl instanceof URLClassLoader) {
@@ -68,10 +69,13 @@ public class SwaggerUiResolver {
         return null;
     }
 
-    public static String findSwaggerUiRoot(String swaggerUiVersion) {
-        String root = HELPER.findSwaggerUiRootInternal(swaggerUiVersion);
+    public static String findSwaggerUiRoot(String swaggerUiMavenGroupAndArtifact, 
+                                           String swaggerUiVersion) {
+        String root = HELPER.findSwaggerUiRootInternal(swaggerUiMavenGroupAndArtifact, 
+                                                       swaggerUiVersion);
         if (root == null && HELPER.getClass() != SwaggerUiResolver.class) {
-            root = new SwaggerUiResolver().findSwaggerUiRootInternal(swaggerUiVersion);
+            root = new SwaggerUiResolver().findSwaggerUiRootInternal(swaggerUiMavenGroupAndArtifact,

+                                                                     swaggerUiVersion);
         }
         return root;
     }


Mime
View raw message