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 c079b4a5cdc7 CAMEL-22931: to only check if can be yaml parsered
c079b4a5cdc7 is described below

commit c079b4a5cdc73afaf6e75205be5cd737541c674d
Author: Claus Ibsen <[email protected]>
AuthorDate: Wed Feb 11 20:51:53 2026 +0100

    CAMEL-22931: to only check if can be yaml parsered
---
 .../camel/dsl/yaml/validator/YamlParser.java       | 48 ++++++++++++++++++++++
 ...{YamlValidatorTest.java => YamlParserTest.java} | 20 ++++-----
 .../dsl/yaml/validator/YamlValidatorTest.java      |  1 -
 .../src/test/resources/parse-bad.yaml              | 25 +++++++++++
 4 files changed, 83 insertions(+), 11 deletions(-)

diff --git 
a/dsl/camel-yaml-dsl/camel-yaml-dsl-validator/src/main/java/org/apache/camel/dsl/yaml/validator/YamlParser.java
 
b/dsl/camel-yaml-dsl/camel-yaml-dsl-validator/src/main/java/org/apache/camel/dsl/yaml/validator/YamlParser.java
new file mode 100644
index 000000000000..ccf1ca30ec2a
--- /dev/null
+++ 
b/dsl/camel-yaml-dsl/camel-yaml-dsl-validator/src/main/java/org/apache/camel/dsl/yaml/validator/YamlParser.java
@@ -0,0 +1,48 @@
+/*
+ * 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.dsl.yaml.validator;
+
+import java.io.File;
+import java.util.Collections;
+import java.util.List;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
+import com.networknt.schema.ValidationMessage;
+
+/**
+ * YAML DSL parser that tooling can use to parse Camel source files to check 
if they can be YAML parsed.
+ *
+ * Notice that this parser can only check if the source can be parsed as YAML, 
but cannot check if any of the content is
+ * correct Camel DSL, such as if EIPs have typos etc.
+ */
+public class YamlParser {
+
+    private final ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
+
+    public List<ValidationMessage> parse(File file) throws Exception {
+        try {
+            mapper.readTree(file);
+            return Collections.emptyList();
+        } catch (Exception e) {
+            ValidationMessage vm = ValidationMessage.builder().type("parser")
+                    .messageSupplier(() -> e.getClass().getName() + ": " + 
e.getMessage()).build();
+            return List.of(vm);
+        }
+    }
+
+}
diff --git 
a/dsl/camel-yaml-dsl/camel-yaml-dsl-validator/src/test/java/org/apache/camel/dsl/yaml/validator/YamlValidatorTest.java
 
b/dsl/camel-yaml-dsl/camel-yaml-dsl-validator/src/test/java/org/apache/camel/dsl/yaml/validator/YamlParserTest.java
similarity index 67%
copy from 
dsl/camel-yaml-dsl/camel-yaml-dsl-validator/src/test/java/org/apache/camel/dsl/yaml/validator/YamlValidatorTest.java
copy to 
dsl/camel-yaml-dsl/camel-yaml-dsl-validator/src/test/java/org/apache/camel/dsl/yaml/validator/YamlParserTest.java
index d53e7a107dc3..a689f97d0048 100644
--- 
a/dsl/camel-yaml-dsl/camel-yaml-dsl-validator/src/test/java/org/apache/camel/dsl/yaml/validator/YamlValidatorTest.java
+++ 
b/dsl/camel-yaml-dsl/camel-yaml-dsl-validator/src/test/java/org/apache/camel/dsl/yaml/validator/YamlParserTest.java
@@ -22,27 +22,27 @@ import org.junit.jupiter.api.Assertions;
 import org.junit.jupiter.api.BeforeAll;
 import org.junit.jupiter.api.Test;
 
-public class YamlValidatorTest {
+public class YamlParserTest {
 
-    private static YamlValidator validator;
+    private static YamlParser parser;
 
     @BeforeAll
     public static void setup() throws Exception {
-        validator = new YamlValidator();
-        validator.init();
+        parser = new YamlParser();
     }
 
     @Test
-    public void testValidateOk() throws Exception {
-        Assertions.assertTrue(validator.validate(new 
File("src/test/resources/foo.yaml")).isEmpty());
+    public void testParseOk() throws Exception {
+        Assertions.assertTrue(parser.parse(new 
File("src/test/resources/foo.yaml")).isEmpty());
+        Assertions.assertTrue(parser.parse(new 
File("src/test/resources/bad.yaml")).isEmpty());
     }
 
     @Test
-    public void testValidateBad() throws Exception {
-        var report = validator.validate(new 
File("src/test/resources/bad.yaml"));
+    public void testParseBad() throws Exception {
+        var report = parser.parse(new 
File("src/test/resources/parse-bad.yaml"));
         Assertions.assertFalse(report.isEmpty());
         Assertions.assertEquals(1, report.size());
-        
Assertions.assertTrue(report.get(0).getMessage().contains("setCheese"));
-        System.out.println(report);
+        Assertions.assertTrue(report.get(0).getMessage().contains("while 
parsing a block mapping"));
+        Assertions.assertTrue(report.get(0).getMessage().contains("- 
setBody:"));
     }
 }
diff --git 
a/dsl/camel-yaml-dsl/camel-yaml-dsl-validator/src/test/java/org/apache/camel/dsl/yaml/validator/YamlValidatorTest.java
 
b/dsl/camel-yaml-dsl/camel-yaml-dsl-validator/src/test/java/org/apache/camel/dsl/yaml/validator/YamlValidatorTest.java
index d53e7a107dc3..5c6ca2e6c963 100644
--- 
a/dsl/camel-yaml-dsl/camel-yaml-dsl-validator/src/test/java/org/apache/camel/dsl/yaml/validator/YamlValidatorTest.java
+++ 
b/dsl/camel-yaml-dsl/camel-yaml-dsl-validator/src/test/java/org/apache/camel/dsl/yaml/validator/YamlValidatorTest.java
@@ -43,6 +43,5 @@ public class YamlValidatorTest {
         Assertions.assertFalse(report.isEmpty());
         Assertions.assertEquals(1, report.size());
         
Assertions.assertTrue(report.get(0).getMessage().contains("setCheese"));
-        System.out.println(report);
     }
 }
diff --git 
a/dsl/camel-yaml-dsl/camel-yaml-dsl-validator/src/test/resources/parse-bad.yaml 
b/dsl/camel-yaml-dsl/camel-yaml-dsl-validator/src/test/resources/parse-bad.yaml
new file mode 100644
index 000000000000..a78b7d66d6f9
--- /dev/null
+++ 
b/dsl/camel-yaml-dsl/camel-yaml-dsl-validator/src/test/resources/parse-bad.yaml
@@ -0,0 +1,25 @@
+#
+# 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.
+#
+
+- route:
+    from:
+      uri: timer:yaml
+      parameters:
+        period: "1000"
+      - setBody:
+          simple: Hello Camel from ${routeId}
+      - log: ${body}
\ No newline at end of file

Reply via email to