How to use the yamale.validators.Validator function in yamale

To help you get started, we’ve selected a few yamale 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 23andMe / Yamale / yamale / schema / schema.py View on Github external
def _validate_item(self, validator, data, path, strict, key):
        """
        Fetch item from data at the postion key and validate with validator.

        Returns an array of errors.
        """
        errors = []
        path = path + DataPath(key)
        try:  # Pull value out of data. Data can be a map or a list/sequence
            data_item = data[key]
        except (KeyError, IndexError):  # Oops, that field didn't exist.
            # Optional? Who cares.
            if isinstance(validator, val.Validator) and validator.is_optional:
                return errors
            # SHUT DOWN EVERTYHING
            errors.append('%s: Required field missing' % path)
            return errors

        return self._validate(validator, data_item, path, strict)