'How to remove "- Swagger UI" from HTML Page title of OpenAPI docs in FastAPI
I am trying to customize my OpenAPI (Swagger UI) docs generated by FastAPI, but that string - Swagger UI still remains.
app = FastAPI(
title="Test",
version="0.1.0"
)
HTML result :
<title>Test - Swagger UI</title>
Is there a way to remove this - Swagger UI from the title?
Solution 1:[1]
The - Swagger UI part is added to the title by FastAPI. To change that, you need to override the /docs route, as shown in the documentation when one wishes to self-host the JS and CSS files for docs. FastAPI provides the CDN URLs for JS and CSS files, thus you could pass those to the parameters below (not necessarily need to download and serve them as static files). Example is given below:
from fastapi.openapi.docs import (
get_swagger_ui_html,
get_swagger_ui_oauth2_redirect_html,
)
app = FastAPI(title ="Test", version="0.1.0", docs_url=None)
@app.get("/docs", include_in_schema=False)
async def custom_swagger_ui_html():
return get_swagger_ui_html(
openapi_url=app.openapi_url,
title=app.title,
oauth2_redirect_url=app.swagger_ui_oauth2_redirect_url,
swagger_js_url="https://cdn.jsdelivr.net/npm/swagger-ui-dist@3/swagger-ui-bundle.js",
swagger_css_url="https://cdn.jsdelivr.net/npm/swagger-ui-dist@3/swagger-ui.css")
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
