fred_reimer
01/06/2022, 5:03 PMdef from_dict(cls, data, definitions=None, **schema_defaults):
'''Initialize a Schema object based on the JSON Schema structure.
:param schema_defaults: The default values to the Schema
constructor.'''
kwargs = schema_defaults.copy()
properties = data.get('properties')
items = data.get('items')
defs = data.get('definitions') if definitions == None else definitions
if properties is not None:
kwargs['properties'] = {
k: Schema.from_dict(v, definitions=defs, **schema_defaults)
for k, v in properties.items()
}
if items is not None:
kwargs['items'] = Schema.from_dict(items, definitions=defs, **schema_defaults)
for key in STANDARD_KEYS:
if key in data:
kwargs[key] = data[key]
if data.get("$ref", "").startswith("#definitions/"):
kwargs.update(defs[data["$ref"].removeprefix("#definitions/")])
return Schema(**kwargs)
Seems to work for me to make refs work, although I have not tested it recursively; not sure if JSON schema allows recursive or not.