cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject cxf git commit: More SwaggerUI media type updates, making it configurable
Date Wed, 17 Aug 2016 10:11:07 GMT
Repository: cxf
Updated Branches:
  refs/heads/master 2d72016e8 -> 8587301fb


More SwaggerUI media type updates, making it configurable


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

Branch: refs/heads/master
Commit: 8587301fb4a8e548c14457fbe52e742205462c6d
Parents: 2d72016
Author: Sergey Beryozkin <sberyozkin@gmail.com>
Authored: Wed Aug 17 11:10:52 2016 +0100
Committer: Sergey Beryozkin <sberyozkin@gmail.com>
Committed: Wed Aug 17 11:10:52 2016 +0100

----------------------------------------------------------------------
 .../cxf/jaxrs/swagger/Swagger2Feature.java      | 38 ++++++++++++++------
 1 file changed, 28 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/8587301f/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 d69d955..c8807dd 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
@@ -86,7 +86,8 @@ public class Swagger2Feature extends AbstractSwaggerFeature {
     
     private boolean supportSwaggerUi = true;
     private String swaggerUiVersion;
-
+    private Map<String, String> swaggerUiMediaTypes;
+    
     @Override
     protected void addSwaggerResource(Server server, Bus bus) {
         List<Object> swaggerResources = new LinkedList<Object>();
@@ -97,7 +98,7 @@ public class Swagger2Feature extends AbstractSwaggerFeature {
         if (supportSwaggerUi) {
             String swaggerUiRoot = SwaggerUiResolver.findSwaggerUiRoot(swaggerUiVersion);
             if (swaggerUiRoot != null) {
-                swaggerUiService = new SwaggerUIService(swaggerUiRoot);
+                swaggerUiService = new SwaggerUIService(swaggerUiRoot, swaggerUiMediaTypes);
                 swaggerResources.add(swaggerUiService);
                 bus.setProperty("swagger.service.ui.available", "true");
             }
@@ -291,18 +292,26 @@ public class Swagger2Feature extends AbstractSwaggerFeature {
     @Path("api-docs")
     public static class SwaggerUIService {
         private static final String FAVICON = "favicon";
-        private static final Map<String, String> DEFAULT_STATIC_CONTENT_TYPES;
+        private static final Map<String, String> DEFAULT_MEDIA_TYPES;
         
         static {
-            DEFAULT_STATIC_CONTENT_TYPES = new HashMap<String, String>();
-            DEFAULT_STATIC_CONTENT_TYPES.put("html", "text/html");
-            DEFAULT_STATIC_CONTENT_TYPES.put("txt", "text/plain");
-            DEFAULT_STATIC_CONTENT_TYPES.put("css", "text/css");
-            DEFAULT_STATIC_CONTENT_TYPES.put("js", "application/javascript");
+            DEFAULT_MEDIA_TYPES = new HashMap<String, String>();
+            DEFAULT_MEDIA_TYPES.put("html", "text/html");
+            DEFAULT_MEDIA_TYPES.put("png", "image/png");
+            DEFAULT_MEDIA_TYPES.put("gif", "image/gif");
+            DEFAULT_MEDIA_TYPES.put("css", "text/css");
+            DEFAULT_MEDIA_TYPES.put("js", "application/javascript");
+            DEFAULT_MEDIA_TYPES.put("eot", "application/vnd.ms-fontobject");
+            DEFAULT_MEDIA_TYPES.put("ttf", "application/font-sfnt");
+            DEFAULT_MEDIA_TYPES.put("svg", "image/svg+xml");
+            DEFAULT_MEDIA_TYPES.put("woff", "application/font-woff");
+            DEFAULT_MEDIA_TYPES.put("woff2", "application/font-woff2");
         }
         private String swaggerUiRoot;
-        public SwaggerUIService(String swaggerUiRoot) {
+        private Map<String, String> mediaTypes;
+        public SwaggerUIService(String swaggerUiRoot, Map<String, String> mediaTypes)
{
             this.swaggerUiRoot = swaggerUiRoot;
+            this.mediaTypes = mediaTypes;
         }
         
         @GET
@@ -324,7 +333,12 @@ public class Swagger2Feature extends AbstractSwaggerFeature {
                 String mediaType = null;
                 int ind = resourcePath.lastIndexOf(".");
                 if (ind != -1 && ind < resourcePath.length()) {
-                    mediaType = DEFAULT_STATIC_CONTENT_TYPES.get(resourcePath.substring(ind
+ 1));
+                    String resourceExt = resourcePath.substring(ind + 1);
+                    if (mediaTypes != null && mediaTypes.containsKey(resourceExt))
{
+                        mediaType = mediaTypes.get(resourceExt);
+                    } else {
+                        mediaType = DEFAULT_MEDIA_TYPES.get(resourceExt);
+                    }
                 }
                 
                 ResponseBuilder rb = Response.ok(resourceURL.openStream());
@@ -363,4 +377,8 @@ public class Swagger2Feature extends AbstractSwaggerFeature {
         this.supportSwaggerUi = supportSwaggerUi;
     }
 
+    public void setSwaggerUiMediaTypes(Map<String, String> swaggerUiMediaTypes) {
+        this.swaggerUiMediaTypes = swaggerUiMediaTypes;
+    }
+
 }


Mime
View raw message