Claus Ibsen created CAMEL-25324:
-----------------------------------
Summary: camel-dataweave - common DataWeave constructs are
converted wrongly or dropped
Key: CAMEL-25324
URL: https://issues.apache.org/jira/browse/CAMEL-25324
Project: Camel
Issue Type: Bug
Reporter: Claus Ibsen
Each of these was run through a Camel route with camel-datasonnet (on main,
4.23.0-SNAPSHOT; the converter shipped in 4.22.0):
||DataWeave||Result||
|{{payload.items map \{ id: $.id \}}}|runtime: "Wrong parameter type: expected
Function, got object" (an object passed to std.map)|
|{{payload.items filter ($.qty > 1)}}|route fails to start with a parse error
in the generated code|
|{{payload.items reduce ($$ + $.price)}}|route fails to start ({{function($,
$)}})|
|{{var rate = 0.08}} / {{fun ...}} above the {{---}} line|declaration dropped,
so "Unknown variable rate"|
|{{payload.Order.@id}}|{{@}} dropped, so {{body.Order.id}}: "Field does not
exist: id" (should be {{body.Order\['@id'\]}})|
|{{"Hello $(payload.name)"}}|*wrong output, no error*: the literal text {{Hello
$(payload.name)}}|
|{{payload.a?}}|becomes {{body.a}}, which fails instead of returning a boolean|
|{{payload..name}}|becomes {{body.name}}: wrong output|
|{{payload.items\[?($.qty > 1)\]}}|becomes an index with a function|
|{{mapObject}}, {{pluck}}|broken output|
|{{"say \"hi\""}}|the quote is escaped twice, so the route fails to start|
|{{groupBy ((i) -> i.qty)}}|fails, because the group key is a number ("expected
String, got number" in camel.libsonnet); DataWeave turns keys into strings|
|{{payload.Order.Items.*Item}}|becomes {{std.map(function(x) x.Item,
body.Order.Items)}}, mapping over the object instead of collecting all Item
children (one or many)|
|{{fun f(a: Number): Number = ...}}|type annotations are added to the parameter
list|
These are everyday DataWeave, so most real MuleSoft scripts hit at least one.
Fix the straightforward ones first ($/$$ shorthand, var/fun above the {{---}},
@attr, $(...) interpolation, ?, escaping, groupBy keys as strings, .* with
one-or-many, typed params). {{match}}, {{mapObject}}, {{pluck}}, {{..}} and
{{\[?()\]}} can come next. Each fix gets a case in the executed test set (see
the related issue).
_Claude Code on behalf of davsclaus_
--
This message was sent by Atlassian Jira
(v8.20.10#820010)