From bf629956ecee53d9c92f2fe739184be11f1755f6 Mon Sep 17 00:00:00 2001 From: Silvio Heinze Date: Thu, 10 Oct 2024 15:44:12 +0200 Subject: [PATCH] update openapi tags --- code/main.py | 13 ++++++++++++- code/routers/city.py | 4 ++-- code/routers/station.py | 6 +++--- 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/code/main.py b/code/main.py index de2b594..87e8cf9 100644 --- a/code/main.py +++ b/code/main.py @@ -2,7 +2,18 @@ from fastapi.middleware.cors import CORSMiddleware from routers import city_router, station_router -app = FastAPI() +app = FastAPI( + openapi_tags=[ + { + "name": "station", + "description": "Operations related to station data (e.g., historical, current)." + }, + { + "name": "city", + "description": "Operations related to city-level data." + } + ] +) origins = ["*"] diff --git a/code/routers/city.py b/code/routers/city.py index bc85cbe..167fcc1 100644 --- a/code/routers/city.py +++ b/code/routers/city.py @@ -12,7 +12,7 @@ router = APIRouter() -@router.get("/all", tags= {"city"}) +@router.get("/all", tags=["city"]) async def get_all_cities(db: Session = Depends(get_db)): # Abfrage aller Städte in der Datenbank cities = db.query(City, Country).join(Country, City.country_id == Country.id).all() @@ -37,7 +37,7 @@ async def get_all_cities(db: Session = Depends(get_db)): return response -@router.get("/current", tags= {"city", "current"}) +@router.get("/current", tags=["city", "current"]) async def get_average_measurements_by_city( city_slug: str = Query(..., description="The name of the city to get the average measurements for."), db: Session = Depends(get_db) diff --git a/code/routers/station.py b/code/routers/station.py index ef16c85..b5e4e3f 100644 --- a/code/routers/station.py +++ b/code/routers/station.py @@ -38,7 +38,7 @@ async def get_history_station_data( # New endpoints -@router.get("/current", response_class=Response, tags= {"station", "current"}) +@router.get("/current", response_class=Response, tags=["station", "current"]) async def get_current_station_data( station_ids: str = None, last_active: int = 3600, @@ -120,7 +120,7 @@ async def get_current_station_data( return Response(content=content, media_type=media_type) -@router.post("/data", tags= {"station"}) +@router.post("/data", tags=["station"]) async def create_station_data( station: StationDataCreate, sensors: SensorsCreate, @@ -227,7 +227,7 @@ async def create_station_data( return {"status": "success"} -@router.get("/historical", response_class=Response, tags= {"station"}) +@router.get("/historical", response_class=Response, tags=["station"]) async def get_historical_station_data( station_ids: str = Query(..., description="Comma-separated list of station devices"), start: str = Query(..., description="Supply in format: YYYY-MM-DDThh:mm. Time is optional."),