|
@ -1,7 +1,6 @@ |
|
|
import asyncio |
|
|
import asyncio |
|
|
import dataclasses |
|
|
import dataclasses |
|
|
import email.message |
|
|
import email.message |
|
|
import inspect |
|
|
|
|
|
import json |
|
|
import json |
|
|
from contextlib import AsyncExitStack, asynccontextmanager |
|
|
from contextlib import AsyncExitStack, asynccontextmanager |
|
|
from enum import Enum, IntEnum |
|
|
from enum import Enum, IntEnum |
|
@ -56,6 +55,7 @@ from fastapi.utils import ( |
|
|
get_value_or_default, |
|
|
get_value_or_default, |
|
|
is_body_allowed_for_status_code, |
|
|
is_body_allowed_for_status_code, |
|
|
) |
|
|
) |
|
|
|
|
|
from griffe import Docstring |
|
|
from pydantic import BaseModel |
|
|
from pydantic import BaseModel |
|
|
from starlette import routing |
|
|
from starlette import routing |
|
|
from starlette.concurrency import run_in_threadpool |
|
|
from starlette.concurrency import run_in_threadpool |
|
@ -437,7 +437,7 @@ class APIRoute(routing.Route): |
|
|
dependencies: Optional[Sequence[params.Depends]] = None, |
|
|
dependencies: Optional[Sequence[params.Depends]] = None, |
|
|
summary: Optional[str] = None, |
|
|
summary: Optional[str] = None, |
|
|
description: 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, |
|
|
responses: Optional[Dict[Union[int, str], Dict[str, Any]]] = None, |
|
|
deprecated: Optional[bool] = None, |
|
|
deprecated: Optional[bool] = None, |
|
|
name: Optional[str] = None, |
|
|
name: Optional[str] = None, |
|
@ -528,10 +528,13 @@ class APIRoute(routing.Route): |
|
|
self.response_field = None # type: ignore |
|
|
self.response_field = None # type: ignore |
|
|
self.secure_cloned_response_field = None |
|
|
self.secure_cloned_response_field = None |
|
|
self.dependencies = list(dependencies or []) |
|
|
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, |
|
|
# if a "form feed" character (page break) is found in the description text, |
|
|
# truncate description text to the content preceding the first "form feed" |
|
|
# truncate description text to the content preceding the first "form feed" |
|
|
self.description = self.description.split("\f")[0].strip() |
|
|
|
|
|
response_fields = {} |
|
|
response_fields = {} |
|
|
for additional_status_code, response in self.responses.items(): |
|
|
for additional_status_code, response in self.responses.items(): |
|
|
assert isinstance(response, dict), "An additional response must be a dict" |
|
|
assert isinstance(response, dict), "An additional response must be a dict" |
|
@ -889,7 +892,7 @@ class APIRouter(routing.Router): |
|
|
dependencies: Optional[Sequence[params.Depends]] = None, |
|
|
dependencies: Optional[Sequence[params.Depends]] = None, |
|
|
summary: Optional[str] = None, |
|
|
summary: Optional[str] = None, |
|
|
description: 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, |
|
|
responses: Optional[Dict[Union[int, str], Dict[str, Any]]] = None, |
|
|
deprecated: Optional[bool] = None, |
|
|
deprecated: Optional[bool] = None, |
|
|
methods: Optional[Union[Set[str], List[str]]] = None, |
|
|
methods: Optional[Union[Set[str], List[str]]] = None, |
|
@ -970,7 +973,7 @@ class APIRouter(routing.Router): |
|
|
dependencies: Optional[Sequence[params.Depends]] = None, |
|
|
dependencies: Optional[Sequence[params.Depends]] = None, |
|
|
summary: Optional[str] = None, |
|
|
summary: Optional[str] = None, |
|
|
description: 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, |
|
|
responses: Optional[Dict[Union[int, str], Dict[str, Any]]] = None, |
|
|
deprecated: Optional[bool] = None, |
|
|
deprecated: Optional[bool] = None, |
|
|
methods: Optional[List[str]] = None, |
|
|
methods: Optional[List[str]] = None, |
|
@ -1480,7 +1483,7 @@ class APIRouter(routing.Router): |
|
|
), |
|
|
), |
|
|
] = None, |
|
|
] = None, |
|
|
response_description: Annotated[ |
|
|
response_description: Annotated[ |
|
|
str, |
|
|
Optional[str], |
|
|
Doc( |
|
|
Doc( |
|
|
""" |
|
|
""" |
|
|
The description for the default response. |
|
|
The description for the default response. |
|
@ -1488,7 +1491,7 @@ class APIRouter(routing.Router): |
|
|
It will be added to the generated OpenAPI (e.g. visible at `/docs`). |
|
|
It will be added to the generated OpenAPI (e.g. visible at `/docs`). |
|
|
""" |
|
|
""" |
|
|
), |
|
|
), |
|
|
] = "Successful Response", |
|
|
] = None, |
|
|
responses: Annotated[ |
|
|
responses: Annotated[ |
|
|
Optional[Dict[Union[int, str], Dict[str, Any]]], |
|
|
Optional[Dict[Union[int, str], Dict[str, Any]]], |
|
|
Doc( |
|
|
Doc( |
|
@ -1857,7 +1860,7 @@ class APIRouter(routing.Router): |
|
|
), |
|
|
), |
|
|
] = None, |
|
|
] = None, |
|
|
response_description: Annotated[ |
|
|
response_description: Annotated[ |
|
|
str, |
|
|
Optional[str], |
|
|
Doc( |
|
|
Doc( |
|
|
""" |
|
|
""" |
|
|
The description for the default response. |
|
|
The description for the default response. |
|
@ -1865,7 +1868,7 @@ class APIRouter(routing.Router): |
|
|
It will be added to the generated OpenAPI (e.g. visible at `/docs`). |
|
|
It will be added to the generated OpenAPI (e.g. visible at `/docs`). |
|
|
""" |
|
|
""" |
|
|
), |
|
|
), |
|
|
] = "Successful Response", |
|
|
] = None, |
|
|
responses: Annotated[ |
|
|
responses: Annotated[ |
|
|
Optional[Dict[Union[int, str], Dict[str, Any]]], |
|
|
Optional[Dict[Union[int, str], Dict[str, Any]]], |
|
|
Doc( |
|
|
Doc( |
|
@ -2239,7 +2242,7 @@ class APIRouter(routing.Router): |
|
|
), |
|
|
), |
|
|
] = None, |
|
|
] = None, |
|
|
response_description: Annotated[ |
|
|
response_description: Annotated[ |
|
|
str, |
|
|
Optional[str], |
|
|
Doc( |
|
|
Doc( |
|
|
""" |
|
|
""" |
|
|
The description for the default response. |
|
|
The description for the default response. |
|
@ -2247,7 +2250,7 @@ class APIRouter(routing.Router): |
|
|
It will be added to the generated OpenAPI (e.g. visible at `/docs`). |
|
|
It will be added to the generated OpenAPI (e.g. visible at `/docs`). |
|
|
""" |
|
|
""" |
|
|
), |
|
|
), |
|
|
] = "Successful Response", |
|
|
] = None, |
|
|
responses: Annotated[ |
|
|
responses: Annotated[ |
|
|
Optional[Dict[Union[int, str], Dict[str, Any]]], |
|
|
Optional[Dict[Union[int, str], Dict[str, Any]]], |
|
|
Doc( |
|
|
Doc( |
|
@ -2621,7 +2624,7 @@ class APIRouter(routing.Router): |
|
|
), |
|
|
), |
|
|
] = None, |
|
|
] = None, |
|
|
response_description: Annotated[ |
|
|
response_description: Annotated[ |
|
|
str, |
|
|
Optional[str], |
|
|
Doc( |
|
|
Doc( |
|
|
""" |
|
|
""" |
|
|
The description for the default response. |
|
|
The description for the default response. |
|
@ -2629,7 +2632,7 @@ class APIRouter(routing.Router): |
|
|
It will be added to the generated OpenAPI (e.g. visible at `/docs`). |
|
|
It will be added to the generated OpenAPI (e.g. visible at `/docs`). |
|
|
""" |
|
|
""" |
|
|
), |
|
|
), |
|
|
] = "Successful Response", |
|
|
] = None, |
|
|
responses: Annotated[ |
|
|
responses: Annotated[ |
|
|
Optional[Dict[Union[int, str], Dict[str, Any]]], |
|
|
Optional[Dict[Union[int, str], Dict[str, Any]]], |
|
|
Doc( |
|
|
Doc( |
|
@ -2998,7 +3001,7 @@ class APIRouter(routing.Router): |
|
|
), |
|
|
), |
|
|
] = None, |
|
|
] = None, |
|
|
response_description: Annotated[ |
|
|
response_description: Annotated[ |
|
|
str, |
|
|
Optional[str], |
|
|
Doc( |
|
|
Doc( |
|
|
""" |
|
|
""" |
|
|
The description for the default response. |
|
|
The description for the default response. |
|
@ -3006,7 +3009,7 @@ class APIRouter(routing.Router): |
|
|
It will be added to the generated OpenAPI (e.g. visible at `/docs`). |
|
|
It will be added to the generated OpenAPI (e.g. visible at `/docs`). |
|
|
""" |
|
|
""" |
|
|
), |
|
|
), |
|
|
] = "Successful Response", |
|
|
] = None, |
|
|
responses: Annotated[ |
|
|
responses: Annotated[ |
|
|
Optional[Dict[Union[int, str], Dict[str, Any]]], |
|
|
Optional[Dict[Union[int, str], Dict[str, Any]]], |
|
|
Doc( |
|
|
Doc( |
|
@ -3375,7 +3378,7 @@ class APIRouter(routing.Router): |
|
|
), |
|
|
), |
|
|
] = None, |
|
|
] = None, |
|
|
response_description: Annotated[ |
|
|
response_description: Annotated[ |
|
|
str, |
|
|
Optional[str], |
|
|
Doc( |
|
|
Doc( |
|
|
""" |
|
|
""" |
|
|
The description for the default response. |
|
|
The description for the default response. |
|
@ -3383,7 +3386,7 @@ class APIRouter(routing.Router): |
|
|
It will be added to the generated OpenAPI (e.g. visible at `/docs`). |
|
|
It will be added to the generated OpenAPI (e.g. visible at `/docs`). |
|
|
""" |
|
|
""" |
|
|
), |
|
|
), |
|
|
] = "Successful Response", |
|
|
] = None, |
|
|
responses: Annotated[ |
|
|
responses: Annotated[ |
|
|
Optional[Dict[Union[int, str], Dict[str, Any]]], |
|
|
Optional[Dict[Union[int, str], Dict[str, Any]]], |
|
|
Doc( |
|
|
Doc( |
|
@ -3757,7 +3760,7 @@ class APIRouter(routing.Router): |
|
|
), |
|
|
), |
|
|
] = None, |
|
|
] = None, |
|
|
response_description: Annotated[ |
|
|
response_description: Annotated[ |
|
|
str, |
|
|
Optional[str], |
|
|
Doc( |
|
|
Doc( |
|
|
""" |
|
|
""" |
|
|
The description for the default response. |
|
|
The description for the default response. |
|
@ -3765,7 +3768,7 @@ class APIRouter(routing.Router): |
|
|
It will be added to the generated OpenAPI (e.g. visible at `/docs`). |
|
|
It will be added to the generated OpenAPI (e.g. visible at `/docs`). |
|
|
""" |
|
|
""" |
|
|
), |
|
|
), |
|
|
] = "Successful Response", |
|
|
] = None, |
|
|
responses: Annotated[ |
|
|
responses: Annotated[ |
|
|
Optional[Dict[Union[int, str], Dict[str, Any]]], |
|
|
Optional[Dict[Union[int, str], Dict[str, Any]]], |
|
|
Doc( |
|
|
Doc( |
|
@ -4139,7 +4142,7 @@ class APIRouter(routing.Router): |
|
|
), |
|
|
), |
|
|
] = None, |
|
|
] = None, |
|
|
response_description: Annotated[ |
|
|
response_description: Annotated[ |
|
|
str, |
|
|
Optional[str], |
|
|
Doc( |
|
|
Doc( |
|
|
""" |
|
|
""" |
|
|
The description for the default response. |
|
|
The description for the default response. |
|
@ -4147,7 +4150,7 @@ class APIRouter(routing.Router): |
|
|
It will be added to the generated OpenAPI (e.g. visible at `/docs`). |
|
|
It will be added to the generated OpenAPI (e.g. visible at `/docs`). |
|
|
""" |
|
|
""" |
|
|
), |
|
|
), |
|
|
] = "Successful Response", |
|
|
] = None, |
|
|
responses: Annotated[ |
|
|
responses: Annotated[ |
|
|
Optional[Dict[Union[int, str], Dict[str, Any]]], |
|
|
Optional[Dict[Union[int, str], Dict[str, Any]]], |
|
|
Doc( |
|
|
Doc( |
|
|