qiskit/validation/jsonschema/schema_validation.py
def _get_validator(name, schema=None, check_schema=True,
                   validator_class=None, **validator_kwargs):
    """Generate validator for JSON schema.

    Args:
        name (str): Name for validator. Will be validator key in
            `_VALIDATORS` dict.
        schema (dict): JSON schema `dict`. If not provided searches for schema
            in `_SCHEMAS`.
        check_schema (bool): Verify schema is valid.
        validator_class (jsonschema.IValidator): jsonschema IValidator instance.
            Default behavior is to determine this from the schema `$schema`
            field.
        **validator_kwargs (dict): Additional keyword arguments for validator.

    Return:
        jsonschema.IValidator: Validator for JSON schema.

    Raises:
        SchemaValidationError: Raised if validation fails.
    """
    if schema is None:
        try:
            schema = _SCHEMAS[name]
        except KeyError:
            raise SchemaValidationError("Valid schema name or schema must "
                                        "be provided.")

    if name not in _VALIDATORS:

        # Resolve JSON spec from schema if needed
        if validator_class is None:
            validator_class = jsonschema.validators.validator_for(schema)

        # Generate and store validator in _VALIDATORS
        _VALIDATORS[name] = validator_class(schema, **validator_kwargs)

    validator = _VALIDATORS[name]

    if check_schema:
        validator.check_schema(schema)

    return validator
def _get_validator(name, schema=None, check_schema=True,
                   validator_class=None, **validator_kwargs):
    if schema is None:
        try:
            schema = _SCHEMAS[name]
        except KeyError:
            raise SchemaValidationError("Valid schema name or schema must "
                                        "be provided.")

    if name not in _VALIDATORS:

        # Resolve JSON spec from schema if needed
        if validator_class is None:
            validator_class = jsonschema.validators.validator_for(schema)

        # Generate and store validator in _VALIDATORS
        _VALIDATORS[name] = validator_class(schema, **validator_kwargs)

    validator = _VALIDATORS[name]

    if check_schema:
        validator.check_schema(schema)

    return validator
def _get_validator ( name , schema = None , check_schema = True , validator_class = None , * * validator_kwargs ) : if schema is None : try : schema = _SCHEMAS [ name ] except KeyError : raise SchemaValidationError ( "Valid schema name or schema must " "be provided." ) if name not in _VALIDATORS : # Resolve JSON spec from schema if needed if validator_class is None : validator_class = jsonschema . validators . validator_for ( schema ) # Generate and store validator in _VALIDATORS _VALIDATORS [ name ] = validator_class ( schema , * * validator_kwargs ) validator = _VALIDATORS [ name ] if check_schema : validator . check_schema ( schema ) return validator
Generate validator for JSON schema.

    Args:
        name (str): Name for validator. Will be validator key in
            `_VALIDATORS` dict.
        schema (dict): JSON schema `dict`. If not provided searches for schema
            in `_SCHEMAS`.
        check_schema (bool): Verify schema is valid.
        validator_class (jsonschema.IValidator): jsonschema IValidator instance.
            Default behavior is to determine this from the schema `$schema`
            field.
        **validator_kwargs (dict): Additional keyword arguments for validator.

    Return:
        jsonschema.IValidator: Validator for JSON schema.

    Raises:
        SchemaValidationError: Raised if validation fails.
Generate validator for JSON schema .