for example ,when get a post parameter , if have a validate error, return a responce value 。not just a 422 error,Unprocessable Entity 。need
when name error,return {“value”: "Name","error":"lenth C5" }
when userName error,return {“value”: userName ","error":"lenth C5" }
when contact error,return {“value”: "contact ","error":"not exit" }
class AdminUserReRequestSchemaSchema(Schema):
Name = fields.Str(required=True,
validate= validate.Length(min=5),
error_messages={"required": {"message": "True required", "code": 400}},
description="用户名")
userName = fields.Str(required=True,
validate= validate.Length(min=5),
description="用户登录名称")
contact = fields.Str(required=True,description="联系方式")
limit = fields.Int(required=True,description="API type of awesome API", )
for example ,when get a post parameter , if have a validate error, return a responce value 。not just a 422 error,Unprocessable Entity 。need when name error,return {“value”: "Name","error":"lenth C5" } when userName error,return {“value”: userName ","error":"lenth C5" } when contact error,return {“value”: "contact ","error":"not exit" } class AdminUserReRequestSchemaSchema(Schema): Name = fields.Str(required=True, validate= validate.Length(min=5), error_messages={"required": {"message": "True required", "code": 400}}, description="用户名") userName = fields.Str(required=True, validate= validate.Length(min=5), description="用户登录名称") contact = fields.Str(required=True,description="联系方式")
limit = fields.Int(required=True,description="API type of awesome API", )
class UserRegisterAPI(MethodResource, Resource): @doc(description='UserRegister. ', tags=['UserRegister']) @use_kwargs(AdminUserReRequestSchemaSchema, location=('json')) @marshal_with(AdminUserReResponseSchema,description = "fdfafafasfasd",apply ="") # marshalling
@marshal_with( AdminUserReResponse2Schema)