From 0a27fa91d8ce663deb4449a2cc21837a05f81a25 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Szafra=C5=84ski?= Date: Mon, 20 May 2024 11:51:09 +0200 Subject: [PATCH 1/2] Add HTTP 429 Too Many Requests as a possible generic error response --- CHANGELOG.md | 6 ++ example/tests/__snapshots__/test_openapi.ambr | 60 +++++++++++++++++++ rest_framework_json_api/schemas/openapi.py | 1 + 3 files changed, 67 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e1d08de6..7ea98bdf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 Note that in line with [Django REST framework policy](https://www.django-rest-framework.org/topics/release-notes/), any parts of the framework not mentioned in the documentation should generally be considered private API, and may be subject to change. +## [Unreleased] + +* Added `429 Too Many Requests` as a possible error response in the OpenAPI schema. + +### Added + ## [7.0.0] - 2024-05-02 ### Added diff --git a/example/tests/__snapshots__/test_openapi.ambr b/example/tests/__snapshots__/test_openapi.ambr index 1de8057b..f72c6ff8 100644 --- a/example/tests/__snapshots__/test_openapi.ambr +++ b/example/tests/__snapshots__/test_openapi.ambr @@ -68,6 +68,16 @@ } }, "description": "[Resource does not exist](https://jsonapi.org/format/#crud-deleting-responses-404)" + }, + "429": { + "content": { + "application/vnd.api+json": { + "schema": { + "$ref": "#/components/schemas/failure" + } + } + }, + "description": "too many requests" } }, "tags": [ @@ -264,6 +274,16 @@ } }, "description": "[Conflict]([Conflict](https://jsonapi.org/format/#crud-updating-responses-409)" + }, + "429": { + "content": { + "application/vnd.api+json": { + "schema": { + "$ref": "#/components/schemas/failure" + } + } + }, + "description": "too many requests" } }, "tags": [ @@ -399,6 +419,16 @@ } }, "description": "not found" + }, + "429": { + "content": { + "application/vnd.api+json": { + "schema": { + "$ref": "#/components/schemas/failure" + } + } + }, + "description": "too many requests" } }, "tags": [ @@ -546,6 +576,16 @@ } }, "description": "not found" + }, + "429": { + "content": { + "application/vnd.api+json": { + "schema": { + "$ref": "#/components/schemas/failure" + } + } + }, + "description": "too many requests" } }, "tags": [ @@ -754,6 +794,16 @@ } }, "description": "[Conflict](https://jsonapi.org/format/#crud-creating-responses-409)" + }, + "429": { + "content": { + "application/vnd.api+json": { + "schema": { + "$ref": "#/components/schemas/failure" + } + } + }, + "description": "too many requests" } }, "tags": [ @@ -1341,6 +1391,16 @@ } }, "description": "not found" + }, + "429": { + "content": { + "application/vnd.api+json": { + "schema": { + "$ref": "#/components/schemas/failure" + } + } + }, + "description": "too many requests" } }, "tags": [ diff --git a/rest_framework_json_api/schemas/openapi.py b/rest_framework_json_api/schemas/openapi.py index 650876e6..b44ce7a4 100644 --- a/rest_framework_json_api/schemas/openapi.py +++ b/rest_framework_json_api/schemas/openapi.py @@ -807,6 +807,7 @@ def _add_generic_failure_responses(self, operation): for code, reason in [ ("400", "bad request"), ("401", "not authorized"), + ("429", "too many requests"), ]: operation["responses"][code] = self._failure_response(reason) From 11743deae3b8ea7b869b821904c8eebc265e5c76 Mon Sep 17 00:00:00 2001 From: Oliver Sauder Date: Wed, 29 May 2024 10:02:44 +0200 Subject: [PATCH 2/2] Update CHANGELOG.md --- CHANGELOG.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7ea98bdf..a61d5faf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,9 +10,9 @@ any parts of the framework not mentioned in the documentation should generally b ## [Unreleased] -* Added `429 Too Many Requests` as a possible error response in the OpenAPI schema. +### Added -### Added +* Added `429 Too Many Requests` as a possible error response in the OpenAPI schema. ## [7.0.0] - 2024-05-02