加入webargs验证扩展,分区用于验证的inschema和用户序列化的outschema

This commit is contained in:
mkg
2021-11-17 18:07:36 +08:00
parent fba22bbcbf
commit cdea48c7d4
21 changed files with 96 additions and 74 deletions
+13 -2
View File
@@ -1,8 +1,19 @@
from applications.extensions import ma
from applications.extensions import ma
from marshmallow import fields, validate
class DeptSchema(ma.Schema):
class DeptInSchema(ma.Schema):
parentId = fields.Integer(required=True)
deptName = fields.Str(required=True)
leader = fields.Str(required=True)
phone = fields.Str(required=True)
email = fields.Str(validate=validate.Email())
address = fields.Str()
status = fields.Str(validate=validate.OneOf(["0", "1"]))
sort = fields.Integer()
class DeptOutSchema(ma.Schema):
deptId = fields.Integer(attribute="id")
parentId = fields.Integer(attribute="parent_id")
deptName = fields.Str(attribute="dept_name")