本文整理汇总了Python中jsonschema.validators.RefResolver.from_schema方法的典型用法代码示例。如果您正苦于以下问题:Python RefResolver.from_schema方法的具体用法?Python RefResolver.from_schema怎么用?Python RefResolver.from_schema使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类jsonschema.validators.RefResolver
的用法示例。
在下文中一共展示了RefResolver.from_schema方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_it_resolves_local_refs_with_id
# 需要导入模块: from jsonschema.validators import RefResolver [as 别名]
# 或者: from jsonschema.validators.RefResolver import from_schema [as 别名]
def test_it_resolves_local_refs_with_id(self):
schema = {"id": "foo://bar/schema#", "a": {"foo": "bar"}}
resolver = RefResolver.from_schema(schema)
with resolver.resolving("#/a") as resolved:
self.assertEqual(resolved, schema["a"])
with resolver.resolving("foo://bar/schema#/a") as resolved:
self.assertEqual(resolved, schema["a"])
示例2: test_it_can_construct_a_base_uri_from_a_schema_without_id
# 需要导入模块: from jsonschema.validators import RefResolver [as 别名]
# 或者: from jsonschema.validators.RefResolver import from_schema [as 别名]
def test_it_can_construct_a_base_uri_from_a_schema_without_id(self):
schema = {}
resolver = RefResolver.from_schema(schema)
self.assertEqual(resolver.base_uri, "")
with resolver.resolving("") as resolved:
self.assertEqual(resolved, schema)
with resolver.resolving("#") as resolved:
self.assertEqual(resolved, schema)
示例3: __init__
# 需要导入模块: from jsonschema.validators import RefResolver [as 别名]
# 或者: from jsonschema.validators.RefResolver import from_schema [as 别名]
def __init__(self, name, schema):
self.name = name
self.base_uri = schema.get('id', '')
# replace all relative references with absolute refs to avoid
# clashes in self.definitions
self.schema = Reference.replace_relative_references(self.base_uri, schema)
# maps full jsonschema fragment path to internal structure,
# for example a StructDef or a TypeDef.
self.definitions = {}
self.refresolver = RefResolver.from_schema(schema)
示例4: test_it_can_construct_a_base_uri_from_a_schema
# 需要导入模块: from jsonschema.validators import RefResolver [as 别名]
# 或者: from jsonschema.validators.RefResolver import from_schema [as 别名]
def test_it_can_construct_a_base_uri_from_a_schema(self):
schema = {"id": "foo"}
resolver = RefResolver.from_schema(schema)
self.assertEqual(resolver.base_uri, "foo")
self.assertEqual(resolver.resolution_scope, "foo")
with resolver.resolving("") as resolved:
self.assertEqual(resolved, schema)
with resolver.resolving("#") as resolved:
self.assertEqual(resolved, schema)
with resolver.resolving("foo") as resolved:
self.assertEqual(resolved, schema)
with resolver.resolving("foo#") as resolved:
self.assertEqual(resolved, schema)
示例5: validate_schema_value
# 需要导入模块: from jsonschema.validators import RefResolver [as 别名]
# 或者: from jsonschema.validators.RefResolver import from_schema [as 别名]
def validate_schema_value(schema, value, swagger_resolver=None):
# pass resolver to avoid to refetch schema files
if swagger_resolver is None:
swagger_resolver = RefResolver.from_schema(schema)
create_dereffing_validator(swagger_resolver)(schema, resolver=swagger_resolver).validate(value)