flask - something more strict than @api.expect for input data?

后端 未结 3 1402
一向
一向 2021-02-04 17:18

In my flask-restplus API I\'d like not only to check that input data, like in the following example

resource_fields = api.model(\'Resource\', {
    \'name\': fie         


        
3条回答
  •  臣服心动
    2021-02-04 17:56

    Here is another answer to complete the one from @shiv. The following code snippet allows you to have your payload documented in the Swagger doc generated by Flask Restplus. Taken from the documentation about the expect decorator:

    my_resource_parser = api.parser()
    my_resource_parser.add_argument('name', type=str, default='string: name', required=True)
    my_resource_parser.add_argument('state', type=str, default='string: state')
    
    @api.route('/my-resource/', endpoint='with-parser')
    class MyResource(Resource):
        @api.expect(my_resource_parser)
        def post(self):
            args = my_resource_parser.parse_args(strict=True)
            ...
    

提交回复
热议问题