Skip to content

5.8 Customize Swagger

If you want to change that “FastAPI 0.1.0 OAS 3.1 /openapi.json” header in Swagger UI, you can override it by customizing FastAPI’s title, version, and swagger_ui_parameters.

The simplest approach is to set title and version when creating your FastAPI app:

from fastapi import FastAPI
app = FastAPI(
title="My Custom API Docs",
version="2.5.7",
description="Custom Swagger UI header example",
swagger_ui_parameters={"docExpansion": "none"}
)

This will make Swagger UI show:

My Custom API Docs
2.5.7
OAS 3.1
/openapi.json

If you want to remove the OAS 3.1 /openapi.json bit

Section titled “If you want to remove the OAS 3.1 /openapi.json bit”

FastAPI itself doesn’t expose a direct parameter to remove that part, but you can override the Swagger UI HTML template:

from fastapi import FastAPI
from fastapi.openapi.docs import get_swagger_ui_html
app = FastAPI(docs_url=None) # Disable default docs
@app.get("/docs", include_in_schema=False)
async def custom_swagger_ui_html():
return get_swagger_ui_html(
openapi_url="/openapi.json",
title="My Custom API Docs",
swagger_favicon_url="https://example.com/favicon.ico",
swagger_js_url="https://cdn.jsdelivr.net/npm/swagger-ui-dist/swagger-ui-bundle.js",
swagger_css_url="https://cdn.jsdelivr.net/npm/swagger-ui-dist/swagger-ui.css"
)

Then you could tweak the CSS or JS in that template to hide or replace the header line entirely.


If you want, I can give you a version that fully hides the /openapi.json and OAS 3.1 display so it only shows your API name. That requires adding one small CSS override.