fastapi-extra 0.2.2__cp312-cp312-win_amd64.whl → 0.2.3__cp312-cp312-win_amd64.whl

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/__init__.py CHANGED
@@ -1,4 +1,4 @@
1
- __version__ = "0.2.2"
1
+ __version__ = "0.2.3"
2
2
 
3
3
 
4
4
  from fastapi import FastAPI
Binary file
fastapi_extra/response.py CHANGED
@@ -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):
Binary file
fastapi_extra/routing.pyi CHANGED
@@ -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
@@ -1,12 +1,12 @@
1
- fastapi_extra/__init__.py,sha256=15p7teY89i6qSlOfYqQjU6a7fRvBPC-tPXGQU6Oo0O8,286
2
- fastapi_extra/cursor.cp312-win_amd64.pyd,sha256=_Lkcm1Mi2PRMXa4M4QO5ydq-5N8Pk0pAjb8hiDLp13A,53760
1
+ fastapi_extra/__init__.py,sha256=R03bRZYl4AVdbnAFZ3g-AlNlR6fvByDmK7lqJuApDgI,286
2
+ fastapi_extra/cursor.cp312-win_amd64.pyd,sha256=cmeCdfqVMua1kmwFAMUjlWPeC28fQbmJneNcjaUz2bI,53760
3
3
  fastapi_extra/cursor.pyi,sha256=t1_ub-dRhu3OcXB_dIw5MdBG9r1n7853Vtgzc6bk6dw,115
4
4
  fastapi_extra/dependency.py,sha256=LtYnOTMyhOQUFSbNEViw7lxJvAFpPWbyuY4e2goSG-8,2130
5
5
  fastapi_extra/form.py,sha256=Fs9uEDOQThjFroDVTrjWnIGJ107BgXCppIVTymwQLzg,1247
6
6
  fastapi_extra/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
7
- fastapi_extra/response.py,sha256=DHvhOSgwot5eBNKuI_jPYxZ5rshZ55Xkg-FNBJlHD1E,9609
8
- fastapi_extra/routing.cp312-win_amd64.pyd,sha256=e_t1yZsSSJm-z1ppnXVOch9TGQF2q9ipphYNsY_9Otk,91136
9
- fastapi_extra/routing.pyi,sha256=QslcOUnVJqFCqt14VJQwjUYQ7Qd3bQBTo34Yx1xS7TA,243
7
+ fastapi_extra/response.py,sha256=9rSoFDjLGBQTXrKrLuiX0rlaGSxR7YAFVlGKDc4Q9S8,10173
8
+ fastapi_extra/routing.cp312-win_amd64.pyd,sha256=L92GqIq7WQdzcSJfJt9qsdGt4mrHQ1hMj1adPj_vwRY,91648
9
+ fastapi_extra/routing.pyi,sha256=pW9O3noU4F-7l7LLViTVBLgzY468JS0jO96vdfL7CPA,243
10
10
  fastapi_extra/settings.py,sha256=cCcwaper5GiNNoT4gNKqf-iloSOTNnMsiUR0knJx4Mw,1461
11
11
  fastapi_extra/types.py,sha256=3z6gUnao6WZL76asZYmex20xfY9mvYA-RbnsxUcui30,819
12
12
  fastapi_extra/utils.py,sha256=tsPX3kpF_P5D9Bd3gnlG6rkVsLkv5gbxjml-s6ZL_6I,346
@@ -18,8 +18,8 @@ fastapi_extra/database/service.py,sha256=V5ojRpiWs9_B3XVQz-PtyvBePfmByTn8WG2gXwu
18
18
  fastapi_extra/database/session.py,sha256=PALArHhXNS2gCgeMkiKjyatvINV_VW1LjgEIwXDKyfQ,1903
19
19
  fastapi_extra/native/cursor.pyx,sha256=GchJIPY6e5scuyl1BbA-Et0CdRcHOI3xgsTvDem0B70,1141
20
20
  fastapi_extra/native/routing.pyx,sha256=NisJ9YaxzceDVWJnF3EeVXWT8rv_6WRDuIfLEK0eWbc,6233
21
- fastapi_extra-0.2.2.dist-info/licenses/LICENSE,sha256=0vTjHDa3VDsxTT-R-sH6SpYcA2F1hKtbX9ZFZQm-EcU,1516
22
- fastapi_extra-0.2.2.dist-info/METADATA,sha256=buJJyc4jA2ve_5jdhJ0Gm6HXiazZC2rwJm6oGEktH3A,1371
23
- fastapi_extra-0.2.2.dist-info/WHEEL,sha256=8UP9x9puWI0P1V_d7K2oMTBqfeLNm21CTzZ_Ptr0NXU,101
24
- fastapi_extra-0.2.2.dist-info/top_level.txt,sha256=B7D80bEftE2E-eSd1be2r9BWkLLMZN21dRTWpb4y4Ig,14
25
- fastapi_extra-0.2.2.dist-info/RECORD,,
21
+ fastapi_extra-0.2.3.dist-info/licenses/LICENSE,sha256=0vTjHDa3VDsxTT-R-sH6SpYcA2F1hKtbX9ZFZQm-EcU,1516
22
+ fastapi_extra-0.2.3.dist-info/METADATA,sha256=ncCoVqk0MpEjPC2GE-wHHKhfVvocUbKvjlweKpSbvuY,1371
23
+ fastapi_extra-0.2.3.dist-info/WHEEL,sha256=8UP9x9puWI0P1V_d7K2oMTBqfeLNm21CTzZ_Ptr0NXU,101
24
+ fastapi_extra-0.2.3.dist-info/top_level.txt,sha256=B7D80bEftE2E-eSd1be2r9BWkLLMZN21dRTWpb4y4Ig,14
25
+ fastapi_extra-0.2.3.dist-info/RECORD,,