Skip to content

Commit

Permalink
Add HTTP 400 Bad Request as a possible generic error response (#1165)
Browse files Browse the repository at this point in the history
  • Loading branch information
arttuperala authored Jul 3, 2023
1 parent 590dbb4 commit 39a9c92
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 0 deletions.
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

0 comments on commit 39a9c92

Please sign in to comment.