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

acosentino pushed a commit to branch camel-4.18.x
in repository https://gitbox.apache.org/repos/asf/camel.git


The following commit(s) were added to refs/heads/camel-4.18.x by this push:
     new 0c32c1be89a6 CAMEL-23174 - Kamelet: transformer in aws-ddb-sink is not 
executed (#21933)
0c32c1be89a6 is described below

commit 0c32c1be89a6194f2492a1d59ef92ff9e6f0dc06
Author: Andrea Cosentino <[email protected]>
AuthorDate: Wed Mar 11 13:58:47 2026 +0100

    CAMEL-23174 - Kamelet: transformer in aws-ddb-sink is not executed (#21933)
    
    * CAMEL-23174 - Kamelet: transformer in aws-ddb-sink is not executed
    
    Signed-off-by: Andrea Cosentino <[email protected]>
    
    * CAMEL-23174 - Kamelet: transformer in aws-ddb-sink is not executed
    
    Signed-off-by: Andrea Cosentino <[email protected]>
    
    ---------
    
    Signed-off-by: Andrea Cosentino <[email protected]>
---
 .../camel/dsl/yaml/KameletRoutesBuilderLoader.java |  52 +++++++++
 .../apache/camel/dsl/yaml/KameletLoaderTest.groovy | 118 +++++++++++++++++++++
 2 files changed, 170 insertions(+)

diff --git 
a/dsl/camel-yaml-dsl/camel-yaml-dsl/src/main/java/org/apache/camel/dsl/yaml/KameletRoutesBuilderLoader.java
 
b/dsl/camel-yaml-dsl/camel-yaml-dsl/src/main/java/org/apache/camel/dsl/yaml/KameletRoutesBuilderLoader.java
index 22baf4968b7d..50b0aa75c6e6 100644
--- 
a/dsl/camel-yaml-dsl/camel-yaml-dsl/src/main/java/org/apache/camel/dsl/yaml/KameletRoutesBuilderLoader.java
+++ 
b/dsl/camel-yaml-dsl/camel-yaml-dsl/src/main/java/org/apache/camel/dsl/yaml/KameletRoutesBuilderLoader.java
@@ -31,6 +31,7 @@ import 
org.apache.camel.model.RouteTemplateParameterDefinition;
 import org.apache.camel.spi.CamelContextCustomizer;
 import org.apache.camel.spi.DependencyStrategy;
 import org.apache.camel.spi.annotations.RoutesLoader;
+import org.snakeyaml.engine.v2.nodes.MappingNode;
 import org.snakeyaml.engine.v2.nodes.Node;
 import org.snakeyaml.engine.v2.nodes.NodeTuple;
 
@@ -67,6 +68,12 @@ public class KameletRoutesBuilderLoader extends 
YamlRoutesBuilderLoaderSupport {
         final RouteTemplateDefinition rtd = ctx.construct(template, 
RouteTemplateDefinition.class);
         rtd.id(asText(nodeAt(root, "/metadata/name")));
 
+        // process data types (inputType/outputType) if defined
+        Node dataTypesNode = nodeAt(root, "/spec/dataTypes");
+        if (dataTypesNode != null) {
+            configureDataTypes(asMappingNode(dataTypesNode), rtd);
+        }
+
         Node properties = nodeAt(root, "/spec/definition/properties");
         if (properties != null) {
             rtd.setTemplateParameters(new ArrayList<>());
@@ -101,6 +108,51 @@ public class KameletRoutesBuilderLoader extends 
YamlRoutesBuilderLoaderSupport {
         };
     }
 
+    private void configureDataTypes(MappingNode dataTypes, 
RouteTemplateDefinition rtd) {
+        MappingNode in = asMappingNode(nodeAt(dataTypes, "/in"));
+        if (in != null) {
+            String dataType = extractKameletDataType(in);
+            if (dataType != null) {
+                rtd.route().inputType(dataType);
+            }
+        }
+        MappingNode out = asMappingNode(nodeAt(dataTypes, "/out"));
+        if (out != null) {
+            String dataType = extractKameletDataType(out);
+            if (dataType != null) {
+                rtd.route().outputType(dataType);
+            }
+        }
+    }
+
+    /**
+     * Extracts the data type name from a kamelet dataTypes direction node (in 
or out). The kamelet structure uses a
+     * default type name referencing a types map entry that contains scheme 
and format fields.
+     */
+    private String extractKameletDataType(MappingNode directionNode) {
+        String defaultType = extractTupleValue(directionNode.getValue(), 
"default");
+        if (defaultType == null) {
+            return null;
+        }
+        MappingNode types = asMappingNode(nodeAt(directionNode, "/types"));
+        if (types == null) {
+            return null;
+        }
+        MappingNode typeNode = asMappingNode(nodeAt(types, "/" + defaultType));
+        if (typeNode == null) {
+            return null;
+        }
+        String scheme = extractTupleValue(typeNode.getValue(), "scheme");
+        String format = extractTupleValue(typeNode.getValue(), "format");
+        if (format == null) {
+            return null;
+        }
+        if (scheme != null) {
+            return scheme + ":" + format;
+        }
+        return format;
+    }
+
     private CamelContextCustomizer preConfigureDependencies(Node node) {
         final List<String> dep = YamlDeserializerSupport.asStringList(node);
         return new CamelContextCustomizer() {
diff --git 
a/dsl/camel-yaml-dsl/camel-yaml-dsl/src/test/groovy/org/apache/camel/dsl/yaml/KameletLoaderTest.groovy
 
b/dsl/camel-yaml-dsl/camel-yaml-dsl/src/test/groovy/org/apache/camel/dsl/yaml/KameletLoaderTest.groovy
index aa081e1f6e0d..b341c62d37f2 100644
--- 
a/dsl/camel-yaml-dsl/camel-yaml-dsl/src/test/groovy/org/apache/camel/dsl/yaml/KameletLoaderTest.groovy
+++ 
b/dsl/camel-yaml-dsl/camel-yaml-dsl/src/test/groovy/org/apache/camel/dsl/yaml/KameletLoaderTest.groovy
@@ -333,6 +333,124 @@ class KameletLoaderTest extends YamlTestSupport {
             MockEndpoint.assertIsSatisfied(context)
     }
 
+    def "kamelet with dataTypes input"() {
+        when:
+            loadKamelets('''
+                apiVersion: camel.apache.org/v1
+                kind: Kamelet
+                metadata:
+                  name: my-sink
+                spec:
+                  definition:
+                    title: "My Sink"
+                    required:
+                      - table
+                    properties:
+                      table:
+                        title: Table
+                        type: string
+                  dataTypes:
+                    in:
+                      default: json
+                      types:
+                        json:
+                          scheme: my-component
+                          format: application-json
+                  template:
+                    from:
+                      uri: "kamelet:source"
+                      steps:
+                        - to: "log:test"
+            ''')
+        then:
+            context.routeTemplateDefinitions.size() == 1
+
+            with (context.routeTemplateDefinitions[0]) {
+                id == 'my-sink'
+
+                with(route) {
+                    inputType.urn == 'my-component:application-json'
+                    outputType == null
+                }
+            }
+    }
+
+    def "kamelet with dataTypes input and output"() {
+        when:
+            loadKamelets('''
+                apiVersion: camel.apache.org/v1
+                kind: Kamelet
+                metadata:
+                  name: my-action
+                spec:
+                  definition:
+                    title: "My Action"
+                  dataTypes:
+                    in:
+                      default: json
+                      types:
+                        json:
+                          scheme: my-component
+                          format: application-json
+                    out:
+                      default: binary
+                      types:
+                        binary:
+                          format: application-octet-stream
+                  template:
+                    from:
+                      uri: "kamelet:source"
+                      steps:
+                        - to: "log:test"
+            ''')
+        then:
+            context.routeTemplateDefinitions.size() == 1
+
+            with (context.routeTemplateDefinitions[0]) {
+                id == 'my-action'
+
+                with(route) {
+                    inputType.urn == 'my-component:application-json'
+                    outputType.urn == 'application-octet-stream'
+                }
+            }
+    }
+
+    def "kamelet with dataTypes format only"() {
+        when:
+            loadKamelets('''
+                apiVersion: camel.apache.org/v1
+                kind: Kamelet
+                metadata:
+                  name: my-source
+                spec:
+                  definition:
+                    title: "My Source"
+                  dataTypes:
+                    out:
+                      default: binary
+                      types:
+                        binary:
+                          format: application-octet-stream
+                  template:
+                    from:
+                      uri: "kamelet:source"
+                      steps:
+                        - to: "log:test"
+            ''')
+        then:
+            context.routeTemplateDefinitions.size() == 1
+
+            with (context.routeTemplateDefinitions[0]) {
+                id == 'my-source'
+
+                with(route) {
+                    inputType == null
+                    outputType.urn == 'application-octet-stream'
+                }
+            }
+    }
+
     def "kamelet with bean constructors"() {
         when:
         loadKamelets('''

Reply via email to