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 80318815a06b CAMEL-23611: camel-yaml-dsl - Log WARN when compact
notation is detected
80318815a06b is described below
commit 80318815a06bcb958184c9185e9266f9248daa0b
Author: Claus Ibsen <[email protected]>
AuthorDate: Tue May 26 11:35:19 2026 +0200
CAMEL-23611: camel-yaml-dsl - Log WARN when compact notation is detected
Co-Authored-By: Claude Opus 4.6 <[email protected]>
---
.../MainConfigurationPropertiesConfigurer.java | 7 +++++++
.../camel-main-configuration-metadata.json | 1 +
core/camel-main/src/main/docs/main.adoc | 3 ++-
.../camel/main/DefaultConfigurationProperties.java | 24 ++++++++++++++++++++++
.../ROOT/pages/camel-4x-upgrade-guide-4_21.adoc | 5 +++++
.../yaml/common/YamlDeserializationContext.java | 23 +++++++++++++++++++++
.../dsl/yaml/common/YamlDeserializerBase.java | 8 ++++++++
.../camel-yaml-dsl/src/main/docs/yaml-dsl.adoc | 21 +++++++++++++++++++
.../camel/dsl/yaml/YamlRoutesBuilderLoader.java | 1 +
.../dsl/yaml/YamlRoutesBuilderLoaderSupport.java | 9 ++++++++
10 files changed, 101 insertions(+), 1 deletion(-)
diff --git
a/core/camel-main/src/generated/java/org/apache/camel/main/MainConfigurationPropertiesConfigurer.java
b/core/camel-main/src/generated/java/org/apache/camel/main/MainConfigurationPropertiesConfigurer.java
index 6f0c3b4febe3..1f0ddf7f7ff8 100644
---
a/core/camel-main/src/generated/java/org/apache/camel/main/MainConfigurationPropertiesConfigurer.java
+++
b/core/camel-main/src/generated/java/org/apache/camel/main/MainConfigurationPropertiesConfigurer.java
@@ -153,6 +153,7 @@ public class MainConfigurationPropertiesConfigurer extends
org.apache.camel.supp
map.put("UseMdcLogging", boolean.class);
map.put("UuidGenerator", java.lang.String.class);
map.put("VirtualThreadsEnabled", boolean.class);
+ map.put("YamlDslCompactNotationWarn", boolean.class);
ALL_OPTIONS = map;
}
@@ -416,6 +417,8 @@ public class MainConfigurationPropertiesConfigurer extends
org.apache.camel.supp
case "uuidGenerator": target.setUuidGenerator(property(camelContext,
java.lang.String.class, value)); return true;
case "virtualthreadsenabled":
case "virtualThreadsEnabled":
target.setVirtualThreadsEnabled(property(camelContext, boolean.class, value));
return true;
+ case "yamldslcompactnotationwarn":
+ case "yamlDslCompactNotationWarn":
target.setYamlDslCompactNotationWarn(property(camelContext, boolean.class,
value)); return true;
default: return false;
}
}
@@ -684,6 +687,8 @@ public class MainConfigurationPropertiesConfigurer extends
org.apache.camel.supp
case "uuidGenerator": return java.lang.String.class;
case "virtualthreadsenabled":
case "virtualThreadsEnabled": return boolean.class;
+ case "yamldslcompactnotationwarn":
+ case "yamlDslCompactNotationWarn": return boolean.class;
default: return null;
}
}
@@ -948,6 +953,8 @@ public class MainConfigurationPropertiesConfigurer extends
org.apache.camel.supp
case "uuidGenerator": return target.getUuidGenerator();
case "virtualthreadsenabled":
case "virtualThreadsEnabled": return target.isVirtualThreadsEnabled();
+ case "yamldslcompactnotationwarn":
+ case "yamlDslCompactNotationWarn": return
target.isYamlDslCompactNotationWarn();
default: return null;
}
}
diff --git
a/core/camel-main/src/generated/resources/META-INF/camel-main-configuration-metadata.json
b/core/camel-main/src/generated/resources/META-INF/camel-main-configuration-metadata.json
index 492481cf9b4c..9e39a3ecdeff 100644
---
a/core/camel-main/src/generated/resources/META-INF/camel-main-configuration-metadata.json
+++
b/core/camel-main/src/generated/resources/META-INF/camel-main-configuration-metadata.json
@@ -161,6 +161,7 @@
{ "name": "camel.main.useMdcLogging", "required": false, "description":
"To turn on MDC logging (deprecated, use camel-mdc component instead)",
"sourceType": "org.apache.camel.main.DefaultConfigurationProperties", "type":
"boolean", "javaType": "boolean", "defaultValue": false, "secret": false,
"deprecated": true },
{ "name": "camel.main.uuidGenerator", "required": false, "description":
"UUID generator to use. default (32 bytes), short (16 bytes), classic (32 bytes
or longer), simple (long incrementing counter), off (turned off for exchanges -
only intended for performance profiling)", "sourceType":
"org.apache.camel.main.DefaultConfigurationProperties", "type": "enum",
"javaType": "java.lang.String", "defaultValue": "default", "secret": false,
"enum": [ "classic", "default", "short", "simple", [...]
{ "name": "camel.main.virtualThreadsEnabled", "required": false,
"description": "Whether to enable virtual threads when creating thread pools.
When enabled, Camel will use virtual threads instead of platform threads for
its thread pools. This can also be enabled via the JVM system property {code
camel.threads.virtual.enabled=true} . This option must be read early during
bootstrap, so it is set as a system property before thread pools are created.",
"sourceType": "org.apache.camel.mai [...]
+ { "name": "camel.main.yamlDslCompactNotationWarn", "required": false,
"description": "Whether to log a WARN when YAML DSL routes use compact
(shorthand) notation instead of the canonical (explicit\/normalized) form. The
canonical style is recommended as it is more tooling and AI friendly. Use Camel
JBang to normalize existing routes: camel yaml normalize <file>",
"sourceType": "org.apache.camel.main.DefaultConfigurationProperties", "type":
"boolean", "javaType": "boolean", "def [...]
{ "name": "camel.debug.bodyIncludeFiles", "required": false,
"description": "Whether to include the message body of file based messages. The
overhead is that the file content has to be read from the file.", "sourceType":
"org.apache.camel.main.DebuggerConfigurationProperties", "type": "boolean",
"javaType": "boolean", "defaultValue": true, "secret": false },
{ "name": "camel.debug.bodyIncludeStreams", "required": false,
"description": "Whether to include the message body of stream based messages.
If enabled then beware the stream may not be re-readable later. See more about
Stream Caching.", "sourceType":
"org.apache.camel.main.DebuggerConfigurationProperties", "type": "boolean",
"javaType": "boolean", "defaultValue": false, "secret": false },
{ "name": "camel.debug.bodyMaxChars", "required": false, "description":
"To limit the message body to a maximum size in the traced message. Use 0 or
negative value to use unlimited size.", "sourceType":
"org.apache.camel.main.DebuggerConfigurationProperties", "type": "integer",
"javaType": "int", "defaultValue": 32768, "secret": false },
diff --git a/core/camel-main/src/main/docs/main.adoc
b/core/camel-main/src/main/docs/main.adoc
index 7c86e7ea1feb..ba4bd0907e18 100644
--- a/core/camel-main/src/main/docs/main.adoc
+++ b/core/camel-main/src/main/docs/main.adoc
@@ -19,7 +19,7 @@ The following tables lists all the options:
// main options: START
=== Camel Main configurations
-The camel.main supports 131 options, which are listed below.
+The camel.main supports 132 options, which are listed below.
[width="100%",cols="2,5,^1,2",options="header"]
|===
@@ -155,6 +155,7 @@ The camel.main supports 131 options, which are listed below.
| *camel.main.useMdcLogging* | To turn on MDC logging (deprecated, use
camel-mdc component instead) | false | boolean
| *camel.main.uuidGenerator* | UUID generator to use. default (32 bytes),
short (16 bytes), classic (32 bytes or longer), simple (long incrementing
counter), off (turned off for exchanges - only intended for performance
profiling) | default | String
| *camel.main.virtualThreadsEnabled* | Whether to enable virtual threads when
creating thread pools. When enabled, Camel will use virtual threads instead of
platform threads for its thread pools. This can also be enabled via the JVM
system property {code camel.threads.virtual.enabled=true} . This option must be
read early during bootstrap, so it is set as a system property before thread
pools are created. | false | boolean
+| *camel.main.yamlDslCompactNotationWarn* | Whether to log a WARN when YAML
DSL routes use compact (shorthand) notation instead of the canonical
(explicit/normalized) form. The canonical style is recommended as it is more
tooling and AI friendly. Use Camel JBang to normalize existing routes: camel
yaml normalize <file> | true | boolean
|===
diff --git
a/core/camel-main/src/main/java/org/apache/camel/main/DefaultConfigurationProperties.java
b/core/camel-main/src/main/java/org/apache/camel/main/DefaultConfigurationProperties.java
index 32dc30a7b927..b341db33d56f 100644
---
a/core/camel-main/src/main/java/org/apache/camel/main/DefaultConfigurationProperties.java
+++
b/core/camel-main/src/main/java/org/apache/camel/main/DefaultConfigurationProperties.java
@@ -66,6 +66,8 @@ public abstract class DefaultConfigurationProperties<T> {
@Metadata(security = "insecure:dev")
private boolean devConsoleEnabled;
private boolean modeline;
+ @Metadata(defaultValue = "true")
+ private boolean yamlDslCompactNotationWarn = true;
private int logDebugMaxChars;
private boolean streamCachingEnabled = true;
private String streamCachingAllowClasses;
@@ -499,6 +501,19 @@ public abstract class DefaultConfigurationProperties<T> {
this.modeline = modeline;
}
+ public boolean isYamlDslCompactNotationWarn() {
+ return yamlDslCompactNotationWarn;
+ }
+
+ /**
+ * Whether to log a WARN when YAML DSL routes use compact (shorthand)
notation instead of the canonical
+ * (explicit/normalized) form. The canonical style is recommended as it is
more tooling and AI friendly. Use Camel
+ * JBang to normalize existing routes: camel yaml normalize <file>
+ */
+ public void setYamlDslCompactNotationWarn(boolean
yamlDslCompactNotationWarn) {
+ this.yamlDslCompactNotationWarn = yamlDslCompactNotationWarn;
+ }
+
public int getLogDebugMaxChars() {
return logDebugMaxChars;
}
@@ -2000,6 +2015,15 @@ public abstract class DefaultConfigurationProperties<T> {
return (T) this;
}
+ /**
+ * Whether to log a WARN when YAML DSL routes use compact (shorthand)
notation instead of the canonical
+ * (explicit/normalized) form.
+ */
+ public T withYamlDslCompactNotationWarn(boolean
yamlDslCompactNotationWarn) {
+ this.yamlDslCompactNotationWarn = yamlDslCompactNotationWarn;
+ return (T) this;
+ }
+
/**
* Whether to enable developer console (requires camel-console on
classpath).
*
diff --git
a/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_21.adoc
b/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_21.adoc
index cdac43bbd6d6..d5902c60d10d 100644
--- a/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_21.adoc
+++ b/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_21.adoc
@@ -189,6 +189,11 @@ A new `camel yaml normalize` command has been added to
Camel JBang. It rewrites
classic (shorthand) form to the canonical (explicit) form. The `camel validate
yaml` command also
supports a new `--canonical` flag to validate against the canonical schema.
+Camel now logs a WARN message when YAML DSL routes use compact (shorthand)
notation instead of
+the canonical form. This encourages adopting the canonical style which is more
tooling and AI friendly.
+The warning is logged once per resource file. To disable this warning, set
+`camel.main.yamlDslCompactNotationWarn = false` in `application.properties`.
+
=== camel-kafka / Spring Boot
When using `camel-kafka-starter` with Spring Boot, the standard
`spring.kafka.*` properties are now automatically
diff --git
a/dsl/camel-yaml-dsl/camel-yaml-dsl-common/src/main/java/org/apache/camel/dsl/yaml/common/YamlDeserializationContext.java
b/dsl/camel-yaml-dsl/camel-yaml-dsl-common/src/main/java/org/apache/camel/dsl/yaml/common/YamlDeserializationContext.java
index e4882c943b6a..c8f6b3ca4264 100644
---
a/dsl/camel-yaml-dsl/camel-yaml-dsl-common/src/main/java/org/apache/camel/dsl/yaml/common/YamlDeserializationContext.java
+++
b/dsl/camel-yaml-dsl/camel-yaml-dsl-common/src/main/java/org/apache/camel/dsl/yaml/common/YamlDeserializationContext.java
@@ -34,6 +34,7 @@ import
org.apache.camel.dsl.yaml.common.exception.UnknownNodeIdException;
import org.apache.camel.dsl.yaml.common.exception.YamlDeserializationException;
import org.apache.camel.spi.Resource;
import org.apache.camel.util.ObjectHelper;
+import org.slf4j.Logger;
import org.snakeyaml.engine.v2.api.ConstructNode;
import org.snakeyaml.engine.v2.api.LoadSettings;
import org.snakeyaml.engine.v2.constructor.StandardConstructor;
@@ -48,6 +49,8 @@ public class YamlDeserializationContext extends
StandardConstructor implements C
private final Map<String, ConstructNode> constructors;
private CamelContext camelContext;
private Resource resource;
+ private boolean compactNotationWarn = true;
+ private boolean compactNotationWarned;
public YamlDeserializationContext(LoadSettings settings) {
super(settings);
@@ -75,6 +78,26 @@ public class YamlDeserializationContext extends
StandardConstructor implements C
this.resource = resource;
}
+ public boolean isCompactNotationWarn() {
+ return compactNotationWarn;
+ }
+
+ public void setCompactNotationWarn(boolean compactNotationWarn) {
+ this.compactNotationWarn = compactNotationWarn;
+ }
+
+ public void warnCompactNotationOnce(Logger log) {
+ if (compactNotationWarn && !compactNotationWarned) {
+ compactNotationWarned = true;
+ String loc = resource != null ? resource.getLocation() : "unknown";
+ log.warn("YAML DSL compact notation detected in: {}."
+ + " It is recommended to use canonical/normalized YAML
DSL notation"
+ + " which is more tooling and AI friendly."
+ + " Use Camel JBang to normalize: camel yaml normalize
<file>",
+ loc);
+ }
+ }
+
@Override
public CamelContext getCamelContext() {
return camelContext;
diff --git
a/dsl/camel-yaml-dsl/camel-yaml-dsl-common/src/main/java/org/apache/camel/dsl/yaml/common/YamlDeserializerBase.java
b/dsl/camel-yaml-dsl/camel-yaml-dsl-common/src/main/java/org/apache/camel/dsl/yaml/common/YamlDeserializerBase.java
index 0bc1ce97b9e7..b078257335b8 100644
---
a/dsl/camel-yaml-dsl/camel-yaml-dsl-common/src/main/java/org/apache/camel/dsl/yaml/common/YamlDeserializerBase.java
+++
b/dsl/camel-yaml-dsl/camel-yaml-dsl-common/src/main/java/org/apache/camel/dsl/yaml/common/YamlDeserializerBase.java
@@ -21,6 +21,8 @@ import org.apache.camel.LineNumberAware;
import org.apache.camel.dsl.yaml.common.exception.UnsupportedFieldException;
import org.apache.camel.dsl.yaml.common.exception.UnsupportedNodeTypeException;
import org.apache.camel.spi.ResourceAware;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import org.snakeyaml.engine.v2.api.ConstructNode;
import org.snakeyaml.engine.v2.nodes.MappingNode;
import org.snakeyaml.engine.v2.nodes.Node;
@@ -30,6 +32,8 @@ import org.snakeyaml.engine.v2.nodes.ScalarNode;
public abstract class YamlDeserializerBase<T> extends YamlDeserializerSupport
implements ConstructNode {
+ private static final Logger LOG =
LoggerFactory.getLogger(YamlDeserializerBase.class);
+
private final Class<T> type;
protected YamlDeserializerBase(Class<T> type) {
@@ -52,6 +56,10 @@ public abstract class YamlDeserializerBase<T> extends
YamlDeserializerSupport im
if (node.getNodeType() == NodeType.SCALAR) {
ScalarNode mn = (ScalarNode) node;
target = newInstance(mn.getValue());
+ YamlDeserializationContext ctx = getDeserializationContext(node);
+ if (ctx != null) {
+ ctx.warnCompactNotationOnce(LOG);
+ }
// line number points to the scalar itself, so it should be +1
if (line != -1) {
line++;
diff --git a/dsl/camel-yaml-dsl/camel-yaml-dsl/src/main/docs/yaml-dsl.adoc
b/dsl/camel-yaml-dsl/camel-yaml-dsl/src/main/docs/yaml-dsl.adoc
index c8d6684b5519..6b4d76686ff3 100644
--- a/dsl/camel-yaml-dsl/camel-yaml-dsl/src/main/docs/yaml-dsl.adoc
+++ b/dsl/camel-yaml-dsl/camel-yaml-dsl/src/main/docs/yaml-dsl.adoc
@@ -681,6 +681,27 @@ or directory using the `--output` option:
camel validate normalize --output normalized/ myroute.yaml
----
+=== Compact notation warning
+
+Camel logs a WARN message when YAML routes use compact (shorthand) notation
instead of
+the canonical (explicit) form. This is to encourage adopting the canonical
style which is
+more friendly for tooling and AI assistants.
+
+The warning is logged once per resource file and looks like:
+
+----
+YAML DSL compact notation detected in: myroute.yaml.
+It is recommended to use canonical/normalized YAML DSL notation which is more
tooling and AI friendly.
+Use Camel JBang to normalize: camel yaml normalize <file>
+----
+
+To disable this warning, set the following property in
`application.properties`:
+
+[source,properties]
+----
+camel.main.yamlDslCompactNotationWarn = false
+----
+
=== Validating with the canonical schema
To validate YAML routes against the canonical schema:
diff --git
a/dsl/camel-yaml-dsl/camel-yaml-dsl/src/main/java/org/apache/camel/dsl/yaml/YamlRoutesBuilderLoader.java
b/dsl/camel-yaml-dsl/camel-yaml-dsl/src/main/java/org/apache/camel/dsl/yaml/YamlRoutesBuilderLoader.java
index 898af8440dee..16862746b179 100644
---
a/dsl/camel-yaml-dsl/camel-yaml-dsl/src/main/java/org/apache/camel/dsl/yaml/YamlRoutesBuilderLoader.java
+++
b/dsl/camel-yaml-dsl/camel-yaml-dsl/src/main/java/org/apache/camel/dsl/yaml/YamlRoutesBuilderLoader.java
@@ -176,6 +176,7 @@ public class YamlRoutesBuilderLoader extends
YamlRoutesBuilderLoaderSupport {
private boolean doConfigure(Object item) throws Exception {
if (item instanceof OutputAwareFromDefinition) {
+ ctx.warnCompactNotationOnce(LOG);
RouteDefinition route = new RouteDefinition();
route.setInput(((OutputAwareFromDefinition)
item).getDelegate());
route.setOutputs(((OutputAwareFromDefinition)
item).getOutputs());
diff --git
a/dsl/camel-yaml-dsl/camel-yaml-dsl/src/main/java/org/apache/camel/dsl/yaml/YamlRoutesBuilderLoaderSupport.java
b/dsl/camel-yaml-dsl/camel-yaml-dsl/src/main/java/org/apache/camel/dsl/yaml/YamlRoutesBuilderLoaderSupport.java
index 68479b25066f..1e3bb0d5ec70 100644
---
a/dsl/camel-yaml-dsl/camel-yaml-dsl/src/main/java/org/apache/camel/dsl/yaml/YamlRoutesBuilderLoaderSupport.java
+++
b/dsl/camel-yaml-dsl/camel-yaml-dsl/src/main/java/org/apache/camel/dsl/yaml/YamlRoutesBuilderLoaderSupport.java
@@ -58,6 +58,15 @@ public abstract class YamlRoutesBuilderLoaderSupport extends
RouteBuilderLoaderS
ctx.setCamelContext(getCamelContext());
ctx.addResolvers(new CustomResolver(beansDeserializer));
ctx.addResolvers(new ModelDeserializersResolver());
+ // check if compact notation warning is disabled
+ try {
+ String v =
getCamelContext().resolvePropertyPlaceholders("{{?camel.main.yamlDslCompactNotationWarn}}");
+ if (v != null && "false".equalsIgnoreCase(v)) {
+ ctx.setCompactNotationWarn(false);
+ }
+ } catch (Exception e) {
+ // ignore
+ }
return ctx;
}