From eef0dae6176d5ee2243d8fdbb43b21fe181525b9 Mon Sep 17 00:00:00 2001 From: Leonard Techel Date: Tue, 5 Jul 2022 20:28:46 +0200 Subject: [PATCH] docs: Improve auto-generated OpenAPI docs --- backend/dpt_app/trails/api.py | 2 +- backend/dpt_app/trails/schemas.py | 22 +++++++++++++++++----- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/backend/dpt_app/trails/api.py b/backend/dpt_app/trails/api.py index ac3c55f..c4cb69a 100644 --- a/backend/dpt_app/trails/api.py +++ b/backend/dpt_app/trails/api.py @@ -9,7 +9,7 @@ from .qr_models import Code from .schemas import ClockSchema, GameSchema, PlayerSchema -api = NinjaAPI() +api = NinjaAPI(title="Kaigo API") class CodeAlreadyUsed(Exception): diff --git a/backend/dpt_app/trails/schemas.py b/backend/dpt_app/trails/schemas.py index a05f871..0eccb1d 100644 --- a/backend/dpt_app/trails/schemas.py +++ b/backend/dpt_app/trails/schemas.py @@ -12,8 +12,11 @@ class Data(GenericModel, Generic[TypeT, AttributesT]): attributes: AttributesT -class Document(GenericModel, Generic[TypeT, AttributesT]): - data: Data[TypeT, AttributesT] +DataT = TypeVar("DataT", bound=Data) + + +class Document(GenericModel, Generic[DataT]): + data: DataT class ClockAttributes(BaseModel): @@ -21,7 +24,10 @@ class ClockAttributes(BaseModel): speed: Optional[float] -ClockSchema = Document[Literal["clock"], ClockAttributes] +ClockData = Data[Literal["clock"], ClockAttributes] +ClockData.__name__ = "ClockData" + +ClockSchema = Document[ClockData] ClockSchema.__name__ = "Clock" @@ -30,7 +36,10 @@ class GameAttributes(BaseModel): hasUserParameterScope: Optional[bool] -GameSchema = Document[Literal["game"], GameAttributes] +GameData = Data[Literal["game"], GameAttributes] +GameData.__name__ = "GameData" + +GameSchema = Document[GameData] GameSchema.__name__ = "Game" @@ -39,5 +48,8 @@ class PlayerAttributes(BaseModel): character: Optional[str] -PlayerSchema = Document[Literal["player"], PlayerAttributes] +PlayerData = Data[Literal["player"], PlayerAttributes] +PlayerData.__name__ = "PlayerData" + +PlayerSchema = Document[PlayerData] PlayerSchema.__name__ = "Player"