Skip to content

Add HTTP 400 Bad Request as a possible generic error response #1165

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

Merged
merged 1 commit into from
Jul 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ any parts of the framework not mentioned in the documentation should generally b

* Added support for Python 3.11.
* Added support for Django 4.2.
* Added `400 Bad Request` as a possible error response in the OpenAPI schema.

### Changed

Expand Down
60 changes: 60 additions & 0 deletions example/tests/__snapshots__/test_openapi.ambr
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,16 @@
"204": {
"description": "[no content](https://jsonapi.org/format/#crud-deleting-responses-204)"
},
"400": {
"content": {
"application/vnd.api+json": {
"schema": {
"$ref": "#/components/schemas/failure"
}
}
},
"description": "bad request"
},
"401": {
"content": {
"application/vnd.api+json": {
Expand Down Expand Up @@ -204,6 +214,16 @@
},
"description": "update/authors/{id}"
},
"400": {
"content": {
"application/vnd.api+json": {
"schema": {
"$ref": "#/components/schemas/failure"
}
}
},
"description": "bad request"
},
"401": {
"content": {
"application/vnd.api+json": {
Expand Down Expand Up @@ -349,6 +369,16 @@
},
"description": "retrieve/authors/{id}/"
},
"400": {
"content": {
"application/vnd.api+json": {
"schema": {
"$ref": "#/components/schemas/failure"
}
}
},
"description": "bad request"
},
"401": {
"content": {
"application/vnd.api+json": {
Expand Down Expand Up @@ -486,6 +516,16 @@
},
"description": "List/authors/"
},
"400": {
"content": {
"application/vnd.api+json": {
"schema": {
"$ref": "#/components/schemas/failure"
}
}
},
"description": "bad request"
},
"401": {
"content": {
"application/vnd.api+json": {
Expand Down Expand Up @@ -664,6 +704,16 @@
"204": {
"description": "[Created](https://jsonapi.org/format/#crud-creating-responses-204) with the supplied `id`. No other changes from what was POSTed."
},
"400": {
"content": {
"application/vnd.api+json": {
"schema": {
"$ref": "#/components/schemas/failure"
}
}
},
"description": "bad request"
},
"401": {
"content": {
"application/vnd.api+json": {
Expand Down Expand Up @@ -1231,6 +1281,16 @@
},
"description": "List/authors/"
},
"400": {
"content": {
"application/vnd.api+json": {
"schema": {
"$ref": "#/components/schemas/failure"
}
}
},
"description": "bad request"
},
"401": {
"content": {
"application/vnd.api+json": {
Expand Down
1 change: 1 addition & 0 deletions rest_framework_json_api/schemas/openapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -779,6 +779,7 @@ def _add_generic_failure_responses(self, operation):
Add generic failure response(s) to operation
"""
for code, reason in [
("400", "bad request"),
("401", "not authorized"),
]:
operation["responses"][code] = self._failure_response(reason)
Expand Down