Browse Source

feat: add offline swagger docs

KX 4 months ago
parent
commit
ab8f8bcf92

+ 11 - 0
backend/open_webui/main.py

@@ -27,8 +27,10 @@ from fastapi import (
     Request,
     UploadFile,
     status,
+    applications
 )
 from fastapi.middleware.cors import CORSMiddleware
+from fastapi.openapi.docs import get_swagger_ui_html
 from fastapi.responses import JSONResponse, RedirectResponse
 from fastapi.staticfiles import StaticFiles
 
@@ -1103,6 +1105,15 @@ async def healthcheck_with_db():
 
 app.mount("/static", StaticFiles(directory=STATIC_DIR), name="static")
 app.mount("/cache", StaticFiles(directory=CACHE_DIR), name="cache")
+def swagger_monkey_patch(*args, **kwargs):
+    return get_swagger_ui_html(
+        *args,
+        **kwargs,
+        swagger_js_url="/static/swagger-ui/swagger-ui-bundle.js",
+        swagger_css_url="/static/swagger-ui/swagger-ui.css",
+        swagger_favicon_url="/static/swagger-ui/favicon.png"
+    )
+applications.get_swagger_ui_html = swagger_monkey_patch
 
 if os.path.exists(FRONTEND_BUILD_DIR):
     mimetypes.add_type("text/javascript", ".js")

BIN
backend/open_webui/static/swagger-ui/favicon.png


File diff suppressed because it is too large
+ 1 - 0
backend/open_webui/static/swagger-ui/swagger-ui-bundle.js


File diff suppressed because it is too large
+ 0 - 0
backend/open_webui/static/swagger-ui/swagger-ui.css


Some files were not shown because too many files changed in this diff