Closed
Description
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'>
$