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-kamelets.git


The following commit(s) were added to refs/heads/main by this push:
     new c7beaecf6 chore: fail the build when a Kamelet is not in canonical 
YAML DSL (#3090)
c7beaecf6 is described below

commit c7beaecf6be3f78149ce26ce90d18ea85f9f0112
Author: Claus Ibsen <[email protected]>
AuthorDate: Tue Oct 6 21:52:51 2026 +0200

    chore: fail the build when a Kamelet is not in canonical YAML DSL (#3090)
    
    * chore: write the Kamelets in canonical YAML DSL
    
    The templates of 187 of the 262 Kamelets used the compact notation, so Camel
    logged "YAML DSL compact notation detected" for every one of them on each 
load
    and reload: a warning a user cannot act on, about a file inside a jar.
    
    Generated with camel validate normalize (apache/camel#27449, CAMEL-25381), 
which
    rewrites only spec.template and keeps the rest of each file as written. The
    Kamelet validator now checks the parameters of from: against the component 
of
    its uri (not the first dependency) and accepts prefixed options such as
    mail.imaps.auth.mechanisms, which the canonical form makes visible to it.
    
    Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
    Claude-Session: https://claude.ai/code/session_01STT6whBgK1AqsSsUKrnE8m
    
    * chore: keep the comments of the Kamelet templates, and normalize them as 
Camel builds the uris
    
    Review: the comments inside spec.template were dropped (82 lines in 16 
Kamelets).
    Regenerated with camel validate normalize from apache/camel#27449 as it is 
now:
    the comments are back where they were, normalizing a normalized Kamelet 
changes
    nothing, azure-storage-files-source is kept as written (an option given two 
path
    parts was broken by the uri Camel builds), and the options are in the order 
Camel
    builds them with secret options in RAW(), as the YAML DSL wraps them.
    
    Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
    Claude-Session: https://claude.ai/code/session_01STT6whBgK1AqsSsUKrnE8m
    
    * chore: fail the build when a Kamelet is not in canonical YAML DSL
    
    KameletsCanonicalTest loads every file of kamelets/ with the YAML DSL and 
fails
    when Camel logs "YAML DSL compact notation detected" for one, naming them 
and
    how to normalize them. On main before the canonical Kamelets it reports the 
187
    compact ones.
    
    Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
    Claude-Session: https://claude.ai/code/session_01STT6whBgK1AqsSsUKrnE8m
    
    ---------
    
    Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
---
 library/camel-kamelets-catalog/pom.xml             | 13 +++
 .../kamelets/catalog/KameletsCanonicalTest.java    | 95 ++++++++++++++++++++++
 2 files changed, 108 insertions(+)

diff --git a/library/camel-kamelets-catalog/pom.xml 
b/library/camel-kamelets-catalog/pom.xml
index b5017a6fd..08796eca4 100644
--- a/library/camel-kamelets-catalog/pom.xml
+++ b/library/camel-kamelets-catalog/pom.xml
@@ -111,6 +111,19 @@
             <scope>test</scope>
             <version>${junit-jupiter-version}</version>
         </dependency>
+        <!-- KameletsCanonicalTest: loads every Kamelet with the YAML DSL to 
find the compact notation -->
+        <dependency>
+            <groupId>org.apache.camel</groupId>
+            <artifactId>camel-core-engine</artifactId>
+            <version>${camel.version}</version>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.camel</groupId>
+            <artifactId>camel-yaml-dsl</artifactId>
+            <version>${camel.version}</version>
+            <scope>test</scope>
+        </dependency>
         <dependency>
             <groupId>org.apache.camel</groupId>
             <artifactId>camel-tooling-model</artifactId>
diff --git 
a/library/camel-kamelets-catalog/src/test/java/org/apache/camel/kamelets/catalog/KameletsCanonicalTest.java
 
b/library/camel-kamelets-catalog/src/test/java/org/apache/camel/kamelets/catalog/KameletsCanonicalTest.java
new file mode 100644
index 000000000..c2de452e3
--- /dev/null
+++ 
b/library/camel-kamelets-catalog/src/test/java/org/apache/camel/kamelets/catalog/KameletsCanonicalTest.java
@@ -0,0 +1,95 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.kamelets.catalog;
+
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.stream.Stream;
+
+import org.apache.camel.impl.DefaultCamelContext;
+import org.apache.camel.support.PluginHelper;
+import org.apache.camel.support.ResourceHelper;
+import org.apache.logging.log4j.Level;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.core.LogEvent;
+import org.apache.logging.log4j.core.Logger;
+import org.apache.logging.log4j.core.appender.AbstractAppender;
+import org.apache.logging.log4j.core.config.Property;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+/**
+ * Every Kamelet is written in the canonical YAML DSL: Camel logs "YAML DSL 
compact notation detected" for a template
+ * in the compact notation, on every load and reload, to a user who cannot 
change a file inside the catalog jar. A
+ * Kamelet is normalized with: camel validate normalize --output=kamelets 
kamelets/my-kamelet.kamelet.yaml
+ */
+public class KameletsCanonicalTest {
+
+    // the source files, not the catalog jar: Camel does not warn about a file 
inside a jar
+    private static final Path KAMELETS = Path.of("../../kamelets");
+
+    private final List<String> warnings = new ArrayList<>();
+    private AbstractAppender appender;
+
+    @BeforeEach
+    void captureWarnings() {
+        appender = new AbstractAppender("compact-notation", null, null, false, 
Property.EMPTY_ARRAY) {
+            @Override
+            public void append(LogEvent event) {
+                if (event.getLevel() == Level.WARN
+                        && 
event.getMessage().getFormattedMessage().contains("compact notation")) {
+                    warnings.add(event.getMessage().getFormattedMessage());
+                }
+            }
+        };
+        appender.start();
+        ((Logger) LogManager.getRootLogger()).addAppender(appender);
+    }
+
+    @AfterEach
+    void stopCapturing() {
+        ((Logger) LogManager.getRootLogger()).removeAppender(appender);
+        appender.stop();
+    }
+
+    @Test
+    void everyKameletIsCanonical() throws Exception {
+        List<Path> files;
+        try (Stream<Path> s = Files.list(KAMELETS)) {
+            files = s.filter(p -> 
p.getFileName().toString().endsWith(".kamelet.yaml")).sorted().toList();
+        }
+        assertTrue(files.size() > 200, "the Kamelets of " + 
KAMELETS.toAbsolutePath().normalize());
+        List<String> compact = new ArrayList<>();
+        for (Path file : files) {
+            warnings.clear();
+            try (DefaultCamelContext context = new DefaultCamelContext()) {
+                PluginHelper.getRoutesLoader(context)
+                        .loadRoutes(ResourceHelper.resolveResource(context, 
"file:" + file.toAbsolutePath()));
+            }
+            if (!warnings.isEmpty()) {
+                compact.add(file.getFileName().toString());
+            }
+        }
+        assertTrue(compact.isEmpty(), compact.size() + " Kamelet(s) in the 
compact notation, normalize them with"
+                + " camel validate normalize --output=kamelets 
kamelets/<name>.kamelet.yaml: " + compact);
+    }
+}

Reply via email to