Skip to content

Nested references are not loaded and the exception is unclear #209

Closed
@traut

Description

@traut

Test case (all files are in the same directory):

File schema-a.json

{
    "$schema": "http://json-schema.org/draft-04/schema",

    "title": "schema A",
    "type": "object",
    "allOf": [
        {"$ref": "file:schema-b.json"}
    ]
}

File schema-b.json:

{
    "$schema": "http://json-schema.org/draft-04/schema",

    "title": "schema B",
    "type": "object",
    "allOf": [
        {"$ref": "file:schema-c.json"}
    ]
}

File schema-c.json:

{
    "$schema": "http://json-schema.org/draft-04/schema",

    "title": "schema C",
    "type": "object"
}

File validate.py:

import json
from os.path import dirname
from jsonschema import validate, RefResolver

with open('schema-a.json', 'r') as f:
    schema_a = json.loads(f.read())

try:
    validate({}, schema_a)
except Exception, e:
    print "1 failed: %s" % e

try:
    CURRENT_DIR = dirname(__file__)
    resolver = RefResolver(base_uri='file://' + CURRENT_DIR + '/', referrer=None)
    validate({}, schema_a, resolver=resolver)
except Exception, e:
    print "2 failed: %s" % e

Result:

$ python validate.py
1 failed: <urlopen error [Errno 2] No such file or directory: '/schema-c.json'>
2 failed: <urlopen error [Errno 2] No such file or directory: '/schema-b.json'>
$

Metadata

Metadata

Assignees

No one assigned

    Labels

    InvalidNot a bug, PEBKAC, or an unsupported setup

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions