From 872fa74f18544a602af1eb0fdd87c751f3cfd6f1 Mon Sep 17 00:00:00 2001 From: johnpccd Date: Sat, 24 May 2025 07:20:06 +0200 Subject: [PATCH] fix swagger --- main.py | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) 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"):