davsclaus opened a new pull request, #27227:
URL: https://github.com/apache/camel/pull/27227
A `.kamelet.yaml` is a YAML **object**, not the list of entries a route file
is, so the route schema failed every one of them:
```
object found, array expected (a Camel YAML file is a list of entries, each
starting
with "- ": - route:, - from:, - beans:, - rest:, - onException:)
```
That reached three surfaces — `camel validate yaml`,
`camel_validate_source`, and `YamlLoadFailureReport` — and because
`camel_write_file` and `camel_edit_file` validate before they write, **a custom
Kamelet could not be written through the tools at all**. An agent on the
supported path had to go around them to do it.
It also misdirected when the error was real: a `jq` step written as a step
of its own fails in the loader *at the step*, and the report printed the array
hint at the envelope instead, pointing away from the fault.
## The change
The validator compiles a second schema for a Kamelet, built from the route
schema so that one stays the source of truth. The route schema's `items` node
is kept at `/items` so the `#/items/definitions/...` references inside it still
resolve, and `spec.template` points at it — because the template of a Kamelet
*is* one entry of a route file, which is what `KameletRoutesBuilderLoader`
makes of it.
A document with `kind: Kamelet` is checked against that, everything else
against the route schema as before. One line decides which, so every hint and
extra check that follows is untouched and the locations come out naturally:
```
Line 12: /spec/template/from/steps/0: property 'jq' is not defined in the
schema
and the schema does not allow additional properties (did you mean
'to'?)
```
Correct line, correct path, and the existing "did you mean" hint.
**The envelope is described loosely on purpose.** Camel does not own the
Kamelet CRD, so `metadata.annotations` and `spec` keys it does not read are
accepted as they come rather than failed for being unknown.
## Verified end to end
On the Kamelet from the issue — the one `camel run` executes and logs the
filtered body for:
```
$ camel validate yaml content-filter-action.kamelet.yaml
Validation success (files:1)
camel_write_file -> {"status":"created","lines":23,"bytes":609, ...}
```
Tests: `KameletValidationTest` — a Kamelet that runs is valid; a mistake in
the template is reported in the template with the right line and no "array
expected"; a route file is still validated as a list of entries, and a bare
object still gets the array error; the envelope is not failed for what Camel
does not read. The 175 tests of `camel-yaml-dsl-validator` are green, plus a
full reactor build.
## One thing left for later
`BodyTypeFlow` returns early for a root that is not an array, so the
body-type checks of CAMEL-24844 do not run over a Kamelet's template. Worth
doing, but it wants its own change — this one unblocks authoring.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
https://claude.ai/code/session_01Bp3538HRBPMQkb5ta9xRaj
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]