You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2014/06/10 15:18:00 UTC

[2/2] git commit: CAMEL-7494: Added support for enum for parameter json schema

CAMEL-7494: Added support for enum for parameter json schema


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

Branch: refs/heads/camel-2.13.x
Commit: 85f7778b24b261f43fd8a108290eaa349d3e3748
Parents: 0bc742b
Author: Claus Ibsen <da...@apache.org>
Authored: Tue Jun 10 15:16:44 2014 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Tue Jun 10 15:17:41 2014 +0200

----------------------------------------------------------------------
 .../org/apache/camel/impl/ParameterConfiguration.java  | 13 ++++++++++++-
 ...aSetComponentConfigurationAndDocumentationTest.java |  2 ++
 2 files changed, 14 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/85f7778b/camel-core/src/main/java/org/apache/camel/impl/ParameterConfiguration.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/impl/ParameterConfiguration.java b/camel-core/src/main/java/org/apache/camel/impl/ParameterConfiguration.java
index af6883c..652746a 100644
--- a/camel-core/src/main/java/org/apache/camel/impl/ParameterConfiguration.java
+++ b/camel-core/src/main/java/org/apache/camel/impl/ParameterConfiguration.java
@@ -19,6 +19,7 @@ package org.apache.camel.impl;
 import java.lang.reflect.Field;
 
 import org.apache.camel.spi.UriParam;
+import org.apache.camel.util.CollectionStringBuffer;
 
 import static org.apache.camel.util.StringQuoteHelper.doubleQuote;
 
@@ -68,6 +69,16 @@ public class ParameterConfiguration {
         String typeName = parameterType.getCanonicalName();
         // TODO would be nice to add a description; wonder if we can find that from somewhere
         // generated by the APT tool?
-        return doubleQuote(name) + ": { \"type\": " + doubleQuote(typeName) + " }";
+
+        if (parameterType.isEnum()) {
+            typeName = "string";
+            CollectionStringBuffer sb = new CollectionStringBuffer();
+            for (Object value : parameterType.getEnumConstants()) {
+                sb.append(doubleQuote(value.toString()));
+            }
+            return doubleQuote(name) + ": { \"type\": " + doubleQuote(typeName) + ", \"enum\": [ " +  sb.toString() + " ] }";
+        } else {
+            return doubleQuote(name) + ": { \"type\": " + doubleQuote(typeName) + " }";
+        }
     }
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/85f7778b/camel-core/src/test/java/org/apache/camel/component/dataset/DataSetComponentConfigurationAndDocumentationTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/component/dataset/DataSetComponentConfigurationAndDocumentationTest.java b/camel-core/src/test/java/org/apache/camel/component/dataset/DataSetComponentConfigurationAndDocumentationTest.java
index 41eb4a9..7b886d5 100644
--- a/camel-core/src/test/java/org/apache/camel/component/dataset/DataSetComponentConfigurationAndDocumentationTest.java
+++ b/camel-core/src/test/java/org/apache/camel/component/dataset/DataSetComponentConfigurationAndDocumentationTest.java
@@ -43,6 +43,8 @@ public class DataSetComponentConfigurationAndDocumentationTest extends ContextTe
 
         assertTrue(json.contains("\"preloadSize\": { \"type\": \"long\" }"));
         assertTrue(json.contains("\"minRate\": { \"type\": \"int\" }"));
+        assertTrue(json.contains("\"exchangePattern\": { \"type\": \"string\", \"enum\":"));
+        assertTrue(json.contains("\"InOut\""));
     }
 
     @Test