From ae5fbb8e8a24c061888855284bd9ee3ca0d8a790 Mon Sep 17 00:00:00 2001 From: Brett Rowan <121075405+b-rowan@users.noreply.github.com> Date: Fri, 23 Aug 2024 09:08:22 -0600 Subject: [PATCH] Remove `/redoc` and add further configuration to `/docs` Remove `/redoc` by setting `redoc_url` to `None`, and move `/docs` to a custom endpoint which returns the swagger UI with some custom configuration. --- goosebit/__init__.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/goosebit/__init__.py b/goosebit/__init__.py index a1d2c0c1..bc04a887 100644 --- a/goosebit/__init__.py +++ b/goosebit/__init__.py @@ -3,6 +3,7 @@ from typing import Annotated from fastapi import Depends, FastAPI +from fastapi.openapi.docs import get_swagger_ui_html from fastapi.requests import Request from fastapi.responses import RedirectResponse from fastapi.security import OAuth2PasswordRequestForm @@ -33,7 +34,8 @@ async def lifespan(_: FastAPI): "name": "Apache 2.0", "identifier": "Apache-2.0", }, - swagger_ui_parameters={"operationsSorter": "alpha"}, + redoc_url=None, + docs_url=None, openapi_tags=[ { "name": "login", @@ -82,3 +84,13 @@ async def logout(request: Request): resp = RedirectResponse(request.url_for("login_get"), status_code=302) resp.delete_cookie(key="session_id") return resp + + +@app.get("/docs") +async def swagger_docs(request: Request): + return get_swagger_ui_html( + title="gooseBit docs", + openapi_url="/openapi.json", + swagger_favicon_url=str(request.url_for("static", path="/favicon.svg")), + swagger_ui_parameters={"operationsSorter": "alpha"}, + )