Add option for custom validator for Path params.
Nowadays, the only supported validation for Path params are the given ones (le, ge, etc). I think there are many use cases where we want to sanitize and validate input of Path parameters that is "smarter" than the given options. I will add documentation once I get approval of concept :)
Codecov Report
Merging #2083 into master will not change coverage. The diff coverage is
100.00%.
@@ Coverage Diff @@
## master #2083 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 239 239
Lines 7079 7087 +8
=========================================
+ Hits 7079 7087 +8
| Impacted Files | Coverage Δ | |
|---|---|---|
| tests/test_application.py | 100.00% <ø> (ø) |
|
| fastapi/dependencies/utils.py | 100.00% <100.00%> (ø) |
|
| fastapi/params.py | 100.00% <100.00%> (ø) |
|
| tests/test_query.py | 100.00% <100.00%> (ø) |
Continue to review full report at Codecov.
Legend - Click here to learn more
Δ = absolute <relative> (impact),ø = not affected,? = missing dataPowered by Codecov. Last update e77ea63...d68b606. Read the comment docs.
📝 Docs preview for commit d68b606d316c0c990791f92f8eca90f0d39bcb00 at: https://5f68fb0db0e55a07209024bb--fastapi.netlify.app
@tiangolo I hope things are going well, hopefully you can check this out :)
@aviramha Any chance you can add this feature for query parameters too, Currently query parameters have similar validation options as path parameters and they should be similar to setup in Pydantic I think.
@tiangolo Please consider this merge request, having custom validators would be a nice feature when one is doing more complex validations.
@M-e-r-c-u-r-y Yes I can add but I'd like initial approval of current implementation before adding it to any more places :)
Thanks @aviramha! :nerd_face:
I think this would make sense at the Pydantic level, Field() could take a validator directly, right?
Then that functionality would only be inherited here instead of extended.
That would probably need to wait for Pydantic v2 or be part of it, as I guess no new PRs will be accepted for v1.
What do you think?
Sorry for the long delay! 🙈 I wanted to personally address each issue and they piled up through time, but now I'm checking each one in order.
Hi @tiangolo I have pretty much lost the context and can't really answer correctly as I'm not following nor using FastAPI in the last few months (just not using Python, still love FastAPI :)) I suggest to close this and if someone else wants something similar, they'll take another attempt on it.
Thanks for coming back! And yep, makes sense.
I'll close this one then. Thanks! 🍰