|
|
@ -1,7 +1,6 @@ |
|
|
|
import asyncio |
|
|
|
import dataclasses |
|
|
|
import email.message |
|
|
|
import inspect |
|
|
|
import json |
|
|
|
from contextlib import AsyncExitStack, asynccontextmanager |
|
|
|
from enum import Enum, IntEnum |
|
|
@ -57,6 +56,7 @@ from fastapi.utils import ( |
|
|
|
get_value_or_default, |
|
|
|
is_body_allowed_for_status_code, |
|
|
|
) |
|
|
|
from griffe import Docstring |
|
|
|
from pydantic import BaseModel |
|
|
|
from starlette import routing |
|
|
|
from starlette.concurrency import run_in_threadpool |
|
|
@ -438,7 +438,7 @@ class APIRoute(routing.Route): |
|
|
|
dependencies: Optional[Sequence[params.Depends]] = None, |
|
|
|
summary: Optional[str] = None, |
|
|
|
description: Optional[str] = None, |
|
|
|
response_description: str = "Successful Response", |
|
|
|
response_description: Optional[str] = None, |
|
|
|
responses: Optional[Dict[Union[int, str], Dict[str, Any]]] = None, |
|
|
|
deprecated: Optional[bool] = None, |
|
|
|
name: Optional[str] = None, |
|
|
@ -529,10 +529,13 @@ class APIRoute(routing.Route): |
|
|
|
self.response_field = None # type: ignore |
|
|
|
self.secure_cloned_response_field = None |
|
|
|
self.dependencies = list(dependencies or []) |
|
|
|
self.description = description or inspect.cleandoc(self.endpoint.__doc__ or "") |
|
|
|
self.description = description |
|
|
|
self.docstring = self.endpoint.__doc__ or "" |
|
|
|
self.parsed_docstring = Docstring( |
|
|
|
self.docstring, parser="google", parser_options={"warnings": False} |
|
|
|
).parsed |
|
|
|
# if a "form feed" character (page break) is found in the description text, |
|
|
|
# truncate description text to the content preceding the first "form feed" |
|
|
|
self.description = self.description.split("\f")[0].strip() |
|
|
|
response_fields = {} |
|
|
|
for additional_status_code, response in self.responses.items(): |
|
|
|
assert isinstance(response, dict), "An additional response must be a dict" |
|
|
@ -890,7 +893,7 @@ class APIRouter(routing.Router): |
|
|
|
dependencies: Optional[Sequence[params.Depends]] = None, |
|
|
|
summary: Optional[str] = None, |
|
|
|
description: Optional[str] = None, |
|
|
|
response_description: str = "Successful Response", |
|
|
|
response_description: Optional[str] = None, |
|
|
|
responses: Optional[Dict[Union[int, str], Dict[str, Any]]] = None, |
|
|
|
deprecated: Optional[bool] = None, |
|
|
|
methods: Optional[Union[Set[str], List[str]]] = None, |
|
|
@ -971,7 +974,7 @@ class APIRouter(routing.Router): |
|
|
|
dependencies: Optional[Sequence[params.Depends]] = None, |
|
|
|
summary: Optional[str] = None, |
|
|
|
description: Optional[str] = None, |
|
|
|
response_description: str = "Successful Response", |
|
|
|
response_description: Optional[str] = None, |
|
|
|
responses: Optional[Dict[Union[int, str], Dict[str, Any]]] = None, |
|
|
|
deprecated: Optional[bool] = None, |
|
|
|
methods: Optional[List[str]] = None, |
|
|
@ -1481,7 +1484,7 @@ class APIRouter(routing.Router): |
|
|
|
), |
|
|
|
] = None, |
|
|
|
response_description: Annotated[ |
|
|
|
str, |
|
|
|
Optional[str], |
|
|
|
Doc( |
|
|
|
""" |
|
|
|
The description for the default response. |
|
|
@ -1489,7 +1492,7 @@ class APIRouter(routing.Router): |
|
|
|
It will be added to the generated OpenAPI (e.g. visible at `/docs`). |
|
|
|
""" |
|
|
|
), |
|
|
|
] = "Successful Response", |
|
|
|
] = None, |
|
|
|
responses: Annotated[ |
|
|
|
Optional[Dict[Union[int, str], Dict[str, Any]]], |
|
|
|
Doc( |
|
|
@ -1858,7 +1861,7 @@ class APIRouter(routing.Router): |
|
|
|
), |
|
|
|
] = None, |
|
|
|
response_description: Annotated[ |
|
|
|
str, |
|
|
|
Optional[str], |
|
|
|
Doc( |
|
|
|
""" |
|
|
|
The description for the default response. |
|
|
@ -1866,7 +1869,7 @@ class APIRouter(routing.Router): |
|
|
|
It will be added to the generated OpenAPI (e.g. visible at `/docs`). |
|
|
|
""" |
|
|
|
), |
|
|
|
] = "Successful Response", |
|
|
|
] = None, |
|
|
|
responses: Annotated[ |
|
|
|
Optional[Dict[Union[int, str], Dict[str, Any]]], |
|
|
|
Doc( |
|
|
@ -2240,7 +2243,7 @@ class APIRouter(routing.Router): |
|
|
|
), |
|
|
|
] = None, |
|
|
|
response_description: Annotated[ |
|
|
|
str, |
|
|
|
Optional[str], |
|
|
|
Doc( |
|
|
|
""" |
|
|
|
The description for the default response. |
|
|
@ -2248,7 +2251,7 @@ class APIRouter(routing.Router): |
|
|
|
It will be added to the generated OpenAPI (e.g. visible at `/docs`). |
|
|
|
""" |
|
|
|
), |
|
|
|
] = "Successful Response", |
|
|
|
] = None, |
|
|
|
responses: Annotated[ |
|
|
|
Optional[Dict[Union[int, str], Dict[str, Any]]], |
|
|
|
Doc( |
|
|
@ -2622,7 +2625,7 @@ class APIRouter(routing.Router): |
|
|
|
), |
|
|
|
] = None, |
|
|
|
response_description: Annotated[ |
|
|
|
str, |
|
|
|
Optional[str], |
|
|
|
Doc( |
|
|
|
""" |
|
|
|
The description for the default response. |
|
|
@ -2630,7 +2633,7 @@ class APIRouter(routing.Router): |
|
|
|
It will be added to the generated OpenAPI (e.g. visible at `/docs`). |
|
|
|
""" |
|
|
|
), |
|
|
|
] = "Successful Response", |
|
|
|
] = None, |
|
|
|
responses: Annotated[ |
|
|
|
Optional[Dict[Union[int, str], Dict[str, Any]]], |
|
|
|
Doc( |
|
|
@ -2999,7 +3002,7 @@ class APIRouter(routing.Router): |
|
|
|
), |
|
|
|
] = None, |
|
|
|
response_description: Annotated[ |
|
|
|
str, |
|
|
|
Optional[str], |
|
|
|
Doc( |
|
|
|
""" |
|
|
|
The description for the default response. |
|
|
@ -3007,7 +3010,7 @@ class APIRouter(routing.Router): |
|
|
|
It will be added to the generated OpenAPI (e.g. visible at `/docs`). |
|
|
|
""" |
|
|
|
), |
|
|
|
] = "Successful Response", |
|
|
|
] = None, |
|
|
|
responses: Annotated[ |
|
|
|
Optional[Dict[Union[int, str], Dict[str, Any]]], |
|
|
|
Doc( |
|
|
@ -3376,7 +3379,7 @@ class APIRouter(routing.Router): |
|
|
|
), |
|
|
|
] = None, |
|
|
|
response_description: Annotated[ |
|
|
|
str, |
|
|
|
Optional[str], |
|
|
|
Doc( |
|
|
|
""" |
|
|
|
The description for the default response. |
|
|
@ -3384,7 +3387,7 @@ class APIRouter(routing.Router): |
|
|
|
It will be added to the generated OpenAPI (e.g. visible at `/docs`). |
|
|
|
""" |
|
|
|
), |
|
|
|
] = "Successful Response", |
|
|
|
] = None, |
|
|
|
responses: Annotated[ |
|
|
|
Optional[Dict[Union[int, str], Dict[str, Any]]], |
|
|
|
Doc( |
|
|
@ -3758,7 +3761,7 @@ class APIRouter(routing.Router): |
|
|
|
), |
|
|
|
] = None, |
|
|
|
response_description: Annotated[ |
|
|
|
str, |
|
|
|
Optional[str], |
|
|
|
Doc( |
|
|
|
""" |
|
|
|
The description for the default response. |
|
|
@ -3766,7 +3769,7 @@ class APIRouter(routing.Router): |
|
|
|
It will be added to the generated OpenAPI (e.g. visible at `/docs`). |
|
|
|
""" |
|
|
|
), |
|
|
|
] = "Successful Response", |
|
|
|
] = None, |
|
|
|
responses: Annotated[ |
|
|
|
Optional[Dict[Union[int, str], Dict[str, Any]]], |
|
|
|
Doc( |
|
|
@ -4140,7 +4143,7 @@ class APIRouter(routing.Router): |
|
|
|
), |
|
|
|
] = None, |
|
|
|
response_description: Annotated[ |
|
|
|
str, |
|
|
|
Optional[str], |
|
|
|
Doc( |
|
|
|
""" |
|
|
|
The description for the default response. |
|
|
@ -4148,7 +4151,7 @@ class APIRouter(routing.Router): |
|
|
|
It will be added to the generated OpenAPI (e.g. visible at `/docs`). |
|
|
|
""" |
|
|
|
), |
|
|
|
] = "Successful Response", |
|
|
|
] = None, |
|
|
|
responses: Annotated[ |
|
|
|
Optional[Dict[Union[int, str], Dict[str, Any]]], |
|
|
|
Doc( |
|
|
|