Repository: camel Updated Branches: refs/heads/master 81b8de2ce -> 00e86dbbc
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/00e86dbb Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/00e86dbb Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/00e86dbb Branch: refs/heads/master Commit: 00e86dbbc1944a0f5b3d0ae29713fa61329a24ab Parents: 81b8de2 Author: Claus Ibsen <davscl...@apache.org> Authored: Mon Aug 11 15:45:15 2014 +0200 Committer: Claus Ibsen <davscl...@apache.org> Committed: Mon Aug 11 15:45:15 2014 +0200 ---------------------------------------------------------------------- .../component/swagger/RestSwaggerReader.scala | 35 ++++++++++++++++---- 1 file changed, 28 insertions(+), 7 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/00e86dbb/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 b9ea729..baa7dbd 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 @@ -33,6 +33,7 @@ import com.wordnik.swagger.model.ApiDescription import scala.Some import com.wordnik.swagger.model.Operation import com.wordnik.swagger.model.ApiListing +import scala.util.Sorting // to iterate Java list using for loop import scala.collection.JavaConverters._ @@ -64,14 +65,9 @@ class RestSwaggerReader { val operations = new ListBuffer[Operation] var path: String = null - // must sort the verbs by uri so we group them together when an uri has multiple operations - // TODO: we want to sort /{xx} first, so we may need some regexp matching to trigger sorting them before non {} - // TODO: and then 2nd sort by http method var list = rest.getVerbs.asScala - list = list.sortBy(v => v.getUri match { - case v: Any => v - case _ => "" - }) + // must sort the verbs by uri so we group them together when an uri has multiple operations + list = list.sorted(VerbOrdering) for (verb: VerbDefinition <- list) { @@ -260,4 +256,29 @@ class RestSwaggerReader { } } + /** + * To sort the rest operations + */ + object VerbOrdering extends Ordering[VerbDefinition] { + def compare(a:VerbDefinition, b:VerbDefinition) = { + var u1 = "" + if (a.getUri != null) { + // replace { with _ which comes before a when soring by char + u1 = a.getUri.replace("{", "_") + } + var u2 = "" + if (b.getUri != null) { + // replace { with _ which comes before a when soring by char + u2 = b.getUri.replace("{", "_") + } + + var num = u1.compareTo(u2) + if (num == 0) { + // same uri, so use http method as sorting + num = a.asVerb().compareTo(b.asVerb()) + } + num + } + } + }