I want to write a function that returns an array. The array contains objects, where some of them need to reuse a certain object (metadata
in this example). This object depends on a parameter of the function and repeating it would be a bit cumbersome.
I tried this:
local fn(name) = [
local metadata = { name: name };
{ metadata: metadata, value: "foo" },
{ metadata: metadata, value: "bar" },
];
fn("blub")
Unfortunately I get this error:
STATIC ERROR: example.jsonnet:4:17-24: Unknown variable: metadata
I would expect that metadata
is also available within the second item. Is there a way to solve this without repeating metadata
and without having the function return an object?