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

[Feature Request] z.choice Show choice(s) on validation error #48

Open
sjfhsjfh opened this issue Sep 15, 2024 · 3 comments
Open

[Feature Request] z.choice Show choice(s) on validation error #48

sjfhsjfh opened this issue Sep 15, 2024 · 3 comments

Comments

@sjfhsjfh
Copy link

I would like to request support for a literal type in valkyrie. The feature should allow defining a literal value from a fixed set of options. For example, something like:

z.literal("full", "simplified", "none")

In addition to enforcing the literal value, I would also like the error message to clearly indicate the accepted literals when a validation fails. For instance, if the input does not match one of the defined literals (“full”, “simplified”, or “none”), the error message should display something like:

Invalid value provided. Expected one of: "full", "simplified", "none".

Thank you for considering this request!

@tingerrr
Copy link
Member

You're looking for choice(values: array, ..args), i.e. z.choice(("full", "simplified", "none")) (note the double parentheses), although it will not show the supported choices in the error message.

@sjfhsjfh
Copy link
Author

Thanks, sorry for my carelessness, I wish there would be a better documentation tho😭

@sjfhsjfh sjfhsjfh closed this as not planned Won't fix, can't repro, duplicate, stale Sep 15, 2024
@tingerrr
Copy link
Member

We can leave the issue open to track the latter suggestion of displaying the valid choices.

@tingerrr tingerrr reopened this Sep 15, 2024
@tingerrr tingerrr changed the title [Feature Request] Literal type Include valid chocies in choice error message Sep 15, 2024
@sjfhsjfh sjfhsjfh changed the title Include valid chocies in choice error message [Feature Request] z.choice Show choice(s) on validation error Sep 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants