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.
Files changed (28) hide show
  1. {fastapi_extra-0.2.2 → fastapi_extra-0.2.3}/PKG-INFO +1 -1
  2. {fastapi_extra-0.2.2 → fastapi_extra-0.2.3}/fastapi_extra/__init__.py +1 -1
  3. {fastapi_extra-0.2.2 → fastapi_extra-0.2.3}/fastapi_extra/response.py +22 -4
  4. {fastapi_extra-0.2.2 → fastapi_extra-0.2.3}/fastapi_extra/routing.pyi +1 -1
  5. {fastapi_extra-0.2.2 → fastapi_extra-0.2.3}/fastapi_extra.egg-info/PKG-INFO +1 -1
  6. {fastapi_extra-0.2.2 → fastapi_extra-0.2.3}/LICENSE +0 -0
  7. {fastapi_extra-0.2.2 → fastapi_extra-0.2.3}/README.rst +0 -0
  8. {fastapi_extra-0.2.2 → fastapi_extra-0.2.3}/fastapi_extra/cache/__init__.py +0 -0
  9. {fastapi_extra-0.2.2 → fastapi_extra-0.2.3}/fastapi_extra/cache/redis.py +0 -0
  10. {fastapi_extra-0.2.2 → fastapi_extra-0.2.3}/fastapi_extra/cursor.pyi +0 -0
  11. {fastapi_extra-0.2.2 → fastapi_extra-0.2.3}/fastapi_extra/database/__init__.py +0 -0
  12. {fastapi_extra-0.2.2 → fastapi_extra-0.2.3}/fastapi_extra/database/model.py +0 -0
  13. {fastapi_extra-0.2.2 → fastapi_extra-0.2.3}/fastapi_extra/database/service.py +0 -0
  14. {fastapi_extra-0.2.2 → fastapi_extra-0.2.3}/fastapi_extra/database/session.py +0 -0
  15. {fastapi_extra-0.2.2 → fastapi_extra-0.2.3}/fastapi_extra/dependency.py +0 -0
  16. {fastapi_extra-0.2.2 → fastapi_extra-0.2.3}/fastapi_extra/form.py +0 -0
  17. {fastapi_extra-0.2.2 → fastapi_extra-0.2.3}/fastapi_extra/native/cursor.pyx +0 -0
  18. {fastapi_extra-0.2.2 → fastapi_extra-0.2.3}/fastapi_extra/native/routing.pyx +0 -0
  19. {fastapi_extra-0.2.2 → fastapi_extra-0.2.3}/fastapi_extra/py.typed +0 -0
  20. {fastapi_extra-0.2.2 → fastapi_extra-0.2.3}/fastapi_extra/settings.py +0 -0
  21. {fastapi_extra-0.2.2 → fastapi_extra-0.2.3}/fastapi_extra/types.py +0 -0
  22. {fastapi_extra-0.2.2 → fastapi_extra-0.2.3}/fastapi_extra/utils.py +0 -0
  23. {fastapi_extra-0.2.2 → fastapi_extra-0.2.3}/fastapi_extra.egg-info/SOURCES.txt +0 -0
  24. {fastapi_extra-0.2.2 → fastapi_extra-0.2.3}/fastapi_extra.egg-info/dependency_links.txt +0 -0
  25. {fastapi_extra-0.2.2 → fastapi_extra-0.2.3}/fastapi_extra.egg-info/requires.txt +0 -0
  26. {fastapi_extra-0.2.2 → fastapi_extra-0.2.3}/fastapi_extra.egg-info/top_level.txt +0 -0
  27. {fastapi_extra-0.2.2 → fastapi_extra-0.2.3}/pyproject.toml +0 -0
  28. {fastapi_extra-0.2.2 → fastapi_extra-0.2.3}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: fastapi-extra
3
- Version: 0.2.2
3
+ Version: 0.2.3
4
4
  Summary: extra package for fastapi.
5
5
  Author-email: Ziyan Yin <408856732@qq.com>
6
6
  License: BSD-3-Clause
@@ -1,4 +1,4 @@
1
- __version__ = "0.2.2"
1
+ __version__ = "0.2.3"
2
2
 
3
3
 
4
4
  from fastapi import FastAPI
@@ -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
- @classmethod
197
- def ok(cls, data: T | None = None) -> "APIResult[T]":
198
- return APIResult(data=data)
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):
@@ -3,8 +3,8 @@ __describe__ = ""
3
3
 
4
4
 
5
5
  from typing import Any
6
- from fastapi import FastAPI
7
6
 
7
+ from fastapi import FastAPI
8
8
 
9
9
  class RouteNode:
10
10
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: fastapi-extra
3
- Version: 0.2.2
3
+ Version: 0.2.3
4
4
  Summary: extra package for fastapi.
5
5
  Author-email: Ziyan Yin <408856732@qq.com>
6
6
  License: BSD-3-Clause
File without changes
File without changes
File without changes