Claus Ibsen created CAMEL-25562:
-----------------------------------

             Summary: Camel 5 - YAML DSL: write each branch of a choice as its 
own when, as the Java and XML DSLs do
                 Key: CAMEL-25562
                 URL: https://issues.apache.org/jira/browse/CAMEL-25562
             Project: Camel
          Issue Type: Improvement
          Components: camel-yaml-dsl
            Reporter: Claus Ibsen


h3. The trap

In the Java and XML DSLs, a choice has a when for each branch:
{code:java}
.choice()
    .when(simple("${header.country} == 'DK'")).log("local")
    .when(simple("${header.country} == 'DE'")).log("eu")
    .otherwise().log("export")
.end()
{code}
In the YAML DSL, a choice has one {{when:}} key, and the branches are its list:
{code:yaml}
- choice:
    when:
      - simple: "${header.country} == 'DK'"
        steps:
          - log: local
      - simple: "${header.country} == 'DE'"
        steps:
          - log: eu
    otherwise:
      steps:
        - log: export
{code}
Whoever writes YAML with the Java or XML habit, people and AI models alike, 
writes a {{when:}} for each branch. YAML has no repeated keys: the YAML DSL 
keeps the last {{when:}} and drops the branches before it, without an error. 
The local-model benchmark hit this: a choice with two {{when:}} keys ran with 
one branch.

CAMEL-25560 makes the validator report a key given twice and say how to merge 
the branches. The shape itself stays a trap, and changing it breaks every YAML 
choice, so it is for Camel 5.

h3. Goal

Each branch of a choice is written as its own entry, as in the Java and XML 
DSLs, so a branch cannot replace another one.

h3. To decide

* *The shape.* For example, a list of {{- when:}} and {{- otherwise:}} items, 
as the children of the XML {{<choice>}} element are, and where the options of 
the choice itself ({{id}}, {{precondition}}) go next to that list.
* *The other EIPs with the same pattern*, where XML repeats a child element and 
YAML lists the children under one key: {{doTry}} with {{doCatch:}}, the REST 
DSL verbs ({{get:}}, {{post:}}, ...) and others. Decide them as one set, so the 
YAML DSL keeps one style.
* *Migration of existing YAML routes*: accept the 4.x shape in 5.0 with a 
deprecation warning, and/or an OpenRewrite recipe in camel-upgrade-recipes.
* *What reads and writes the shape*: the YAML DSL JSON schema (classic and 
canonical), the generated YAML DSL deserializers, camel-yaml-io (the YAML 
writer), the validator and its hints, the documentation and examples, and 
tooling such as Kaoto.




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

Reply via email to