Skip to content

Commit 7d329e0

Browse files
authored
FastAPI update and serve static Swagger assets (#324)
* update FastAPI 0.54.1 -> 0.60.1 * static Swagger files
1 parent 375794e commit 7d329e0

File tree

7 files changed

+679
-401
lines changed

7 files changed

+679
-401
lines changed

Pipfile.lock

Lines changed: 372 additions & 354 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/main.py

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@
66
import pydantic
77
import sentry_sdk
88
import uvicorn
9-
from fastapi import FastAPI, Request, Response
9+
from fastapi import FastAPI, Request, Response, openapi
1010
from fastapi.middleware.cors import CORSMiddleware
1111
from fastapi.middleware.gzip import GZipMiddleware
1212
from fastapi.responses import JSONResponse
13+
from fastapi.staticfiles import StaticFiles
1314
from scout_apm.async_.starlette import ScoutMiddleware
1415
from sentry_sdk.integrations.asgi import SentryAsgiMiddleware
1516

@@ -35,8 +36,8 @@
3536
" Project page: https://github.com/ExpDev07/coronavirus-tracker-api."
3637
),
3738
version="2.0.3",
38-
docs_url="/",
39-
redoc_url="/docs",
39+
docs_url=None,
40+
redoc_url=None,
4041
on_startup=[setup_client_session],
4142
on_shutdown=[teardown_client_session],
4243
)
@@ -108,6 +109,31 @@ async def handle_validation_error(
108109
# Include routers.
109110
APP.include_router(V1, prefix="", tags=["v1"])
110111
APP.include_router(V2, prefix="/v2", tags=["v2"])
112+
APP.mount("/static", StaticFiles(directory="static"), name="static")
113+
114+
# ##############
115+
# Swagger/Redocs
116+
# ##############
117+
118+
119+
@APP.get("/", include_in_schema=False)
120+
async def custom_swagger_ui_html():
121+
"""Serve Swagger UI."""
122+
return openapi.docs.get_swagger_ui_html(
123+
openapi_url=APP.openapi_url,
124+
title=f"{APP.title} - Swagger UI",
125+
oauth2_redirect_url=APP.swagger_ui_oauth2_redirect_url,
126+
swagger_js_url="/static/swagger-ui-bundle.js",
127+
swagger_css_url="/static/swagger-ui.css",
128+
)
129+
130+
131+
@APP.get("/docs", include_in_schema=False)
132+
async def redoc_html():
133+
"""Serve ReDoc UI."""
134+
return openapi.docs.get_redoc_html(
135+
openapi_url=APP.openapi_url, title=f"{APP.title} - ReDoc", redoc_js_url="/static/redoc.standalone.js",
136+
)
111137

112138

113139
# Running of app.

requirements-dev.txt

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,49 @@
11
-i https://pypi.org/simple
2-
appdirs==1.4.3
3-
astroid==2.4.1
2+
appdirs==1.4.4
3+
astroid==2.4.2
44
async-asgi-testclient==1.4.4
55
async-generator==1.10
66
asyncmock==0.4.2
77
attrs==19.3.0
88
bandit==1.6.2
99
black==19.10b0
10-
certifi==2020.4.5.1
10+
certifi==2020.6.20
1111
chardet==3.0.4
1212
click==7.1.2
13-
coverage==5.1
14-
coveralls==2.0.0
13+
coverage==5.2.1
14+
coveralls==2.1.1
1515
docopt==0.6.2
1616
gitdb==4.0.5
17-
gitpython==3.1.2
18-
idna==2.9
19-
importlib-metadata==1.6.0 ; python_version < '3.8'
17+
gitpython==3.1.7
18+
idna==2.10
19+
importlib-metadata==1.7.0 ; python_version < '3.8'
2020
invoke==1.4.1
2121
isort==4.3.21
2222
lazy-object-proxy==1.4.3
2323
mccabe==0.6.1
2424
mock==4.0.2
25-
more-itertools==8.2.0
26-
multidict==4.7.5
27-
packaging==20.3
25+
more-itertools==8.4.0
26+
multidict==4.7.6
27+
packaging==20.4
2828
pathspec==0.8.0
2929
pbr==5.4.5
3030
pluggy==0.13.1
31-
py==1.8.1
32-
pylint==2.5.2
31+
py==1.9.0
32+
pylint==2.5.3
3333
pyparsing==2.4.7
34-
pytest-asyncio==0.12.0
35-
pytest-cov==2.8.1
36-
pytest==5.4.2
34+
pytest-asyncio==0.14.0
35+
pytest-cov==2.10.0
36+
pytest==5.4.3
3737
pyyaml==5.3.1
38-
regex==2020.5.7
39-
requests==2.23.0
40-
responses==0.10.14
41-
six==1.14.0
38+
regex==2020.7.14
39+
requests==2.24.0
40+
responses==0.10.15
41+
six==1.15.0
4242
smmap==3.0.4
43-
stevedore==1.32.0
44-
toml==0.10.0
43+
stevedore==3.2.0
44+
toml==0.10.1
4545
typed-ast==1.4.1
46-
urllib3[secure]==1.25.9 ; python_version >= '3.5'
47-
wcwidth==0.1.9
46+
urllib3[secure]==1.25.10 ; python_version >= '3.5'
47+
wcwidth==0.2.5
4848
wrapt==1.12.1
4949
zipp==3.1.0

requirements.txt

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,39 +3,40 @@ aiocache[redis]==0.11.1
33
aiofiles==0.5.0
44
aiohttp==3.6.2
55
aioredis==1.3.1
6-
asgiref==3.2.7 ; python_version >= '3.5'
6+
asgiref==3.2.10 ; python_version >= '3.5'
77
async-timeout==3.0.1
88
asyncache==0.1.1
99
attrs==19.3.0
10-
cachetools==4.1.0
11-
certifi==2020.4.5.1
12-
cffi==1.14.0
10+
cachetools==4.1.1
11+
certifi==2020.6.20
12+
cffi==1.14.1
1313
chardet==3.0.4
1414
click==7.1.2
15-
cryptography==2.9.2
15+
cryptography==3.0
1616
dataclasses==0.6 ; python_version < '3.7'
17-
fastapi==0.54.1
17+
fastapi==0.60.1
1818
gunicorn==20.0.4
1919
h11==0.9.0
20-
hiredis==1.0.1
20+
hiredis==1.1.0
2121
httptools==0.1.1 ; sys_platform != 'win32' and sys_platform != 'cygwin' and platform_python_implementation != 'PyPy'
2222
idna-ssl==1.1.0 ; python_version < '3.7'
23-
idna==2.9
24-
multidict==4.7.5
25-
psutil==5.7.0
23+
idna==2.10
24+
multidict==4.7.6
25+
psutil==5.7.2
2626
pycparser==2.20
27-
pydantic[dotenv]==1.5.1
27+
pydantic[dotenv]==1.6.1
2828
pyopenssl==19.1.0
2929
python-dateutil==2.8.1
30-
python-dotenv==0.13.0
31-
requests==2.23.0
32-
scout-apm==2.14.1
33-
sentry-sdk==0.14.3
34-
six==1.14.0
35-
starlette==0.13.2
36-
urllib3[secure]==1.25.9 ; python_version >= '3.5'
37-
uvicorn==0.11.5
30+
python-dotenv==0.14.0
31+
requests==2.24.0
32+
scout-apm==2.15.2
33+
sentry-sdk==0.16.2
34+
six==1.15.0
35+
starlette==0.13.6
36+
typing-extensions==3.7.4.2
37+
urllib3[secure]==1.25.10 ; python_version >= '3.5'
38+
uvicorn==0.11.7
3839
uvloop==0.14.0 ; sys_platform != 'win32' and sys_platform != 'cygwin' and platform_python_implementation != 'PyPy'
3940
websockets==8.1
4041
wrapt==1.12.1
41-
yarl==1.4.2
42+
yarl==1.5.0

static/redoc.standalone.js

Lines changed: 137 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

static/swagger-ui-bundle.js

Lines changed: 92 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

static/swagger-ui.css

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)