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

   Fixes [CAMEL-24826](https://issues.apache.org/jira/browse/CAMEL-24826).
   
   ## The problem
   
   Simple **does** have a ternary operator (CAMEL-22873, 4.18), but only inside 
a single `${...}`. At the top level an expression is a template, so the `?` and 
the `:` are literal text:
   
   ```yaml
   - setBody:
       simple: "${body.size()} == 0 ? ${null} : ${body[0]}"
   ```
   
   sets the body to the text `1 == 0 ?  : {sku=CAMEL-MUG, qty=42}`, and both 
`camel validate yaml` and the MCP validate tool accepted it. The ticket 
proposed reporting the ternary as unsupported, which would be inaccurate; this 
reports the top-level placement instead, with the position and the form to 
write.
   
   ## Why the check is not in the parser
   
   Reporting this from the Simple parser would break literal text, which 
regressed twice already: CAMEL-22904 (`>>> Message received from WebSocket 
Client : ${body}`) and CAMEL-23035, with `SimpleOperatorTest.testTernaryLog` 
left as the guard. It is instead a check in `SimpleChecks`, which is the single 
place reaching `camel validate yaml`, `camel validate source`, the MCP 
write-time checks, the TUI editor and `AnswerChecks`, so the MCP tool reports 
the same message.
   
   To keep false positives at zero the check fires only when the expression 
already uses a function, and never for a `log:` message, where a `?` followed 
by a `:` is usually a sentence. That rule matches nothing across this 
repository: no `simple:`/`message:` YAML value and no `simple("…")`/`log("…")` 
Java DSL string in the tree.
   
   ## Two related defects fixed
   
   **An unquoted number or boolean in a ternary branch failed to parse**, even 
in the fully supported form, because `parseValueExpression` wrapped any 
unrecognised branch in `${}`:
   
   ```
   ${header.foo == 5 ? 0 : 1}                 -> Unknown function: 0
   ${header.foo == 5 ? ${header.foo} : true}  -> Unknown function: true (did 
you mean ${type}?)
   ```
   
   Numbers and booleans now become `NumericExpression` and `BooleanExpression`, 
which is how the same literals behave everywhere else in Simple, so `Integer` 
vs `Double` selection and type conversion are unchanged.
   
   **A validate/runtime divergence:**
   
   ```
   ${header.foo == 5 ? ${header.foo} : 0}
     catalog validate : ACCEPTED
     runtime          : FAIL  Unknown function: 0
   ```
   
   The parser fix closes it, since the catalog validator calls the same 
`createExpression`. No separate change was needed.
   
   ## Documentation
   
   The documented syntax was the broken form:
   
   ```
   ${leftValue} OP rightValue ? trueValue : falseValue
   ```
   
   which is most likely where the shape in the ticket was copied from. It now 
shows the enclosed form, states that a `?` and a `:` outside `${...}` are 
literal text, and gives the value forms a branch accepts. The mirrored copy 
under `catalog/camel-catalog/src/generated/resources/.../docs/` is regenerated.
   
   No upgrade guide entry: the number/boolean change makes a previously failing 
expression work, so there is nothing to migrate.
   
   ## Verification
   
   - `SimpleOperatorTest` 60/60; all camel-core Simple tests **558/558**, 0 
failures.
   - `camel-jbang-core` full suite **1169/1169**, 0 failures.
   - `-Psourcecheck verify` on both modules: BUILD SUCCESS; `formatter:format 
impsort:sort` applied.
   - New tests cover the reported expression, both accepted forms, the 
top-level ternary in a predicate (which does evaluate, so it must not be 
reported), the CAMEL-22904 and CAMEL-23035 literal-text strings, a ternary 
inside a quoted literal, and that a syntax error is reported instead of the 
hint.
   
   🤖 Generated with [Claude Code](https://claude.com/claude-code) on behalf of 
Adriano Machado (@ammachado)
   
   _This was generated by an AI agent and may contain inaccuracies. Please 
verify before relying on it._


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