Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wangxbwang opened this issue Dec 20, 2021 · 0 comments
Open

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

wangxbwang opened this issue Dec 20, 2021 · 0 comments

Comments

@wangxbwang
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant