|
|
@ -479,26 +479,22 @@ def get_openapi_path( |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _get_api_route_for_openapi( |
|
|
def _get_api_route_for_openapi( |
|
|
route: BaseRoute, route_context: routing._EffectiveRouteContext | None |
|
|
route_context: routing.RouteContext, |
|
|
) -> routing._APIRouteLike | None: |
|
|
) -> routing._APIRouteLike | None: |
|
|
if route_context is not None and isinstance( |
|
|
if isinstance(route_context.original_route, routing.APIRoute): |
|
|
route_context.original_route, routing.APIRoute |
|
|
|
|
|
): |
|
|
|
|
|
return cast(routing._APIRouteLike, route_context) |
|
|
return cast(routing._APIRouteLike, route_context) |
|
|
if isinstance(route, routing.APIRoute): |
|
|
|
|
|
return cast(routing._APIRouteLike, route) |
|
|
|
|
|
return None |
|
|
return None |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_fields_from_routes( |
|
|
def get_fields_from_routes( |
|
|
routes: Sequence[BaseRoute], |
|
|
routes: Sequence[BaseRoute | routing.RouteContext], |
|
|
) -> list[ModelField]: |
|
|
) -> list[ModelField]: |
|
|
body_fields_from_routes: list[ModelField] = [] |
|
|
body_fields_from_routes: list[ModelField] = [] |
|
|
responses_from_routes: list[ModelField] = [] |
|
|
responses_from_routes: list[ModelField] = [] |
|
|
request_fields_from_routes: list[ModelField] = [] |
|
|
request_fields_from_routes: list[ModelField] = [] |
|
|
callback_flat_models: list[ModelField] = [] |
|
|
callback_flat_models: list[ModelField] = [] |
|
|
for route, route_context in routing._iter_routes_with_context(routes): |
|
|
for route_context in routing.iter_route_contexts(routes): |
|
|
api_route = _get_api_route_for_openapi(route, route_context) |
|
|
api_route = _get_api_route_for_openapi(route_context) |
|
|
if api_route is None: |
|
|
if api_route is None: |
|
|
continue |
|
|
continue |
|
|
if api_route.include_in_schema: |
|
|
if api_route.include_in_schema: |
|
|
@ -531,8 +527,8 @@ def get_openapi( |
|
|
openapi_version: str = "3.1.0", |
|
|
openapi_version: str = "3.1.0", |
|
|
summary: str | None = None, |
|
|
summary: str | None = None, |
|
|
description: str | None = None, |
|
|
description: str | None = None, |
|
|
routes: Sequence[BaseRoute], |
|
|
routes: Sequence[BaseRoute | routing.RouteContext], |
|
|
webhooks: Sequence[BaseRoute] | None = None, |
|
|
webhooks: Sequence[BaseRoute | routing.RouteContext] | None = None, |
|
|
tags: list[dict[str, Any]] | None = None, |
|
|
tags: list[dict[str, Any]] | None = None, |
|
|
servers: list[dict[str, str | Any]] | None = None, |
|
|
servers: list[dict[str, str | Any]] | None = None, |
|
|
terms_of_service: str | None = None, |
|
|
terms_of_service: str | None = None, |
|
|
@ -567,8 +563,8 @@ def get_openapi( |
|
|
model_name_map=model_name_map, |
|
|
model_name_map=model_name_map, |
|
|
separate_input_output_schemas=separate_input_output_schemas, |
|
|
separate_input_output_schemas=separate_input_output_schemas, |
|
|
) |
|
|
) |
|
|
for route, route_context in routing._iter_routes_with_context(routes): |
|
|
for route_context in routing.iter_route_contexts(routes): |
|
|
api_route = _get_api_route_for_openapi(route, route_context) |
|
|
api_route = _get_api_route_for_openapi(route_context) |
|
|
if api_route is not None: |
|
|
if api_route is not None: |
|
|
result = get_openapi_path( |
|
|
result = get_openapi_path( |
|
|
route=api_route, |
|
|
route=api_route, |
|
|
@ -587,8 +583,8 @@ def get_openapi( |
|
|
) |
|
|
) |
|
|
if path_definitions: |
|
|
if path_definitions: |
|
|
definitions.update(path_definitions) |
|
|
definitions.update(path_definitions) |
|
|
for webhook, webhook_context in routing._iter_routes_with_context(webhooks or []): |
|
|
for webhook_context in routing.iter_route_contexts(webhooks or []): |
|
|
api_webhook = _get_api_route_for_openapi(webhook, webhook_context) |
|
|
api_webhook = _get_api_route_for_openapi(webhook_context) |
|
|
if api_webhook is not None: |
|
|
if api_webhook is not None: |
|
|
result = get_openapi_path( |
|
|
result = get_openapi_path( |
|
|
route=api_webhook, |
|
|
route=api_webhook, |
|
|
|