Question: I need to change the styling and add extra HTML to the default generated docs in my FastAPI application, so I use get_swagger_ui_html to achieve this. This causes the operation level options for 'Servers' to appear when clicking the 'Try it out' section button - I do not want this visible for users. I am using FastAPI version 0.111.0 for context. Bug also raised in this question, but without the use of get_swagger_ui_html: fastapi swagger interface showing operation level options override server options This minimal example does not have the problem: # imports from fastapi import FastAPI import uvicorn # set up app app = FastAPI( description='some description', title=' a title', version="1.0.0", ) @app.get("/dummy_endpoint") async def endpoint(): return 'woohoo' if __name__ == "__main__": # run API with uvicorn uvicorn.run(app, host="127.0.0.1", port=8000)  If we introduce the use of get_swagger_ui_html, then we get problems. See the code and screenshot below: # imports from fastapi import FastAPI from fastapi.responses import HTMLResponse from fastapi.openapi.docs import ( get_swagger_ui_html, get_swagger_ui_oauth2_redirect_html, ) import uvicorn # set up app app = FastAPI( docs_url = None, description='some description', title=' a title', version="1.0.0", ) @app.get("/dummy_endpoint") async def endpoint(): return 'woohoo' @app.get("/docs", include_in_schema=False) async def custom_swagger_ui_html(): swagger_ui_content = get_swagger_ui_html( openapi_url=app.openapi_url, swagger_ui_parameters={ "syntaxHighlight": False, "defaultModelsExpandDepth": -1}, title=app.title, oauth2_redirect_url=app.swagger_ui_oauth2_redirect_url, swagger_js_url="https://unpkg.com/swagger-ui-dist@5/swagger-ui-bundle.js", swagger_css_url="https://unpkg.com/swagger-ui-dist@5/swagger-ui.css", ) #allows us to add header, footer, css etc. html_content = f'{swagger_ui_content.body.decode("utf-8")}' return HTMLResponse(html_content) if __name__ == "__main__": # run API with uvicorn uvicorn.run(app, host="127.0.0.1", port=8000)  Screenshot:  Can we simply remove the Servers part from the HTML? It seems unobvious from any docs how to do this. At the moment I get the HTML elements and add CSS to hide them, but I'd rather a proper solution. Thanks!

Answer: It's most likely this Swagger UI bug that affects OpenAPI 3.1 documents. The bug seems to have been introduced in Swagger UI v. 5.9.2. FastAPI 0.111 uses Swagger UI v. 5.9.0 by default, whereas your 2nd example fetches v. 5.17.14 as of this writing, hence the difference. (By the way, the next update of FastAPI will switch from the pinned Swagger UI v. 5.9.0 to "latest 5.x" so it will also be affected by this bug.) Until Swagger UI fixes this bug, the only workaround is to fix the Swagger UI layout manually. Option 1. Hide operation-level "Servers" by using CSS (You said this is what you're currently doing.) For future readers - you'll need to add something like this to your Swagger UI CSS: .swagger-ui .operation-servers { display: none; }  Option 2. Hide operation-level "Servers" by using a Swagger UI plugin Another (more verbose) option is to write a Swagger UI plugin to remove the unwanted element from the DOM entirely. The code of simple "hide this element" plugins can be added directly to the Swagger UI initialization code. For example, to hide operation-level servers, change your Swagger UI initialization code as follows; the changes are marked "Part 1" and "Part 2": window.onload = function() { // Part 1. Custom plugin to hide the operation-level "Servers" section const HideOperationServers = () => { return { wrapComponents: { OperationServers: () => () => null } } } // END of custom plugin window.ui = SwaggerUIBundle({ ... dom_id: '#swagger-ui', ... plugins: [ SwaggerUIBundle.plugins.DownloadUrl, HideOperationServers // <------ Part 2. Add the custom plugin to this list ], layout: "StandaloneLayout" }); };