增加环绕侦察场景适配

This commit is contained in:
2026-01-08 15:44:38 +08:00
parent 3eba1f962b
commit 10c5bb5a8a
5441 changed files with 40219 additions and 379695 deletions

View File

@@ -1,14 +1,10 @@
from collections.abc import Awaitable, Coroutine, Sequence
from enum import Enum
from typing import (
Annotated,
Any,
Awaitable,
Callable,
Coroutine,
Dict,
List,
Optional,
Sequence,
Type,
TypeVar,
Union,
)
@@ -44,7 +40,7 @@ from starlette.requests import Request
from starlette.responses import HTMLResponse, JSONResponse, Response
from starlette.routing import BaseRoute
from starlette.types import ASGIApp, ExceptionHandler, Lifespan, Receive, Scope, Send
from typing_extensions import Annotated, deprecated
from typing_extensions import deprecated
AppType = TypeVar("AppType", bound="FastAPI")
@@ -81,7 +77,7 @@ class FastAPI(Starlette):
),
] = False,
routes: Annotated[
Optional[List[BaseRoute]],
Optional[list[BaseRoute]],
Doc(
"""
**Note**: you probably shouldn't use this parameter, it is inherited
@@ -230,7 +226,7 @@ class FastAPI(Starlette):
),
] = "/openapi.json",
openapi_tags: Annotated[
Optional[List[Dict[str, Any]]],
Optional[list[dict[str, Any]]],
Doc(
"""
A list of tags used by OpenAPI, these are the same `tags` you can set
@@ -290,7 +286,7 @@ class FastAPI(Starlette):
),
] = None,
servers: Annotated[
Optional[List[Dict[str, Union[str, Any]]]],
Optional[list[dict[str, Union[str, Any]]]],
Doc(
"""
A `list` of `dict`s with connectivity information to a target server.
@@ -301,7 +297,12 @@ class FastAPI(Starlette):
browser tabs open). Or if you want to leave fixed the possible URLs.
If the servers `list` is not provided, or is an empty `list`, the
default value would be a `dict` with a `url` value of `/`.
`servers` property in the generated OpenAPI will be:
* a `dict` with a `url` value of the application's mounting point
(`root_path`) if it's different from `/`.
* otherwise, the `servers` property will be omitted from the OpenAPI
schema.
Each item in the `list` is a `dict` containing:
@@ -356,7 +357,7 @@ class FastAPI(Starlette):
),
] = None,
default_response_class: Annotated[
Type[Response],
type[Response],
Doc(
"""
The default response class to be used.
@@ -462,7 +463,7 @@ class FastAPI(Starlette):
),
] = "/docs/oauth2-redirect",
swagger_ui_init_oauth: Annotated[
Optional[Dict[str, Any]],
Optional[dict[str, Any]],
Doc(
"""
OAuth2 configuration for the Swagger UI, by default shown at `/docs`.
@@ -488,8 +489,8 @@ class FastAPI(Starlette):
] = None,
exception_handlers: Annotated[
Optional[
Dict[
Union[int, Type[Exception]],
dict[
Union[int, type[Exception]],
Callable[[Request, Any], Coroutine[Any, Any, Response]],
]
],
@@ -562,7 +563,7 @@ class FastAPI(Starlette):
),
] = None,
contact: Annotated[
Optional[Dict[str, Union[str, Any]]],
Optional[dict[str, Union[str, Any]]],
Doc(
"""
A dictionary with the contact information for the exposed API.
@@ -595,7 +596,7 @@ class FastAPI(Starlette):
),
] = None,
license_info: Annotated[
Optional[Dict[str, Union[str, Any]]],
Optional[dict[str, Union[str, Any]]],
Doc(
"""
A dictionary with the license information for the exposed API.
@@ -684,7 +685,7 @@ class FastAPI(Starlette):
),
] = True,
responses: Annotated[
Optional[Dict[Union[int, str], Dict[str, Any]]],
Optional[dict[Union[int, str], dict[str, Any]]],
Doc(
"""
Additional responses to be shown in OpenAPI.
@@ -700,7 +701,7 @@ class FastAPI(Starlette):
),
] = None,
callbacks: Annotated[
Optional[List[BaseRoute]],
Optional[list[BaseRoute]],
Doc(
"""
OpenAPI callbacks that should apply to all *path operations*.
@@ -757,7 +758,7 @@ class FastAPI(Starlette):
),
] = True,
swagger_ui_parameters: Annotated[
Optional[Dict[str, Any]],
Optional[dict[str, Any]],
Doc(
"""
Parameters to configure Swagger UI, the autogenerated interactive API
@@ -815,7 +816,7 @@ class FastAPI(Starlette):
),
] = True,
openapi_external_docs: Annotated[
Optional[Dict[str, Any]],
Optional[dict[str, Any]],
Doc(
"""
This field allows you to provide additional external documentation links.
@@ -901,7 +902,7 @@ class FastAPI(Starlette):
"""
),
] = "3.1.0"
self.openapi_schema: Optional[Dict[str, Any]] = None
self.openapi_schema: Optional[dict[str, Any]] = None
if self.openapi_url:
assert self.title, "A title must be provided for OpenAPI, e.g.: 'My API'"
assert self.version, "A version must be provided for OpenAPI, e.g.: '2.1.0'"
@@ -944,7 +945,7 @@ class FastAPI(Starlette):
),
] = State()
self.dependency_overrides: Annotated[
Dict[Callable[..., Any], Callable[..., Any]],
dict[Callable[..., Any], Callable[..., Any]],
Doc(
"""
A dictionary with overrides for the dependencies.
@@ -975,7 +976,7 @@ class FastAPI(Starlette):
responses=responses,
generate_unique_id_function=generate_unique_id_function,
)
self.exception_handlers: Dict[
self.exception_handlers: dict[
Any, Callable[[Request, Any], Union[Response, Awaitable[Response]]]
] = {} if exception_handlers is None else dict(exception_handlers)
self.exception_handlers.setdefault(HTTPException, http_exception_handler)
@@ -988,7 +989,7 @@ class FastAPI(Starlette):
websocket_request_validation_exception_handler, # type: ignore
)
self.user_middleware: List[Middleware] = (
self.user_middleware: list[Middleware] = (
[] if middleware is None else list(middleware)
)
self.middleware_stack: Union[ASGIApp, None] = None
@@ -1042,7 +1043,7 @@ class FastAPI(Starlette):
app = cls(app, *args, **kwargs)
return app
def openapi(self) -> Dict[str, Any]:
def openapi(self) -> dict[str, Any]:
"""
Generate the OpenAPI schema of the application. This is called by FastAPI
internally.
@@ -1140,14 +1141,14 @@ class FastAPI(Starlette):
*,
response_model: Any = Default(None),
status_code: Optional[int] = None,
tags: Optional[List[Union[str, Enum]]] = None,
tags: Optional[list[Union[str, Enum]]] = None,
dependencies: Optional[Sequence[Depends]] = None,
summary: Optional[str] = None,
description: Optional[str] = None,
response_description: str = "Successful Response",
responses: Optional[Dict[Union[int, str], Dict[str, Any]]] = None,
responses: Optional[dict[Union[int, str], dict[str, Any]]] = None,
deprecated: Optional[bool] = None,
methods: Optional[List[str]] = None,
methods: Optional[list[str]] = None,
operation_id: Optional[str] = None,
response_model_include: Optional[IncEx] = None,
response_model_exclude: Optional[IncEx] = None,
@@ -1156,11 +1157,11 @@ class FastAPI(Starlette):
response_model_exclude_defaults: bool = False,
response_model_exclude_none: bool = False,
include_in_schema: bool = True,
response_class: Union[Type[Response], DefaultPlaceholder] = Default(
response_class: Union[type[Response], DefaultPlaceholder] = Default(
JSONResponse
),
name: Optional[str] = None,
openapi_extra: Optional[Dict[str, Any]] = None,
openapi_extra: Optional[dict[str, Any]] = None,
generate_unique_id_function: Callable[[routing.APIRoute], str] = Default(
generate_unique_id
),
@@ -1198,14 +1199,14 @@ class FastAPI(Starlette):
*,
response_model: Any = Default(None),
status_code: Optional[int] = None,
tags: Optional[List[Union[str, Enum]]] = None,
tags: Optional[list[Union[str, Enum]]] = None,
dependencies: Optional[Sequence[Depends]] = None,
summary: Optional[str] = None,
description: Optional[str] = None,
response_description: str = "Successful Response",
responses: Optional[Dict[Union[int, str], Dict[str, Any]]] = None,
responses: Optional[dict[Union[int, str], dict[str, Any]]] = None,
deprecated: Optional[bool] = None,
methods: Optional[List[str]] = None,
methods: Optional[list[str]] = None,
operation_id: Optional[str] = None,
response_model_include: Optional[IncEx] = None,
response_model_exclude: Optional[IncEx] = None,
@@ -1214,9 +1215,9 @@ class FastAPI(Starlette):
response_model_exclude_defaults: bool = False,
response_model_exclude_none: bool = False,
include_in_schema: bool = True,
response_class: Type[Response] = Default(JSONResponse),
response_class: type[Response] = Default(JSONResponse),
name: Optional[str] = None,
openapi_extra: Optional[Dict[str, Any]] = None,
openapi_extra: Optional[dict[str, Any]] = None,
generate_unique_id_function: Callable[[routing.APIRoute], str] = Default(
generate_unique_id
),
@@ -1338,7 +1339,7 @@ class FastAPI(Starlette):
*,
prefix: Annotated[str, Doc("An optional path prefix for the router.")] = "",
tags: Annotated[
Optional[List[Union[str, Enum]]],
Optional[list[Union[str, Enum]]],
Doc(
"""
A list of tags to be applied to all the *path operations* in this
@@ -1380,7 +1381,7 @@ class FastAPI(Starlette):
),
] = None,
responses: Annotated[
Optional[Dict[Union[int, str], Dict[str, Any]]],
Optional[dict[Union[int, str], dict[str, Any]]],
Doc(
"""
Additional responses to be shown in OpenAPI.
@@ -1447,7 +1448,7 @@ class FastAPI(Starlette):
),
] = True,
default_response_class: Annotated[
Type[Response],
type[Response],
Doc(
"""
Default response class to be used for the *path operations* in this
@@ -1475,7 +1476,7 @@ class FastAPI(Starlette):
),
] = Default(JSONResponse),
callbacks: Annotated[
Optional[List[BaseRoute]],
Optional[list[BaseRoute]],
Doc(
"""
List of *path operations* that will be used as OpenAPI callbacks.
@@ -1598,7 +1599,7 @@ class FastAPI(Starlette):
),
] = None,
tags: Annotated[
Optional[List[Union[str, Enum]]],
Optional[list[Union[str, Enum]]],
Doc(
"""
A list of tags to be applied to the *path operation*.
@@ -1664,7 +1665,7 @@ class FastAPI(Starlette):
),
] = "Successful Response",
responses: Annotated[
Optional[Dict[Union[int, str], Dict[str, Any]]],
Optional[dict[Union[int, str], dict[str, Any]]],
Doc(
"""
Additional responses that could be returned by this *path operation*.
@@ -1805,7 +1806,7 @@ class FastAPI(Starlette):
),
] = True,
response_class: Annotated[
Type[Response],
type[Response],
Doc(
"""
Response class to be used for this *path operation*.
@@ -1826,7 +1827,7 @@ class FastAPI(Starlette):
),
] = None,
callbacks: Annotated[
Optional[List[BaseRoute]],
Optional[list[BaseRoute]],
Doc(
"""
List of *path operations* that will be used as OpenAPI callbacks.
@@ -1842,7 +1843,7 @@ class FastAPI(Starlette):
),
] = None,
openapi_extra: Annotated[
Optional[Dict[str, Any]],
Optional[dict[str, Any]],
Doc(
"""
Extra metadata to be included in the OpenAPI schema for this *path
@@ -1971,7 +1972,7 @@ class FastAPI(Starlette):
),
] = None,
tags: Annotated[
Optional[List[Union[str, Enum]]],
Optional[list[Union[str, Enum]]],
Doc(
"""
A list of tags to be applied to the *path operation*.
@@ -2037,7 +2038,7 @@ class FastAPI(Starlette):
),
] = "Successful Response",
responses: Annotated[
Optional[Dict[Union[int, str], Dict[str, Any]]],
Optional[dict[Union[int, str], dict[str, Any]]],
Doc(
"""
Additional responses that could be returned by this *path operation*.
@@ -2178,7 +2179,7 @@ class FastAPI(Starlette):
),
] = True,
response_class: Annotated[
Type[Response],
type[Response],
Doc(
"""
Response class to be used for this *path operation*.
@@ -2199,7 +2200,7 @@ class FastAPI(Starlette):
),
] = None,
callbacks: Annotated[
Optional[List[BaseRoute]],
Optional[list[BaseRoute]],
Doc(
"""
List of *path operations* that will be used as OpenAPI callbacks.
@@ -2215,7 +2216,7 @@ class FastAPI(Starlette):
),
] = None,
openapi_extra: Annotated[
Optional[Dict[str, Any]],
Optional[dict[str, Any]],
Doc(
"""
Extra metadata to be included in the OpenAPI schema for this *path
@@ -2349,7 +2350,7 @@ class FastAPI(Starlette):
),
] = None,
tags: Annotated[
Optional[List[Union[str, Enum]]],
Optional[list[Union[str, Enum]]],
Doc(
"""
A list of tags to be applied to the *path operation*.
@@ -2415,7 +2416,7 @@ class FastAPI(Starlette):
),
] = "Successful Response",
responses: Annotated[
Optional[Dict[Union[int, str], Dict[str, Any]]],
Optional[dict[Union[int, str], dict[str, Any]]],
Doc(
"""
Additional responses that could be returned by this *path operation*.
@@ -2556,7 +2557,7 @@ class FastAPI(Starlette):
),
] = True,
response_class: Annotated[
Type[Response],
type[Response],
Doc(
"""
Response class to be used for this *path operation*.
@@ -2577,7 +2578,7 @@ class FastAPI(Starlette):
),
] = None,
callbacks: Annotated[
Optional[List[BaseRoute]],
Optional[list[BaseRoute]],
Doc(
"""
List of *path operations* that will be used as OpenAPI callbacks.
@@ -2593,7 +2594,7 @@ class FastAPI(Starlette):
),
] = None,
openapi_extra: Annotated[
Optional[Dict[str, Any]],
Optional[dict[str, Any]],
Doc(
"""
Extra metadata to be included in the OpenAPI schema for this *path
@@ -2727,7 +2728,7 @@ class FastAPI(Starlette):
),
] = None,
tags: Annotated[
Optional[List[Union[str, Enum]]],
Optional[list[Union[str, Enum]]],
Doc(
"""
A list of tags to be applied to the *path operation*.
@@ -2793,7 +2794,7 @@ class FastAPI(Starlette):
),
] = "Successful Response",
responses: Annotated[
Optional[Dict[Union[int, str], Dict[str, Any]]],
Optional[dict[Union[int, str], dict[str, Any]]],
Doc(
"""
Additional responses that could be returned by this *path operation*.
@@ -2934,7 +2935,7 @@ class FastAPI(Starlette):
),
] = True,
response_class: Annotated[
Type[Response],
type[Response],
Doc(
"""
Response class to be used for this *path operation*.
@@ -2955,7 +2956,7 @@ class FastAPI(Starlette):
),
] = None,
callbacks: Annotated[
Optional[List[BaseRoute]],
Optional[list[BaseRoute]],
Doc(
"""
List of *path operations* that will be used as OpenAPI callbacks.
@@ -2971,7 +2972,7 @@ class FastAPI(Starlette):
),
] = None,
openapi_extra: Annotated[
Optional[Dict[str, Any]],
Optional[dict[str, Any]],
Doc(
"""
Extra metadata to be included in the OpenAPI schema for this *path
@@ -3100,7 +3101,7 @@ class FastAPI(Starlette):
),
] = None,
tags: Annotated[
Optional[List[Union[str, Enum]]],
Optional[list[Union[str, Enum]]],
Doc(
"""
A list of tags to be applied to the *path operation*.
@@ -3166,7 +3167,7 @@ class FastAPI(Starlette):
),
] = "Successful Response",
responses: Annotated[
Optional[Dict[Union[int, str], Dict[str, Any]]],
Optional[dict[Union[int, str], dict[str, Any]]],
Doc(
"""
Additional responses that could be returned by this *path operation*.
@@ -3307,7 +3308,7 @@ class FastAPI(Starlette):
),
] = True,
response_class: Annotated[
Type[Response],
type[Response],
Doc(
"""
Response class to be used for this *path operation*.
@@ -3328,7 +3329,7 @@ class FastAPI(Starlette):
),
] = None,
callbacks: Annotated[
Optional[List[BaseRoute]],
Optional[list[BaseRoute]],
Doc(
"""
List of *path operations* that will be used as OpenAPI callbacks.
@@ -3344,7 +3345,7 @@ class FastAPI(Starlette):
),
] = None,
openapi_extra: Annotated[
Optional[Dict[str, Any]],
Optional[dict[str, Any]],
Doc(
"""
Extra metadata to be included in the OpenAPI schema for this *path
@@ -3473,7 +3474,7 @@ class FastAPI(Starlette):
),
] = None,
tags: Annotated[
Optional[List[Union[str, Enum]]],
Optional[list[Union[str, Enum]]],
Doc(
"""
A list of tags to be applied to the *path operation*.
@@ -3539,7 +3540,7 @@ class FastAPI(Starlette):
),
] = "Successful Response",
responses: Annotated[
Optional[Dict[Union[int, str], Dict[str, Any]]],
Optional[dict[Union[int, str], dict[str, Any]]],
Doc(
"""
Additional responses that could be returned by this *path operation*.
@@ -3680,7 +3681,7 @@ class FastAPI(Starlette):
),
] = True,
response_class: Annotated[
Type[Response],
type[Response],
Doc(
"""
Response class to be used for this *path operation*.
@@ -3701,7 +3702,7 @@ class FastAPI(Starlette):
),
] = None,
callbacks: Annotated[
Optional[List[BaseRoute]],
Optional[list[BaseRoute]],
Doc(
"""
List of *path operations* that will be used as OpenAPI callbacks.
@@ -3717,7 +3718,7 @@ class FastAPI(Starlette):
),
] = None,
openapi_extra: Annotated[
Optional[Dict[str, Any]],
Optional[dict[str, Any]],
Doc(
"""
Extra metadata to be included in the OpenAPI schema for this *path
@@ -3846,7 +3847,7 @@ class FastAPI(Starlette):
),
] = None,
tags: Annotated[
Optional[List[Union[str, Enum]]],
Optional[list[Union[str, Enum]]],
Doc(
"""
A list of tags to be applied to the *path operation*.
@@ -3912,7 +3913,7 @@ class FastAPI(Starlette):
),
] = "Successful Response",
responses: Annotated[
Optional[Dict[Union[int, str], Dict[str, Any]]],
Optional[dict[Union[int, str], dict[str, Any]]],
Doc(
"""
Additional responses that could be returned by this *path operation*.
@@ -4053,7 +4054,7 @@ class FastAPI(Starlette):
),
] = True,
response_class: Annotated[
Type[Response],
type[Response],
Doc(
"""
Response class to be used for this *path operation*.
@@ -4074,7 +4075,7 @@ class FastAPI(Starlette):
),
] = None,
callbacks: Annotated[
Optional[List[BaseRoute]],
Optional[list[BaseRoute]],
Doc(
"""
List of *path operations* that will be used as OpenAPI callbacks.
@@ -4090,7 +4091,7 @@ class FastAPI(Starlette):
),
] = None,
openapi_extra: Annotated[
Optional[Dict[str, Any]],
Optional[dict[str, Any]],
Doc(
"""
Extra metadata to be included in the OpenAPI schema for this *path
@@ -4224,7 +4225,7 @@ class FastAPI(Starlette):
),
] = None,
tags: Annotated[
Optional[List[Union[str, Enum]]],
Optional[list[Union[str, Enum]]],
Doc(
"""
A list of tags to be applied to the *path operation*.
@@ -4290,7 +4291,7 @@ class FastAPI(Starlette):
),
] = "Successful Response",
responses: Annotated[
Optional[Dict[Union[int, str], Dict[str, Any]]],
Optional[dict[Union[int, str], dict[str, Any]]],
Doc(
"""
Additional responses that could be returned by this *path operation*.
@@ -4431,7 +4432,7 @@ class FastAPI(Starlette):
),
] = True,
response_class: Annotated[
Type[Response],
type[Response],
Doc(
"""
Response class to be used for this *path operation*.
@@ -4452,7 +4453,7 @@ class FastAPI(Starlette):
),
] = None,
callbacks: Annotated[
Optional[List[BaseRoute]],
Optional[list[BaseRoute]],
Doc(
"""
List of *path operations* that will be used as OpenAPI callbacks.
@@ -4468,7 +4469,7 @@ class FastAPI(Starlette):
),
] = None,
openapi_extra: Annotated[
Optional[Dict[str, Any]],
Optional[dict[str, Any]],
Doc(
"""
Extra metadata to be included in the OpenAPI schema for this *path
@@ -4623,7 +4624,7 @@ class FastAPI(Starlette):
def exception_handler(
self,
exc_class_or_status_code: Annotated[
Union[int, Type[Exception]],
Union[int, type[Exception]],
Doc(
"""
The Exception class this would handle, or a status code.