from fastapi import Depends, FastAPI, HTTPException, status from fastapi.openapi.utils import get_openapi from fastapi.security import OAuth2PasswordBearer from fastapi.middleware.cors import CORSMiddleware from routes.expert_master_routes import router as expert_master_router from routes.expert_mapping_routes import router as expert_mapping_router from utils.auth_utils import oauth2_scheme, security_schemes # Import from your auth_utils module from utils.validators import decode_jwt_token origins = [ "https://dev.moneyadvice.in/imi_u04/appsindianmoney", ] app = FastAPI() app.add_middleware( CORSMiddleware, allow_origins=["*"], # Add valid origins allow_credentials=True, allow_methods=["*"], allow_headers=["*"], ) # Include the router app.include_router(expert_master_router, prefix="/api", tags=["Experts"]) app.include_router(expert_mapping_router, prefix="/api", tags=["Services"]) # Root endpoint @app.get("/") async def root(): return {"message": "Welcome to the FastAPI app"} # Custom OpenAPI schema to add security schemes def custom_openapi(): if app.openapi_schema: return app.openapi_schema openapi_schema = get_openapi( title="FastAPI with JWT Authentication", version="1.0.0", description="FastAPI application with JWT-based authentication for Swagger UI", routes=app.routes, ) # Add security schemes to OpenAPI components openapi_schema["components"]["securitySchemes"] = { "Bearer": { "type": "http", "scheme": "bearer", "bearerFormat": "JWT", } } # Add security requirements to all endpoints for path in openapi_schema["paths"].values(): for method in path.values(): method["security"] = [{"Bearer": []}] app.openapi_schema = openapi_schema return app.openapi_schema # Assign the custom OpenAPI schema app.openapi = custom_openapi