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

Improve JSON req error on disallowed empty body #1761

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Add test
  • Loading branch information
RobbeSneyders committed Nov 1, 2023
commit 58470e861722761340fe4947f7ca9c4d8a8127a4
2 changes: 1 addition & 1 deletion connexion/validators/form_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ async def _parse(self, stream: t.AsyncGenerator[bytes, None], scope: Scope) -> d

return data

def _validate(self, body: t.Any) -> t.Optional[dict]:
def _validate(self, body: t.Any) -> t.Optional[dict]: # type: ignore[return]
if not isinstance(body, dict):
raise BadRequestProblem("Parsed body must be a mapping")
if self._strict_validation:
Expand Down
7 changes: 7 additions & 0 deletions tests/api/test_errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,10 @@ def test_errors(problem_app):
"Invalid Content-type (text/html)"
)
assert unsupported_media_type_body["status"] == 415


def test_should_raise_400_for_no_json(simple_app):
app_client = simple_app.test_client()
response = app_client.post("/v1.0/test-empty-object-body")
assert response.status_code == 400
assert response.json()["detail"] == "Request body must not be empty"
Loading