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

   Backport of #27609 to camel-4.22.x.
   
   JIRA: https://issues.apache.org/jira/browse/CAMEL-25490
   
   ## Problem
   
   `camel validate normalize` turns a valid YAML file with a top-level 
`onException` into a file that `camel validate yaml` rejects: the `onException` 
is written as the first step of every route.
   
   ```yaml
   - onException:
       exception:
         - java.lang.Exception
       handled:
         constant: "true"
       steps:
         - log:
             message: "Failed: ${exception.message}"
   - route:
       id: myRoute
       from:
         uri: timer:tick
         steps:
           - log:
               message: "Hello"
   ```
   
   `camel validate normalize in.yaml --output=out.yaml` (4.22.1) writes the 
`onException` under `route.from.steps`, and then:
   
   ```
   $ camel validate yaml out.yaml
        /0/route/from/steps/0: property 'onException' is not defined in the 
schema and the schema does not allow additional properties
   ```
   
   The `onException` of a `routeConfiguration` loaded before the routes ends up 
in the steps of each route as well (and is also dumped in the 
`routeConfiguration`).
   
   `camel validate yaml` and the compact notation warning recommend `camel 
validate normalize`, so users and AI agents run it and copy its output over 
valid routes.
   
   ## Cause
   
   When a route is prepared (`RouteDefinitionHelper.prepareRoute` / 
`initOnExceptions`), the context scoped onExceptions (top-level ones, those of 
a `RouteBuilder`, and those of the route configurations that apply) are added 
to the outputs of the route with `routeScoped=false`. 
`LwModelToYAMLDumper.dumpModelAsYaml` wrote all the route outputs as steps, but 
the YAML DSL has no `onException` among the steps of a route (see CAMEL-25207).
   
   ## Fix
   
   `LwModelToYAMLDumper` leaves the context scoped onExceptions out of the 
route steps, and writes the ones that do not belong to a route configuration 
once, as top-level `onException` entries before the routes. Route scoped 
onExceptions, such as `from(...).onException(...)` in the Java DSL, are written 
as before.
   
   ## Test
   
   `OnExceptionYamlDumpTest` (camel-yaml-dsl) loads YAML routes, dumps them as 
`camel.main.dumpRoutes` does, and loads the dump back with the YAML DSL JSON 
schema validation of `YamlTestSupport`:
   - a top-level `onException` with two routes, before and after the context is 
started: dumped once, as top-level, and it still applies to both routes after 
the reload;
   - a `routeConfiguration` `onException` loaded before the route: not dumped 
in the route.
   
   The test fails without the fix and passes with it. The camel-yaml-io and 
camel-yaml-dsl tests pass. On camel-4.22.x the test is a Spock spec, as the 
other camel-yaml-dsl tests of that branch, and camel-yaml-io is added as a test 
dependency of camel-yaml-dsl, as on main.
   
   Other top-level elements show related but separate problems with `camel 
validate normalize`; they are listed in the JIRA issue and not changed here.
   


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