Files

20 lines
453 B
Python
Raw Permalink Normal View History

2023-08-14 13:30:10 +08:00
# @Time : 2023/8/14 11:48
# @Author : Lan
# @File : response.py
# @Software: PyCharm
from typing import Generic, Optional, TypeVar
2023-08-14 13:30:10 +08:00
from pydantic import BaseModel
2023-08-14 13:30:10 +08:00
2025-02-15 22:00:53 +08:00
T = TypeVar("T")
2023-08-14 13:30:10 +08:00
class APIResponse(BaseModel, Generic[T]):
2023-08-14 13:30:10 +08:00
code: int = 200
2025-02-15 22:00:53 +08:00
message: str = "ok"
2026-06-03 02:25:36 +08:00
msg: Optional[str] = None
detail: Optional[T] = None
2026-06-03 02:25:36 +08:00
def model_post_init(self, __context) -> None:
if self.msg is None:
self.msg = self.message