Skip to content

Conversation

@YuriiMotov
Copy link
Member

@YuriiMotov YuriiMotov commented Jan 22, 2026

For now there is no easy way to enable StandaloneLayout and dark mode that comes with it.

To do this you need to:

With changes from this PR we will be able to enable StandaloneLayout the following way:

from fastapi import FastAPI
from fastapi.openapi.docs import (
    get_swagger_ui_html,
    get_swagger_ui_oauth2_redirect_html,
)

app = FastAPI(docs_url=None, redoc_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 + " - Swagger UI",
        oauth2_redirect_url=app.swagger_ui_oauth2_redirect_url,
+       swagger_extra_js_urls=["https://cdn.jsdelivr.net/npm/swagger-ui-dist@5/swagger-ui-standalone-preset.js"],
+       swagger_extra_presets=["SwaggerUIStandalonePreset"],
+       swagger_ui_parameters={"layout": "StandaloneLayout"},
    )


@app.get(app.swagger_ui_oauth2_redirect_url, include_in_schema=False)
async def swagger_ui_redirect():
    return get_swagger_ui_oauth2_redirect_html()


@app.get("/users/{username}")
async def read_user(username: str):
    return {"message": f"Hello {username}"}
image

@YuriiMotov YuriiMotov added the feature New feature or request label Jan 22, 2026
@github-actions
Copy link
Contributor

@codspeed-hq
Copy link

codspeed-hq bot commented Jan 22, 2026

CodSpeed Performance Report

Merging this PR will not alter performance

Comparing additional-scripts-and-presets-in-get_swagger_ui_html (841c5c3) with master (74cc27f)1

Summary

✅ 20 untouched benchmarks

Footnotes

  1. No successful run was found on master (597b435) during the generation of this report, so 74cc27f was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants