implemented function for handling schema_template item

This commit is contained in:
iLLiCiTiT 2020-10-02 14:21:26 +02:00
parent dd29192ffe
commit 3a53f8a944

View file

@ -151,6 +151,45 @@ def _fill_schema_template_data(
raise SchemaTemplateMissingKeys(missing_keys, required_keys)
return output
def _fill_schema_template(child_data, schema_collection, schema_templates):
template_name = child_data["name"]
template = schema_templates.get(template_name)
if template is None:
if template_name in schema_collection:
raise KeyError((
"Schema \"{}\" is used as `schema_template`"
).format(template_name))
raise KeyError("Schema template \"{}\" was not found".format(
template_name
))
template_data = child_data.get("template_data") or {}
try:
filled_child = _fill_schema_template_data(
template, template_data
)
except SchemaTemplateMissingKeys as exc:
raise SchemaTemplateMissingKeys(
exc.missing_keys, exc.required_keys, template_name
)
output = []
for item in filled_child:
filled_item = _fill_inner_schemas(
item, schema_collection, schema_templates
)
if filled_item["type"] == "schema_template":
output.extend(_fill_schema_template(
filled_item, schema_collection, schema_templates
))
else:
output.append(filled_item)
return output
def _fill_inner_schemas(schema_data, schema_collection):
if schema_data["type"] == "schema":
raise ValueError("First item in schema data can't be schema.")