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

davsclaus 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 ae152fb6df01 CAMEL-23593: Fix YAML dump for REST DSL and 
routeConfigurations (#23393)
ae152fb6df01 is described below

commit ae152fb6df016d4bd65c4c8321fbc3df8f639b70
Author: Claus Ibsen <[email protected]>
AuthorDate: Thu May 21 09:58:52 2026 +0200

    CAMEL-23593: Fix YAML dump for REST DSL and routeConfigurations (#23393)
    
    * CAMEL-23593: camel-yaml-io - Fix YAML dump for REST DSL and 
routeConfigurations
    
    The YamlWriter only special-cased "routes" and "dataFormats" as root
    container elements. When dumping REST DSL or routeConfiguration blocks,
    startElement/endElement fell through to the EipModel lookup path,
    producing empty objects like "rests: {}" or "routeConfigurations: {}".
    
    Add "rests" and "routeConfigurations" to the container name checks in
    both startElement() and endElement(), and fix NPE in the normalize
    command by wiring up the MavenResolverMixin.
    
    Co-Authored-By: Claude <[email protected]>
    
    * CAMEL-23593: camel-yaml-io - Fix circuitBreaker config placement in YAML 
dump
    
    The resilience4jConfiguration and faultToleranceConfiguration were
    incorrectly placed inside the circuitBreaker steps list instead of
    as direct properties. Add special-case handling in YamlWriter to
    treat them as configuration properties, following the same pattern
    used for resequence batchConfig/streamConfig.
    
    Co-Authored-By: Claude <[email protected]>
    
    ---------
    
    Co-authored-by: Claude <[email protected]>
---
 .../java/org/apache/camel/yaml/io/YamlWriter.java  | 27 ++++++++++++++++++----
 .../commands/validate/YamlNormalizeCommand.java    |  5 ++++
 2 files changed, 28 insertions(+), 4 deletions(-)

diff --git 
a/core/camel-yaml-io/src/main/java/org/apache/camel/yaml/io/YamlWriter.java 
b/core/camel-yaml-io/src/main/java/org/apache/camel/yaml/io/YamlWriter.java
index e9cf74145946..dc698a21e304 100644
--- a/core/camel-yaml-io/src/main/java/org/apache/camel/yaml/io/YamlWriter.java
+++ b/core/camel-yaml-io/src/main/java/org/apache/camel/yaml/io/YamlWriter.java
@@ -106,8 +106,8 @@ public class YamlWriter extends ServiceSupport implements 
CamelContextAware {
     }
 
     public void startElement(String name) throws IOException {
-        if ("routes".equals(name) || "dataFormats".equals(name)) {
-            // special for routes or dataFormats
+        if ("routes".equals(name) || "rests".equals(name) || 
"routeConfigurations".equals(name)
+                || "dataFormats".equals(name)) {
             routesIsRoot = true;
             return;
         }
@@ -138,8 +138,8 @@ public class YamlWriter extends ServiceSupport implements 
CamelContextAware {
     }
 
     public void endElement(String name) throws IOException {
-        if ("routes".equals(name) || "dataFormats".equals(name)) {
-            // we are done
+        if ("routes".equals(name) || "rests".equals(name) || 
"routeConfigurations".equals(name)
+                || "dataFormats".equals(name)) {
             writer.write(toYaml());
             return;
         }
@@ -228,6 +228,10 @@ public class YamlWriter extends ServiceSupport implements 
CamelContextAware {
                         && ("batchConfig".equals(name) || 
"streamConfig".equals(name))) {
                     // special for resequence
                     setMetadata(parent, "resequenceConfig", last);
+                } else if ("circuitBreaker".equals(parent.getName())
+                        && ("resilience4jConfiguration".equals(name)
+                                || 
"faultToleranceConfiguration".equals(name))) {
+                    setMetadata(parent, name, last);
                 } else if (parent.isOutput()) {
                     List<EipModel> list = (List<EipModel>) 
parent.getMetadata().get("_output");
                     if (list == null) {
@@ -368,6 +372,21 @@ public class YamlWriter extends ServiceSupport implements 
CamelContextAware {
                 if (!jo.isEmpty()) {
                     node.addProperty(config.getName(), jo);
                 }
+            } else if ("circuitBreaker".equals(node.getName())
+                    && ("resilience4jConfiguration".equals(key)
+                            || "faultToleranceConfiguration".equals(key))) {
+                EipModel config = (EipModel) entry.getValue();
+                JsonObject jo = new JsonObject();
+                for (var o : config.getOptions()) {
+                    String n = o.getName();
+                    Object v = config.getMetadata().get(n);
+                    if (v != null) {
+                        jo.put(n, v);
+                    }
+                }
+                if (!jo.isEmpty()) {
+                    node.addProperty(config.getName(), jo);
+                }
             } else if ("choice".equals(node.getName()) && 
"otherwise".equals(key)) {
                 EipModel other = (EipModel) entry.getValue();
                 node.addOutput(asNode(other));
diff --git 
a/dsl/camel-jbang/camel-jbang-plugin-validate/src/main/java/org/apache/camel/dsl/jbang/core/commands/validate/YamlNormalizeCommand.java
 
b/dsl/camel-jbang/camel-jbang-plugin-validate/src/main/java/org/apache/camel/dsl/jbang/core/commands/validate/YamlNormalizeCommand.java
index 9281ccfafd59..8e569c2eed00 100644
--- 
a/dsl/camel-jbang/camel-jbang-plugin-validate/src/main/java/org/apache/camel/dsl/jbang/core/commands/validate/YamlNormalizeCommand.java
+++ 
b/dsl/camel-jbang/camel-jbang-plugin-validate/src/main/java/org/apache/camel/dsl/jbang/core/commands/validate/YamlNormalizeCommand.java
@@ -26,6 +26,7 @@ import java.util.Stack;
 
 import org.apache.camel.dsl.jbang.core.commands.CamelCommand;
 import org.apache.camel.dsl.jbang.core.commands.CamelJBangMain;
+import org.apache.camel.dsl.jbang.core.commands.MavenResolverMixin;
 import org.apache.camel.dsl.jbang.core.commands.Run;
 import org.apache.camel.dsl.jbang.core.common.CamelJBangConstants;
 import org.apache.camel.dsl.jbang.core.common.CommandLineHelper;
@@ -41,6 +42,9 @@ public class YamlNormalizeCommand extends CamelCommand {
 
     private static final String IGNORE_FILE = "application";
 
+    @CommandLine.Mixin
+    MavenResolverMixin mavenResolver;
+
     @CommandLine.Option(names = { "--output" },
                         description = "File or directory to write normalized 
output. If not specified, output is printed to console.")
     private String output;
@@ -86,6 +90,7 @@ public class YamlNormalizeCommand extends CamelCommand {
                 main.addInitialProperty("camel.language.bean.validate", 
"false");
             }
         };
+        run.mavenResolver = mavenResolver;
         run.files = matched;
         run.executionLimitOptions.maxSeconds = 1;
         Integer exit = run.runTransform(true);

Reply via email to