FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Include root cause in request body validation errors by p1c2u · Pull Request #1128 · python-openapi/openapi-core · GitHub

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (2) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
2 changes: 2 additions & 0 deletions openapi_core/validation/request/exceptions.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ class RequestValidationError(ValidationError):

class RequestBodyValidationError(RequestValidationError):
def __str__(self) -> str:
if self.__cause__ is not None:
return f"Request body validation error: {self.__cause__}"
return "Request body validation error"


Expand Down
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,31 @@ def test_request_validator_urlencoded_json_part_strict() -> None:
validator.validate(request)


def test_request_validator_error_message_includes_cause_details() -> None:
spec = _spec_schema_path()
validator = V30RequestValidator(spec)

request_json = {
"id": "123e4567-e89b-12d3-a456-426614174000",
"username": "Test User",
"age": "30",
}
request = MockRequest(
"http://example.com",
"post",
"/users",
content_type="application/json",
data=json.dumps(request_json).encode("utf-8"),
)

with pytest.raises(InvalidRequestBody) as exc_info:
validator.validate(request)

error_message = str(exc_info.value)
assert error_message.startswith("Request body validation error:")
assert "'30' is not of type 'integer'" in error_message


def test_response_validator_strict_json_nested_types() -> None:
"""Test that nested JSON structures (arrays, objects) remain strict."""
spec_dict = {
Expand Down
Loading

Back | FazBrowse Home | New Git URL