49 lines
1.4 KiB
Python
49 lines
1.4 KiB
Python
"""
|
|
FastAPI Application Factory Module
|
|
|
|
This module provides functionality to create and configure a FastAPI application with:
|
|
- Custom OpenAPI schema configuration
|
|
- Security scheme configuration for Bearer authentication
|
|
- Automatic router registration
|
|
- Response class configuration
|
|
- Security requirements for protected endpoints
|
|
"""
|
|
|
|
from fastapi import FastAPI
|
|
from fastapi.responses import JSONResponse, RedirectResponse
|
|
|
|
from config import ApiConfig
|
|
from create_routes import get_all_routers
|
|
|
|
|
|
def create_app() -> FastAPI:
|
|
"""
|
|
Create and configure a FastAPI application with dynamic route creation.
|
|
|
|
Returns:
|
|
FastAPI: Configured FastAPI application instance
|
|
"""
|
|
|
|
from open_api_creator import create_openapi_schema
|
|
|
|
app = FastAPI(
|
|
title=ApiConfig.TITLE,
|
|
description=ApiConfig.DESCRIPTION,
|
|
default_response_class=JSONResponse,
|
|
) # Initialize FastAPI app
|
|
|
|
@app.get("/", include_in_schema=False, summary=str(ApiConfig.DESCRIPTION))
|
|
def home() -> RedirectResponse:
|
|
"""Redirect root path to API documentation."""
|
|
return RedirectResponse(url="/docs")
|
|
|
|
# Get all routers and protected routes using the dynamic route creation
|
|
prepare_routing = get_all_routers()
|
|
|
|
# Include all routers
|
|
for router in prepare_routing.routers:
|
|
app.include_router(router)
|
|
|
|
app.openapi = lambda app=app: create_openapi_schema(app)
|
|
return app
|