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

后端 未结 3 1432
一向
一向 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条回答
  •  Happy的楠姐
    2021-02-04 18:00

    For those that want to continue using the api.model rather than request parser, it's possible to iterate over your input (assuming list) versus the model. The model behaves like a dictionary.

    from flask_restplus import abort
    
    def check_exact(response_list, model):
        for response_dict in response_list:
            for key in response_dict:
                if key not in model:
                    abort(400, "Non-specified fields added", field=key)
    

    ...

    @ns.expect(my_model, validate=True)
    def post(self, token):
        """Add new set of responses
        """
        check_exact(api.payload['responses'], my_model)
        ...
    

提交回复
热议问题