This is an automated email from the ASF dual-hosted git repository.

igarashitm pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git


The following commit(s) were added to refs/heads/main by this push:
     new d9452d61f26 [CAMEL-19836] camel-yaml-dsl: schema: fix 
routeConfiguration/{onException,onCompletion,intercept,interceptFrom,interceptSendToEndpoint}
 (#11309)
d9452d61f26 is described below

commit d9452d61f269772c77978620db24f28c2ed7c6c5
Author: Tomohisa Igarashi <tm.igara...@gmail.com>
AuthorDate: Wed Sep 6 06:29:26 2023 -0400

    [CAMEL-19836] camel-yaml-dsl: schema: fix 
routeConfiguration/{onException,onCompletion,intercept,interceptFrom,interceptSendToEndpoint}
 (#11309)
---
 .../apache/camel/spi/annotations/YamlProperty.java |  2 +
 .../RouteConfigurationDefinitionDeserializer.java  | 14 +++--
 .../maven/dsl/yaml/GenerateYamlSchemaMojo.java     | 69 +++++++++++++++-------
 .../generated/resources/schema/camelYamlDsl.json   | 35 +++++++++--
 .../apache/camel/spi/annotations/YamlProperty.java |  2 +
 5 files changed, 91 insertions(+), 31 deletions(-)

diff --git 
a/core/camel-api/src/generated/java/org/apache/camel/spi/annotations/YamlProperty.java
 
b/core/camel-api/src/generated/java/org/apache/camel/spi/annotations/YamlProperty.java
index 922b0d7ea79..764b5b4031e 100644
--- 
a/core/camel-api/src/generated/java/org/apache/camel/spi/annotations/YamlProperty.java
+++ 
b/core/camel-api/src/generated/java/org/apache/camel/spi/annotations/YamlProperty.java
@@ -43,4 +43,6 @@ public @interface YamlProperty {
     String[] values() default {};
 
     String oneOf() default "";
+
+    boolean wrapItem() default false;
 }
diff --git 
a/dsl/camel-yaml-dsl/camel-yaml-dsl-deserializers/src/main/java/org/apache/camel/dsl/yaml/deserializers/RouteConfigurationDefinitionDeserializer.java
 
b/dsl/camel-yaml-dsl/camel-yaml-dsl-deserializers/src/main/java/org/apache/camel/dsl/yaml/deserializers/RouteConfigurationDefinitionDeserializer.java
index eefeb01df99..efecc25942a 100644
--- 
a/dsl/camel-yaml-dsl/camel-yaml-dsl-deserializers/src/main/java/org/apache/camel/dsl/yaml/deserializers/RouteConfigurationDefinitionDeserializer.java
+++ 
b/dsl/camel-yaml-dsl/camel-yaml-dsl-deserializers/src/main/java/org/apache/camel/dsl/yaml/deserializers/RouteConfigurationDefinitionDeserializer.java
@@ -44,12 +44,16 @@ import org.snakeyaml.engine.v2.nodes.NodeTuple;
                   @YamlProperty(name = "id", type = "string"),
                   @YamlProperty(name = "precondition", type = "string"),
                   @YamlProperty(name = "error-handler", type = 
"object:org.apache.camel.model.ErrorHandlerDefinition"),
-                  @YamlProperty(name = "intercept", type = 
"array:org.apache.camel.model.InterceptDefinition"),
-                  @YamlProperty(name = "intercept-from", type = 
"array:org.apache.camel.model.InterceptFromDefinition"),
-                  @YamlProperty(name = "intercept-send-to-endpoint",
+                  @YamlProperty(name = "intercept", wrapItem = true,
+                                type = 
"array:org.apache.camel.model.InterceptDefinition"),
+                  @YamlProperty(name = "intercept-from", wrapItem = true,
+                                type = 
"array:org.apache.camel.model.InterceptFromDefinition"),
+                  @YamlProperty(name = "intercept-send-to-endpoint", wrapItem 
= true,
                                 type = 
"array:org.apache.camel.model.InterceptSendToEndpointDefinition"),
-                  @YamlProperty(name = "on-completion", type = 
"array:org.apache.camel.model.OnCompletionDefinition"),
-                  @YamlProperty(name = "on-exception", type = 
"array:org.apache.camel.model.OnExceptionDefinition")
+                  @YamlProperty(name = "on-completion", wrapItem = true,
+                                type = 
"array:org.apache.camel.model.OnCompletionDefinition"),
+                  @YamlProperty(name = "on-exception", wrapItem = true,
+                                type = 
"array:org.apache.camel.model.OnExceptionDefinition")
           })
 public class RouteConfigurationDefinitionDeserializer extends 
YamlDeserializerBase<RouteConfigurationDefinition> {
     public RouteConfigurationDefinitionDeserializer() {
diff --git 
a/dsl/camel-yaml-dsl/camel-yaml-dsl-maven-plugin/src/main/java/org/apache/camel/maven/dsl/yaml/GenerateYamlSchemaMojo.java
 
b/dsl/camel-yaml-dsl/camel-yaml-dsl-maven-plugin/src/main/java/org/apache/camel/maven/dsl/yaml/GenerateYamlSchemaMojo.java
index 6f49eab9dda..281c211dfc9 100644
--- 
a/dsl/camel-yaml-dsl/camel-yaml-dsl-maven-plugin/src/main/java/org/apache/camel/maven/dsl/yaml/GenerateYamlSchemaMojo.java
+++ 
b/dsl/camel-yaml-dsl/camel-yaml-dsl-maven-plugin/src/main/java/org/apache/camel/maven/dsl/yaml/GenerateYamlSchemaMojo.java
@@ -235,6 +235,9 @@ public class GenerateYamlSchemaMojo extends 
GenerateYamlSupportMojo {
             final String propertyOneOf = annotationValue(property, "oneOf")
                     .map(AnnotationValue::asString)
                     .orElse("");
+            final boolean propertyWrapItem = annotationValue(property, 
"wrapItem")
+                    .map(AnnotationValue::asBoolean)
+                    .orElse(false);
 
             boolean isInOneOf = !StringUtils.isEmpty(propertyOneOf);
             if (isInOneOf) {
@@ -297,7 +300,8 @@ public class GenerateYamlSchemaMojo extends 
GenerateYamlSupportMojo {
                     propertyDisplayName,
                     propertyDefaultValue,
                     propertyFormat,
-                    propertyDeprecated);
+                    propertyDeprecated,
+                    propertyWrapItem);
 
             if (propertyRequired) {
                 String name = kebabCase ? propertyName : 
StringHelper.dashToCamelCase(propertyName);
@@ -320,26 +324,34 @@ public class GenerateYamlSchemaMojo extends 
GenerateYamlSupportMojo {
             if (node.has("required")) {
                 required = node.withArray("required");
             }
-            Map<String, JsonNode> rebuild = new LinkedHashMap<>();
-            // the properties are in mixed kebab-case and camelCase
-            for (Iterator<String> it = props.fieldNames(); it.hasNext();) {
-                String n = it.next();
-                String t = StringHelper.dashToCamelCase(n);
-                JsonNode prop = props.get(n);
-                rebuild.put(t, prop);
-                if (required != null) {
-                    for (int i = 0; i < required.size(); i++) {
-                        String r = required.get(i).asText();
-                        if (r.equals(n)) {
-                            required.set(i, t);
-                        }
+            kebabToCamelCaseProperties(props, required);
+        }
+    }
+
+    private void kebabToCamelCaseProperties(ObjectNode props, ArrayNode 
required) {
+        Map<String, JsonNode> rebuild = new LinkedHashMap<>();
+        // the properties are in mixed kebab-case and camelCase
+        for (Iterator<String> it = props.fieldNames(); it.hasNext();) {
+            String n = it.next();
+            String t = StringHelper.dashToCamelCase(n);
+            JsonNode prop = props.get(n);
+            JsonNode subProps = prop.findPath("properties");
+            if (!subProps.isMissingNode()) {
+                kebabToCamelCaseProperties((ObjectNode) subProps, null);
+            }
+            rebuild.put(t, prop);
+            if (required != null) {
+                for (int i = 0; i < required.size(); i++) {
+                    String r = required.get(i).asText();
+                    if (r.equals(n)) {
+                        required.set(i, t);
                     }
                 }
             }
-            if (!rebuild.isEmpty()) {
-                props.removeAll();
-                rebuild.forEach(props::set);
-            }
+        }
+        if (!rebuild.isEmpty()) {
+            props.removeAll();
+            rebuild.forEach(props::set);
         }
     }
 
@@ -351,7 +363,8 @@ public class GenerateYamlSchemaMojo extends 
GenerateYamlSupportMojo {
             String propertyDisplayName,
             String propertyDefaultValue,
             String propertyFormat,
-            boolean deprecated) {
+            boolean deprecated,
+            boolean wrapItem) {
 
         final ObjectNode current = objectDefinition.withObject("/properties/" 
+ propertyName);
         current.put("type", propertyType);
@@ -385,9 +398,23 @@ public class GenerateYamlSchemaMojo extends 
GenerateYamlSupportMojo {
 
             String arrayType = StringHelper.after(propertyType, ":");
             if (arrayType.contains(".")) {
-                current.withObject("/items").put("$ref", 
"#/items/definitions/" + arrayType);
+                if (wrapItem) {
+                    current.withObject("/items")
+                            .put("type", "object")
+                            .withObject("/properties/" + propertyName)
+                            .put("$ref", "#/items/definitions/" + arrayType);
+                } else {
+                    current.withObject("/items").put("$ref", 
"#/items/definitions/" + arrayType);
+                }
             } else {
-                current.withObject("/items").put("type", arrayType);
+                if (wrapItem) {
+                    current.withObject("/items")
+                            .put("type", "object")
+                            .withObject("/properties/" + propertyName)
+                            .put("type", arrayType);
+                } else {
+                    current.withObject("/items").put("type", arrayType);
+                }
             }
         } else if (propertyType.startsWith("enum:")) {
 
diff --git 
a/dsl/camel-yaml-dsl/camel-yaml-dsl/src/generated/resources/schema/camelYamlDsl.json
 
b/dsl/camel-yaml-dsl/camel-yaml-dsl/src/generated/resources/schema/camelYamlDsl.json
index fea10503fad..3c3b0ac7d31 100644
--- 
a/dsl/camel-yaml-dsl/camel-yaml-dsl/src/generated/resources/schema/camelYamlDsl.json
+++ 
b/dsl/camel-yaml-dsl/camel-yaml-dsl/src/generated/resources/schema/camelYamlDsl.json
@@ -4702,31 +4702,56 @@
           "intercept" : {
             "type" : "array",
             "items" : {
-              "$ref" : 
"#/items/definitions/org.apache.camel.model.InterceptDefinition"
+              "type" : "object",
+              "properties" : {
+                "intercept" : {
+                  "$ref" : 
"#/items/definitions/org.apache.camel.model.InterceptDefinition"
+                }
+              }
             }
           },
           "interceptFrom" : {
             "type" : "array",
             "items" : {
-              "$ref" : 
"#/items/definitions/org.apache.camel.model.InterceptFromDefinition"
+              "type" : "object",
+              "properties" : {
+                "interceptFrom" : {
+                  "$ref" : 
"#/items/definitions/org.apache.camel.model.InterceptFromDefinition"
+                }
+              }
             }
           },
           "interceptSendToEndpoint" : {
             "type" : "array",
             "items" : {
-              "$ref" : 
"#/items/definitions/org.apache.camel.model.InterceptSendToEndpointDefinition"
+              "type" : "object",
+              "properties" : {
+                "interceptSendToEndpoint" : {
+                  "$ref" : 
"#/items/definitions/org.apache.camel.model.InterceptSendToEndpointDefinition"
+                }
+              }
             }
           },
           "onCompletion" : {
             "type" : "array",
             "items" : {
-              "$ref" : 
"#/items/definitions/org.apache.camel.model.OnCompletionDefinition"
+              "type" : "object",
+              "properties" : {
+                "onCompletion" : {
+                  "$ref" : 
"#/items/definitions/org.apache.camel.model.OnCompletionDefinition"
+                }
+              }
             }
           },
           "onException" : {
             "type" : "array",
             "items" : {
-              "$ref" : 
"#/items/definitions/org.apache.camel.model.OnExceptionDefinition"
+              "type" : "object",
+              "properties" : {
+                "onException" : {
+                  "$ref" : 
"#/items/definitions/org.apache.camel.model.OnExceptionDefinition"
+                }
+              }
             }
           },
           "precondition" : {
diff --git 
a/tooling/spi-annotations/src/main/java/org/apache/camel/spi/annotations/YamlProperty.java
 
b/tooling/spi-annotations/src/main/java/org/apache/camel/spi/annotations/YamlProperty.java
index 922b0d7ea79..764b5b4031e 100644
--- 
a/tooling/spi-annotations/src/main/java/org/apache/camel/spi/annotations/YamlProperty.java
+++ 
b/tooling/spi-annotations/src/main/java/org/apache/camel/spi/annotations/YamlProperty.java
@@ -43,4 +43,6 @@ public @interface YamlProperty {
     String[] values() default {};
 
     String oneOf() default "";
+
+    boolean wrapItem() default false;
 }

Reply via email to