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: Context Data for custom validations #1696

Closed
softwarerero opened this issue Dec 14, 2022 · 3 comments
Closed

Feature Request: Context Data for custom validations #1696

softwarerero opened this issue Dec 14, 2022 · 3 comments

Comments

@softwarerero
Copy link

It would be great if custom validations with refine or superRefine could access data that is given as a parameter to parse, parseAsync, safeParse or safeParseAsync.

Joi for example allows to give a context object as a second parameter to its validate function which then can be evaluated in custom rules.

@colinhacks
Copy link
Owner

colinhacks commented Dec 14, 2022

Discussed extensively elsewhere: #84 #148

TLDR: Probably not happening any time soon I'm afraid

@fkrauthan
Copy link

I know this is currently closed but I would also love some way to pass context information to custom validators. For example, I want to validate duplicates but exclude the current object id (currently I have to add id as a field to my schema and then have to remove it again when saving the data in the database). Or for example, my validation might have stricter rules if it is an admin user vs a regular user.

Right now it seems like the only way is to add them to the actual schema, pass the data in and then remove it again from the schema before processing the safeParsed data (defeating slightly the idea behind safe parse in my opinion)

@jotatoledo
Copy link

jotatoledo commented Oct 24, 2023

The lack of this feature was a deal breaker for my use case - had to replace it with yup, which offers this function, and refactor.
Would be nice to see sometime in the future.

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

4 participants