You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Facing the same problem. by looking at the code it seems impossible to put it at the top level. Because the decorator just uses validator = Validator(schema) there is no way to add it to the top. For internal dictionaries you can just use :
Maybe there is another way to do it but can't find anything on Cerberus documentation. I will try to make a PR when I have time. For now I recommend creating a fork and doing it yourself, something like:
defvalidate_json(schema, clean=False, status_code=400, allow_unknown=False):
'''Decorator. Validates request body json. When *clean* is true, normalized data is passed to the decorated method as *valid_json*. Args: schema (dict): Cerberus-compatible schema description clean (bool): should cleaned json be passed to the decorated method status_code (number): status code to return when data is incorrect '''validator=Validator(schema, allow_unknown)
defvd(f):
...... # the rest of the function, nothing needs to be changed
or maybe:
defvalidate_json(schema, clean=False, status_code=400, **kwargs):
'''Decorator. Validates request body json. When *clean* is true, normalized data is passed to the decorated method as *valid_json*. Args: schema (dict): Cerberus-compatible schema description clean (bool): should cleaned json be passed to the decorated method status_code (number): status code to return when data is incorrect '''validator=Validator(schema, **kwargs)
defvd(f):
...... # the rest of the function, nothing needs to be changed
Hello, how can I set the parameter allow_unknown to support unknown parameters
The text was updated successfully, but these errors were encountered: