[ 
https://issues.apache.org/jira/browse/CAMEL-25492?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18125498#comment-18125498
 ] 

Federico Mariani commented on CAMEL-25492:
------------------------------------------

Not fixed by the CAMEL-25490 PRs 
([#27609|https://github.com/apache/camel/pull/27609], 4.22.x backport 
[#27610|https://github.com/apache/camel/pull/27610]), which only handle 
{{onException}}. Same root cause and same place: once the context scoped 
{{onCompletion}} / {{intercept*}} can be told apart from route scoped ones, the 
fix extends what #27609 does in {{LwModelToYAMLDumper}} (filter them out of 
{{doWriteOutputs}}, write them once as top-level entries, skip those owned by a 
routeConfiguration). Best done after #27609 is merged so it can reuse its 
helpers and the single-file grouping in {{DefaultDumpRoutesStrategy}}.

_Claude Code on behalf of Croway_

> camel-yaml-io - YAML route dump writes top-level onCompletion, intercept, 
> interceptFrom and interceptSendToEndpoint into the steps of each route
> ------------------------------------------------------------------------------------------------------------------------------------------------
>
>                 Key: CAMEL-25492
>                 URL: https://issues.apache.org/jira/browse/CAMEL-25492
>             Project: Camel
>          Issue Type: Bug
>          Components: camel-jbang, camel-yaml-dsl
>    Affects Versions: 4.22.1
>            Reporter: Federico Mariani
>            Assignee: Federico Mariani
>            Priority: Major
>
> {{camel validate normalize}} (the YAML route dump, 
> {{camel.main.dumpRoutes=yaml}}) writes a top-level {{onCompletion}}, 
> {{interceptFrom}}, {{intercept}} or {{interceptSendToEndpoint}} into the 
> steps of each route it applies to. The YAML DSL schema has none of them among 
> the steps of a route (route scoped cross-cutting EIPs are not supported in 
> YAML, see CAMEL-25207), so a valid file becomes invalid. The scope also 
> changes from "all routes of the file" to a copy per route.
> h3. Reproduction (Camel CLI 4.22.1)
> {code:yaml|title=in.yaml}
> - onCompletion:
>     steps:
>       - log:
>           message: "done"
> - interceptFrom:
>     uri: "direct*"
>     steps:
>       - log:
>           message: "intercepted"
> - route:
>     id: myRoute
>     from:
>       uri: direct:start
>       steps:
>         - log:
>             message: "Hello"
> {code}
> {{camel validate yaml in.yaml}}: Validation success. {{camel validate 
> normalize in.yaml --output=out.yaml}}:
> {code:yaml|title=out.yaml}
> - route:
>     id: myRoute
>     from:
>       uri: direct
>       parameters:
>         name: start
>       steps:
>         - interceptFrom:
>             uri: direct*
>             steps:
>               - log:
>                   message: intercepted
>         - onCompletion:
>             steps:
>               - log:
>                   message: done
>         - log:
>             message: Hello
> {code}
> {noformat}
> $ camel validate yaml out.yaml
> Validation error detected (errors:2)
>       File: out.yaml
>               /0/route/from/steps/0: property 'interceptFrom' is not defined 
> in the schema and the schema does not allow additional properties
>               /0/route/from/steps/1: property 'onCompletion' is not defined 
> in the schema and the schema does not allow additional properties
> {noformat}
> With several routes, the {{onCompletion}} is copied into each route 
> ({{interceptFrom}} into each route whose endpoint matches its uri).
> In 4.22.1 a top-level {{intercept}} and {{interceptSendToEndpoint}} are 
> dropped from the output instead (the 4.22.x YAML writer does not write them). 
> On main (4.23.0-SNAPSHOT, after CAMEL-25255) they are written as steps of 
> each route as well:
> {code:yaml}
>       steps:
>         - interceptSendToEndpoint:
>             uri: log*
>             steps:
>               - log:
>                   message: sending
>         - intercept:
>             steps:
>               - log:
>                   message: intercept
>         - to: ...
> {code}
> h3. Cause
> When a route is prepared, {{RouteDefinitionHelper.prepareRoute}} 
> ({{initInterceptors}}, {{initOnCompletions}}) adds the context scoped 
> interceptors and onCompletions (the top-level ones of the file, and those of 
> the route configurations that apply) to the outputs of the route. 
> {{LwModelToYAMLDumper}} (core/camel-yaml-io) writes all route outputs as 
> steps.
> This is the same cause as CAMEL-25490, which fixes it for {{onException}} 
> only: there the context scoped ones are marked with {{routeScoped=false}}. 
> {{InterceptDefinition}}, {{InterceptFromDefinition}} and 
> {{InterceptSendToEndpointDefinition}} have no such marker, and a top-level 
> {{onCompletion}} loaded by the YAML DSL keeps {{routeScoped=true}} (only 
> {{RoutesDefinition.onCompletion()}} of the Java DSL sets it to false), so the 
> dumper cannot tell them from route scoped ones (Java DSL 
> {{from(...).onCompletion()}}). A fix needs a marker set when they are merged 
> into the route (or the dumper to get the {{RoutesDefinition}} lists of the 
> source), and then the same treatment as CAMEL-25490: leave them out of the 
> steps and write them once as top-level entries (or not at all when they come 
> from a routeConfiguration).



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to