31 lines
622 B
Python
31 lines
622 B
Python
"""Shared API response schemas."""
|
|
|
|
from typing import Generic, TypeVar
|
|
|
|
from pydantic import BaseModel, ConfigDict, Field
|
|
|
|
|
|
def to_camel(value: str) -> str:
|
|
head, *tail = value.split("_")
|
|
return head + "".join(part.capitalize() for part in tail)
|
|
|
|
|
|
class ApiSchema(BaseModel):
|
|
model_config = ConfigDict(alias_generator=to_camel, populate_by_name=True)
|
|
|
|
|
|
DataT = TypeVar("DataT")
|
|
|
|
|
|
class ApiResponse(ApiSchema, Generic[DataT]):
|
|
code: int = 200
|
|
message: str = "success"
|
|
data: DataT | None = Field(default=None)
|
|
|
|
|
|
class HealthData(ApiSchema):
|
|
status: str = "ok"
|
|
service: str
|
|
version: str
|
|
|