From b7eb62e38291874a60d90ae499958d2bca577a96 Mon Sep 17 00:00:00 2001 From: Shahar Ilany <31574996+ShaharIlany@users.noreply.github.com> Date: Wed, 24 Aug 2022 22:21:59 +0300 Subject: [PATCH] feat(tutorial002.py): add elements to tutorial --- docs_src/extending_openapi/tutorial002.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/docs_src/extending_openapi/tutorial002.py b/docs_src/extending_openapi/tutorial002.py index 23ea368f8..f7e132636 100644 --- a/docs_src/extending_openapi/tutorial002.py +++ b/docs_src/extending_openapi/tutorial002.py @@ -2,11 +2,12 @@ from fastapi import FastAPI from fastapi.openapi.docs import ( get_redoc_html, get_swagger_ui_html, + get_stoplight_elements_html, get_swagger_ui_oauth2_redirect_html, ) from fastapi.staticfiles import StaticFiles -app = FastAPI(docs_url=None, redoc_url=None) +app = FastAPI(docs_url=None, redoc_url=None, stoplight_elements_url=None) app.mount("/static", StaticFiles(directory="static"), name="static") @@ -35,7 +36,16 @@ async def redoc_html(): redoc_js_url="/static/redoc.standalone.js", ) +@app.get("/elements", include_in_schema=False) +async def elements_html(): + return get_stoplight_elements_html( + openapi_url=app.openapi_url, + title=app.title + " - Elements", + stoplight_elements_js_url="/static/web-components.min.js", + stoplight_elements_css_url="/static/styles.min.css", + ) + @app.get("/users/{username}") async def read_user(username: str): - return {"message": f"Hello {username}"} + return {"message": f"Hello {username}"} \ No newline at end of file