def test_non_default_resolver_validator(markdown_examples):
    ms = URIDict()
    draft3 = load_schema("draft3")
    draft4 = load_schema("draft4")
    ms[draft3["id"]] = draft3
    ms[draft4["id"]] = draft4
    resolver_with_store = RefResolver(draft3["id"], draft3, ms)

    # 'Other' schema should be valid with draft3
    builder = pjo.ObjectBuilder(
        markdown_examples["Other"],
        resolver=resolver_with_store,
        validatorClass=Draft3Validator,
        resolved=markdown_examples,
    )
    klasses = builder.build_classes()
    a = klasses.Other(MyAddress="where I live")
    assert a.MyAddress == "where I live"
Example #2
0
def main():
    # validate schema files
    meta_validator = Draft7Validator(json_shema_utils.load_schema("draft7"))
    process_schema_files(meta_validator, SCHEMA_DIR)
    check_errors("Invalid schema")

    # validate data files
    for schema_name in os.listdir(DATA_DIR):
        schema = get_schema(schema_name)
        resolver = RefResolver(base_uri=f'file://{SCHEMA_DIR}/',
                               referrer=schema)
        validator = Draft7Validator(schema, resolver=resolver)
        examples_dir = os.path.join(DATA_DIR, schema_name)
        process_schema_files(validator, examples_dir, count_name="data")
    check_errors("Invalid data")

    print(
        f"Successfully checked {counts['schema']} schema and {counts['data']} data files"
    )
Example #3
0
    return Validator


def extend(validator, validators, version=None):
    all_validators = dict(validator.VALIDATORS)
    all_validators.update(validators)
    return create(
        meta_schema=validator.META_SCHEMA,
        validators=all_validators,
        version=version,
        default_types=validator.DEFAULT_TYPES,
    )


Draft3Validator = create(
    meta_schema=_utils.load_schema("draft3"),
    validators={
        u"$ref": _validators.ref,
        u"additionalItems": _validators.additionalItems,
        u"additionalProperties": _validators.additionalProperties,
        u"dependencies": _validators.dependencies,
        u"disallow": _validators.disallow_draft3,
        u"divisibleBy": _validators.multipleOf,
        u"enum": _validators.enum,
        u"extends": _validators.extends_draft3,
        u"format": _validators.format,
        u"items": _validators.items,
        u"maxItems": _validators.maxItems,
        u"maxLength": _validators.maxLength,
        u"maximum": _validators.maximum,
        u"minItems": _validators.minItems,
Example #4
0
    return Validator


def extend(validator, validators, version=None):
    all_validators = dict(validator.VALIDATORS)
    all_validators.update(validators)
    return create(
        meta_schema=validator.META_SCHEMA,
        validators=all_validators,
        version=version,
        default_types=validator.DEFAULT_TYPES,
    )


Draft3Validator = create(
    meta_schema=_utils.load_schema("draft3"),
    validators={
        u"$ref" : _validators.ref,
        u"additionalItems" : _validators.additionalItems,
        u"additionalProperties" : _validators.additionalProperties,
        u"dependencies" : _validators.dependencies,
        u"disallow" : _validators.disallow_draft3,
        u"divisibleBy" : _validators.multipleOf,
        u"enum" : _validators.enum,
        u"extends" : _validators.extends_draft3,
        u"format" : _validators.format,
        u"items" : _validators.items,
        u"maxItems" : _validators.maxItems,
        u"maxLength" : _validators.maxLength,
        u"maximum" : _validators.maximum,
        u"minItems" : _validators.minItems,
Example #5
0
def _load_draft4_metaschema():
    from jsonschema import _utils
    return _utils.load_schema('draft4')
Example #6
0
def _load_draft4_metaschema():
    from jsonschema import _utils

    return _utils.load_schema("draft4")
Example #7
0
def _store_schema_list():
    if not _VOCABULARIES:
        _VOCABULARIES.extend(_utils.load_schema("vocabularies").items())
    return [(id, validator.META_SCHEMA)
            for id, validator in _META_SCHEMAS.items()] + _VOCABULARIES
Example #8
0
    if type_checker is None:
        type_checker = validator.TYPE_CHECKER
    if format_checker is None:
        format_checker = validator.FORMAT_CHECKER
    return create(
        meta_schema=validator.META_SCHEMA,
        validators=all_validators,
        version=version,
        type_checker=type_checker,
        format_checker=format_checker,
        id_of=validator.ID_OF,
    )


Draft3Validator = create(
    meta_schema=_utils.load_schema("draft3"),
    validators={
        "$ref": _validators.ref,
        "additionalItems": _validators.additionalItems,
        "additionalProperties": _validators.additionalProperties,
        "dependencies": _legacy_validators.dependencies_draft3,
        "disallow": _legacy_validators.disallow_draft3,
        "divisibleBy": _validators.multipleOf,
        "enum": _validators.enum,
        "extends": _legacy_validators.extends_draft3,
        "format": _validators.format,
        "items": _legacy_validators.items_draft3_draft4,
        "maxItems": _validators.maxItems,
        "maxLength": _validators.maxLength,
        "maximum": _legacy_validators.maximum_draft3_draft4,
        "minItems": _validators.minItems,
Example #9
0
"""
Wrap the draft-4 metaschema and save the source tree
"""
import os

from jsonschema._utils import load_schema
from schemapi import JSONSchema
from schemapi.utils import save_module

schema = load_schema('draft4')
module = '_metaschema'

if os.path.exists(module):
    raise ValueError("{module} already exists.".format(module=module))

schema = JSONSchema(schema)
source_tree = schema.traitlets.source_tree()
print("writing to {module}".format(module=module))
save_module(source_tree, module, os.path.abspath('.'))