Use default response status reasons in additional responses (#313)

* default the description of additional response to status reason phrase

* fix 404 description

* fix lint warning

* allow custom response status code
This commit is contained in:
Eric Du 2019-06-18 15:46:57 +08:00 committed by Sebastián Ramírez
parent bdd794a0e6
commit 5b3adfe449
2 changed files with 6 additions and 2 deletions

View file

@ -1,3 +1,4 @@
import http.client
from typing import Any, Dict, List, Optional, Sequence, Tuple, Type, cast from typing import Any, Dict, List, Optional, Sequence, Tuple, Type, cast
from fastapi import routing from fastapi import routing
@ -187,7 +188,10 @@ def get_openapi_path(
response.setdefault("content", {}).setdefault( response.setdefault("content", {}).setdefault(
"application/json", {} "application/json", {}
)["schema"] = response_schema )["schema"] = response_schema
response.setdefault("description", "Additional Response") status_text = http.client.responses.get(int(additional_status_code))
response.setdefault(
"description", status_text or "Additional Response"
)
operation.setdefault("responses", {})[ operation.setdefault("responses", {})[
str(additional_status_code) str(additional_status_code)
] = response ] = response

View file

@ -12,7 +12,7 @@ openapi_schema = {
"get": { "get": {
"responses": { "responses": {
"404": { "404": {
"description": "Additional Response", "description": "Not Found",
"content": { "content": {
"application/json": { "application/json": {
"schema": {"$ref": "#/components/schemas/Message"} "schema": {"$ref": "#/components/schemas/Message"}