fastapi-extra 0.2.2__tar.gz → 0.2.3__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {fastapi_extra-0.2.2 → fastapi_extra-0.2.3}/PKG-INFO +1 -1
- {fastapi_extra-0.2.2 → fastapi_extra-0.2.3}/fastapi_extra/__init__.py +1 -1
- {fastapi_extra-0.2.2 → fastapi_extra-0.2.3}/fastapi_extra/response.py +22 -4
- {fastapi_extra-0.2.2 → fastapi_extra-0.2.3}/fastapi_extra/routing.pyi +1 -1
- {fastapi_extra-0.2.2 → fastapi_extra-0.2.3}/fastapi_extra.egg-info/PKG-INFO +1 -1
- {fastapi_extra-0.2.2 → fastapi_extra-0.2.3}/LICENSE +0 -0
- {fastapi_extra-0.2.2 → fastapi_extra-0.2.3}/README.rst +0 -0
- {fastapi_extra-0.2.2 → fastapi_extra-0.2.3}/fastapi_extra/cache/__init__.py +0 -0
- {fastapi_extra-0.2.2 → fastapi_extra-0.2.3}/fastapi_extra/cache/redis.py +0 -0
- {fastapi_extra-0.2.2 → fastapi_extra-0.2.3}/fastapi_extra/cursor.pyi +0 -0
- {fastapi_extra-0.2.2 → fastapi_extra-0.2.3}/fastapi_extra/database/__init__.py +0 -0
- {fastapi_extra-0.2.2 → fastapi_extra-0.2.3}/fastapi_extra/database/model.py +0 -0
- {fastapi_extra-0.2.2 → fastapi_extra-0.2.3}/fastapi_extra/database/service.py +0 -0
- {fastapi_extra-0.2.2 → fastapi_extra-0.2.3}/fastapi_extra/database/session.py +0 -0
- {fastapi_extra-0.2.2 → fastapi_extra-0.2.3}/fastapi_extra/dependency.py +0 -0
- {fastapi_extra-0.2.2 → fastapi_extra-0.2.3}/fastapi_extra/form.py +0 -0
- {fastapi_extra-0.2.2 → fastapi_extra-0.2.3}/fastapi_extra/native/cursor.pyx +0 -0
- {fastapi_extra-0.2.2 → fastapi_extra-0.2.3}/fastapi_extra/native/routing.pyx +0 -0
- {fastapi_extra-0.2.2 → fastapi_extra-0.2.3}/fastapi_extra/py.typed +0 -0
- {fastapi_extra-0.2.2 → fastapi_extra-0.2.3}/fastapi_extra/settings.py +0 -0
- {fastapi_extra-0.2.2 → fastapi_extra-0.2.3}/fastapi_extra/types.py +0 -0
- {fastapi_extra-0.2.2 → fastapi_extra-0.2.3}/fastapi_extra/utils.py +0 -0
- {fastapi_extra-0.2.2 → fastapi_extra-0.2.3}/fastapi_extra.egg-info/SOURCES.txt +0 -0
- {fastapi_extra-0.2.2 → fastapi_extra-0.2.3}/fastapi_extra.egg-info/dependency_links.txt +0 -0
- {fastapi_extra-0.2.2 → fastapi_extra-0.2.3}/fastapi_extra.egg-info/requires.txt +0 -0
- {fastapi_extra-0.2.2 → fastapi_extra-0.2.3}/fastapi_extra.egg-info/top_level.txt +0 -0
- {fastapi_extra-0.2.2 → fastapi_extra-0.2.3}/pyproject.toml +0 -0
- {fastapi_extra-0.2.2 → fastapi_extra-0.2.3}/setup.cfg +0 -0
|
@@ -3,8 +3,9 @@ __date__ = "2024-12-24"
|
|
|
3
3
|
|
|
4
4
|
|
|
5
5
|
from enum import Enum
|
|
6
|
-
from typing import Generic
|
|
6
|
+
from typing import TYPE_CHECKING, Generic
|
|
7
7
|
|
|
8
|
+
from fastapi.responses import JSONResponse
|
|
8
9
|
from pydantic import BaseModel, Field
|
|
9
10
|
|
|
10
11
|
from fastapi_extra.types import T
|
|
@@ -193,9 +194,26 @@ class ResultEnum(Enum):
|
|
|
193
194
|
class APIResult(BaseModel, Generic[T]):
|
|
194
195
|
data: T | None = Field(default=None, title="返回数据")
|
|
195
196
|
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
197
|
+
if TYPE_CHECKING:
|
|
198
|
+
@classmethod
|
|
199
|
+
def ok(cls, data: T | None = None) -> "APIResult[T]":
|
|
200
|
+
return APIResult(data=data)
|
|
201
|
+
else:
|
|
202
|
+
@classmethod
|
|
203
|
+
def ok(cls, data: T | None = None) -> "APIResponse":
|
|
204
|
+
return APIResponse(APIResult(data=data))
|
|
205
|
+
|
|
206
|
+
|
|
207
|
+
class APIResponse(JSONResponse):
|
|
208
|
+
|
|
209
|
+
def render(self, content: APIResult) -> bytes:
|
|
210
|
+
return content.__pydantic_serializer__.to_json(
|
|
211
|
+
indent=None,
|
|
212
|
+
by_alias=True,
|
|
213
|
+
exclude_defaults=False,
|
|
214
|
+
exclude_none=False,
|
|
215
|
+
exclude_unset=False
|
|
216
|
+
)
|
|
199
217
|
|
|
200
218
|
|
|
201
219
|
class APIError(Exception):
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|