如何使用jsonschema.RefResolver验证模式中的多个引用?
如果文件中只有一个引用,则我的验证脚本可以正常工作。现在我有两个或三个引用在不同的目录中,这些引用在模式中。
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)
我的JSON模式:
{
"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"
}
}
}
我的问题是,我是否应该有两个解析器,一个用于范围,另一个用于值,并在Draft4Validator中分别调用这些解析器?或者有更好的方法来处理这个问题吗?