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-6633] Normalized resource path in SwaggerSerializer
Date Thu, 05 Nov 2015 11:32:39 GMT
Repository: cxf
Updated Branches:
  refs/heads/3.0.x-fixes 9b0e4b5d9 -> de2acc903


[CXF-6633] Normalized resource path in SwaggerSerializer


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

Branch: refs/heads/3.0.x-fixes
Commit: de2acc903c70db1950804c725bcf38ffbacf7826
Parents: 9b0e4b5
Author: Andrei Shakirin <andrei.shakirin@gmail.com>
Authored: Wed Nov 4 20:25:32 2015 +0100
Committer: Sergey Beryozkin <sberyozkin@gmail.com>
Committed: Thu Nov 5 11:32:19 2015 +0000

----------------------------------------------------------------------
 .../cxf/jaxrs/swagger/Swagger2Serializers.java  | 39 +++++++++++++-------
 1 file changed, 25 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/de2acc90/rt/rs/description/src/main/java/org/apache/cxf/jaxrs/swagger/Swagger2Serializers.java
----------------------------------------------------------------------
diff --git a/rt/rs/description/src/main/java/org/apache/cxf/jaxrs/swagger/Swagger2Serializers.java
b/rt/rs/description/src/main/java/org/apache/cxf/jaxrs/swagger/Swagger2Serializers.java
index c67ce85..71810d4 100644
--- a/rt/rs/description/src/main/java/org/apache/cxf/jaxrs/swagger/Swagger2Serializers.java
+++ b/rt/rs/description/src/main/java/org/apache/cxf/jaxrs/swagger/Swagger2Serializers.java
@@ -33,7 +33,6 @@ import javax.ws.rs.core.MultivaluedMap;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.commons.lang3.tuple.ImmutablePair;
 import org.apache.commons.lang3.tuple.Pair;
-
 import org.apache.cxf.jaxrs.ext.MessageContext;
 import org.apache.cxf.jaxrs.model.ClassResourceInfo;
 import org.apache.cxf.jaxrs.model.OperationResourceInfo;
@@ -93,20 +92,11 @@ public class Swagger2Serializers extends SwaggerSerializers {
                 new HashMap<Pair<String, String>, OperationResourceInfo>();
             for (ClassResourceInfo cri : cris) {
                 for (OperationResourceInfo ori : cri.getMethodDispatcher().getOperationResourceInfos())
{
-                    StringBuilder fullPath = new StringBuilder().
-                            append(cri.getURITemplate().getValue()).
-                            append(ori.getURITemplate().getValue());
-                    if (fullPath.charAt(fullPath.length() - 1) == '/') {
-                        fullPath.setLength(fullPath.length() - 1);
-                    }
-                    // Adapt to Swagger's path expression
-                    if (fullPath.toString().endsWith(":.*}")) {
-                        fullPath.setLength(fullPath.length() - 4);
-                        fullPath.append('}');
-                    }
+                    String normalizedPath = getNormalizedPath(cri.getURITemplate().getValue(),
ori
+                        .getURITemplate().getValue());
 
-                    operations.put(fullPath.toString(), cri);
-                    methods.put(ImmutablePair.of(ori.getHttpMethod(), fullPath.toString()),
ori);
+                    operations.put(normalizedPath, cri);
+                    methods.put(ImmutablePair.of(ori.getHttpMethod(), normalizedPath), ori);
                 }
             }
 
@@ -155,4 +145,25 @@ public class Swagger2Serializers extends SwaggerSerializers {
 
         super.writeTo(data, type, genericType, annotations, mediaType, headers, out);
     }
+
+    private String getNormalizedPath(String classResourcePath, String operationResourcePath)
{
+        StringBuilder path = new StringBuilder().
+            append(classResourcePath).
+            append(operationResourcePath);
+
+        StringBuilder normalizedPath = new StringBuilder();
+
+        String[] segments = StringUtils.split(path.toString(), "/");
+        for (String segment : segments) {
+            if (!StringUtils.isEmpty(segment)) {
+                normalizedPath.append("/").append(segment);
+            }
+        }
+        // Adapt to Swagger's path expression
+        if (normalizedPath.toString().endsWith(":.*}")) {
+            normalizedPath.setLength(normalizedPath.length() - 4);
+            normalizedPath.append('}');
+        }
+        return normalizedPath.toString();
+    }
 }


Mime
View raw message