fastapi icon indicating copy to clipboard operation
fastapi copied to clipboard

Add option for custom validator for Path params.

Open aviramha opened this issue 5 years ago • 7 comments

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 :)

aviramha avatar Sep 21 '20 16:09 aviramha

Codecov Report

Merging #2083 into master will not change coverage. The diff coverage is 100.00%.

Impacted file tree graph

@@            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 data Powered by Codecov. Last update e77ea63...d68b606. Read the comment docs.

codecov[bot] avatar Sep 21 '20 16:09 codecov[bot]

📝 Docs preview for commit d68b606d316c0c990791f92f8eca90f0d39bcb00 at: https://5f68fb0db0e55a07209024bb--fastapi.netlify.app

github-actions[bot] avatar Sep 21 '20 19:09 github-actions[bot]

@tiangolo I hope things are going well, hopefully you can check this out :)

aviramha avatar Oct 16 '20 05:10 aviramha

@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 avatar Oct 30 '20 14:10 M-e-r-c-u-r-y

@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 :)

aviramha avatar Oct 30 '20 14:10 aviramha

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.

tiangolo avatar Nov 03 '22 20:11 tiangolo

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.

aviramha avatar Nov 05 '22 15:11 aviramha

Thanks for coming back! And yep, makes sense.

I'll close this one then. Thanks! 🍰

tiangolo avatar Nov 05 '22 23:11 tiangolo