cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject cxf git commit: Adding a test for a swagger doc with no tags
Date Wed, 26 Jul 2017 13:29:41 GMT
Repository: cxf
Updated Branches:
  refs/heads/3.1.x-fixes 0967819ec -> f2ca294d8


Adding a test for a swagger doc with no tags


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

Branch: refs/heads/3.1.x-fixes
Commit: f2ca294d88c3d61265a1513452144670e7b997e7
Parents: 0967819
Author: Sergey Beryozkin <sberyozkin@gmail.com>
Authored: Wed Jul 26 15:56:00 2017 +0300
Committer: Sergey Beryozkin <sberyozkin@gmail.com>
Committed: Wed Jul 26 16:29:24 2017 +0300

----------------------------------------------------------------------
 .../apache/cxf/jaxrs/model/UserResource.java    |  4 +-
 .../jaxrs/swagger/parse/SwaggerParseUtils.java  |  8 ++--
 .../swagger/parse/SwaggerParseUtilsTest.java    | 42 +++++++++++++++++++-
 3 files changed, 46 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/f2ca294d/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/UserResource.java
----------------------------------------------------------------------
diff --git a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/UserResource.java
b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/UserResource.java
index 39e2417..8485fbd 100644
--- a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/UserResource.java
+++ b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/UserResource.java
@@ -76,9 +76,7 @@ public class UserResource {
     }
     
     public void setName(String name) {
-        if (!StringUtils.isEmpty(name)) {
-            className = name;
-        }
+        className = name;
     }
     
     public String getPath() {

http://git-wip-us.apache.org/repos/asf/cxf/blob/f2ca294d/rt/rs/description-swagger/src/main/java/org/apache/cxf/jaxrs/swagger/parse/SwaggerParseUtils.java
----------------------------------------------------------------------
diff --git a/rt/rs/description-swagger/src/main/java/org/apache/cxf/jaxrs/swagger/parse/SwaggerParseUtils.java
b/rt/rs/description-swagger/src/main/java/org/apache/cxf/jaxrs/swagger/parse/SwaggerParseUtils.java
index fe8a96e..8378a16 100644
--- a/rt/rs/description-swagger/src/main/java/org/apache/cxf/jaxrs/swagger/parse/SwaggerParseUtils.java
+++ b/rt/rs/description-swagger/src/main/java/org/apache/cxf/jaxrs/swagger/parse/SwaggerParseUtils.java
@@ -113,6 +113,7 @@ public final class SwaggerParseUtils {
         } else {
             tags.add("");
         }
+        
         for (String tag : tags) {
             userOpsMap.put(tag, new LinkedList<UserOperation>());
         }
@@ -130,9 +131,10 @@ public final class SwaggerParseUtils {
                 
                 Map<String, Object> oper = CastUtils.cast((Map<?, ?>)operEntry.getValue());
                 List<String> opTags = CastUtils.cast((List<?>)oper.get("tags"));
-                String opTag = opTags == null ? "" : opTags.get(0);
-                
-                String realOpPath = operPath.equals("/" + opTag) ? "/" : operPath.substring(opTag.length()
+ 1);
+                String opTag = tagsProp == null || opTags == null ? "" : opTags.get(0);
+
+                String realOpPath = operPath.equals("/" + opTag) ? "/" 
+                    : tagsProp != null ? operPath.substring(opTag.length() + 1) : operPath;
                 userOp.setPath(realOpPath);
                 
                 userOp.setName((String)oper.get("operationId"));

http://git-wip-us.apache.org/repos/asf/cxf/blob/f2ca294d/rt/rs/description-swagger/src/test/java/org/apache/cxf/jaxrs/swagger/parse/SwaggerParseUtilsTest.java
----------------------------------------------------------------------
diff --git a/rt/rs/description-swagger/src/test/java/org/apache/cxf/jaxrs/swagger/parse/SwaggerParseUtilsTest.java
b/rt/rs/description-swagger/src/test/java/org/apache/cxf/jaxrs/swagger/parse/SwaggerParseUtilsTest.java
index 13b20dc7..8063cc7 100644
--- a/rt/rs/description-swagger/src/test/java/org/apache/cxf/jaxrs/swagger/parse/SwaggerParseUtilsTest.java
+++ b/rt/rs/description-swagger/src/test/java/org/apache/cxf/jaxrs/swagger/parse/SwaggerParseUtilsTest.java
@@ -33,7 +33,7 @@ import org.junit.Test;
 public class SwaggerParseUtilsTest extends Assert {
 
     @Test
-    public void testConvertSwaggerPetShopToUserApp() {
+    public void testConvertPetShopDocToUserApp() {
         UserApplication ap = SwaggerParseUtils.getUserApplication("/swagger2petShop.json");
         assertNotNull(ap);
         assertEquals("/v2", ap.getBasePath());
@@ -367,7 +367,7 @@ public class SwaggerParseUtilsTest extends Assert {
     
     
     @Test
-    public void testConvertSwaggerToUserApp() {
+    public void testConvertSimpleDocToUserApp() {
         UserApplication ap = SwaggerParseUtils.getUserApplication("/swagger20.json");
         assertNotNull(ap);
         assertEquals("/services/helloservice", ap.getBasePath());
@@ -407,4 +407,42 @@ public class SwaggerParseUtilsTest extends Assert {
         assertEquals(String.class, param2.getJavaType());
         
     }
+    
+    @Test
+    public void testConvertSimpleDocNoTagsToUserApp() {
+        UserApplication ap = SwaggerParseUtils.getUserApplication("/swagger20NoTags.json");
+        assertNotNull(ap);
+        assertEquals("/services/helloservice", ap.getBasePath());
+        Map<String, UserResource> map = ap.getResourcesAsMap();
+        assertEquals(1, map.size());
+
+        UserResource ur = map.get("");
+        assertNotNull(ur);
+        assertEquals("/", ur.getPath());
+        assertEquals(2, ur.getOperations().size());
+        UserOperation op = ur.getOperations().get(0);
+        assertEquals("sayHello", op.getName());
+        assertEquals("/sayHello/{a}", op.getPath());
+        assertEquals("GET", op.getVerb());
+        assertEquals("text/plain", op.getProduces());
+
+        assertEquals(1, op.getParameters().size());
+        Parameter param1 = op.getParameters().get(0);
+        assertEquals("a", param1.getName());
+        assertEquals(ParameterType.PATH, param1.getType());
+        assertEquals(String.class, param1.getJavaType());
+
+        UserOperation op2 = ur.getOperations().get(1);
+        assertEquals("sayHello2", op2.getName());
+        assertEquals("/sayHello2/{a}", op2.getPath());
+        assertEquals("GET", op2.getVerb());
+        assertEquals("text/plain", op2.getProduces());
+
+        assertEquals(1, op2.getParameters().size());
+        Parameter param2 = op.getParameters().get(0);
+        assertEquals("a", param2.getName());
+        assertEquals(ParameterType.PATH, param2.getType());
+        assertEquals(String.class, param2.getJavaType());
+
+    }
 }


Mime
View raw message