Skip to content

Commit

Permalink
docs: Improve auto-generated OpenAPI docs
Browse files Browse the repository at this point in the history
  • Loading branch information
barnslig committed Jul 6, 2022
1 parent 48f4beb commit eef0dae
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
2 changes: 1 addition & 1 deletion backend/dpt_app/trails/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
22 changes: 17 additions & 5 deletions backend/dpt_app/trails/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,22 @@ 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):
state: Literal["running", "paused"]
speed: Optional[float]


ClockSchema = Document[Literal["clock"], ClockAttributes]
ClockData = Data[Literal["clock"], ClockAttributes]
ClockData.__name__ = "ClockData"

ClockSchema = Document[ClockData]
ClockSchema.__name__ = "Clock"


Expand All @@ -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"


Expand All @@ -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"

0 comments on commit eef0dae

Please sign in to comment.