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

Automatically use correct format_checker for versioned Validators #861

Closed
TiborVoelcker opened this issue Oct 16, 2021 · 5 comments
Closed
Labels
Enhancement Some new desired functionality Help Wanted An enhancement or bug for which a pull request is welcomed and which should have a clear definition.

Comments

@TiborVoelcker
Copy link
Contributor

(Not sure if this is already a feature, and I just could not get it to work.)

I want my validator automatically detected using the "$schema" keyword, to leave it customizable. But I would also need the formats to be validated. I know I could use validate(instance, schema, format_checker=draft202012_format_checker). But I would like to just use the corresponding format_checker. Meaning, if my "$schema" keyword leads to using the Draft202012Validator, I would want to automatically use the draft202012_format_checker. If I use Draft7Validator, use the draft7_format_checker, etc.

My proposal would be to accept format_checker=True, to then use the corresponding Format Validator.

@Julian
Copy link
Member

Julian commented Oct 16, 2021

Thanks, this is indeed something I was aware of (and support adding) -- though the way I'd want to do so would be more similar to how TYPE_CHECKER is an attribute on validators.

So, in your example, you'd use:

Validator = validator_for(schema)
Validator(schema, format_checker=Validator.FORMAT_CHECKER).validate(instance)

with the addition of the FORMAT_CHECKER attribute.

Certainly willing to see a PR adding it!

@Julian Julian added Enhancement Some new desired functionality Help Wanted An enhancement or bug for which a pull request is welcomed and which should have a clear definition. labels Oct 16, 2021
@TiborVoelcker
Copy link
Contributor Author

Alright, I will see what I can do. I am very busy at the moment tho, so I will try to look into it when I have the time. Great package BTW!

@Julian
Copy link
Member

Julian commented Oct 21, 2021

Thanks, sounds great, and appreciated!

@TiborVoelcker
Copy link
Contributor Author

Hi! Sorry for lettings this sit for such a long time. I found some time a while ago, but was completely lost when looking through the code.
Now I found time again, and was determined to succeed. I tried to get an overview, but I am still a bit overwhelmed. But if I assessed it correctly, the change needed for this is very minor. So I did make a PR #905.

BTW: I could not figure out how to assign you to the PR, or link this issue with the PR.

@Julian
Copy link
Member

Julian commented Jan 31, 2022

Closed in #905.

@Julian Julian closed this as completed Jan 31, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement Some new desired functionality Help Wanted An enhancement or bug for which a pull request is welcomed and which should have a clear definition.
Projects
None yet
Development

No branches or pull requests

2 participants