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 validation does not work on first key in list dict #915

Closed
henry-spanka opened this issue May 24, 2024 · 3 comments
Closed

Schema validation does not work on first key in list dict #915

henry-spanka opened this issue May 24, 2024 · 3 comments
Labels
carvel triage This issue has not yet been triaged for relevance helping with an issue Debugging happening to identify the problem

Comments

@henry-spanka
Copy link

What steps did you take:

A schema key is not validated when it's the first key in a list of dicts.

schema.yaml

#@data/values-schema
---
apps:
  - #@schema/validation min_len=1
    name: ""
    #@schema/validation min_len=1
    revision: master

values.yaml

#@data/values
---
apps:
  - name: argocd
    revision: dev
  - name: cert-manager
    revision: dev
  - name: ""
    revision: dev

What happened:

Templating with ytt -f schema.yaml -f values.yaml --data-values-inspect completes successfully.

What did you expect:

Templating to fail due to name being an empty string.

Anything else you would like to add:

Adding the comment after the value does trigger validation. However this is only necessary on the first key. Subsequent dict successfully validate when the comment is above the key.

#@data/values-schema
---
apps:
  - name: "" #@schema/validation min_len=1
    #@schema/validation min_len=1
    revision: master

Environment:

  • ytt version (use ytt --version):
    ytt version 0.49.0
  • OS (e.g. from /etc/os-release):
    macOS M1 Pro 14.5

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.

@henry-spanka henry-spanka added bug This issue describes a defect or unexpected behavior carvel triage This issue has not yet been triaged for relevance labels May 24, 2024
@prembhaskal
Copy link
Contributor

@henry-spanka
I notice that if we move the schema validation comment to next line instead of putting in front of the name , the schema validation works fine
see working example here https://carvel.dev/ytt/#gist:https://gist.github.com/prembhaskal/d5385d09183ed2f1959e03106674f485

#@data/values-schema
---
apps:
  - 
    #@schema/validation min_len=1
    name: ""
    #@schema/validation min_len=1
    revision: master

we will need to check this in detail a bit.

@prembhaskal
Copy link
Contributor

prembhaskal commented May 29, 2024

Also according to this slack discussion here, https://kubernetes.slack.com/archives/CH8KCCKA5/p1618934385381800
the - #@schema/validation.... should have ideally caused an ytt error.

Also Dmitriy clarifies in same chat that

- #@x...

is same as

#@x...
-   

@renuy renuy added helping with an issue Debugging happening to identify the problem and removed bug This issue describes a defect or unexpected behavior carvel triage This issue has not yet been triaged for relevance labels May 31, 2024
@renuy renuy closed this as completed May 31, 2024
@renuy
Copy link

renuy commented May 31, 2024

Thanks @prembhaskal !

@github-actions github-actions bot added the carvel triage This issue has not yet been triaged for relevance label May 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
carvel triage This issue has not yet been triaged for relevance helping with an issue Debugging happening to identify the problem
Projects
Archived in project
Development

No branches or pull requests

3 participants