Skip to content

Commit 720e154

Browse files
committed
fix: set Problem responses content type to application/problem+json in openapi specification
1 parent 5dc1625 commit 720e154

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

src/fastapi_problem_details/error_handlers.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,15 @@ def init_app(
1717
validation_error_detail: str = "Request validation failed",
1818
include_exc_info_in_response: bool = False,
1919
) -> FastAPI:
20-
app.router.responses.setdefault("default", {"model": Problem})
20+
app.router.responses.setdefault(
21+
"default",
22+
{
23+
"description": "Problem",
24+
"content": {
25+
"application/problem+json": {"schema": Problem.model_json_schema()}
26+
},
27+
},
28+
)
2129

2230
@app.exception_handler(RequestValidationError)
2331
async def handle_validation_error(

tests/test_app_integration.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,15 @@ def test_init_app_register_problem_details_as_default_response() -> None:
5656
# When
5757
problem.init_app(app)
5858
# Then
59-
assert ("default", {"model": Problem}) in app.router.responses.items()
59+
assert (
60+
"default",
61+
{
62+
"description": "Problem",
63+
"content": {
64+
"application/problem+json": {"schema": Problem.model_json_schema()}
65+
},
66+
},
67+
) in app.router.responses.items()
6068

6169

6270
class TestValidationError:

0 commit comments

Comments
 (0)