How to use the cerberus.errors.ValidationError function in Cerberus

To help you get started, we’ve selected a few Cerberus examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github pypa / pipenv / pipenv / vendor / cerberus / validator.py View on Github external
if not rule:
                constraint = None
            else:
                field_definitions = self._resolve_rules_set(self.schema[field])
                if rule == 'nullable':
                    constraint = field_definitions.get(rule, False)
                elif rule == 'required':
                    constraint = field_definitions.get(rule, self.require_all)
                    if rule not in field_definitions:
                        schema_path = "__require_all__"
                else:
                    constraint = field_definitions[rule]

            value = self.document.get(field)

            self.recent_error = errors.ValidationError(
                document_path, schema_path, code, rule, constraint, value, info
            )
            self._error([self.recent_error])
github CentOS-PaaS-SIG / linchpin / linchpin / validator / anyofvalidator.py View on Github external
schema[field][rule] = self.schema[field][rule]
            if 'allow_unknown' not in schema[field]:
                schema[field]['allow_unknown'] = self.allow_unknown

            validator = self._get_child_validator(
                schema_crumb=(field, 'role', value['role']), schema=schema,
                allow_unknown=True
            )
            if validator(self.document, update=self.update, normalize=False):
                valids += 1
            else:
                _errors.extend(validator._errors)

        if valids == 0:
            if not found_valid_role:
                role_error = errors.ValidationError(
                    ("resource_definitions", 0, "role"),
                    ("res_defs", "schema", "anyof", -1, "schema", "role"),
                    0x44, "rule", valid_roles, value['role'], ""
                )
                self._error([role_error])
            else:
                self._error(validator._errors)
github pyeve / cerberus / cerberus / base.py View on Github external
if not rule:
                constraint = None
            else:
                field_definitions = self._resolve_rules_set(self.schema[field])
                if rule == 'nullable':
                    constraint = field_definitions.get(rule, False)
                elif rule == 'required':
                    constraint = field_definitions.get(rule, self.require_all)
                    if rule not in field_definitions:
                        schema_path = "__require_all__"
                else:
                    constraint = field_definitions[rule]

            value = self.document.get(field)

            self.recent_error = errors.ValidationError(
                document_path, schema_path, code, rule, constraint, value, info
            )
            self._error([self.recent_error])
github pyeve / cerberus / cerberus / validator.py View on Github external
schema_path = self.schema_path
            if code != errors.UNKNOWN_FIELD.code and rule is not None:
                schema_path += (field, rule)

            if not rule:
                constraint = None
            else:
                field_definitions = self._resolve_rules_set(self.schema[field])
                if rule == 'nullable':
                    constraint = field_definitions.get(rule, False)
                else:
                    constraint = field_definitions[rule]

            value = self.document.get(field)

            self.recent_error = errors.ValidationError(
                document_path, schema_path, code, rule, constraint, value, info
            )
            self._error([self.recent_error])