Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@schema/default Annotation #295

Closed
pivotaljohn opened this issue Feb 8, 2021 · 1 comment
Closed

@schema/default Annotation #295

pivotaljohn opened this issue Feb 8, 2021 · 1 comment
Assignees
Labels
enhancement This issue is a feature request priority/important-soon Must be staffed and worked on currently or soon.

Comments

@pivotaljohn
Copy link
Contributor

pivotaljohn commented Feb 8, 2021

@schema/default

work is on ytt branch: schema-default
Explicitly sets the default value of the annotated node.

@schema/default value
  • value (any except function) — the overriding default value.

Notes:

  • value must be of the type of the annotated node.
  • The type of a node is never inferred from the overriding default value.
  • this annotation is the only way to set a non-empty default value for arrays.

Narrative:
As a configuration author
I want to explicitly set a default value for a data value
so that I can specify default values for arrays


🍏 Set the default value

Given a document, array item, or map item is annotated with @schema/default <value>
And the value is of the same type as the key below it
When I run ytt that includes that schema
Then that value shows up as the default for that array

Scenario 1: 🍏 Set the default value of an int

#! schema.yml
#@data/values-schema
---
#@schema/default 1
number: 0
#! template.yml
#@ load("@ytt:data", "data")
---
output: #@ data.values.number

Then the result of ytt -f schema.yml -f template.yml is:

---
output: 1

Scenario 2: 🍏 Set the default value of an array

#! schema.yml
#@data/values-schema
---
#@ def array_definition():
#@ return "this is the default value"
#@ end

#@schema/default [array_definition()]
the_array:
- this defines the type only
#! template.yml
#@ load("@ytt:data", "data")
---
output: #@ data.values.the_array

Then the result of ytt -f schema.yml -f template.yml is:

---
output: 
- this is the default value

Scenario 3: 🟥 Keyword argument(s) of incorrect format

Given a document, array item, or map item is annotated with @schema/default with any other keyword argument (kwarg) except a value of the same type that is defined inline for arrays or maps
When I run ytt that includes that schema
Then I see an error message which includes line numbers to help point to where the error is, alongside a helpful message that describes the problem and how to fix it (unknown kwarg, fix by removing or using the only currently supported on, any)

More examples in the original ytt schema doc

Notes:

  • Documentation should be included as part of this issue
@cari-lynn cari-lynn changed the title (placeholder) @schema/default @schema/default Annotation Aug 30, 2021
@pivotaljohn pivotaljohn added enhancement This issue is a feature request priority/important-soon Must be staffed and worked on currently or soon. labels Aug 31, 2021
@cari-lynn cari-lynn self-assigned this Sep 1, 2021
@gcheadle-vmware gcheadle-vmware self-assigned this Sep 14, 2021
@cari-lynn
Copy link
Contributor

Available in v0.38.0

@github-actions github-actions bot added the carvel triage This issue has not yet been triaged for relevance label Nov 19, 2021
@aaronshurley aaronshurley removed the carvel triage This issue has not yet been triaged for relevance label Nov 30, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement This issue is a feature request priority/important-soon Must be staffed and worked on currently or soon.
Projects
None yet
Development

No branches or pull requests

4 participants