feat(tutorial002.py): add elements to tutorial

This commit is contained in:
Shahar Ilany 2022-08-24 22:21:59 +03:00 committed by GitHub
parent 703499e940
commit b7eb62e382
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 12 additions and 2 deletions

View File

@ -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}"}