mirror of https://github.com/tiangolo/fastapi.git
✨ 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:
parent
bdd794a0e6
commit
5b3adfe449
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ openapi_schema = {
|
|||
"get": {
|
||||
"responses": {
|
||||
"404": {
|
||||
"description": "Additional Response",
|
||||
"description": "Not Found",
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {"$ref": "#/components/schemas/Message"}
|
||||
|
|
|
|||
Loading…
Reference in New Issue