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

🐛 Fix JSON Schema for ValidationError at field loc #3810

Merged
merged 4 commits into from Apr 17, 2022

Conversation

dconathan
Copy link
Contributor

See #3790

Basically, Pydantic's schema for the loc field of the error detail is Union[str, int] not str for e.g. cases when the invalid data is at a particular index of an array:

See the type defined in Pydantic's source here:
https://github.com/samuelcolvin/pydantic/blob/5ccbdcb5904f35834300b01432a665c75dc02296/pydantic/error_wrappers.py#L12

The openapi.json schema for a ValidationError should match this.

This is particularly important for automated testing using https://schemathesis.readthedocs.io/en/stable/ because ValidationErrors that don't match the schema will lead to failing tests.

I've updated the validation_error_definition (h/t to @silversurfer34 for creating the issue and supplying the fixed schema 😄 ).
Also I had to update all the tests since the openapi.jsons are hardcoded in that.

@github-actions
Copy link
Contributor

📝 Docs preview for commit 95ce749 at: https://612e50e590ccc9407a6d3a82--fastapi.netlify.app

@codecov
Copy link

codecov bot commented Aug 31, 2021

Codecov Report

Merging #3810 (ae1128a) into master (864643e) will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff            @@
##            master     #3810   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          409       409           
  Lines        10264     10264           
=========================================
  Hits         10264     10264           
Impacted Files Coverage Δ
fastapi/openapi/utils.py 100.00% <ø> (ø)
tests/test_additional_properties.py 100.00% <ø> (ø)
...t_additional_responses_custom_model_in_callback.py 100.00% <ø> (ø)
...st_additional_responses_default_validationerror.py 100.00% <ø> (ø)
tests/test_application.py 100.00% <ø> (ø)
tests/test_dependency_duplicates.py 100.00% <ø> (ø)
tests/test_extra_routes.py 100.00% <ø> (ø)
tests/test_filter_pydantic_sub_model.py 100.00% <ø> (ø)
tests/test_get_request_body.py 100.00% <ø> (ø)
tests/test_include_router_defaults_overrides.py 100.00% <ø> (ø)
... and 68 more

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 864643e...ae1128a. Read the comment docs.

@github-actions
Copy link
Contributor

📝 Docs preview for commit 6caac74 at: https://612ea7456baaa23ddbd68c4c--fastapi.netlify.app

Copy link

@silversurfer34 silversurfer34 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me

@github-actions
Copy link
Contributor

github-actions bot commented Oct 7, 2021

📝 Docs preview for commit ae1128a at: https://615f4487606f2867f92c1744--fastapi.netlify.app

@tiangolo tiangolo changed the title Fix validation error loc schema 🐛 Fix JSON Schema for ValidationError at field loc Apr 17, 2022
@tiangolo
Copy link
Owner

Awesome, thanks @dconatha for the work and explanation! 🤓 🍰

This will be available in FastAPI 0.75.2, released in a couple of hours. 🚀

@tiangolo tiangolo merged commit c449ae5 into tiangolo:master Apr 17, 2022
JeanArhancet pushed a commit to JeanArhancet/fastapi that referenced this pull request Aug 20, 2022
Co-authored-by: Devin Conathan <dconatha@amfam.com>
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

Successfully merging this pull request may close these issues.

None yet

5 participants