Changed the json schema slightly to alwyas include the javaType as well.

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

Branch: refs/heads/master
Commit: 5f5a29b850949af45e23e5fda883e0da2b80c552
Parents: 3aba7d0
Author: Claus Ibsen <davscl...@apache.org>
Authored: Fri Nov 7 09:08:58 2014 +0100
Committer: Claus Ibsen <davscl...@apache.org>
Committed: Fri Nov 7 13:25:20 2014 +0100

----------------------------------------------------------------------
 .../management/mbean/CamelOpenMBeanTypes.java   |  8 +--
 .../apache/camel/impl/DefaultCamelContext.java  | 15 ++++--
 .../camel/impl/ParameterConfiguration.java      | 16 +++---
 .../org/apache/camel/util/JsonSchemaHelper.java | 52 --------------------
 .../camel/tools/apt/util/JsonSchemaHelper.java  |  7 ++-
 5 files changed, 25 insertions(+), 73 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/5f5a29b8/camel-core/src/main/java/org/apache/camel/api/management/mbean/CamelOpenMBeanTypes.java
----------------------------------------------------------------------
diff --git 
a/camel-core/src/main/java/org/apache/camel/api/management/mbean/CamelOpenMBeanTypes.java
 
b/camel-core/src/main/java/org/apache/camel/api/management/mbean/CamelOpenMBeanTypes.java
index 6549e9e..fc75bdd 100644
--- 
a/camel-core/src/main/java/org/apache/camel/api/management/mbean/CamelOpenMBeanTypes.java
+++ 
b/camel-core/src/main/java/org/apache/camel/api/management/mbean/CamelOpenMBeanTypes.java
@@ -66,13 +66,13 @@ public final class CamelOpenMBeanTypes {
 
     public static TabularType explainEndpointTabularType() throws 
OpenDataException {
         CompositeType ct = explainEndpointsCompositeType();
-        return new TabularType("explainEndpoint", "Explain how this endpoint 
is configured", ct, new String[]{"option", "type", "value", "description"});
+        return new TabularType("explainEndpoint", "Explain how this endpoint 
is configured", ct, new String[]{"option", "type", "java type", "value", 
"description"});
     }
 
     public static CompositeType explainEndpointsCompositeType() throws 
OpenDataException {
-        return new CompositeType("endpoint", "Explain Endpoint", new 
String[]{"option", "type", "value", "description"},
-                new String[]{"Option", "Type", "Value", "Description"},
-                new OpenType[]{SimpleType.STRING, SimpleType.STRING, 
SimpleType.STRING, SimpleType.STRING});
+        return new CompositeType("endpoint", "Explain Endpoint", new 
String[]{"option", "type", "java type", "value", "description"},
+                new String[]{"Option", "Type", "Java Type", "Value", 
"Description"},
+                new OpenType[]{SimpleType.STRING, SimpleType.STRING, 
SimpleType.STRING, SimpleType.STRING, SimpleType.STRING});
     }
 
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/5f5a29b8/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
----------------------------------------------------------------------
diff --git 
a/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java 
b/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
index c627cce..567a474 100644
--- a/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
+++ b/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
@@ -1153,17 +1153,19 @@ public class DefaultCamelContext extends ServiceSupport 
implements ModelCamelCon
 
             // find type and description from the json schema
             String type = null;
+            String javaType = null;
             String description = null;
             for (Map<String, String> row : rows) {
                 if (name.equals(row.get("name"))) {
                     type = row.get("type");
+                    javaType = row.get("javaType");
                     description = row.get("description");
                     break;
                 }
             }
 
             // add as selected row
-            selected.put(name, new String[]{name, type, value, description});
+            selected.put(name, new String[]{name, type, javaType, value, 
description});
         }
 
         if (includeAllOptions) {
@@ -1172,12 +1174,13 @@ public class DefaultCamelContext extends ServiceSupport 
implements ModelCamelCon
                 String name = row.get("name");
                 String value = row.get("value");
                 String type = row.get("type");
+                String javaType = row.get("javaType");
                 value = URISupport.sanitizePath(value);
                 String description = row.get("description");
 
                 // add as selected row
                 if (!selected.containsKey(name)) {
-                    selected.put(name, new String[]{name, type, value, 
description});
+                    selected.put(name, new String[]{name, type, javaType, 
value, description});
                 }
             }
         }
