當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。