71 lines
1.7 KiB
Python
71 lines
1.7 KiB
Python
from fastapi import FastAPI
|
|
from fastapi.concurrency import asynccontextmanager
|
|
from fastapi.openapi.utils import get_openapi
|
|
|
|
from app.routers import auth, channels, playlist, priorities
|
|
from app.utils.database import init_db
|
|
|
|
|
|
@asynccontextmanager
|
|
async def lifespan(app: FastAPI):
|
|
# Initialize database tables on startup
|
|
init_db()
|
|
yield
|
|
|
|
|
|
app = FastAPI(
|
|
lifespan=lifespan,
|
|
title="IPTV Manager API",
|
|
description="API for IPTV Manager service",
|
|
version="1.0.0",
|
|
)
|
|
|
|
|
|
def custom_openapi():
|
|
if app.openapi_schema:
|
|
return app.openapi_schema
|
|
|
|
openapi_schema = get_openapi(
|
|
title=app.title,
|
|
version=app.version,
|
|
description=app.description,
|
|
routes=app.routes,
|
|
)
|
|
|
|
# Ensure components object exists
|
|
if "components" not in openapi_schema:
|
|
openapi_schema["components"] = {}
|
|
|
|
# Add schemas if they don't exist
|
|
if "schemas" not in openapi_schema["components"]:
|
|
openapi_schema["components"]["schemas"] = {}
|
|
|
|
# Add security scheme component
|
|
openapi_schema["components"]["securitySchemes"] = {
|
|
"Bearer": {"type": "http", "scheme": "bearer", "bearerFormat": "JWT"}
|
|
}
|
|
|
|
# Add global security requirement
|
|
openapi_schema["security"] = [{"Bearer": []}]
|
|
|
|
# Set OpenAPI version explicitly
|
|
openapi_schema["openapi"] = "3.1.0"
|
|
|
|
app.openapi_schema = openapi_schema
|
|
return app.openapi_schema
|
|
|
|
|
|
app.openapi = custom_openapi
|
|
|
|
|
|
@app.get("/")
|
|
async def root():
|
|
return {"message": "IPTV Manager API"}
|
|
|
|
|
|
# Include routers
|
|
app.include_router(auth.router)
|
|
app.include_router(channels.router)
|
|
app.include_router(playlist.router)
|
|
app.include_router(priorities.router)
|