'When a method is decorated with this, json data submitted to the endpoint will be validated with the given
`model`. This also auto-documents the expected model, as well as the possible :class:`ValidationError` response.'

def validate(self, model, schema_override=None, description=None):

    def decorator(func):
        @api.expect((model, description))
        @api.response(ValidationError)
        @wraps(func)
        def wrapper(*args, **kwargs):
            payload = request.json
            try:
                schema = (schema_override if schema_override else model.__schema__)
                errors = process_config(config=payload, schema=schema, set_defaults=False)
                if errors:
                    raise ValidationError(errors)
            except RefResolutionError as e:
                raise APIError(str(e))
            return func(*args, **kwargs)
        return wrapper
    return decorator
