mirror of
https://github.com/dcs-retribution/dcs-retribution.git
synced 2025-11-10 15:41:24 +00:00
Add metadata to FastAPI endpoints for OpenAPI.
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.
This commit is contained in:
@@ -16,6 +16,9 @@ class HoldZonesJs(BaseModel):
|
||||
permissible_zones: list[LeafletPoly] = Field(alias="permissibleZones")
|
||||
preferred_lines: list[LeafletPoly] = Field(alias="preferredLines")
|
||||
|
||||
class Config:
|
||||
title = "HoldZones"
|
||||
|
||||
@classmethod
|
||||
def empty(cls) -> HoldZonesJs:
|
||||
return HoldZonesJs(
|
||||
@@ -62,6 +65,9 @@ class IpZonesJs(BaseModel):
|
||||
permissibleZone: LeafletPoly = Field(alias="permissibleZone")
|
||||
safeZones: list[LeafletPoly] = Field(alias="safeZones")
|
||||
|
||||
class Config:
|
||||
title = "IpZones"
|
||||
|
||||
@classmethod
|
||||
def empty(cls) -> IpZonesJs:
|
||||
return IpZonesJs(homeBubble=[], ipBubble=[], permissibleZone=[], safeZones=[])
|
||||
@@ -89,6 +95,9 @@ class JoinZonesJs(BaseModel):
|
||||
permissible_zones: list[LeafletPoly] = Field(alias="permissibleZones")
|
||||
preferred_lines: list[LeafletPoly] = Field(alias="preferredLines")
|
||||
|
||||
class Config:
|
||||
title = "JoinZones"
|
||||
|
||||
@classmethod
|
||||
def empty(cls) -> JoinZonesJs:
|
||||
return JoinZonesJs(
|
||||
|
||||
@@ -9,19 +9,25 @@ from .models import HoldZonesJs, IpZonesJs, JoinZonesJs
|
||||
router: APIRouter = APIRouter(prefix="/debug/waypoint-geometries")
|
||||
|
||||
|
||||
@router.get("/hold/{flight_id}")
|
||||
@router.get(
|
||||
"/hold/{flight_id}", operation_id="get_debug_hold_zones", response_model=HoldZonesJs
|
||||
)
|
||||
def hold_zones(
|
||||
flight_id: UUID, game: Game = Depends(GameContext.require)
|
||||
) -> HoldZonesJs:
|
||||
return HoldZonesJs.for_flight(game.db.flights.get(flight_id), game)
|
||||
|
||||
|
||||
@router.get("/ip/{flight_id}")
|
||||
@router.get(
|
||||
"/ip/{flight_id}", operation_id="get_debug_ip_zones", response_model=IpZonesJs
|
||||
)
|
||||
def ip_zones(flight_id: UUID, game: Game = Depends(GameContext.require)) -> IpZonesJs:
|
||||
return IpZonesJs.for_flight(game.db.flights.get(flight_id), game)
|
||||
|
||||
|
||||
@router.get("/join/{flight_id}")
|
||||
@router.get(
|
||||
"/join/{flight_id}", operation_id="get_debug_join_zones", response_model=JoinZonesJs
|
||||
)
|
||||
def join_zones(
|
||||
flight_id: UUID, game: Game = Depends(GameContext.require)
|
||||
) -> JoinZonesJs:
|
||||
|
||||
Reference in New Issue
Block a user