Skip to content

How to return specific value according to each request parameter #228

Description

@wangxbwang

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)
def post(self, col,**kwargs):
return result,200

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions