/
urusai
/
code_sample
Обзор
Документация
Войти
/
urusai
/
code_sample
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
src/api/v1/docs.py
34 строки
1 KB
nick
init
30 сен 2024, 16:12
30 сен 2024, 16:12
c68451c
Код
Авторство
О чём код?
from fastapi import Depends, APIRouter from starlette.requests import Request from fastapi.openapi.utils import get_openapi from di.markers import SettingsAPIMarker from api.v1.swagger.render import custom_swagger_ui_html from settings.api.settings import SettingsApplication from services.security.base_http import get_username_http_auth docs_router = APIRouter() @docs_router.get("/docs", include_in_schema=False) async def docs_handler(request: Request): root_path = f'{request.scope.get("root_path", "")}/openapi.json' return custom_swagger_ui_html(openapi_url=root_path, title="Документация v1") @docs_router.get("/openapi.json", include_in_schema=False) async def docs_handler_openapi( request: Request, _: str = Depends(get_username_http_auth), settings_app: SettingsApplication = Depends(SettingsAPIMarker), ): if request.app.openapi_schema: return request.app.openapi_schema open_api = get_openapi( title="NRI Core Microservice", version=settings_app.APP_VERSION, routes=request.app.routes, servers=[{"url": f"{settings_app.BASE_DOMAIN}/api/v1/"}], ) request.app.openapi_schema = open_api return request.app.openapi_schema