fix swagger

This commit is contained in:
johnpccd 2025-05-24 07:20:06 +02:00
parent e8e750bc7d
commit 872fa74f18

20
main.py
View File

@ -103,17 +103,23 @@ def custom_openapi():
routes=app.routes, routes=app.routes,
) )
# Initialize components if not present
if "components" not in openapi_schema:
openapi_schema["components"] = {}
# Add API key security scheme # Add API key security scheme
openapi_schema["components"] = { openapi_schema["components"]["securitySchemes"] = {
"securitySchemes": { "ApiKeyAuth": {
"ApiKeyAuth": { "type": "apiKey",
"type": "apiKey", "in": "header",
"in": "header", "name": "X-API-Key"
"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 # Apply security to all endpoints except auth endpoints
for path in openapi_schema["paths"]: for path in openapi_schema["paths"]:
if not path.startswith("/api/v1/auth"): if not path.startswith("/api/v1/auth"):