Federico Mariani created CAMEL-25494:
----------------------------------------

             Summary: camel-yaml-io - YAML route dump writes routeConfiguration 
onException items without their onException key, which neither the schema nor 
the loader accept
                 Key: CAMEL-25494
                 URL: https://issues.apache.org/jira/browse/CAMEL-25494
             Project: Camel
          Issue Type: Bug
          Components: camel-jbang, camel-yaml-dsl
    Affects Versions: 4.22.1
            Reporter: Federico Mariani


{{camel validate normalize}} (the YAML route dump, 
{{camel.main.dumpRoutes=yaml}}) writes the {{onException}} items of a 
{{routeConfiguration}} without their {{onException:}} key. The result is 
rejected by the YAML DSL schema, and the runtime does not load it either.

h3. Reproduction (Camel CLI 4.22.1, same on main)

{code:yaml|title=in.yaml}
- routeConfiguration:
    id: myConfig
    onException:
      - onException:
          exception:
            - java.lang.Exception
          handled:
            constant: "true"
          steps:
            - log:
                message: "failed"
- 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}
- routeConfiguration:
    id: myConfig
    onException:
      - exception:
          - java.lang.Exception
        handled:
          constant:
            expression: "true"
        steps:
          - log:
              message: failed
- route:
    id: myRoute
    from:
      uri: direct
      parameters:
        name: start
      steps:
        - log:
            message: Hello
{code}

{noformat}
$ camel validate yaml out.yaml
Validation error detected (errors:3)
        File: out.yaml
                /0/routeConfiguration/onException/0: property 'exception' is 
not defined in the schema and the schema does not allow additional properties
                /0/routeConfiguration/onException/0: property 'handled' is not 
defined in the schema and the schema does not allow additional properties
                /0/routeConfiguration/onException/0: property 'steps' is not 
defined in the schema and the schema does not allow additional properties

$ camel run out.yaml
ERROR ... Error starting Camel: Node should have only have 1 key, was: 3 keys: 
[exception,handled,steps] (Maybe this is an indent problem in the YAML source).
{noformat}

h3. Cause

The generated {{YamlModelWriter.doWriteRouteConfigurationDefinition}} 
(core/camel-yaml-io, generated by camel-package-maven-plugin) writes the 
{{onException}}, {{intercept}}, {{interceptFrom}}, {{interceptSendToEndpoint}} 
and {{onCompletion}} lists of a route configuration as lists of bare objects, 
while the YAML DSL reads each item as a one-key map ({{- onException: ...}}, 
{{- intercept: ...}}). The same likely applies to the other lists of the route 
configuration (the {{intercept}} list is written as {{- steps: ...}}).

The existing writer test expects the wrong form: 
{{core/camel-yaml-io/src/test/resources/yaml-routeconfig.yaml}} (used by 
{{YamlModelWriterTest.testRouteConfiguration}}) has {{onException: - exception: 
...}} and {{intercept: - steps: ...}}, so it has to be changed with the fix.




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

Reply via email to