Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork8.3k
Feature Request: Option to Use Stoplight.io as OpenAPI Viewer#14385
-
First Check
Commit to Help
Example Codesuggestion:app=FastAPI(docs_viewer="stoplight") DescriptionHi, I'd like to suggest a new feature: Stoplight offers a more modern and user-friendly interface for API exploration, including features such as improved navigation, schema visualization, and endpoint interaction and sample code generation in multiple program language. Having a configuration option like: Would the FastAPI team consider supporting this as a built-in alternative or sharing guidelines on how to integrate Stoplight as the docs viewer? Thanks in advance, and keep up the great work! Operating SystemmacOS Operating System Details26.1 Tahoe FastAPI Version0.104.1 Pydantic Version2.5.2 Python Version3.9.6 Additional ContextNo response |
BetaWas this translation helpful?Give feedback.
All reactions
Replies: 3 comments 1 reply
-
This is a great suggestion. Stoplight Elements definitely offers a cleaner UI for many use cases. While waiting to see if this gets added natively, you can actually implement this today without any changes to FastAPI internals. You just need to disable the default docs and serve the Elements web component via a custom HTML response. fromfastapiimportFastAPIfromfastapi.responsesimportHTMLResponse# Disable default docs to free up the /docs routeapp=FastAPI(docs_url=None,redoc_url=None)@app.get("/docs",include_in_schema=False)asyncdefstoplight_elements():returnHTMLResponse("""<!doctype html><html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"> <title>API Docs</title> <script src="https://unpkg.com/@stoplight/elements/web-components.min.js"></script> <link rel="stylesheet" href="https://unpkg.com/@stoplight/elements/styles.min.css"> </head> <body> <elements-api apiDescriptionUrl="/openapi.json" router="hash" layout="sidebar" /> </body></html>""")@app.get("/")defread_root():return {"Hello":"World"} If you find this breakdown helpful for your debugging, please mark this response as the answer so others with similar credit-tracking needs can find it easily! |
BetaWas this translation helpful?Give feedback.
All reactions
This comment was marked as disruptive content.
This comment was marked as disruptive content.
-
@terapias-pro, please, stop posting LLM-generated answers here! |
BetaWas this translation helpful?Give feedback.
All reactions
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
-
We already have PR to add such support:#5168 As for me, the Stoplight's UI is quite raw. I'm not sure it's good idea to add such support to FastAPI. I think theapproach suggested byJunjieAraoXiong us simple enough. You can use any documentation system you want |
BetaWas this translation helpful?Give feedback.