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 2016/01/04 21:52:52 UTC

[5/6] camel git commit: Camel component docs - Should include information if an endpoint is lenient properties

Camel component docs - Should include information if an endpoint is lenient properties


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

Branch: refs/heads/camel-2.16.x
Commit: ab77d3d8991500df785b75766cd61e8a6efd38d0
Parents: 7d6eaf2
Author: Claus Ibsen <da...@apache.org>
Authored: Mon Jan 4 21:31:52 2016 +0100
Committer: Claus Ibsen <da...@apache.org>
Committed: Mon Jan 4 21:48:08 2016 +0100

----------------------------------------------------------------------
 .../camel/catalog/DefaultCamelCatalog.java      | 21 +++++++++++++++-----
 .../apache/camel/catalog/JSonSchemaHelper.java  |  9 +++++++++
 .../apache/camel/catalog/CamelCatalogTest.java  |  4 ++++
 3 files changed, 29 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/ab77d3d8/platforms/catalog/src/main/java/org/apache/camel/catalog/DefaultCamelCatalog.java
----------------------------------------------------------------------
diff --git a/platforms/catalog/src/main/java/org/apache/camel/catalog/DefaultCamelCatalog.java b/platforms/catalog/src/main/java/org/apache/camel/catalog/DefaultCamelCatalog.java
index 79a50bf..83b9c58 100644
--- a/platforms/catalog/src/main/java/org/apache/camel/catalog/DefaultCamelCatalog.java
+++ b/platforms/catalog/src/main/java/org/apache/camel/catalog/DefaultCamelCatalog.java
@@ -50,6 +50,7 @@ import static org.apache.camel.catalog.JSonSchemaHelper.getPropertyKind;
 import static org.apache.camel.catalog.JSonSchemaHelper.getPropertyNameFromNameWithPrefix;
 import static org.apache.camel.catalog.JSonSchemaHelper.getPropertyPrefix;
 import static org.apache.camel.catalog.JSonSchemaHelper.getRow;
+import static org.apache.camel.catalog.JSonSchemaHelper.isComponentLenientProperties;
 import static org.apache.camel.catalog.JSonSchemaHelper.isPropertyBoolean;
 import static org.apache.camel.catalog.JSonSchemaHelper.isPropertyInteger;
 import static org.apache.camel.catalog.JSonSchemaHelper.isPropertyMultiValue;
@@ -736,6 +737,7 @@ public class DefaultCamelCatalog implements CamelCatalog {
 
         Map<String, String> properties;
         List<Map<String, String>> rows;
+        boolean lenientProperties;
 
         try {
             // parse the uri
@@ -746,6 +748,10 @@ public class DefaultCamelCatalog implements CamelCatalog {
                 result.addUnknownComponent(scheme);
                 return result;
             }
+
+            rows = JSonSchemaHelper.parseJsonSchema("component", json, false);
+            lenientProperties = isComponentLenientProperties(rows);
+
             rows = JSonSchemaHelper.parseJsonSchema("properties", json, true);
             properties = endpointProperties(uri);
         } catch (URISyntaxException e) {
@@ -778,11 +784,16 @@ public class DefaultCamelCatalog implements CamelCatalog {
             Map<String, String> row = getRow(rows, name);
             if (row == null) {
                 // unknown option
-                result.addUnknown(name);
-                if (suggestionStrategy != null) {
-                    String[] suggestions = suggestionStrategy.suggestEndpointOptions(getNames(rows), name);
-                    if (suggestions != null) {
-                        result.addUnknownSuggestions(name, suggestions);
+
+                // only add as error if the component is not lenient properties
+                // as if we are lenient then the option is a dynamic extra option which we cannot validate
+                if (!lenientProperties) {
+                    result.addUnknown(name);
+                    if (suggestionStrategy != null) {
+                        String[] suggestions = suggestionStrategy.suggestEndpointOptions(getNames(rows), name);
+                        if (suggestions != null) {
+                            result.addUnknownSuggestions(name, suggestions);
+                        }
                     }
                 }
             } else {

http://git-wip-us.apache.org/repos/asf/camel/blob/ab77d3d8/platforms/catalog/src/main/java/org/apache/camel/catalog/JSonSchemaHelper.java
----------------------------------------------------------------------
diff --git a/platforms/catalog/src/main/java/org/apache/camel/catalog/JSonSchemaHelper.java b/platforms/catalog/src/main/java/org/apache/camel/catalog/JSonSchemaHelper.java
index 4e4624a..3a31027 100644
--- a/platforms/catalog/src/main/java/org/apache/camel/catalog/JSonSchemaHelper.java
+++ b/platforms/catalog/src/main/java/org/apache/camel/catalog/JSonSchemaHelper.java
@@ -114,6 +114,15 @@ public final class JSonSchemaHelper {
         return value;
     }
 
+    public static boolean isComponentLenientProperties(List<Map<String, String>> rows) {
+        for (Map<String, String> row : rows) {
+            if (row.containsKey("lenientProperties")) {
+                return "true".equals(row.get("lenientProperties"));
+            }
+        }
+        return false;
+    }
+
     public static boolean isPropertyRequired(List<Map<String, String>> rows, String name) {
         for (Map<String, String> row : rows) {
             boolean required = false;

http://git-wip-us.apache.org/repos/asf/camel/blob/ab77d3d8/platforms/catalog/src/test/java/org/apache/camel/catalog/CamelCatalogTest.java
----------------------------------------------------------------------
diff --git a/platforms/catalog/src/test/java/org/apache/camel/catalog/CamelCatalogTest.java b/platforms/catalog/src/test/java/org/apache/camel/catalog/CamelCatalogTest.java
index 28c8cef..fc804aa 100644
--- a/platforms/catalog/src/test/java/org/apache/camel/catalog/CamelCatalogTest.java
+++ b/platforms/catalog/src/test/java/org/apache/camel/catalog/CamelCatalogTest.java
@@ -484,6 +484,10 @@ public class CamelCatalogTest {
         // prefix
         result = catalog.validateEndpointProperties("file:inbox?delay=5000&scheduler.foo=123&scheduler.bar=456");
         assertTrue(result.isSuccess());
+
+        // lenient
+        result = catalog.validateEndpointProperties("stub:foo?me=123&you=456");
+        assertTrue(result.isSuccess());
     }
 
     @Test