diff --git a/main.py b/main.py index 5e060e6..21f0afa 100644 --- a/main.py +++ b/main.py @@ -103,17 +103,23 @@ def custom_openapi(): routes=app.routes, ) + # Initialize components if not present + if "components" not in openapi_schema: + openapi_schema["components"] = {} + # Add API key security scheme - openapi_schema["components"] = { - "securitySchemes": { - "ApiKeyAuth": { - "type": "apiKey", - "in": "header", - "name": "X-API-Key" - } + openapi_schema["components"]["securitySchemes"] = { + "ApiKeyAuth": { + "type": "apiKey", + "in": "header", + "name": "X-API-Key" } } + # Ensure schemas are included + if "schemas" not in openapi_schema["components"]: + openapi_schema["components"]["schemas"] = {} + # Apply security to all endpoints except auth endpoints for path in openapi_schema["paths"]: if not path.startswith("/api/v1/auth"):