本文整理汇总了Python中jsonschema.Draft7Validator方法的典型用法代码示例。如果您正苦于以下问题:Python jsonschema.Draft7Validator方法的具体用法?Python jsonschema.Draft7Validator怎么用?Python jsonschema.Draft7Validator使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类jsonschema
的用法示例。
在下文中一共展示了jsonschema.Draft7Validator方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: validate_object
# 需要导入模块: import jsonschema [as 别名]
# 或者: from jsonschema import Draft7Validator [as 别名]
def validate_object(obj, schema_name): # type: (dict, str) -> List[str]
schema = os.path.join(SCHEMA_DIR, "{}.json".format(schema_name))
if not os.path.exists(schema):
raise ValueError("Schema {} does not exist.".format(schema_name))
with open(schema, encoding="utf-8") as f:
schema = json.loads(f.read())
validator = jsonschema.Draft7Validator(schema)
validation_errors = sorted(validator.iter_errors(obj), key=lambda e: e.path)
errors = []
for error in validation_errors:
message = error.message
if error.path:
message = "[{}] {}".format(
".".join(str(x) for x in error.absolute_path), message
)
errors.append(message)
return errors
示例2: create_daijin_validator
# 需要导入模块: import jsonschema [as 别名]
# 或者: from jsonschema import Draft7Validator [as 别名]
def create_daijin_validator(simple=True):
cname = resource_filename("Mikado.configuration", "configuration_blueprint.json")
# We have to repeate twice the ending configuration (bug in jsonref?)
baseuri = "file://" + os.path.join(os.path.dirname(cname), os.path.basename(os.path.dirname(cname)))
with io.TextIOWrapper(resource_stream("Mikado.configuration",
"daijin_schema.json")) as blue:
blue_print = jsonref.load(blue,
jsonschema=True,
base_uri=baseuri)
# _substitute_conf(blue_print)
validator = extend_with_default(jsonschema.Draft7Validator,
simple=simple)
validator = validator(blue_print)
return validator
示例3: __init__
# 需要导入模块: import jsonschema [as 别名]
# 或者: from jsonschema import Draft7Validator [as 别名]
def __init__(self, schema_path):
schema = self._load_json(schema_path)
self.schema = Draft7Validator(schema)
示例4: load_dag_schema
# 需要导入模块: import jsonschema [as 别名]
# 或者: from jsonschema import Draft7Validator [as 别名]
def load_dag_schema() -> Validator:
"""
Load & Validate Json Schema for DAG
"""
schema = load_dag_schema_dict()
jsonschema.Draft7Validator.check_schema(schema)
return jsonschema.Draft7Validator(schema)
示例5: __init__
# 需要导入模块: import jsonschema [as 别名]
# 或者: from jsonschema import Draft7Validator [as 别名]
def __init__(self, conf):
# schema for rule yaml
self.rule_schema = jsonschema.Draft7Validator(
yaml.load(open(os.path.join(os.path.dirname(__file__), 'schema.yaml')), Loader=yaml.FullLoader))
self.base_config = copy.deepcopy(conf)
示例6: test_get_validator
# 需要导入模块: import jsonschema [as 别名]
# 或者: from jsonschema import Draft7Validator [as 别名]
def test_get_validator(self):
schema = {
"$schema": JSON_SCHEMA_DRAFT_7,
"title": "Item with Schema Draft",
}
draft7_validator = JsonSchemaItem._get_validator(schema)
self.assertTrue(isinstance(draft7_validator, Draft7Validator))
no_draft_chema = {"title": "Item without schema Draft"}
default_validator = JsonSchemaItem._get_validator(no_draft_chema)
self.assertTrue(isinstance(default_validator, Draft4Validator))
示例7: assertObjectValidates
# 需要导入模块: import jsonschema [as 别名]
# 或者: from jsonschema import Draft7Validator [as 别名]
def assertObjectValidates(self, obj):
jsonschema.Draft7Validator(self.builder.to_schema()).validate(obj)
示例8: assertObjectDoesNotValidate
# 需要导入模块: import jsonschema [as 别名]
# 或者: from jsonschema import Draft7Validator [as 别名]
def assertObjectDoesNotValidate(self, obj):
with self.assertRaises(jsonschema.exceptions.ValidationError):
jsonschema.Draft7Validator(self.builder.to_schema()).validate(obj)
示例9: _assertSchemaIsValid
# 需要导入模块: import jsonschema [as 别名]
# 或者: from jsonschema import Draft7Validator [as 别名]
def _assertSchemaIsValid(self):
jsonschema.Draft7Validator.check_schema(self.builder.to_schema())
示例10: _assertComponentObjectsValidate
# 需要导入模块: import jsonschema [as 别名]
# 或者: from jsonschema import Draft7Validator [as 别名]
def _assertComponentObjectsValidate(self):
compiled_schema = self.builder.to_schema()
for obj in self._objects:
jsonschema.Draft7Validator(compiled_schema).validate(obj)
示例11: create_validator
# 需要导入模块: import jsonschema [as 别名]
# 或者: from jsonschema import Draft7Validator [as 别名]
def create_validator(simple=False):
"""Method to create a validator class (see extend_with_default).
The simple keyword (boolean) is used to determine whether to keep
only SimpleComment or full Comments from the schema.
:type simple: bool
:return validator
:rtype: jsonschema.Draft7Validator
"""
validator = extend_with_default(jsonschema.Draft7Validator,
simple=simple)
resolver = jsonschema.RefResolver("file:///{}".format(os.path.abspath(
os.path.dirname(pkg_resources.resource_filename("Mikado.configuration", os.path.basename(__file__)))
)), None)
with io.TextIOWrapper(resource_stream("Mikado.configuration",
"configuration_blueprint.json")) as blue:
blue_print = json.loads(blue.read())
validator = validator(blue_print, resolver=resolver)
return validator