How may we validate multiple refs in a schema using jsonschema.RefResolver?
I have a validation script that works good if I have one ref in a file. I now have two or three refs in a schema, that are in a different directory.
base_dir = '/schema/models/'
with open (os.path.join(base_dir, 'Defined.json')) as file_object:
schema = json.load(file_object)
resolver = jsonschema.RefResolver('file://' + base_dir + '/' + 'Fields/Ranges.json', schema)
jsonschema.Draft4Validator(schema, resolver=resolver).validate(data)
My json schema:
{
"properties": {
"description": {
"type": "object",
"after": {"type": ["string", "null"]},
"before": {"type": "string"}
},
"width": {"type": "number"} ,
"range_specifier": {"type": "string"},
"start": {"type": "number", "enum" : [0, 1] } ,
"ranges": {
"$ref": "Fields/Ranges.json"
},
"values": {
"$ref": "Fields/Values.json"
}
}
}
So my question is should I have two resolvers one for ranges and one for values and call the resolvers separately in Draft4Validator ? Or is there a better way to do this?