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-upgrade-recipes.git


The following commit(s) were added to refs/heads/main by this push:
     new d985c3c  Limit YamlDsl413Recipe to Camel YAML DSL files (#93)
d985c3c is described below

commit d985c3c6277f42b6fcb1bdcc1488cb58ce18ffb1
Author: Tim te Beek <[email protected]>
AuthorDate: Fri Apr 17 14:55:31 2026 +0200

    Limit YamlDsl413Recipe to Camel YAML DSL files (#93)
    
    * Limit YamlDsl413Recipe to Camel YAML DSL files
    
    Previously the recipe rewrote kebab-case keys in every YAML file on the
    classpath, including GitHub Actions workflows, Kubernetes manifests and
    other unrelated YAML. Add a content-based precondition that only triggers
    the rewrite when a document's root block contains a known Camel YAML DSL
    key (route, from, rest, beans, route-configuration, etc.).
    
    _Claude Code on behalf of Tim te Beek_
    
    * Drop expected cycle count for Spring Boot yamlFile test
    
    With YamlDsl413Recipe now gated on Camel YAML DSL root keys, the Spring
    Boot application.yaml no longer goes through a kebab-to-camelCase pass
    before UpdateCamelSpringBootPropertiesAndYamlKeys runs. The latter
    already handles case conversion via ChangePropertyKeyWithCaseChange,
    so the recipe stabilizes in one cycle instead of two. The final output
    is unchanged.
    
    _Claude Code on behalf of Tim te Beek_
    
    * Keep kebab-case in yamlFile test expectation
    
    With YamlDsl413Recipe now gated on Camel YAML DSL root keys, the Spring
    Boot application.yaml is no longer kebab-to-camelCased as a side effect.
    The explicit rename camel.springboot.main-run-controller -> 
camel.main.run-controller
    preserves its kebab-case form, matching the .properties test and the
    examples.yml example output.
    
    _Claude Code on behalf of Tim te Beek_
---
 .../upgrade/springboot/CamelSpringBoot413Test.java |  8 ++--
 .../camel/upgrade/camel413/YamlDsl413Recipe.java   | 45 +++++++++++++++++++++-
 .../apache/camel/upgrade/CamelUpdate413Test.java   | 44 +++++++++++++++++++++
 3 files changed, 91 insertions(+), 6 deletions(-)

diff --git 
a/camel-spring-boot-upgrade-recipes/src/test/java/org/apache/camel/upgrade/springboot/CamelSpringBoot413Test.java
 
b/camel-spring-boot-upgrade-recipes/src/test/java/org/apache/camel/upgrade/springboot/CamelSpringBoot413Test.java
index 7bde988..cad8e94 100644
--- 
a/camel-spring-boot-upgrade-recipes/src/test/java/org/apache/camel/upgrade/springboot/CamelSpringBoot413Test.java
+++ 
b/camel-spring-boot-upgrade-recipes/src/test/java/org/apache/camel/upgrade/springboot/CamelSpringBoot413Test.java
@@ -60,9 +60,9 @@ class CamelSpringBoot413Test implements RewriteTest {
     @Test
     void yamlFile() {
         rewriteRun(
-                //both 
org.apache.camel.upgrade.camel413.CamelSpringBootMigrationRecipe and
-                // 
org.apache.camel.upgrade.UpdateCamelSpringBootPropertiesAndYamlKeys modifies 
this properties
-                spec -> spec.expectedCyclesThatMakeChanges(2),
+                //only 
org.apache.camel.upgrade.UpdateCamelSpringBootPropertiesAndYamlKeys modifies 
this file;
+                // YamlDsl413Recipe is gated on Camel YAML DSL root keys and 
does not apply to Spring Boot application.yaml
+                spec -> spec.expectedCyclesThatMakeChanges(1),
             yaml(
                     """
                       camel:
@@ -82,7 +82,7 @@ class CamelSpringBoot413Test implements RewriteTest {
                             name: 'Foo'
                           routecontroller.backOffMultiplier: 5
                           routecontroller.backOffDelay: true
-                          main.runController: something
+                          main.run-controller: something
                         another:
                           ignored:
                             property: true
diff --git 
a/camel-upgrade-recipes/src/main/java/org/apache/camel/upgrade/camel413/YamlDsl413Recipe.java
 
b/camel-upgrade-recipes/src/main/java/org/apache/camel/upgrade/camel413/YamlDsl413Recipe.java
index 635d4d6..9c7593d 100644
--- 
a/camel-upgrade-recipes/src/main/java/org/apache/camel/upgrade/camel413/YamlDsl413Recipe.java
+++ 
b/camel-upgrade-recipes/src/main/java/org/apache/camel/upgrade/camel413/YamlDsl413Recipe.java
@@ -21,10 +21,15 @@ import lombok.Value;
 import org.apache.camel.upgrade.AbstractCamelYamlVisitor;
 import org.apache.camel.upgrade.RecipesUtil;
 import org.openrewrite.ExecutionContext;
+import org.openrewrite.Preconditions;
 import org.openrewrite.Recipe;
 import org.openrewrite.TreeVisitor;
+import org.openrewrite.marker.SearchResult;
+import org.openrewrite.yaml.YamlIsoVisitor;
 import org.openrewrite.yaml.tree.Yaml;
 
+import java.util.Set;
+
 /**
  * <p>
  * <a 
href="https://camel.apache.org/manual/camel-4x-upgrade-guide-4_13.html#_camel_yaml_dsl";>YML
 DSL</a>
@@ -35,6 +40,19 @@ import org.openrewrite.yaml.tree.Yaml;
 @Value
 public class YamlDsl413Recipe extends Recipe {
 
+    // Root-level keys that identify a YAML document as Camel YAML DSL,
+    // so the rewrite does not touch unrelated YAML (Kubernetes, GitHub 
Actions, Helm, etc.).
+    private static final Set<String> CAMEL_DSL_ROOT_KEYS = Set.of(
+            "route", "routes", "from", "rest", "beans",
+            "route-configuration", "routeConfiguration",
+            "route-template", "routeTemplate",
+            "templated-route", "templatedRoute",
+            "rest-configuration", "restConfiguration",
+            "error-handler", "errorHandler",
+            "on-exception", "onException",
+            "intercept", "intercept-from", "interceptFrom",
+            "intercept-send-to-endpoint", "interceptSendToEndpoint");
+
     @Override
     public String getDisplayName() {
         return "Camel YML DSL changes";
@@ -48,7 +66,17 @@ public class YamlDsl413Recipe extends Recipe {
     @Override
     public TreeVisitor<?, ExecutionContext> getVisitor() {
 
-        return new AbstractCamelYamlVisitor() {
+        TreeVisitor<?, ExecutionContext> camelYamlDslCheck = new 
YamlIsoVisitor<ExecutionContext>() {
+            @Override
+            public Yaml.Document visitDocument(Yaml.Document document, 
ExecutionContext ctx) {
+                if (hasCamelRootKey(document.getBlock())) {
+                    return SearchResult.found(document);
+                }
+                return document;
+            }
+        };
+
+        return Preconditions.check(camelYamlDslCheck, new 
AbstractCamelYamlVisitor() {
 
             @Override
             protected void clearLocalCache() {
@@ -77,7 +105,20 @@ public class YamlDsl413Recipe extends Recipe {
                 return e;
             }
 
-        };
+        });
+    }
+
+    private static boolean hasCamelRootKey(Yaml.Block block) {
+        if (block instanceof Yaml.Mapping) {
+            return ((Yaml.Mapping) block).getEntries().stream()
+                    .anyMatch(entry -> 
CAMEL_DSL_ROOT_KEYS.contains(entry.getKey().getValue()));
+        }
+        if (block instanceof Yaml.Sequence) {
+            return ((Yaml.Sequence) block).getEntries().stream()
+                    .map(Yaml.Sequence.Entry::getBlock)
+                    .anyMatch(YamlDsl413Recipe::hasCamelRootKey);
+        }
+        return false;
     }
 
 }
diff --git 
a/camel-upgrade-recipes/src/test/java/org/apache/camel/upgrade/CamelUpdate413Test.java
 
b/camel-upgrade-recipes/src/test/java/org/apache/camel/upgrade/CamelUpdate413Test.java
index 300b9bd..a8cde71 100644
--- 
a/camel-upgrade-recipes/src/test/java/org/apache/camel/upgrade/CamelUpdate413Test.java
+++ 
b/camel-upgrade-recipes/src/test/java/org/apache/camel/upgrade/CamelUpdate413Test.java
@@ -78,6 +78,50 @@ public class CamelUpdate413Test implements RewriteTest {
             """));
     }
 
+    /**
+     * Non-Camel YAML (GitHub Actions workflow, Kubernetes manifest) must not 
be rewritten
+     * even when it contains kebab-case keys.
+     */
+    @Test
+    void yamlDslLeavesUnrelatedYamlAlone() {
+        rewriteRun(
+          //language=yaml
+          yaml(
+            """
+              name: CI
+              on:
+                push:
+                  branches: [main]
+              jobs:
+                build:
+                  runs-on: ubuntu-latest
+                  steps:
+                    - uses: actions/checkout@v4
+                    - uses: actions/setup-java@v4
+                      with:
+                        distribution: zulu
+                        java-version: '17'
+              """),
+          //language=yaml
+          yaml(
+            """
+              apiVersion: apps/v1
+              kind: Deployment
+              metadata:
+                name: my-app
+              spec:
+                replicas: 1
+                selector:
+                  match-labels:
+                    app: my-app
+                template:
+                  spec:
+                    containers:
+                      - name: app
+                        image-pull-policy: IfNotPresent
+              """));
+    }
+
     /**
      * <a 
href="https://camel.apache.org/manual/camel-4x-upgrade-guide-4_13.html#_camel_http";>camel-http</a>
      */

Reply via email to