ammachado opened a new pull request, #26921: URL: https://github.com/apache/camel/pull/26921
# Description [CAMEL-24704](https://issues.apache.org/jira/browse/CAMEL-24704): the YAML DSL now accepts `beans` written as a map keyed by the bean name, next to the canonical list: ```yaml - beans: myProcessor: type: "#class:com.example.MyProcessor" ``` This is the shape people and models write first; it was rejected with "object found, array expected". The map form is accepted at the top level, in `routeTemplate` and in `templatedRoute`. The list stays the canonical form: `camelYamlDsl-canonical.json` (and `camelYamlDsl-model.json` derived from it) is unchanged, and the YAML Camel writes still uses the list. **Schema** - New `@YamlProperty.mapKey()` (`tooling/spi-annotations`, copied into `camel-api`, `@since 4.23`): marks a list whose items may also be written as a map keyed by that property. Only the schema generator reads it; the deserializer of the property accepts the map form itself. - `GenerateYamlSchemaMojo`, non-canonical only: such a property becomes `oneOf [array, object]`, with a synthesized `BeanFactoryDefinitionByName` (the bean definition without `name`) for the map values. The mojo fails the build if the item definition is missing or two properties give the same item type different keys. - `beans` (top level, `routeTemplate`, `templatedRoute`) is marked with `mapKey = "name"`. **Runtime** - `BeansDeserializer.asBeanDefinitions(Node)` reads either form and is used by the three deserializers (including the pre-parse). A map entry is read as the list item `- name: <key>` followed by its properties, so every existing check, the `#class:` prefix and the pre-parse dedup cache behave the same. - Errors name the bean: `name:` inside a map-form bean, a name declared twice, and an entry without properties under it. A list-form bean written without its `- ` keeps a "beans is a list" message instead of being read as a bean called `name`. **Validator and camel-jbang** - `SchemaHints`: the missing-`- ` bean keeps its "beans is a list" hint under the new `oneOf`, and the `id:`/`class:` hint also covers map-form beans. - `BeanRefChecks`: `declaredBeans` and `declaredBeanTypes` recognize map-form names through one shared `beans:` block scanner. `declaredBeanTypes` used to bind every `type:` in the file to the last `name:` seen, which could attribute a bean's type to another bean; it now stays inside `beans:` blocks. **Docs** - `yaml-dsl.adoc`: a NOTE with a fragment example of the map form. It is written as a fragment on purpose, so the doc sample generator does not offer it as a `beans` sample in `camel_catalog_sample`; the samples keep teaching the list. - Upgrade guide 4.23: tools that read `camelYamlDsl.json` (editors such as Kaoto) and expect `beans` to be `type: array` need to handle the `oneOf`. Out of scope, as the JIRA suggests doing them one at a time: the other name-keyed lists (`setHeaders`, `setVariables`, template `parameters`, rest `param`, ...). With `mapKey` in place, each is an annotation plus its deserializer branch. **Tests**: map form at the top level, in `routeTemplate` and in `templatedRoute`; empty map; quoted and dotted names; no double registration through the pre-parse; the error cases above; lenient vs canonical validation; the validator hints; the jbang bean reference and bean type checks. Results on the final head: camel-yaml-dsl 419/419, camel-yaml-dsl-validator 155/155, camel-yaml-dsl-maven-plugin 2/2, camel-jbang-core `ai.*` 268 run, 0 failures, 1 skipped (`ExpressionEvaluatorLanguageTest`, an existing skip). # Target - [x] I checked that the commit is targeting the correct branch (Camel 4 uses the `main` branch) # Tracking - [x] If this is a large change, bug fix, or code improvement, I checked there is a [JIRA issue](https://issues.apache.org/jira/browse/CAMEL) filed for the change (usually before you start working on it). # Apache Camel coding standards and style - [x] I checked that each commit in the pull request has a meaningful subject line and body. - [ ] I have run `mvn clean install -DskipTests` locally from root folder and I have committed all auto-generated changes. Not from the root folder: I built the touched modules (`tooling/spi-annotations`, `core/camel-api`, the four `dsl/camel-yaml-dsl` modules, `catalog/camel-catalog`, `dsl/camel-jbang/camel-jbang-core`, `dsl/camel-jbang/camel-jbang-plugin-tui`), committed the regenerated `camelYamlDsl.json`, `YamlProperty` copy and catalog `yaml-dsl.adoc`, and `git status` was clean afterwards. # AI-assisted contributions - [x] If this PR includes AI-generated code, commits have proper co-authorship attribution (e.g., `Co-authored-by` trailers) and the PR description identifies the AI tool used. 🤖 Generated with [Claude Code](https://claude.com/claude-code) on behalf of Adriano Machado (@ammachado) _This was generated by an AI agent and may contain inaccuracies. Please verify before relying on it._ -- 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]
