davsclaus opened a new pull request, #26513:
URL: https://github.com/apache/camel/pull/26513

   Resolves [CAMEL-24775](https://issues.apache.org/jira/browse/CAMEL-24775). 
Found while checking the documentation examples (CAMEL-24773, #26512): the 
`<templateBean scriptLanguage="groovy">` blocks of the 
route-template-bean-binding page have no `type`, which `camel-spring.xsd` 
rejects while the runtime and the Java DSL do not need it.
   
   ## Why `type` was required
   `BeanFactoryDefinition.type` has been `@XmlAttribute(required = true)` since 
CAMEL-17611 (4.0), when `type` was the *kind* selector (`#class`, `#type`, 
`bean`, `groovy`, `joor`, `mvel`…). CAMEL-19953 (4.1) moved the kind to 
`scriptLanguage` and redefined `type` as the class name, but the `required` 
stayed. For a bean created by a script the class is optional: 
`BeanModelHelper.bind()` (route template and kamelet local beans) already falls 
back to `Object.class`, and the Java DSL `templateBean(name, language, script)` 
sets no type at all — that is what `KameletLocalBeanGroovyTest`, 
`KameletEipAggregateGroovyTest` and friends run.
   
   The one annotation fans out to four generated artifacts, and they disagreed 
with the runtime: `camel-spring.xsd` (Spring XML rejects a scripted bean 
without type), `camel-xml-io.xsd` (the xml-io parser accepts it), 
`camelYamlDsl.json` (the YAML validator, `camel validate`, the TUI and the MCP 
tools reject it; the YAML runtime loader has its own hard check and rejects it 
too), and the catalog `beanFactory.json` (every doc table says required). Every 
test fixture happened to set `type`, which is why nothing caught it.
   
   ## Change
   - **model** — `type` is no longer `required`; its description says when it 
is needed: "Required unless the bean is created by a script (`scriptLanguage`) 
or a builder (`builderClass`), where the type is optional and is then the type 
the bean is registered as"
   - **`BeanModelHelper.newInstance()`** (`<beans><bean>`) — matches `bind()`: 
`Object.class` fallback for the script path, null-safe builder path, and a 
class or factory bean without a type fails with `IllegalArgumentException: Bean 
myBean must have a type (class name) unless created by a script or a builder` 
instead of the `NullPointerException` at `type.startsWith("#")` it threw before
   - **`BeansDeserializer`** (YAML `beans:`) — the `notNull(type)` check only 
applies to a bean that is neither scripted nor built
   - **regenerated** — `beanFactory.json` (model and catalog), 
`camel-spring.xsd`, `camel-xml-io.xsd`, the YAML deserializers and the three 
YAML schemas: `"required": ["name"]`
   - **tests** — xml-io: a scripted bean, a builder bean, and a plain bean 
without type (the last one asserts the new exception); YAML loader: `beans:` 
and `routeTemplate:` scripted beans without type; YAML validator: `beans:`, a 
builder bean and a `routeTemplate:` scripted bean without type validate; Spring 
XML: `SpringTemplatedRouteScriptBeanNoTypeTest` loads a scripted bean without 
type against the regenerated XSD
   - **upgrade guide 4.23** — the schema relaxation and the new exception
   
   Run: camel-core route template tests (857), camel-xml-io-dsl (66), 
camel-yaml-dsl (430), camel-yaml-dsl-validator, camel-spring-xml route template 
tests — all pass.
   
   JAXB/XSD cannot express "required unless `scriptLanguage`", so 
optional-with-a-runtime-check is the only encoding that matches what Camel does.
   
   _Claude Code on behalf of @davsclaus_
   
   🤖 Generated with [Claude Code](https://claude.com/claude-code)
   


-- 
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]

Reply via email to