CAMEL-22987: Add canonical YAML DSL JSON Schema variant#22059
CAMEL-22987: Add canonical YAML DSL JSON Schema variant#22059
Conversation
|
🌟 Thank you for your contribution to the Apache Camel project! 🌟 🐫 Apache Camel Committers, please review the following items:
|
|
🧪 CI tested the following changed modules:
All tested modules (40 modules)
|
|
✅ Parent POM dependency changes: targeted tests passed Changed properties: smallrye-fault-tolerance-version Affected modules (1)
|
2ea6aa0 to
81903c5
Compare
|
The CI failure here is caused by flaky This should be fixed by #22081 which addresses the SMB test issues. Once that's merged, re-running CI here should go green. |
apupier
left a comment
There was a problem hiding this comment.
I think it will be worthy that some people from Kaoto review also this PR to see if the strict way is matching what is supported currently, or at least if there is no blocker to support it easily.
//cc @lordrip
Note that we will need to change the default when exporting from Camel JBang, updating most examples and publish it along the other one in Json schemastore
|
Hi @apupier, thanks for the heads up 🙏 From our side, given that we still need to keep backward compatibility, we'll continue generating the catalogs out of the previous schema (full one). Nevertheless, this is a very interesting change for introducing a "strict mode" in Kaoto were all the shorthand will be flaggeg. Food for thought, @gnodet, do you think this could be the standard for a new major version? I know it would be a breaking change, but the syntax will thank you 😄 |
There was a problem hiding this comment.
based on @lordrip comment, there won't be any problems with Kaoto (even be simpler)
it remains all the surroundings to have it useful in practice (json schema store, when to change the default?, update all examples?, provide migration steps?)
given the age of the PR and that there is genrated code based on the model, i think it will be worthy to rebase the PR to avoid breaking the main branch due to uncommitted change)
Add a strict JSON Schema variant (camelYamlDsl-strict.json) that removes
all implicit patterns from the YAML DSL schema:
- No string shorthands (e.g. log: "${body}" must be log: { message: ... })
- No inline expressions (e.g. setBody: { simple: ... } must use expression wrapper)
- No oneOf/anyOf/not constructs
This results in a ~25% smaller schema that is significantly easier for
tooling (IDEs, code generators, AI assistants) to process.
Changes:
- GenerateYamlSchemaMojo: add strict parameter to skip inline, __extends, oneOf
- pom.xml: add second execution to generate strict schema
- YamlValidator: add strict constructor to validate against strict schema
- 7 new tests validating strict vs classic schema behavior
- Documentation in yaml-dsl.adoc and upgrade guide
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
cd56b88 to
db987f9
Compare
… normalize command - Rename "strict" to "canonical" throughout: schema filename, Java API, tests, docs, and upgrade guide - Add --canonical flag to `camel validate yaml` command - Add `camel validate normalize` command that rewrites YAML routes from shorthand to canonical (explicit) form - Update documentation with normalize and validate --canonical examples Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
db987f9 to
d2ee856
Compare
…hema examples - Add JBang command docs: camel-jbang-validate, validate-yaml, validate-normalize - Register validate command in the JBang commands reference index - Expand yaml-dsl.adoc with side-by-side classic vs canonical examples for log, setBody, setHeader, choice/when, and complete route patterns - Document how to use the canonical schema with IDEs Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The camel-jbang-commands.adoc is auto-generated by camel-package-maven-plugin. Manual edits get overwritten during build, causing CI to fail with "uncommitted changes". The validate command docs are cross-referenced from the yaml-dsl.adoc documentation instead. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…assic Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…mand docs Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
@apupier Thanks for the review and approval! Since your review, the PR has been significantly expanded based on your feedback and further discussion: Changes since your last review:
Re: "when to make canonical the default?" — the classic schema remains the default everywhere (SchemaStore, Would appreciate a re-review of the expanded changeset when you get a chance! Claude Code on behalf of Guillaume Nodet |
...te/src/main/java/org/apache/camel/dsl/jbang/core/commands/validate/YamlNormalizeCommand.java
Outdated
Show resolved
Hide resolved
...te/src/main/java/org/apache/camel/dsl/jbang/core/commands/validate/YamlNormalizeCommand.java
Outdated
Show resolved
Hide resolved
...te/src/main/java/org/apache/camel/dsl/jbang/core/commands/validate/YamlNormalizeCommand.java
Outdated
Show resolved
Hide resolved
...te/src/main/java/org/apache/camel/dsl/jbang/core/commands/validate/YamlNormalizeCommand.java
Outdated
Show resolved
Hide resolved
...te/src/main/java/org/apache/camel/dsl/jbang/core/commands/validate/YamlNormalizeCommand.java
Outdated
Show resolved
Hide resolved
- Use printErr for error messages instead of stdout - Continue processing remaining files on error instead of aborting - Use try-with-resources for CamelContext - Extract type converter registry to local variable - Use camelCase property names instead of dashed notation Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
…ml-schema # Conflicts: # dsl/camel-yaml-dsl/camel-yaml-dsl-validator/src/main/java/org/apache/camel/dsl/yaml/validator/YamlValidator.java
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
… main Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>


Summary
Adds a canonical variant of the Camel YAML DSL JSON Schema (
camelYamlDsl-canonical.json) that removes alloneOf/anyOf/notconstructs and implicit patterns. This results in a schema ~25% smaller that is significantly easier for tooling (IDEs, code generators, AI assistants) to process.The canonical form is a strict subset of the classic form: any YAML file that validates against the canonical schema will also validate against the classic schema and work with the Camel runtime.
Changes
canonicalparameter inGenerateYamlSchemaMojothat suppresses inline shorthands,oneOfgrouping, and__extendsmergingschema/camelYamlDsl-canonical.jsonalongside the existing classic schemaYamlValidatorsupports both schemas vianew YamlValidator(canonical)constructorcamel validate yaml --canonical: Validates YAML routes against the canonical schema (rejects shorthands/implicit expressions)camel validate normalize: Rewrites YAML routes from shorthand to canonical form (loads routes via CamelContext, dumps back viaModelToYAMLDumper)yaml-dsl.adocwith 5 tabbed side-by-side classic vs canonical examplesvalidate yamlandvalidate normalizewith usage examples and sample outputNaming
Renamed from "strict" to "canonical" based on review feedback — "canonical" better conveys "the explicit, unambiguous form" rather than implying the classic form is "wrong."
Schema Store
The classic schema is already registered in SchemaStore for
*.camel.yaml/*.camelk.yaml. A follow-up PR to SchemaStore can register the canonical variant URL once this is merged.Default schema
The classic schema remains the default everywhere:
*.camel.yaml)YamlValidator()no-arg constructorcamel validate yamlcommand (without--canonicalflag)ValidateMojo)TransformTools)Whether to make canonical the default (e.g., in a future major version) is an open community discussion.
Test plan
YamlCanonicalValidatorTest— validates canonical schema accepts explicit forms, rejects shorthandsYamlValidatorTest— ensures classic schema still works