From 75b6e2e9caa0d86a3e5cf5da0940344676d05175 Mon Sep 17 00:00:00 2001 From: Thomas Date: Fri, 3 Jan 2025 11:18:56 +0800 Subject: [PATCH] chore: add swagger server --- openagent/app.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/openagent/app.py b/openagent/app.py index 64d80764..bdc69d5b 100644 --- a/openagent/app.py +++ b/openagent/app.py @@ -4,6 +4,7 @@ from dotenv import load_dotenv from fastapi import FastAPI, Request from fastapi.middleware.cors import CORSMiddleware +from fastapi.openapi.utils import get_openapi from loguru import logger from starlette.staticfiles import StaticFiles import traceback @@ -60,3 +61,28 @@ async def global_exception_handler(request: Request, exc: Exception): status_code=500, content={"error": str(exc), "traceback": traceback.format_exc()}, ) + + +def custom_openapi(): + if app.openapi_schema: + return app.openapi_schema + + openapi_schema = get_openapi( + title="OpenAgent API", + version="1.0.0", + description="OpenAgent API documentation", + routes=app.routes, + ) + + openapi_schema["servers"] = [ + { + "url": "https://agent.open.network", + "description": "Production server" + } + ] + + app.openapi_schema = openapi_schema + return app.openapi_schema + + +app.openapi = custom_openapi