当前位置: 首页>>代码示例>>Python>>正文


Python jsonschema.Draft7Validator方法代码示例

本文整理汇总了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 
开发者ID:python-poetry,项目名称:poetry,代码行数:26,代码来源:__init__.py

示例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 
开发者ID:EI-CoreBioinformatics,项目名称:mikado,代码行数:20,代码来源:daijin_configurator.py

示例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) 
开发者ID:BradenM,项目名称:micropy-cli,代码行数:5,代码来源:validate.py

示例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) 
开发者ID:apache,项目名称:airflow,代码行数:9,代码来源:json_schema.py

示例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) 
开发者ID:Yelp,项目名称:elastalert,代码行数:8,代码来源:loaders.py

示例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)) 
开发者ID:scrapy-plugins,项目名称:scrapy-jsonschema,代码行数:14,代码来源:test_item.py

示例7: assertObjectValidates

# 需要导入模块: import jsonschema [as 别名]
# 或者: from jsonschema import Draft7Validator [as 别名]
def assertObjectValidates(self, obj):
        jsonschema.Draft7Validator(self.builder.to_schema()).validate(obj) 
开发者ID:wolverdude,项目名称:GenSON,代码行数:4,代码来源:base.py

示例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) 
开发者ID:wolverdude,项目名称:GenSON,代码行数:5,代码来源:base.py

示例9: _assertSchemaIsValid

# 需要导入模块: import jsonschema [as 别名]
# 或者: from jsonschema import Draft7Validator [as 别名]
def _assertSchemaIsValid(self):
        jsonschema.Draft7Validator.check_schema(self.builder.to_schema()) 
开发者ID:wolverdude,项目名称:GenSON,代码行数:4,代码来源:base.py

示例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) 
开发者ID:wolverdude,项目名称:GenSON,代码行数:6,代码来源:base.py

示例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 
开发者ID:EI-CoreBioinformatics,项目名称:mikado,代码行数:28,代码来源:configurator.py


注:本文中的jsonschema.Draft7Validator方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。