Add support for Swagger
This commit is contained in:
parent
179947b536
commit
75e2f05f48
20
app/main.py
20
app/main.py
@ -1,15 +1,19 @@
|
||||
import os
|
||||
|
||||
from fastapi import FastAPI
|
||||
from fastapi import FastAPI, Request
|
||||
from fastapi.openapi.docs import get_swagger_ui_html
|
||||
from fastapi.openapi.utils import get_openapi
|
||||
|
||||
# from fastapi.staticfiles import StaticFiles
|
||||
# from fastapi.templating import Jinja2Templates
|
||||
|
||||
from .routers_v2 import (
|
||||
current, teams, rarity, cardsets, players, packtypes, packs, cards, events, results, rewards, decisions,
|
||||
current, awards, teams, rarity, cardsets, players, packtypes, packs, cards, events, results, rewards, decisions,
|
||||
batstats, pitstats, notifications, paperdex, gamerewards, gauntletrewards, gauntletruns, battingcards,
|
||||
battingcardratings, pitchingcards, pitchingcardratings, cardpositions, scouting, mlbplayers, stratgame, stratplays)
|
||||
|
||||
app = FastAPI(
|
||||
root_path='/api',
|
||||
responses={404: {'description': 'Not found'}},
|
||||
docs_url='/api/docs',
|
||||
redoc_url='/api/redoc'
|
||||
@ -19,6 +23,7 @@ app = FastAPI(
|
||||
# templates = Jinja2Templates(directory=os.path.dirname(os.path.abspath(__file__)))
|
||||
|
||||
app.include_router(current.router)
|
||||
app.include_router(awards.router)
|
||||
app.include_router(teams.router)
|
||||
app.include_router(rarity.router)
|
||||
app.include_router(cardsets.router)
|
||||
@ -46,3 +51,14 @@ app.include_router(mlbplayers.router)
|
||||
app.include_router(stratgame.router)
|
||||
app.include_router(stratplays.router)
|
||||
app.include_router(decisions.router)
|
||||
|
||||
|
||||
@app.get("/api/docs", include_in_schema=False)
|
||||
async def get_docs(req: Request):
|
||||
print(req.scope)
|
||||
return get_swagger_ui_html(openapi_url=req.scope.get('root_path')+'/openapi.json', title='Swagger')
|
||||
|
||||
|
||||
@app.get("/api/openapi.json", include_in_schema=False)
|
||||
async def openapi():
|
||||
return get_openapi(title='Paper Dynasty API', version=f'0.1.1', routes=app.routes)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user