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鈥檒l 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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 5 additions & 1 deletion fastapi/openapi/utils.py
Expand Up @@ -37,7 +37,11 @@
"title": "ValidationError",
"type": "object",
"properties": {
"loc": {"title": "Location", "type": "array", "items": {"type": "string"}},
"loc": {
"title": "Location",
"type": "array",
"items": {"anyOf": [{"type": "string"}, {"type": "integer"}]},
},
"msg": {"title": "Message", "type": "string"},
"type": {"title": "Error Type", "type": "string"},
},
Expand Down
2 changes: 1 addition & 1 deletion tests/test_additional_properties.py
Expand Up @@ -76,7 +76,7 @@ def foo(items: Items):
"loc": {
"title": "Location",
"type": "array",
"items": {"type": "string"},
"items": {"anyOf": [{"type": "string"}, {"type": "integer"}]},
},
"msg": {"title": "Message", "type": "string"},
"type": {"title": "Error Type", "type": "string"},
Expand Down
Expand Up @@ -119,7 +119,7 @@ def main_route(callback_url: HttpUrl):
"loc": {
"title": "Location",
"type": "array",
"items": {"type": "string"},
"items": {"anyOf": [{"type": "string"}, {"type": "integer"}]},
},
"msg": {"title": "Message", "type": "string"},
"type": {"title": "Error Type", "type": "string"},
Expand Down
2 changes: 1 addition & 1 deletion tests/test_additional_responses_default_validationerror.py
Expand Up @@ -54,7 +54,7 @@ async def a(id):
"loc": {
"title": "Location",
"type": "array",
"items": {"type": "string"},
"items": {"anyOf": [{"type": "string"}, {"type": "integer"}]},
},
"msg": {"title": "Message", "type": "string"},
"type": {"title": "Error Type", "type": "string"},
Expand Down
2 changes: 1 addition & 1 deletion tests/test_application.py
Expand Up @@ -1101,7 +1101,7 @@
"loc": {
"title": "Location",
"type": "array",
"items": {"type": "string"},
"items": {"anyOf": [{"type": "string"}, {"type": "integer"}]},
},
"msg": {"title": "Message", "type": "string"},
"type": {"title": "Error Type", "type": "string"},
Expand Down
2 changes: 1 addition & 1 deletion tests/test_dependency_duplicates.py
Expand Up @@ -177,7 +177,7 @@ async def no_duplicates_sub(
"loc": {
"title": "Location",
"type": "array",
"items": {"type": "string"},
"items": {"anyOf": [{"type": "string"}, {"type": "integer"}]},
},
"msg": {"title": "Message", "type": "string"},
"type": {"title": "Error Type", "type": "string"},
Expand Down
2 changes: 1 addition & 1 deletion tests/test_extra_routes.py
Expand Up @@ -292,7 +292,7 @@ def trace_item(item_id: str):
"loc": {
"title": "Location",
"type": "array",
"items": {"type": "string"},
"items": {"anyOf": [{"type": "string"}, {"type": "integer"}]},
},
"msg": {"title": "Message", "type": "string"},
"type": {"title": "Error Type", "type": "string"},
Expand Down
2 changes: 1 addition & 1 deletion tests/test_filter_pydantic_sub_model.py
Expand Up @@ -116,7 +116,7 @@ async def get_model_a(name: str, model_c=Depends(get_model_c)):
"loc": {
"title": "Location",
"type": "array",
"items": {"type": "string"},
"items": {"anyOf": [{"type": "string"}, {"type": "integer"}]},
},
"msg": {"title": "Message", "type": "string"},
"type": {"title": "Error Type", "type": "string"},
Expand Down
2 changes: 1 addition & 1 deletion tests/test_get_request_body.py
Expand Up @@ -85,7 +85,7 @@ async def create_item(product: Product):
"loc": {
"title": "Location",
"type": "array",
"items": {"type": "string"},
"items": {"anyOf": [{"type": "string"}, {"type": "integer"}]},
},
"msg": {"title": "Message", "type": "string"},
"type": {"title": "Error Type", "type": "string"},
Expand Down
2 changes: 1 addition & 1 deletion tests/test_include_router_defaults_overrides.py
Expand Up @@ -6606,7 +6606,7 @@ def test_paths_level5(override1, override2, override3, override4, override5):
"loc": {
"title": "Location",
"type": "array",
"items": {"type": "string"},
"items": {"anyOf": [{"type": "string"}, {"type": "integer"}]},
},
"msg": {"title": "Message", "type": "string"},
"type": {"title": "Error Type", "type": "string"},
Expand Down
2 changes: 1 addition & 1 deletion tests/test_modules_same_name_body/test_main.py
Expand Up @@ -101,7 +101,7 @@
"loc": {
"title": "Location",
"type": "array",
"items": {"type": "string"},
"items": {"anyOf": [{"type": "string"}, {"type": "integer"}]},
},
"msg": {"title": "Message", "type": "string"},
"type": {"title": "Error Type", "type": "string"},
Expand Down
2 changes: 1 addition & 1 deletion tests/test_multi_body_errors.py
Expand Up @@ -79,7 +79,7 @@ def save_item_no_body(item: List[Item]):
"loc": {
"title": "Location",
"type": "array",
"items": {"type": "string"},
"items": {"anyOf": [{"type": "string"}, {"type": "integer"}]},
},
"msg": {"title": "Message", "type": "string"},
"type": {"title": "Error Type", "type": "string"},
Expand Down
2 changes: 1 addition & 1 deletion tests/test_multi_query_errors.py
Expand Up @@ -63,7 +63,7 @@ def read_items(q: List[int] = Query(None)):
"loc": {
"title": "Location",
"type": "array",
"items": {"type": "string"},
"items": {"anyOf": [{"type": "string"}, {"type": "integer"}]},
},
"msg": {"title": "Message", "type": "string"},
"type": {"title": "Error Type", "type": "string"},
Expand Down
2 changes: 1 addition & 1 deletion tests/test_param_in_path_and_dependency.py
Expand Up @@ -71,7 +71,7 @@ async def read_users(user_id: int):
"loc": {
"title": "Location",
"type": "array",
"items": {"type": "string"},
"items": {"anyOf": [{"type": "string"}, {"type": "integer"}]},
},
"msg": {"title": "Message", "type": "string"},
"type": {"title": "Error Type", "type": "string"},
Expand Down
2 changes: 1 addition & 1 deletion tests/test_put_no_body.py
Expand Up @@ -57,7 +57,7 @@ def save_item_no_body(item_id: str):
"loc": {
"title": "Location",
"type": "array",
"items": {"type": "string"},
"items": {"anyOf": [{"type": "string"}, {"type": "integer"}]},
},
"msg": {"title": "Message", "type": "string"},
"type": {"title": "Error Type", "type": "string"},
Expand Down
2 changes: 1 addition & 1 deletion tests/test_repeated_dependency_schema.py
Expand Up @@ -36,7 +36,7 @@ def get_deps(dep1: str = Depends(get_header), dep2: str = Depends(get_something_
"ValidationError": {
"properties": {
"loc": {
"items": {"type": "string"},
"items": {"anyOf": [{"type": "string"}, {"type": "integer"}]},
"title": "Location",
"type": "array",
},
Expand Down
2 changes: 1 addition & 1 deletion tests/test_schema_extra_examples.py
Expand Up @@ -830,7 +830,7 @@ def cookie_example_examples(
"loc": {
"title": "Location",
"type": "array",
"items": {"type": "string"},
"items": {"anyOf": [{"type": "string"}, {"type": "integer"}]},
},
"msg": {"title": "Message", "type": "string"},
"type": {"title": "Error Type", "type": "string"},
Expand Down
2 changes: 1 addition & 1 deletion tests/test_security_oauth2.py
Expand Up @@ -117,7 +117,7 @@ def read_current_user(current_user: "User" = Depends(get_current_user)):
"loc": {
"title": "Location",
"type": "array",
"items": {"type": "string"},
"items": {"anyOf": [{"type": "string"}, {"type": "integer"}]},
},
"msg": {"title": "Message", "type": "string"},
"type": {"title": "Error Type", "type": "string"},
Expand Down
2 changes: 1 addition & 1 deletion tests/test_security_oauth2_optional.py
Expand Up @@ -121,7 +121,7 @@ def read_users_me(current_user: Optional[User] = Depends(get_current_user)):
"loc": {
"title": "Location",
"type": "array",
"items": {"type": "string"},
"items": {"anyOf": [{"type": "string"}, {"type": "integer"}]},
},
"msg": {"title": "Message", "type": "string"},
"type": {"title": "Error Type", "type": "string"},
Expand Down
2 changes: 1 addition & 1 deletion tests/test_security_oauth2_optional_description.py
Expand Up @@ -122,7 +122,7 @@ def read_users_me(current_user: Optional[User] = Depends(get_current_user)):
"loc": {
"title": "Location",
"type": "array",
"items": {"type": "string"},
"items": {"anyOf": [{"type": "string"}, {"type": "integer"}]},
},
"msg": {"title": "Message", "type": "string"},
"type": {"title": "Error Type", "type": "string"},
Expand Down
2 changes: 1 addition & 1 deletion tests/test_starlette_exception.py
Expand Up @@ -102,7 +102,7 @@ async def read_starlette_item(item_id: str):
"loc": {
"title": "Location",
"type": "array",
"items": {"type": "string"},
"items": {"anyOf": [{"type": "string"}, {"type": "integer"}]},
},
"msg": {"title": "Message", "type": "string"},
"type": {"title": "Error Type", "type": "string"},
Expand Down
2 changes: 1 addition & 1 deletion tests/test_sub_callbacks.py
Expand Up @@ -256,7 +256,7 @@ def create_invoice(invoice: Invoice, callback_url: Optional[HttpUrl] = None):
"loc": {
"title": "Location",
"type": "array",
"items": {"type": "string"},
"items": {"anyOf": [{"type": "string"}, {"type": "integer"}]},
},
"msg": {"title": "Message", "type": "string"},
"type": {"title": "Error Type", "type": "string"},
Expand Down
Expand Up @@ -76,7 +76,7 @@
"loc": {
"title": "Location",
"type": "array",
"items": {"type": "string"},
"items": {"anyOf": [{"type": "string"}, {"type": "integer"}]},
},
"msg": {"title": "Message", "type": "string"},
"type": {"title": "Error Type", "type": "string"},
Expand Down
Expand Up @@ -72,7 +72,7 @@
"loc": {
"title": "Location",
"type": "array",
"items": {"type": "string"},
"items": {"anyOf": [{"type": "string"}, {"type": "integer"}]},
},
"msg": {"title": "Message", "type": "string"},
"type": {"title": "Error Type", "type": "string"},
Expand Down
Expand Up @@ -77,7 +77,7 @@
"loc": {
"title": "Location",
"type": "array",
"items": {"type": "string"},
"items": {"anyOf": [{"type": "string"}, {"type": "integer"}]},
},
"msg": {"title": "Message", "type": "string"},
"type": {"title": "Error Type", "type": "string"},
Expand Down
Expand Up @@ -75,7 +75,7 @@
"loc": {
"title": "Location",
"type": "array",
"items": {"type": "string"},
"items": {"anyOf": [{"type": "string"}, {"type": "integer"}]},
},
"msg": {"title": "Message", "type": "string"},
"type": {"title": "Error Type", "type": "string"},
Expand Down
Expand Up @@ -88,7 +88,7 @@
"loc": {
"title": "Location",
"type": "array",
"items": {"type": "string"},
"items": {"anyOf": [{"type": "string"}, {"type": "integer"}]},
},
"msg": {"title": "Message", "type": "string"},
"type": {"title": "Error Type", "type": "string"},
Expand Down
2 changes: 1 addition & 1 deletion tests/test_tutorial/test_bigger_applications/test_main.py
Expand Up @@ -323,7 +323,7 @@
"loc": {
"title": "Location",
"type": "array",
"items": {"type": "string"},
"items": {"anyOf": [{"type": "string"}, {"type": "integer"}]},
},
"msg": {"title": "Message", "type": "string"},
"type": {"title": "Error Type", "type": "string"},
Expand Down
2 changes: 1 addition & 1 deletion tests/test_tutorial/test_body/test_tutorial001.py
Expand Up @@ -63,7 +63,7 @@
"loc": {
"title": "Location",
"type": "array",
"items": {"type": "string"},
"items": {"anyOf": [{"type": "string"}, {"type": "integer"}]},
},
"msg": {"title": "Message", "type": "string"},
"type": {"title": "Error Type", "type": "string"},
Expand Down
2 changes: 1 addition & 1 deletion tests/test_tutorial/test_body_fields/test_tutorial001.py
Expand Up @@ -87,7 +87,7 @@
"loc": {
"title": "Location",
"type": "array",
"items": {"type": "string"},
"items": {"anyOf": [{"type": "string"}, {"type": "integer"}]},
},
"msg": {"title": "Message", "type": "string"},
"type": {"title": "Error Type", "type": "string"},
Expand Down
Expand Up @@ -79,7 +79,7 @@
"loc": {
"title": "Location",
"type": "array",
"items": {"type": "string"},
"items": {"anyOf": [{"type": "string"}, {"type": "integer"}]},
},
"msg": {"title": "Message", "type": "string"},
"type": {"title": "Error Type", "type": "string"},
Expand Down
Expand Up @@ -90,7 +90,7 @@
"loc": {
"title": "Location",
"type": "array",
"items": {"type": "string"},
"items": {"anyOf": [{"type": "string"}, {"type": "integer"}]},
},
"msg": {"title": "Message", "type": "string"},
"type": {"title": "Error Type", "type": "string"},
Expand Down
Expand Up @@ -53,7 +53,7 @@
"loc": {
"title": "Location",
"type": "array",
"items": {"type": "string"},
"items": {"anyOf": [{"type": "string"}, {"type": "integer"}]},
},
"msg": {"title": "Message", "type": "string"},
"type": {"title": "Error Type", "type": "string"},
Expand Down
2 changes: 1 addition & 1 deletion tests/test_tutorial/test_body_updates/test_tutorial001.py
Expand Up @@ -109,7 +109,7 @@
"loc": {
"title": "Location",
"type": "array",
"items": {"type": "string"},
"items": {"anyOf": [{"type": "string"}, {"type": "integer"}]},
},
"msg": {"title": "Message", "type": "string"},
"type": {"title": "Error Type", "type": "string"},
Expand Down
2 changes: 1 addition & 1 deletion tests/test_tutorial/test_cookie_params/test_tutorial001.py
Expand Up @@ -50,7 +50,7 @@
"loc": {
"title": "Location",
"type": "array",
"items": {"type": "string"},
"items": {"anyOf": [{"type": "string"}, {"type": "integer"}]},
},
"msg": {"title": "Message", "type": "string"},
"type": {"title": "Error Type", "type": "string"},
Expand Down
2 changes: 1 addition & 1 deletion tests/test_tutorial/test_dataclasses/test_tutorial001.py
Expand Up @@ -71,7 +71,7 @@
"loc": {
"title": "Location",
"type": "array",
"items": {"type": "string"},
"items": {"anyOf": [{"type": "string"}, {"type": "integer"}]},
},
"msg": {"title": "Message", "type": "string"},
"type": {"title": "Error Type", "type": "string"},
Expand Down
2 changes: 1 addition & 1 deletion tests/test_tutorial/test_dataclasses/test_tutorial003.py
Expand Up @@ -118,7 +118,7 @@
"loc": {
"title": "Location",
"type": "array",
"items": {"type": "string"},
"items": {"anyOf": [{"type": "string"}, {"type": "integer"}]},
},
"msg": {"title": "Message", "type": "string"},
"type": {"title": "Error Type", "type": "string"},
Expand Down
2 changes: 1 addition & 1 deletion tests/test_tutorial/test_dependencies/test_tutorial001.py
Expand Up @@ -104,7 +104,7 @@
"loc": {
"title": "Location",
"type": "array",
"items": {"type": "string"},
"items": {"anyOf": [{"type": "string"}, {"type": "integer"}]},
},
"msg": {"title": "Message", "type": "string"},
"type": {"title": "Error Type", "type": "string"},
Expand Down
2 changes: 1 addition & 1 deletion tests/test_tutorial/test_dependencies/test_tutorial004.py
Expand Up @@ -62,7 +62,7 @@
"loc": {
"title": "Location",
"type": "array",
"items": {"type": "string"},
"items": {"anyOf": [{"type": "string"}, {"type": "integer"}]},
},
"msg": {"title": "Message", "type": "string"},
"type": {"title": "Error Type", "type": "string"},
Expand Down
2 changes: 1 addition & 1 deletion tests/test_tutorial/test_dependencies/test_tutorial006.py
Expand Up @@ -55,7 +55,7 @@
"loc": {
"title": "Location",
"type": "array",
"items": {"type": "string"},
"items": {"anyOf": [{"type": "string"}, {"type": "integer"}]},
},
"msg": {"title": "Message", "type": "string"},
"type": {"title": "Error Type", "type": "string"},
Expand Down
2 changes: 1 addition & 1 deletion tests/test_tutorial/test_dependencies/test_tutorial012.py
Expand Up @@ -102,7 +102,7 @@
"loc": {
"title": "Location",
"type": "array",
"items": {"type": "string"},
"items": {"anyOf": [{"type": "string"}, {"type": "integer"}]},
},
"msg": {"title": "Message", "type": "string"},
"type": {"title": "Error Type", "type": "string"},
Expand Down
2 changes: 1 addition & 1 deletion tests/test_tutorial/test_events/test_tutorial001.py
Expand Up @@ -47,7 +47,7 @@
"loc": {
"title": "Location",
"type": "array",
"items": {"type": "string"},
"items": {"anyOf": [{"type": "string"}, {"type": "integer"}]},
},
"msg": {"title": "Message", "type": "string"},
"type": {"title": "Error Type", "type": "string"},
Expand Down
Expand Up @@ -89,7 +89,7 @@
"loc": {
"title": "Location",
"type": "array",
"items": {"type": "string"},
"items": {"anyOf": [{"type": "string"}, {"type": "integer"}]},
},
"msg": {"title": "Message", "type": "string"},
"type": {"title": "Error Type", "type": "string"},
Expand Down
2 changes: 1 addition & 1 deletion tests/test_tutorial/test_extra_models/test_tutorial003.py
Expand Up @@ -78,7 +78,7 @@
"loc": {
"title": "Location",
"type": "array",
"items": {"type": "string"},
"items": {"anyOf": [{"type": "string"}, {"type": "integer"}]},
},
"msg": {"title": "Message", "type": "string"},
"type": {"title": "Error Type", "type": "string"},
Expand Down