template item can have multiple item definitions in one schema item

This commit is contained in:
iLLiCiTiT 2020-11-17 15:46:00 +01:00
parent 6edabcb912
commit 8cc56b1465

View file

@ -178,28 +178,34 @@ def _fill_schema_template(child_data, schema_collection, schema_templates):
template_name template_name
)) ))
# Default value must be dictionary (NOT list)
# - empty list would not add any item if `template_data` are not filled
template_data = child_data.get("template_data") or {} template_data = child_data.get("template_data") or {}
try: if isinstance(template_data, dict):
filled_child = _fill_schema_template_data( template_data = [template_data]
template, template_data
)
except SchemaTemplateMissingKeys as exc:
raise SchemaTemplateMissingKeys(
exc.missing_keys, exc.required_keys, template_name
)
output = [] output = []
for item in filled_child: for single_template_data in template_data:
filled_item = _fill_inner_schemas( try:
item, schema_collection, schema_templates filled_child = _fill_schema_template_data(
) template, single_template_data
if filled_item["type"] == "schema_template": )
output.extend(_fill_schema_template(
filled_item, schema_collection, schema_templates except SchemaTemplateMissingKeys as exc:
)) raise SchemaTemplateMissingKeys(
else: exc.missing_keys, exc.required_keys, template_name
output.append(filled_item) )
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 return output