/
ivanstrike
/
tasker
Обзор
Документация
Войти
/
ivanstrike
/
tasker
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
python_Sklyarenko/Lab2/app/main.py
65 строк
2 KB
ivanstrike
Lab3
13 дек 2025, 11:15
13 дек 2025, 11:15
15c0fa5
Код
Авторство
О чём код?
import os from fastapi import FastAPI from fastapi.openapi.utils import get_openapi from .db import init_db from .limiter import RateLimitMiddleware from .routers.v3.tasks import router as v3_tasks_router from .routers.v3.projects import router as v3_projects_router from .routers.internal import router as internal_router from .routers.auth import router as auth_router def create_app() -> FastAPI: app = FastAPI( title="Task API", version="3.0.0", docs_url="/docs", redoc_url="/redoc", openapi_url="/openapi.json", swagger_ui_parameters={"persistAuthorization": True}, ) # middleware: rate limiting app.add_middleware(RateLimitMiddleware) # health @app.get("/healthz", tags=["health"]) def healthz(): return {"status": "ok"} # routers app.include_router(auth_router, tags=["auth"]) app.include_router(v3_tasks_router, prefix="/api/v3", tags=["v3 / Tasks"]) app.include_router(v3_projects_router, prefix="/api/v3", tags=["v3 / Projects"]) app.include_router(internal_router, prefix="/internal", include_in_schema=False) # custom openapi to ensure both security schemes appear def custom_openapi(): if app.openapi_schema: return app.openapi_schema openapi_schema = get_openapi( title=app.title, version=app.version, description="API with JWT or API Key auth, rate limits, pagination, sparse fieldsets, and internal endpoints.", routes=app.routes, ) components = openapi_schema.setdefault("components", {}) security_schemes = components.setdefault("securitySchemes", {}) security_schemes["bearerAuth"] = {"type": "http", "scheme": "bearer", "bearerFormat": "JWT"} security_schemes["apiKeyAuth"] = {"type": "apiKey", "in": "header", "name": "X-API-Key"} app.openapi_schema = openapi_schema return app.openapi_schema app.openapi = custom_openapi # type: ignore @app.on_event("startup") def on_startup(): init_db() return app app = create_app() if __name__ == "__main__": import uvicorn uvicorn.run("app.main:app", host="0.0.0.0", port=8000, reload=True)