mirror of
https://github.com/dcs-liberation/dcs_liberation.git
synced 2025-11-10 14:22:26 +00:00
operation_ids give us better function names when generating the typescript API from the openapi.json. BaseModel.Config.title does the same for type names. Response models (or 204 status codes) need to be explicit or the API will be declared as returning any.
20 lines
587 B
Python
20 lines
587 B
Python
from uuid import UUID
|
|
|
|
from fastapi import APIRouter, Depends
|
|
|
|
from game import Game
|
|
from .models import TgoJs
|
|
from ..dependencies import GameContext
|
|
|
|
router: APIRouter = APIRouter(prefix="/tgos")
|
|
|
|
|
|
@router.get("/", operation_id="list_tgos", response_model=list[TgoJs])
|
|
def list_tgos(game: Game = Depends(GameContext.require)) -> list[TgoJs]:
|
|
return TgoJs.all_in_game(game)
|
|
|
|
|
|
@router.get("/{tgo_id}", operation_id="get_tgo_by_id", response_model=TgoJs)
|
|
def get_tgo(tgo_id: UUID, game: Game = Depends(GameContext.require)) -> TgoJs:
|
|
return TgoJs.for_tgo(game.db.tgos.get(tgo_id))
|