From 213bad436b33050b96aa7b6a844194f54548f571 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arttu=20Per=C3=A4l=C3=A4?= Date: Mon, 3 Jul 2023 14:03:36 +0300 Subject: [PATCH] Add HTTP 400 Bad Request as a possible generic error response --- CHANGELOG.md | 1 + example/tests/__snapshots__/test_openapi.ambr | 60 +++++++++++++++++++ rest_framework_json_api/schemas/openapi.py | 1 + 3 files changed, 62 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index a5f86d1d..05ebecd8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/example/tests/__snapshots__/test_openapi.ambr b/example/tests/__snapshots__/test_openapi.ambr index 93b8f7fb..28cb78f0 100644 --- a/example/tests/__snapshots__/test_openapi.ambr +++ b/example/tests/__snapshots__/test_openapi.ambr @@ -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": { @@ -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": { @@ -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": { @@ -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": { @@ -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": { @@ -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": { diff --git a/rest_framework_json_api/schemas/openapi.py b/rest_framework_json_api/schemas/openapi.py index a0d2be0d..9c1dd620 100644 --- a/rest_framework_json_api/schemas/openapi.py +++ b/rest_framework_json_api/schemas/openapi.py @@ -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) pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy