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 fastapi import routing
@ -187,7 +188,10 @@ def get_openapi_path(
response.setdefault("content", {}).setdefault(
"application/json", {}
)["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", {})[
str(additional_status_code)
] = response

View File

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