0
jsonschema.RefResolver를 사용하여 스키마에서 다중 참조를 어떻게 검증 할 수 있습니까?Jsonschema RefResolver를 사용하여 파이썬에서 다중 참조를 해결할 수 있습니다.
파일에 참조가 하나있는 경우 유효하게 작동하는 유효성 검사 스크립트가 있습니다. 이제 다른 디렉토리에있는 스키마에 2 ~ 3 개의 참조가 있습니다.
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에서 개별적으로 해결 프로그램을 호출해야합니다 그래서 내 질문은? 아니면 이것을 할 수있는 더 좋은 방법이 있습니까?