From ab3ed9b4971c2004bd261a18d02eebafdf2a322a Mon Sep 17 00:00:00 2001 From: julius Date: Fri, 21 Mar 2025 15:06:44 +0100 Subject: [PATCH] feat: add OpenAPI tags --- cutt/analysis.py | 4 ++-- cutt/main.py | 13 ++++++++----- cutt/player.py | 2 +- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/cutt/analysis.py b/cutt/analysis.py index 795482f..bb5c277 100644 --- a/cutt/analysis.py +++ b/cutt/analysis.py @@ -17,7 +17,7 @@ matplotlib.use("agg") import matplotlib.pyplot as plt -analysis_router = APIRouter(prefix="/analysis") +analysis_router = APIRouter(prefix="/analysis", tags=["analysis"]) C = Chemistry @@ -264,7 +264,7 @@ def mvp( analysis_router.add_api_route( "/graph_json/{team_id}", endpoint=graph_json, methods=["GET"] ) -analysis_router.add_api_route("/image", endpoint=render_sociogram, methods=["POST"]) +# analysis_router.add_api_route("/image", endpoint=render_sociogram, methods=["POST"]) analysis_router.add_api_route("/mvp/{team_id}", endpoint=mvp, methods=["GET"]) if __name__ == "__main__": diff --git a/cutt/main.py b/cutt/main.py index 2fb90f5..dfa3c5c 100644 --- a/cutt/main.py +++ b/cutt/main.py @@ -22,7 +22,9 @@ C = Chemistry R = MVPRanking P = Player -app = FastAPI(title="cutt") +app = FastAPI( + title="cutt", swagger_ui_parameters={"syntaxHighlight": {"theme": "monokai"}} +) api_router = APIRouter(prefix="/api") origins = [ "https://cutt.0124816.xyz", @@ -53,6 +55,7 @@ def list_teams(): team_router = APIRouter( prefix="/team", dependencies=[Security(get_current_active_user, scopes=["admin"])], + tags=["team"], ) team_router.add_api_route("/list", endpoint=list_teams, methods=["GET"]) team_router.add_api_route("/add", endpoint=add_team, methods=["POST"]) @@ -67,7 +70,7 @@ somethings_fishy = HTTPException( ) -@api_router.put("/mvps") +@api_router.put("/mvps", tags=["analysis"]) def submit_mvps( mvps: MVPRanking, user: Annotated[Player, Depends(get_current_active_user)], @@ -87,7 +90,7 @@ def submit_mvps( raise wrong_user_id_exception -@api_router.get("/mvps") +@api_router.get("/mvps", tags=["analysis"]) def get_mvps( user: Annotated[Player, Depends(get_current_active_user)], ): @@ -111,7 +114,7 @@ def get_mvps( ) -@api_router.put("/chemistry") +@api_router.put("/chemistry", tags=["analysis"]) def submit_chemistry( chemistry: Chemistry, user: Annotated[Player, Depends(get_current_active_user)] ): @@ -132,7 +135,7 @@ def submit_chemistry( raise wrong_user_id_exception -@api_router.get("/chemistry") +@api_router.get("/chemistry", tags=["analysis"]) def get_chemistry(user: Annotated[Player, Depends(get_current_active_user)]): with Session(engine) as session: subquery = ( diff --git a/cutt/player.py b/cutt/player.py index b50762e..406db51 100644 --- a/cutt/player.py +++ b/cutt/player.py @@ -37,7 +37,7 @@ async def read_teams_me(user: Annotated[P, Depends(get_current_active_user)]): return [p.teams for p in session.exec(select(P).where(P.id == user.id))][0] -player_router = APIRouter(prefix="/player") +player_router = APIRouter(prefix="/player", tags=["player"]) player_router.add_api_route("/list/{team_id}", endpoint=list_players, methods=["GET"]) player_router.add_api_route("/add", endpoint=add_player, methods=["POST"]) player_router.add_api_route("/me", endpoint=read_player_me, methods=["GET"])