本文整理汇总了Python中jsonref.load方法的典型用法代码示例。如果您正苦于以下问题:Python jsonref.load方法的具体用法?Python jsonref.load怎么用?Python jsonref.load使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类jsonref
的用法示例。
在下文中一共展示了jsonref.load方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_full_schema
# 需要导入模块: import jsonref [as 别名]
# 或者: from jsonref import load [as 别名]
def get_full_schema(schema_dir):
print(schema_dir)
os.chdir(schema_dir)
fn = "map.json"
uri = "file:///{}/".format(schema_dir)
with open(fn) as f:
j = jsonref.load(f, base_uri=uri)
jsn = jsonref.dumps(j, indent=4, sort_keys=False)
full_schema = jsonref.dumps(j, indent=4, sort_keys=False)
with open(r"C:\Temp\mapfile.json", "w") as f:
f.write(full_schema)
return full_schema
# create_versioned_schema
示例2: get_expanded_schema
# 需要导入模块: import jsonref [as 别名]
# 或者: from jsonref import load [as 别名]
def get_expanded_schema(self, schema_name):
"""
Return a schema file with all $ref properties expanded
"""
if schema_name not in self.expanded_schemas:
fn = self.get_schema_file(schema_name)
schemas_folder = self.get_schemas_folder()
base_uri = self.get_schema_path(schemas_folder)
with open(fn) as f:
jsn_schema = jsonref.load(f, base_uri=base_uri)
# cache the schema for future use
self.expanded_schemas[schema_name] = jsn_schema
else:
jsn_schema = self.expanded_schemas[schema_name]
return jsn_schema
示例3: _parse_json
# 需要导入模块: import jsonref [as 别名]
# 或者: from jsonref import load [as 别名]
def _parse_json(self, jsonfile, base_path):
"""
Parses JSON as well as resolves any `$ref`s, including references to
local files and remote (HTTP/S) files.
"""
base_path = os.path.abspath(base_path)
if not base_path.endswith("/"):
base_path = base_path + "/"
if os.name == "nt":
base_uri_path = "file:///" + base_path.replace('\\', '/')
else:
base_uri_path = "file://" + base_path
loader = jsonref.JsonLoader(cache_results=False)
with open(jsonfile, "r") as f:
schema = jsonref.load(f, base_uri=base_uri_path, loader=loader, jsonschema=True)
return schema
示例4: create_daijin_validator
# 需要导入模块: import jsonref [as 别名]
# 或者: from jsonref import load [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
示例5: read_schema
# 需要导入模块: import jsonref [as 别名]
# 或者: from jsonref import load [as 别名]
def read_schema(schema_file, absolute=False):
schema_path = get_schema_path(schema_file, absolute)
schema_uri = 'file://{}'.format(schema_path)
with open(schema_path) as f:
return jsonref.load(f, base_uri=schema_uri)
示例6: get_schema_validator
# 需要导入模块: import jsonref [as 别名]
# 或者: from jsonref import load [as 别名]
def get_schema_validator(self, schema_name):
"""
Had to remove the id property from map.json or it uses URLs for validation
See various issues at https://github.com/Julian/jsonschema/pull/306
"""
if schema_name not in self.schemas:
schema_file = self.get_schema_file(schema_name)
with open(schema_file) as f:
try:
jsn_schema = json.load(f)
except ValueError as ex:
log.error("Could not load %s", schema_file)
raise ex
schemas_folder = self.get_schemas_folder()
root_schema_path = self.get_schema_path(schemas_folder)
resolver = jsonschema.RefResolver(root_schema_path, None)
# cache the schema for future use
self.schemas[schema_name] = (jsn_schema, resolver)
else:
jsn_schema, resolver = self.schemas[schema_name]
validator = jsonschema.Draft4Validator(schema=jsn_schema, resolver=resolver)
# validator.check_schema(jsn_schema) # check schema is valid
return validator
示例7: load_resolved_schema
# 需要导入模块: import jsonref [as 别名]
# 或者: from jsonref import load [as 别名]
def load_resolved_schema(spec_path, file_name=None, schema_obj=None, path_prefix=True):
"""
Parses JSON as well as resolves any `$ref`s, including references to
local files and remote (HTTP/S) files.
"""
# Only one of file_name or schema_obj must be set
assert bool(file_name) != bool(schema_obj)
if path_prefix:
spec_path = os.path.join(spec_path, "APIs/schemas/")
base_path = os.path.abspath(spec_path)
if not base_path.endswith("/"):
base_path = base_path + "/"
if os.name == "nt":
base_uri_path = "file:///" + base_path.replace('\\', '/')
else:
base_uri_path = "file://" + base_path
loader = jsonref.JsonLoader(cache_results=False)
if file_name:
json_file = str(Path(base_path) / file_name)
with open(json_file, "r") as f:
schema = jsonref.load(f, base_uri=base_uri_path, loader=loader, jsonschema=True)
elif schema_obj:
# Work around an exception when there's nothing to resolve using an object
if "$ref" in schema_obj:
schema = jsonref.JsonRef.replace_refs(schema_obj, base_uri=base_uri_path, loader=loader, jsonschema=True)
else:
schema = schema_obj
return schema