Hoist functions from their templates to resolve authoring awkwardness #526
Labels
discussion
This issue is not a bug or feature and a conversation is needed to find an appropriate resolution
enhancement
This issue is a feature request
(scratchpad notes: https://hackmd.io/coYgaB_MQQ2EvSHxbXuLOw)
Today, it is easy to write a function definitions in a YAML template that results in surprising behavior (see scenarios, below).
There is an intuitive understanding that functions are not really part of the template at the location in which they are defined, but that they potentially "capture" some
In order to improve the template authoring experience, let's make good on that intuitive understanding and hoist function definitions out of the document in which they are defined.
Of course, this should be done in a way that preserves the semantics of the template.
Problems:
def ...()
), if an annotation appears within that function definition, it must also be hoisted; if an annotation appears above the function definition, it should not be hoisted.Scenario: default value for an array in schema
When writing schema and specifying a default value (especially for an array of items), it's natural to do so using YAML Fragment functions.
Today, it's easy for this to be a BadTime™️: what seems like a straight-forward move results in what is likely a confusing error message.
🟢 Capturing a collection of map items in a YAML Fragment function works:
🔴 But doing the same for array items does not:
... and instead results:
... (which is a sharp edge in
ytt
templates, in general) when 'fixed" (by injecting a document start immediately after the function declaration):🔴 ... which results in:
🟢 ... only when finally the function is pulled entirely out of the schema-flavored document:
... do we get the desired result.
Incidents:
(moments we are aware of this situation occurring)
Vote on this request
This is an invitation to the community to vote on issues, to help us prioritize our backlog. Use the "smiley face" up to the right of this comment to vote.
👍 "I would like to see this addressed as soon as possible"
👎 "There are other more important things to focus on right now"
We are also happy to receive and review Pull Requests if you want to help working on this issue.
The text was updated successfully, but these errors were encountered: