Python jsonschema.validators.validator_for() Examples

The following are 10 code examples for showing how to use jsonschema.validators.validator_for(). These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example.

You may want to check out the right sidebar which shows the related API usage.

You may also want to check out all available functions/classes of the module jsonschema.validators , or try the search function .

Example 1
Project: flocker   Author: ClusterHQ   File: _schema.py    License: Apache License 2.0 6 votes vote down vote up
def getValidator(schema, schema_store):
    """
    Get a L{jsonschema} validator for C{schema}.

    @param schema: The JSON Schema to validate against.
    @type schema: L{dict}

    @param dict schema_store: A mapping between schema paths
        (e.g. ``b/v1/types.json``) and the JSON schema structure.
    """
    # The base_uri here isn't correct for the schema,
    # but does give proper relative paths.
    resolver = LocalRefResolver(
        base_uri=b'',
        referrer=schema, store=schema_store)
    return validator_for(schema)(
        schema, resolver=resolver, format_checker=draft4_format_checker) 
Example 2
Project: arche   Author: scrapinghub   File: schema.py    License: MIT License 6 votes vote down vote up
def full_validate(
    schema: RawSchema, raw_items: RawItems, keys: pd.Index
) -> Dict[str, set]:
    """This function uses jsonschema validator which returns all found error per item.
    See `fast_validate()` for arguments descriptions.
    """
    errors: DefaultDict = defaultdict(set)

    validator = validators.validator_for(schema)(schema)
    validator.format_checker = FormatChecker()
    for i, raw_item in enumerate(tqdm(raw_items, desc="JSON Schema Validation")):
        raw_item.pop("_type", None)
        raw_item.pop("_key", None)
        for e in validator.iter_errors(raw_item):
            error = format_validation_message(
                e.message, e.path, e.schema_path, e.validator
            )
            errors[error].add(keys[i])
    return dict(errors) 
Example 3
Project: misp42splunk   Author: remg427   File: cli.py    License: GNU Lesser General Public License v3.0 5 votes vote down vote up
def parse_args(args):
    arguments = vars(parser.parse_args(args=args or ["--help"]))
    if arguments["validator"] is None:
        arguments["validator"] = validator_for(arguments["schema"])
    return arguments 
Example 4
Project: misp42splunk   Author: remg427   File: cli.py    License: GNU Lesser General Public License v3.0 5 votes vote down vote up
def parse_args(args):
    arguments = vars(parser.parse_args(args=args or ["--help"]))
    if arguments["validator"] is None:
        arguments["validator"] = validator_for(arguments["schema"])
    return arguments 
Example 5
Project: spidermon   Author: scrapinghub   File: validator.py    License: BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def _validate(self, data, strict=False):
        validator_cls = validator_for(self._schema)
        validator = validator_cls(schema=self._schema, format_checker=format_checker)
        errors = validator.iter_errors(data)

        for error in errors:
            absolute_path = list(error.absolute_path)
            required_match = REQUIRED_RE.search(error.message)
            if required_match:
                absolute_path.append(required_match.group(1))
            field_name = ".".join([str(p) for p in absolute_path])
            self._add_errors({field_name: [error.message]}) 
Example 6
Project: deepWordBug   Author: QData   File: cli.py    License: Apache License 2.0 5 votes vote down vote up
def parse_args(args):
    arguments = vars(parser.parse_args(args=args or ["--help"]))
    if arguments["validator"] is None:
        arguments["validator"] = validator_for(arguments["schema"])
    return arguments 
Example 7
Project: accelerated-data-lake   Author: aws-samples   File: cli.py    License: Apache License 2.0 5 votes vote down vote up
def parse_args(args):
    arguments = vars(parser.parse_args(args=args or ["--help"]))
    if arguments["validator"] is None:
        arguments["validator"] = validator_for(arguments["schema"])
    return arguments 
Example 8
Project: Requester   Author: kylebebak   File: cli.py    License: MIT License 5 votes vote down vote up
def parse_args(args):
    arguments = vars(parser.parse_args(args=args or ["--help"]))
    if arguments["validator"] is None:
        arguments["validator"] = validator_for(arguments["schema"])
    return arguments 
Example 9
Project: SA-ctf_scoreboard   Author: splunk   File: cli.py    License: Creative Commons Zero v1.0 Universal 5 votes vote down vote up
def parse_args(args):
    arguments = vars(parser.parse_args(args=args or ["--help"]))
    if arguments["validator"] is None:
        arguments["validator"] = validator_for(arguments["schema"])
    return arguments 
Example 10
Project: truegaze   Author: nightwatchcybersecurity   File: adobe_mobile_sdk.py    License: Apache License 2.0 5 votes vote down vote up
def validate(parsed_data):
        # Load the schema
        schema_file = open(RULES_FILE, 'r')
        schema_data = json.load(schema_file)

        # Validate the file
        validator = validator_for(schema_data)
        errors = validator(schema=schema_data).iter_errors(parsed_data)

        # Extract error messages and return
        messages = []
        for error in errors:
            messages.append('---- ISSUE: ' + error.schema['title'] + '; ' + error.message)
        return messages