Repository: camel Updated Branches: refs/heads/master daaf1e157 -> 55de48785
CAMEL-7999: apt plugin - fixed issue around default values being a double quote sign. Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/9481a551 Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/9481a551 Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/9481a551 Branch: refs/heads/master Commit: 9481a5515c89f1c6d6ecffcbaadd09de2bd060ab Parents: daaf1e1 Author: Claus Ibsen <[email protected]> Authored: Fri Jan 30 13:24:20 2015 +0100 Committer: Claus Ibsen <[email protected]> Committed: Fri Jan 30 13:24:20 2015 +0100 ---------------------------------------------------------------------- .../model/dataformat/FlatpackDataFormat.java | 2 +- .../org/apache/camel/util/JsonSchemaHelper.java | 6 ++++ ...ponentConfigurationAndDocumentationTest.java | 37 ++++++++++++++++++++ .../camel/maven/packaging/JSonSchemaHelper.java | 6 ++++ 4 files changed, 50 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/9481a551/camel-core/src/main/java/org/apache/camel/model/dataformat/FlatpackDataFormat.java ---------------------------------------------------------------------- diff --git a/camel-core/src/main/java/org/apache/camel/model/dataformat/FlatpackDataFormat.java b/camel-core/src/main/java/org/apache/camel/model/dataformat/FlatpackDataFormat.java index 1463581..0b6f85e 100644 --- a/camel-core/src/main/java/org/apache/camel/model/dataformat/FlatpackDataFormat.java +++ b/camel-core/src/main/java/org/apache/camel/model/dataformat/FlatpackDataFormat.java @@ -109,7 +109,7 @@ public class FlatpackDataFormat extends DataFormatDefinition { } /** - * If the text is qualified with a char such as " + * If the text is qualified with a char such as " */ public void setTextQualifier(String textQualifier) { this.textQualifier = textQualifier; http://git-wip-us.apache.org/repos/asf/camel/blob/9481a551/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 9f56d66..c8049ab 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 @@ -31,6 +31,7 @@ import java.util.regex.Pattern; public final class JsonSchemaHelper { private static final Pattern PATTERN = Pattern.compile("\"(.+?)\"|\\[(.+)\\]"); + private static final String QUOT = """; private JsonSchemaHelper() { } @@ -143,6 +144,9 @@ public final class JsonSchemaHelper { break; } + // need to safe encode \" so we can parse the line + line = line.replaceAll("\\\\\"", QUOT); + Map<String, String> row = new LinkedHashMap<String, String>(); Matcher matcher = PATTERN.matcher(line); @@ -166,6 +170,8 @@ public final class JsonSchemaHelper { } if (value != null) { value = value.trim(); + // encode back + value = value.replaceAll(QUOT, "\""); } row.put(key, value); // reset http://git-wip-us.apache.org/repos/asf/camel/blob/9481a551/camel-core/src/test/java/org/apache/camel/component/dataformat/DataFormatComponentConfigurationAndDocumentationTest.java ---------------------------------------------------------------------- diff --git a/camel-core/src/test/java/org/apache/camel/component/dataformat/DataFormatComponentConfigurationAndDocumentationTest.java b/camel-core/src/test/java/org/apache/camel/component/dataformat/DataFormatComponentConfigurationAndDocumentationTest.java index e48ed30..2d7973f 100644 --- a/camel-core/src/test/java/org/apache/camel/component/dataformat/DataFormatComponentConfigurationAndDocumentationTest.java +++ b/camel-core/src/test/java/org/apache/camel/component/dataformat/DataFormatComponentConfigurationAndDocumentationTest.java @@ -16,11 +16,15 @@ */ package org.apache.camel.component.dataformat; +import java.util.List; +import java.util.Map; + import org.apache.camel.CamelContext; import org.apache.camel.ComponentConfiguration; import org.apache.camel.ContextTestSupport; import org.apache.camel.EndpointConfiguration; import org.apache.camel.impl.DefaultCamelContext; +import org.apache.camel.util.JsonSchemaHelper; import org.junit.Test; public class DataFormatComponentConfigurationAndDocumentationTest extends ContextTestSupport { @@ -52,4 +56,37 @@ public class DataFormatComponentConfigurationAndDocumentationTest extends Contex assertNotNull("Should have found some auto-generated HTML", html); } + public void testFlatpackDefaultValue() throws Exception { + CamelContext context = new DefaultCamelContext(); + String json = context.getEipParameterJsonSchema("flatpack"); + assertNotNull(json); + System.out.println(json); + + assertTrue(json.contains("\"name\": \"flatpack")); + + // the default value is a bit tricky as its ", which is written escaped as \" + assertTrue(json.contains("\"textQualifier\": { \"kind\": \"attribute\", \"required\": \"false\", \"type\": \"string\"" + + ", \"javaType\": \"java.lang.String\", \"deprecated\": \"false\", \"defaultValue\": \"\\\"\"")); + + List<Map<String, String>> rows = JsonSchemaHelper.parseJsonSchema("properties", json, true); + assertEquals(9, rows.size()); + + Map<String, String> found = null; + for (Map<String, String> row : rows) { + if ("textQualifier".equals(row.get("name"))) { + found = row; + break; + } + } + assertNotNull(found); + assertEquals("textQualifier", found.get("name")); + assertEquals("attribute", found.get("kind")); + assertEquals("false", found.get("required")); + assertEquals("string", found.get("type")); + assertEquals("java.lang.String", found.get("javaType")); + assertEquals("false", found.get("deprecated")); + assertEquals("\"", found.get("defaultValue")); + assertEquals("If the text is qualified with a char such as "", found.get("description")); + } + } http://git-wip-us.apache.org/repos/asf/camel/blob/9481a551/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/JSonSchemaHelper.java ---------------------------------------------------------------------- diff --git a/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/JSonSchemaHelper.java b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/JSonSchemaHelper.java index a4be2ec..8acf615 100644 --- a/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/JSonSchemaHelper.java +++ b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/JSonSchemaHelper.java @@ -26,6 +26,7 @@ import java.util.regex.Pattern; public final class JSonSchemaHelper { private static final Pattern PATTERN = Pattern.compile("\"(.+?)\"|\\[(.+)\\]"); + private static final String QUOT = """; private JSonSchemaHelper() { } @@ -60,6 +61,9 @@ public final class JSonSchemaHelper { break; } + // need to safe encode \" so we can parse the line + line = line.replaceAll("\\\\\"", QUOT); + Map<String, String> row = new LinkedHashMap<String, String>(); Matcher matcher = PATTERN.matcher(line); @@ -83,6 +87,8 @@ public final class JSonSchemaHelper { } if (value != null) { value = value.trim(); + // encode back + value = value.replaceAll(QUOT, "\""); } row.put(key, value); // reset
