sanic-api 0.3.0a2__py3-none-any.whl → 0.3.0a3__py3-none-any.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.
- sanic_api/__init__.py +1 -1
- sanic_api/api/request.py +23 -23
- {sanic_api-0.3.0a2.dist-info → sanic_api-0.3.0a3.dist-info}/METADATA +1 -1
- {sanic_api-0.3.0a2.dist-info → sanic_api-0.3.0a3.dist-info}/RECORD +6 -6
- {sanic_api-0.3.0a2.dist-info → sanic_api-0.3.0a3.dist-info}/WHEEL +0 -0
- {sanic_api-0.3.0a2.dist-info → sanic_api-0.3.0a3.dist-info}/licenses/LICENSE.txt +0 -0
sanic_api/__init__.py
CHANGED
sanic_api/api/request.py
CHANGED
@@ -12,15 +12,15 @@ class Request(SanicRequest):
|
|
12
12
|
加入便于接口参数获取校验的方法
|
13
13
|
"""
|
14
14
|
|
15
|
-
request_type: type["Request"] | None
|
16
|
-
json_data_type: type[BaseModel] | None
|
17
|
-
form_data_type: type[BaseModel] | None
|
18
|
-
query_data_type: type[BaseModel] | None
|
19
|
-
|
20
15
|
json_data: BaseModel
|
21
16
|
form_data: BaseModel
|
22
17
|
query_data: BaseModel
|
23
18
|
|
19
|
+
_request_type: type["Request"] | None
|
20
|
+
_json_data_type: type[BaseModel] | None
|
21
|
+
_form_data_type: type[BaseModel] | None
|
22
|
+
_query_data_type: type[BaseModel] | None
|
23
|
+
|
24
24
|
def __init__(self, *args, **kwargs):
|
25
25
|
super().__init__(*args, **kwargs)
|
26
26
|
|
@@ -64,22 +64,22 @@ class Request(SanicRequest):
|
|
64
64
|
"""
|
65
65
|
|
66
66
|
# 从函数参数注解上面获取类型
|
67
|
-
self.
|
68
|
-
self.
|
69
|
-
self.
|
70
|
-
self.
|
67
|
+
self._json_data_type = self._get_type("json_data", BaseModel)
|
68
|
+
self._form_data_type = self._get_type("form_data", BaseModel)
|
69
|
+
self._query_data_type = self._get_type("query_data", BaseModel)
|
70
|
+
self._request_type = self._get_type("request", Request)
|
71
71
|
|
72
72
|
# 没有json_data参数 但是有自定义的request类就从request类上面获取json_data类型
|
73
|
-
if self.
|
74
|
-
self.
|
73
|
+
if self._request_type and not self._json_data_type:
|
74
|
+
self._json_data_type = self._request_type.__annotations__.get("json_data")
|
75
75
|
|
76
76
|
# 没有form_data参数 但是有自定义的request类就从request类上面获取form_data类型
|
77
|
-
if self.
|
78
|
-
self.
|
77
|
+
if self._request_type and not self._form_data_type:
|
78
|
+
self._form_data_type = self._request_type.__annotations__.get("form_data")
|
79
79
|
|
80
80
|
# 没有query_data参数 但是有自定义的request类就从request类上面获取query_data类型
|
81
|
-
if self.
|
82
|
-
self.
|
81
|
+
if self._request_type and not self._query_data_type:
|
82
|
+
self._query_data_type = self._request_type.__annotations__.get("query_data")
|
83
83
|
|
84
84
|
# noinspection PyBroadException
|
85
85
|
def _load_data(self):
|
@@ -113,8 +113,8 @@ class Request(SanicRequest):
|
|
113
113
|
json_data = self.json
|
114
114
|
except Exception:
|
115
115
|
json_data = None
|
116
|
-
if json_data and self.
|
117
|
-
self.json_data = self.
|
116
|
+
if json_data and self._json_data_type:
|
117
|
+
self.json_data = self._json_data_type(**json_data)
|
118
118
|
_set_arg("json_data", self.json_data)
|
119
119
|
|
120
120
|
# 由于form和query的参数的key是可以重复的,所以默认类型是类似dict[str, list]的
|
@@ -123,16 +123,16 @@ class Request(SanicRequest):
|
|
123
123
|
form_data = self.form
|
124
124
|
except Exception:
|
125
125
|
form_data = None
|
126
|
-
if form_data and self.
|
127
|
-
form_data = _proc_param_data(form_data, self.
|
128
|
-
self.form_data = self.
|
126
|
+
if form_data and self._form_data_type:
|
127
|
+
form_data = _proc_param_data(form_data, self._form_data_type)
|
128
|
+
self.form_data = self._form_data_type(**form_data)
|
129
129
|
_set_arg("form_data", self.form_data)
|
130
130
|
|
131
131
|
try:
|
132
132
|
query_data = self.args
|
133
133
|
except Exception:
|
134
134
|
query_data = None
|
135
|
-
if query_data and self.
|
136
|
-
query_data = _proc_param_data(query_data, self.
|
137
|
-
self.query_data = self.
|
135
|
+
if query_data and self._query_data_type:
|
136
|
+
query_data = _proc_param_data(query_data, self._query_data_type)
|
137
|
+
self.query_data = self._query_data_type(**query_data)
|
138
138
|
_set_arg("query_data", self.query_data)
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.3
|
2
2
|
Name: sanic-api
|
3
|
-
Version: 0.3.
|
3
|
+
Version: 0.3.0a3
|
4
4
|
Summary: Sanic 框架实用API工具集,拥有自动生成文档、参数校验、配置的导入、日志功能的优化等功能,更好的助力接口的开发
|
5
5
|
Project-URL: homepage, https://github.com/x-haose/sanic-api
|
6
6
|
Project-URL: repository, https://github.com/x-haose/sanic-api
|
@@ -1,8 +1,8 @@
|
|
1
|
-
sanic_api/__init__.py,sha256=
|
1
|
+
sanic_api/__init__.py,sha256=SQVHFSX3ts0MNTCXjVJaEzuEbsC8wEvA_mUAs3kigfk,80
|
2
2
|
sanic_api/app.py,sha256=e5L3pr8MTqmjNh5V-Y276MUb3qw67K55wmhdrE2Sxf4,7386
|
3
3
|
sanic_api/api/__init__.py,sha256=XTYNRtZj3ufh2SaswvHfbNKiUoR5nVzqGSXb766r_Mw,400
|
4
4
|
sanic_api/api/model.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
5
|
-
sanic_api/api/request.py,sha256=
|
5
|
+
sanic_api/api/request.py,sha256=d0ewEkA8KBXKOaQrDmio0vT9QjpKRfxOuW4TmkbBNrM,5283
|
6
6
|
sanic_api/api/response.py,sha256=5b4FLPv1Zl1Rjneqt08taHlrXBqwIKwOgZpoBtqbNNI,1337
|
7
7
|
sanic_api/config/__init__.py,sha256=8hFCE2efii1P5URx8nPgFLqB5ys_8QbBAEOLJNUj-y4,81
|
8
8
|
sanic_api/config/setting.py,sha256=-ANpVP9hak7u468zXwXpXYo0do6AFATxpL_ecsw9Cb4,2254
|
@@ -13,7 +13,7 @@ sanic_api/openapi/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU
|
|
13
13
|
sanic_api/openapi/extension.py,sha256=HCrcEgrj63FXOhx6TJyJDaee6mDuVnuSMA5EtdYUVjc,1009
|
14
14
|
sanic_api/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
15
15
|
sanic_api/utils/enum.py,sha256=4E1O6W9MLGitfGam9ZTc3GZPP6yiL87v5pJ3lhfIUkg,1298
|
16
|
-
sanic_api-0.3.
|
17
|
-
sanic_api-0.3.
|
18
|
-
sanic_api-0.3.
|
19
|
-
sanic_api-0.3.
|
16
|
+
sanic_api-0.3.0a3.dist-info/METADATA,sha256=A1e7zlawSfg7aH6l8hhSz6ePptI7FCUYUhyJXCzJczo,3386
|
17
|
+
sanic_api-0.3.0a3.dist-info/WHEEL,sha256=C2FUgwZgiLbznR-k0b_5k3Ai_1aASOXDss3lzCUsUug,87
|
18
|
+
sanic_api-0.3.0a3.dist-info/licenses/LICENSE.txt,sha256=T20w-F8AfuFO9CHy2mSk_An6T9eV4X4rGA01i-gp4M4,1090
|
19
|
+
sanic_api-0.3.0a3.dist-info/RECORD,,
|
File without changes
|
File without changes
|