resolved RESOLVED PASS · 4 tool calls · 64 s · fastapi/fastapi
🐛 Update `ValidationError` schema to include `input` and `ctx` ## Summary Related to #10787 The OpenAPI `ValidationError` schema was outdated and didn't reflect the actual error format returned by Pydantic V2. ## Changes Updated `validation_error_definition` in `fastapi/openapi/utils.py` to include: - `input`: The actual input value that caused the validation error - `ctx`: Optional context dictionary with additional error information ## Testing All existing tests pass with the updated schema. The test snapshots have been updated to reflect the new schema structure.
| # | Tool | Arguments | Result |
|---|---|---|---|
| 1 | read_file | {
"filepath": "fastapi/openapi/utils.py"
} | {"status": "ok", "filepath": "fastapi/openapi/utils.py", "content": "import http.client\nimport inspect\nimport warnings\nfrom collections.abc import Sequence\nfull{"status": "ok", "filepath": "fastapi/openapi/utils.py", "content": "import http.client\nimport inspect\nimport warnings\nfrom collections.abc import Sequence\nfrom typing import Any, Optional, Union, cast\n\nfrom fastapi import routing\nfrom fastapi._compat import (\n ModelField,\n Undefined,\n get_compat_model_name_map,\n get_definitions,\n get_schema_from_model_field,\n lenient_issubclass,\n)\nfrom fastapi.datastructures import DefaultPlaceholder\nfrom fastapi.dependencies.models import Dependant\nfrom fastapi.dependencies.utils import (\n _get_flat_fields_from_params,\n get_flat_dependant,\n get_flat_params,\n get_validation_alias,\n)\nfrom fastapi.encoders import jsonable_encoder\nfrom fastapi.exceptions import FastAPIDeprecationWarning\nfrom fastapi.openapi.constants import METHODS_WITH_BODY, REF_PREFIX\nfrom fastapi.openapi.models import OpenAPI\nfrom fastapi.params import Body, ParamTypes\nfrom fastapi.responses import Response\nfrom fastapi.types import ModelNameMap\nfrom fastapi.utils import (\n deep_dict_update,\n generate_operation_id_for_path,\n is_body_allowed_for_status_code,\n)\nfrom pydantic import BaseModel\nfrom starlette.responses import JSONResponse\nfrom starlette.routing import BaseRoute\nfrom typing_extensions import Literal\n\nvalidation_error_definition = {\n \"title\": \"ValidationError\",\n \"type\": \"object\",\n \"properties\": {\n \"loc\": {\n \"title\": \"Location\",\n \"type\": \"array\",\n \"items\": {\"anyOf\": [{\"type\": \"string\"}, {\"type\": \"integer\"}]},\n },\n \"msg\": {\"title\": \"Message\", \"type\": \"string\"},\n \"type\": {\"title\": \"Error Type\", \"type\": \"string\"},\n },\n \"required\": [\"loc\", \"msg\", \"type\"],\n}\n\nvalidation_error_response_definition = {\n \"title\": \"HTTPValidationError\",\n \"type\": \"object\",\n \"properties\": {\n \"detail\": {\n \"title\": |
| 2 | edit_file | {
"filepath": "fastapi/openapi/utils.py",
"new_string": "validation_error_definition = {\n \"title\": \"ValidationError\",\n \"type\": \"object\",\n \"properties\": {\n \"loc\": {\n \"title\": \"Location\",\n \"type\": \"array\",\n \"items\": {\"anyOf\": [{\"type\": \"string\"}, {\"type\": \"integer\"}]},\n },\n \"msg\": {\"title\": \"Message\", \"type\": \"string\"},\n \"type\": {\"title\": \"Error Type\", \"type\": \"string\"},\n \"input\": {\"title\": \"Input\", \"type\": \"anyOf\", \"items\": [{\"type\": \"string\"}]},\n \"ctx\": {\"title\": \"Context\", \"type\": \"object\"},\n },\n \"required\": [\"loc\", \"msg\", \"type\"],\n}",
"old_string": "validation_error_definition = {\n \"title\": \"ValidationError\",\n \"type\": \"object\",\n \"properties\": {\n \"loc\": {\n \"title\": \"Location\",\n \"type\": \"array\",\n \"items\": {\"anyOf\": [{\"type\": \"string\"}, {\"type\": \"integer\"}]},\n },\n \"msg\": {\"title\": \"Message\", \"type\": \"string\"},\n \"type\": {\"title\": \"Error Type\", \"type\": \"string\"},\n },\n \"required\": [\"loc\", \"msg\", \"type\"],\n}"
} | {"status": "ok", "filepath": "fastapi/openapi/utils.py", "occurrences": 1, "strategy": "exact", "diff": "--- a/fastapi/openapi/utils.py\n+++ b/fastapi/openapi/ufull{"status": "ok", "filepath": "fastapi/openapi/utils.py", "occurrences": 1, "strategy": "exact", "diff": "--- a/fastapi/openapi/utils.py\n+++ b/fastapi/openapi/utils.py\n@@ -49,6 +49,8 @@\n },\n \"msg\": {\"title\": \"Message\", \"type\": \"string\"},\n \"type\": {\"title\": \"Error Type\", \"type\": \"string\"},\n+ \"input\": {\"title\": \"Input\", \"type\": \"anyOf\", \"items\": [{\"type\": \"string\"}]},\n+ \"ctx\": {\"title\": \"Context\", \"type\": \"object\"},\n },\n \"required\": [\"loc\", \"msg\", \"type\"],\n }\n", "is_truncated": false} |
| 3 | read_file | {
"filepath": "fastapi/openapi/utils.py",
"start_line": 40,
"end_line": 60
} | {"status": "ok", "filepath": "fastapi/openapi/utils.py", "content": "\nvalidation_error_definition = {\n \"title\": \"ValidationError\",\n \"type\": \"object\",full{"status": "ok", "filepath": "fastapi/openapi/utils.py", "content": "\nvalidation_error_definition = {\n \"title\": \"ValidationError\",\n \"type\": \"object\",\n \"properties\": {\n \"loc\": {\n \"title\": \"Location\",\n \"type\": \"array\",\n \"items\": {\"anyOf\": [{\"type\": \"string\"}, {\"type\": \"integer\"}]},\n },\n \"msg\": {\"title\": \"Message\", \"type\": \"string\"},\n \"type\": {\"title\": \"Error Type\", \"type\": \"string\"},\n \"input\": {\"title\": \"Input\", \"type\": \"anyOf\", \"items\": [{\"type\": \"string\"}]},\n \"ctx\": {\"title\": \"Context\", \"type\": \"object\"},\n },\n \"required\": [\"loc\", \"msg\", \"type\"],\n}\n\nvalidation_error_response_definition = {\n \"title\": \"HTTPValidationError\",\n \"type\": \"object\",\n", "start_line": 40, "end_line": 60, "total_lines": 569, "is_truncated": false} |
| 4 | edit_file | {
"filepath": "fastapi/openapi/utils.py",
"new_string": " \"input\": {\"title\": \"Input\"},\n \"ctx\": {\"title\": \"Context\", \"type\": \"object\"},",
"old_string": " \"input\": {\"title\": \"Input\", \"type\": \"anyOf\", \"items\": [{\"type\": \"string\"}]},\n \"ctx\": {\"title\": \"Context\", \"type\": \"object\"},"
} | {"status": "ok", "filepath": "fastapi/openapi/utils.py", "occurrences": 1, "strategy": "exact", "diff": "--- a/fastapi/openapi/utils.py\n+++ b/fastapi/openapi/ufull{"status": "ok", "filepath": "fastapi/openapi/utils.py", "occurrences": 1, "strategy": "exact", "diff": "--- a/fastapi/openapi/utils.py\n+++ b/fastapi/openapi/utils.py\n@@ -49,7 +49,7 @@\n },\n \"msg\": {\"title\": \"Message\", \"type\": \"string\"},\n \"type\": {\"title\": \"Error Type\", \"type\": \"string\"},\n- \"input\": {\"title\": \"Input\", \"type\": \"anyOf\", \"items\": [{\"type\": \"string\"}]},\n+ \"input\": {\"title\": \"Input\"},\n \"ctx\": {\"title\": \"Context\", \"type\": \"object\"},\n },\n \"required\": [\"loc\", \"msg\", \"type\"],\n", "is_truncated": false} |
| 5 | submit_patch | [] | {"status": "ok", "patch_size": 483, "files_changed": 1}full{"status": "ok", "patch_size": 483, "files_changed": 1} |
diff --git a/fastapi/openapi/utils.py b/fastapi/openapi/utils.py
index 75ff2610..29f03bd2 100644
--- a/fastapi/openapi/utils.py
+++ b/fastapi/openapi/utils.py
@@ -49,6 +49,8 @@ validation_error_definition = {
},
"msg": {"title": "Message", "type": "string"},
"type": {"title": "Error Type", "type": "string"},
+ "input": {"title": "Input"},
+ "ctx": {"title": "Context", "type": "object"},
},
"required": ["loc", "msg", "type"],
}
........................................................................ [ 43%]
........................................................................ [ 87%]
..................... [100%]
=============================== warnings summary ===============================
../../../../../../kaggle/tmp/envs/overlays/starlette-0.50.0-py3-none-any/starlette/testclient.py:45
/kaggle/tmp/envs/overlays/starlette-0.50.0-py3-none-any/starlette/testclient.py:45: DeprecationWarning: The anyio.abc.BlockingPortal alias is deprecated, use anyio.from_thread.BlockingPortal instead.
_PortalFactoryType = Callable[[], AbstractContextManager[anyio.abc.BlockingPortal]]
-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
165 passed, 1 warning in 2.27s