mirror of https://github.com/tiangolo/fastapi.git
feat(tutorial002.py): add elements to tutorial
This commit is contained in:
parent
703499e940
commit
b7eb62e382
|
|
@ -2,11 +2,12 @@ from fastapi import FastAPI
|
||||||
from fastapi.openapi.docs import (
|
from fastapi.openapi.docs import (
|
||||||
get_redoc_html,
|
get_redoc_html,
|
||||||
get_swagger_ui_html,
|
get_swagger_ui_html,
|
||||||
|
get_stoplight_elements_html,
|
||||||
get_swagger_ui_oauth2_redirect_html,
|
get_swagger_ui_oauth2_redirect_html,
|
||||||
)
|
)
|
||||||
from fastapi.staticfiles import StaticFiles
|
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")
|
app.mount("/static", StaticFiles(directory="static"), name="static")
|
||||||
|
|
||||||
|
|
@ -35,7 +36,16 @@ async def redoc_html():
|
||||||
redoc_js_url="/static/redoc.standalone.js",
|
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}")
|
@app.get("/users/{username}")
|
||||||
async def read_user(username: str):
|
async def read_user(username: str):
|
||||||
return {"message": f"Hello {username}"}
|
return {"message": f"Hello {username}"}
|
||||||
Loading…
Reference in New Issue