Repository: camel
Updated Branches:
  refs/heads/master 753bf7410 -> 7113dee32


Rest DSL. camel-swagger 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/0472b3e2
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/0472b3e2
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/0472b3e2

Branch: refs/heads/master
Commit: 0472b3e264e3f9a6519b48bf151bd1b3f76ede35
Parents: 753bf74
Author: Claus Ibsen <davscl...@apache.org>
Authored: Sun Aug 10 15:26:45 2014 +0200
Committer: Claus Ibsen <davscl...@apache.org>
Committed: Sun Aug 10 15:26:45 2014 +0200

----------------------------------------------------------------------
 .../component/swagger/RestSwaggerReader.scala   | 81 ++++++++++++++++----
 1 file changed, 67 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/0472b3e2/components/camel-swagger/src/main/scala/org/apache/camel/component/swagger/RestSwaggerReader.scala
----------------------------------------------------------------------
diff --git 
a/components/camel-swagger/src/main/scala/org/apache/camel/component/swagger/RestSwaggerReader.scala
 
b/components/camel-swagger/src/main/scala/org/apache/camel/component/swagger/RestSwaggerReader.scala
index 7522595..aa48d61 100644
--- 
a/components/camel-swagger/src/main/scala/org/apache/camel/component/swagger/RestSwaggerReader.scala
+++ 
b/components/camel-swagger/src/main/scala/org/apache/camel/component/swagger/RestSwaggerReader.scala
@@ -19,7 +19,7 @@ package org.apache.camel.component.swagger
 import java.util.Locale
 
 import com.wordnik.swagger.config.SwaggerConfig
-import com.wordnik.swagger.model.{ApiDescription, Operation, ApiListing}
+import com.wordnik.swagger.model._
 import com.wordnik.swagger.core.util.ModelUtil
 import com.wordnik.swagger.core.SwaggerSpec
 
@@ -28,6 +28,11 @@ import org.apache.camel.util.FileUtil
 import org.slf4j.LoggerFactory
 
 import scala.collection.mutable.ListBuffer
+import com.wordnik.swagger.model.Parameter
+import com.wordnik.swagger.model.ApiDescription
+import scala.Some
+import com.wordnik.swagger.model.Operation
+import com.wordnik.swagger.model.ApiListing
 
 // to iterate Java list using for loop
 import scala.collection.JavaConverters._
@@ -36,18 +41,6 @@ class RestSwaggerReader {
 
   private val LOG = LoggerFactory.getLogger(classOf[RestSwaggerReader])
 
-  def buildUrl(path1: String, path2: String): String = {
-    val s1 = FileUtil.stripTrailingSeparator(path1)
-    val s2 = FileUtil.stripLeadingSeparator(path2)
-    if (s1 != null && s2 != null) {
-      s1 + "/" + s2
-    } else if (path1 != null) {
-      path1
-    } else {
-      path2
-    }
-  }
-
   // TODO: add parameters to operations
   // - {id} is a path type, and required
   // - type/outType is body type and required
@@ -114,6 +107,8 @@ class RestSwaggerReader {
         case _ => List()
       }
 
+
+
       operations += Operation(
         method,
         "",
@@ -125,7 +120,7 @@ class RestSwaggerReader {
         consumes,
         List(),
         List(),
-        List(),
+        createParameters(verb, buildUrl(resourcePath, path)),
         List(),
         None)
     }
@@ -169,6 +164,52 @@ class RestSwaggerReader {
     else None
   }
 
+  def createParameters(verb: VerbDefinition, absPath : String): 
List[Parameter] = {
+    val parameters = new ListBuffer[Parameter]
+
+    // each {} is a parameter
+    val arr = absPath.split("\\/")
+    for (a <- arr) {
+      if (a.startsWith("{") && a.endsWith("}")) {
+        var key = a.substring(1, a.length - 1)
+
+        parameters += Parameter(
+          key,
+          None,
+          None,
+          true,
+          false,
+          "string",
+          AnyAllowableValues,
+          "path",
+          None
+        )
+      }
+    }
+
+    // if we have input type then its a body parameter
+    if (verb.getType != null) {
+      var bodyType = verb.getType
+      if (bodyType.endsWith("[]")) {
+        bodyType = "List[" + bodyType.substring(0, bodyType.length - 2) + "]"
+      }
+
+      parameters += Parameter(
+        "body",
+        None,
+        None,
+        true,
+        false,
+        bodyType,
+        AnyAllowableValues,
+        "body",
+        None
+      )
+    }
+
+    parameters.toList
+  }
+
   def createNickname(method: String, absPath : String): String = {
     val s = method + "/" + absPath
     val arr = s.split("\\/")
@@ -192,4 +233,16 @@ class RestSwaggerReader {
     s.replaceAll("\\W", "")
   }
 
+  def buildUrl(path1: String, path2: String): String = {
+    val s1 = FileUtil.stripTrailingSeparator(path1)
+    val s2 = FileUtil.stripLeadingSeparator(path2)
+    if (s1 != null && s2 != null) {
+      s1 + "/" + s2
+    } else if (path1 != null) {
+      path1
+    } else {
+      path2
+    }
+  }
+
 }

Reply via email to