20 lines
441 B
Python
20 lines
441 B
Python
from __future__ import annotations
|
|
|
|
from typing import Generic, TypeVar
|
|
from pydantic import BaseModel, Field
|
|
|
|
T = TypeVar("T")
|
|
|
|
|
|
class ApiError(BaseModel):
|
|
code: str = Field(..., examples=["validation_error", "db_error"])
|
|
message: str
|
|
details: dict | None = None
|
|
|
|
|
|
class ApiResponse(BaseModel, Generic[T]):
|
|
success: bool = True
|
|
errors: list[ApiError] | None = None
|
|
count: int | None = None
|
|
data: T | None = None
|