camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject [05/21] camel git commit: CAMEL-7800: camel-swagger-java - work in progress
Date Fri, 18 Sep 2015 15:43:51 GMT
CAMEL-7800: camel-swagger-java - work in progress


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

Branch: refs/heads/master
Commit: 2ce6072c4c0e2a69c99edd002bf1273605e2c1bb
Parents: 83261fe
Author: Claus Ibsen <davsclaus@apache.org>
Authored: Thu Sep 17 16:58:42 2015 +0200
Committer: Claus Ibsen <davsclaus@apache.org>
Committed: Fri Sep 18 16:16:12 2015 +0200

----------------------------------------------------------------------
 .../apache/camel/swagger/RestSwaggerReader.java   | 18 ++++++++++++++----
 .../camel/swagger/RestSwaggerReaderTest.java      |  6 +++---
 2 files changed, 17 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/2ce6072c/components/camel-swagger-java/src/main/java/org/apache/camel/swagger/RestSwaggerReader.java
----------------------------------------------------------------------
diff --git a/components/camel-swagger-java/src/main/java/org/apache/camel/swagger/RestSwaggerReader.java
b/components/camel-swagger-java/src/main/java/org/apache/camel/swagger/RestSwaggerReader.java
index 662cb34..b343c5f 100644
--- a/components/camel-swagger-java/src/main/java/org/apache/camel/swagger/RestSwaggerReader.java
+++ b/components/camel-swagger-java/src/main/java/org/apache/camel/swagger/RestSwaggerReader.java
@@ -38,6 +38,7 @@ import org.apache.camel.model.rest.RestOperationParamDefinition;
 import org.apache.camel.model.rest.RestOperationResponseMsgDefinition;
 import org.apache.camel.model.rest.RestParamType;
 import org.apache.camel.model.rest.VerbDefinition;
+import org.apache.camel.util.FileUtil;
 
 public class RestSwaggerReader {
 
@@ -59,7 +60,7 @@ public class RestSwaggerReader {
             // the method must be in lower case
             String method = verb.asVerb().toLowerCase(Locale.US);
             // operation path is a key
-            String opPath = getPath(basePath, verb.getUri());
+            String opPath = buildUrl(basePath, verb.getUri());
 
             Operation op = new Operation();
 
@@ -113,14 +114,23 @@ public class RestSwaggerReader {
 
             // add path
             swagger.path(opPath, path);
+
+            // TODO: add model parser for swagger annotations in the model/schema
         }
 
         return swagger;
     }
 
-    private String getPath(String basePath, String uri) {
-        // TODO: slash check and avoid double slash and all that
-        return basePath + "/" + uri;
+    private String buildUrl(String path1, String path2) {
+        String s1 = FileUtil.stripTrailingSeparator(path1);
+        String s2 = FileUtil.stripLeadingSeparator(path2);
+        if (s1 != null && s2 != null) {
+            return s1 + "/" + s2;
+        } else if (path1 != null) {
+            return path1;
+        } else {
+            return path2;
+        }
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/camel/blob/2ce6072c/components/camel-swagger-java/src/test/java/org/apache/camel/swagger/RestSwaggerReaderTest.java
----------------------------------------------------------------------
diff --git a/components/camel-swagger-java/src/test/java/org/apache/camel/swagger/RestSwaggerReaderTest.java
b/components/camel-swagger-java/src/test/java/org/apache/camel/swagger/RestSwaggerReaderTest.java
index 45aa629..baefb8f 100644
--- a/components/camel-swagger-java/src/test/java/org/apache/camel/swagger/RestSwaggerReaderTest.java
+++ b/components/camel-swagger-java/src/test/java/org/apache/camel/swagger/RestSwaggerReaderTest.java
@@ -80,10 +80,10 @@ public class RestSwaggerReaderTest extends CamelTestSupport {
 
         assertTrue(json.contains("\"host\" : \"localhost:8080\""));
         assertTrue(json.contains("\"basePath\" : \"/api\""));
-        assertTrue(json.contains("\"/hello//bye\""));
+        assertTrue(json.contains("\"/hello/bye\""));
         assertTrue(json.contains("\"summary\" : \"To update the greeting message\""));
-        assertTrue(json.contains("\"/hello//bye/{name}\""));
-        assertTrue(json.contains("\"/hello//hi/{name}\""));
+        assertTrue(json.contains("\"/hello/bye/{name}\""));
+        assertTrue(json.contains("\"/hello/hi/{name}\""));
 
         context.stop();
     }


Mime
View raw message