@@ -1195,8 +1198,9 @@ public class DefaultCamelContext extends ServiceSupport 
implements ModelCamelCon
 
             String name = row[0];
             String type = row[1];
-            String value = row[2];
-            String description = row[3];
+            String javaType = row[2];
+            String value = row[3];
+            String description = row[4];
 
             // add json of the option
             buffer.append(doubleQuote(name) + ": { ");
@@ -1204,6 +1208,9 @@ public class DefaultCamelContext extends ServiceSupport 
implements ModelCamelCon
             if (type != null) {
                 csb.append("\"type\": \"" + type + "\"");
             }
+            if (javaType != null) {
+                csb.append("\"javaType\": \"" + javaType + "\"");
+            }
             if (value != null) {
                 csb.append("\"value\": \"" + value + "\"");
             }

http://git-wip-us.apache.org/repos/asf/camel/blob/5f5a29b8/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 d5b57ee..ebb53bb 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
@@ -73,19 +73,17 @@ public class ParameterConfiguration {
             for (Object value : parameterType.getEnumConstants()) {
                 sb.append(doubleQuote(value.toString()));
             }
-            return doubleQuote(name) + ": { \"type\": " + 
doubleQuote(typeName) + ", \"enum\": [ " + sb.toString() + " ] }";
+            return doubleQuote(name) + ": { \"type\": " + doubleQuote(typeName)
+                    + ", \"javaType\": \"" + parameterType.getCanonicalName() 
+ "\""
+                    + ", \"enum\": [ " + sb.toString() + " ] }";
         } else if (parameterType.isArray()) {
             String typeName = "array";
-            return doubleQuote(name) + ": { \"type\": " + 
doubleQuote(typeName) + " }";
+            return doubleQuote(name) + ": { \"type\": " + doubleQuote(typeName)
+                    + ", \"javaType\": \"" + parameterType.getCanonicalName() 
+ "\" }";
         } else {
             String typeName = JsonSchemaHelper.getType(parameterType);
-            if ("object".equals(typeName)) {
-                // for object then include the javaType as a description so we 
know that
-                return doubleQuote(name) + ": { \"type\": " + 
doubleQuote(typeName)
-                    + ", \"properties\": { \"javaType\": { \"description\": 
\"" + parameterType.getCanonicalName() + "\", \"type\": \"string\" } } }";
-            } else {
-                return doubleQuote(name) + ": { \"type\": " + 
doubleQuote(typeName) + " }";
-            }
+            return doubleQuote(name) + ": { \"type\": " + doubleQuote(typeName)
+                    + ", \"javaType\": \"" + parameterType.getCanonicalName() 
+ "\" }";
         }
     }
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/5f5a29b8/camel-core/src/main/java/org/apache/camel/util/JsonSchemaHelper.java
----------------------------------------------------------------------
diff --git 
a/camel-core/src/main/java/org/apache/camel/util/JsonSchemaHelper.java 
b/camel-core/src/main/java/org/apache/camel/util/JsonSchemaHelper.java
index 98efc3e..6ce3a34 100644
--- a/camel-core/src/main/java/org/apache/camel/util/JsonSchemaHelper.java
+++ b/camel-core/src/main/java/org/apache/camel/util/JsonSchemaHelper.java
@@ -109,58 +109,6 @@ public final class JsonSchemaHelper {
     }
 
     /**
-     * Extracts the type value from the blob of json with the given property 
name
-     *
-     * @param json the blob of json
-     * @param name the name of the property to extract the type
-     * @return the value of the type, or <tt>null</tt> if no type exists
-     */
-    public static String extractTypeFromJson(String json, String name) {
-        // we dont have a json parser, but we know the structure, so just do 
this simple way
-        String[] lines = json.split("\n");
-        for (String line : lines) {
-            line = line.trim();
-            if (line.startsWith("\"" + name + "\":")) {
-                // grab text after type
-                String value = ObjectHelper.after(line, "\"type\": \"");
-                if (value != null) {
-                    int lastQuote = value.lastIndexOf('"');
-                    value = value.substring(0, lastQuote);
-                    value = StringHelper.removeLeadingAndEndingQuotes(value);
-                    return value;
-                }
-            }
-        }
-        return null;
-    }
-
-    /**
-     * Extracts the description value from the blob of json with the given 
property name
-     *
-     * @param json the blob of json
-     * @param name the name of the property to extract the description
-     * @return the value of the description, or <tt>null</tt> if no 
description exists
-     */
-    public static String extractDescriptionFromJson(String json, String name) {
-        // we dont have a json parser, but we know the structure, so just do 
this simple way
-        String[] lines = json.split("\n");
-        for (String line : lines) {
-            line = line.trim();
-            if (line.startsWith("\"" + name + "\":")) {
-                // grab text after description
-                String value = ObjectHelper.after(line, "\"description\": \"");
-                if (value != null) {
-                    int lastQuote = value.lastIndexOf('"');
-                    value = value.substring(0, lastQuote);
-                    value = StringHelper.removeLeadingAndEndingQuotes(value);
-                    return value;
-                }
-            }
-        }
-        return null;
-    }
-
-    /**
      * Parses the json schema to split it into a list or rows, where each row 
contains key value pairs with the metadata
      *
      * @param json the json

http://git-wip-us.apache.org/repos/asf/camel/blob/5f5a29b8/tooling/apt/src/main/java/org/apache/camel/tools/apt/util/JsonSchemaHelper.java
----------------------------------------------------------------------
diff --git 
a/tooling/apt/src/main/java/org/apache/camel/tools/apt/util/JsonSchemaHelper.java
 
b/tooling/apt/src/main/java/org/apache/camel/tools/apt/util/JsonSchemaHelper.java
index 0549d22..5646dee 100644
--- 
a/tooling/apt/src/main/java/org/apache/camel/tools/apt/util/JsonSchemaHelper.java
+++ 
b/tooling/apt/src/main/java/org/apache/camel/tools/apt/util/JsonSchemaHelper.java
@@ -37,6 +37,7 @@ public final class JsonSchemaHelper {
 
         if ("enum".equals(typeName)) {
             sb.append(doubleQuote("string"));
+            sb.append(", \"javaType\": \"" + type + "\"");
             CollectionStringBuffer enumValues = new CollectionStringBuffer();
             for (Object value : enums) {
                 enumValues.append(doubleQuote(value.toString()));
@@ -46,8 +47,10 @@ public final class JsonSchemaHelper {
             sb.append(" ]");
         } else if ("array".equals(typeName)) {
             sb.append(doubleQuote("array"));
+            sb.append(", \"javaType\": \"" + type + "\"");
         } else {
             sb.append(doubleQuote(typeName));
+            sb.append(", \"javaType\": \"" + type + "\"");
         }
 
         if (!Strings.isNullOrEmpty(description)) {
@@ -56,10 +59,6 @@ public final class JsonSchemaHelper {
             sb.append(doubleQuote(text));
         }
 
-        if ("object".equals(typeName)) {
-            // for object then include the javaType as a description so we 
know that
-            sb.append(", \"properties\": { \"javaType\": { \"description\": 
\"" + type + "\", \"type\": \"string\" } }");
-        }
         sb.append(" }");
         return sb.toString();
     }

Reply via email to