From 7f085f4112cdd4734aa8dfd8dfa00120c9348e65 Mon Sep 17 00:00:00 2001 From: Dorota Jarecka Date: Mon, 11 Mar 2024 10:59:35 -0400 Subject: [PATCH] allow for usage of inner_key when list is expected, used for any_of --- schemasheets/schemamaker.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/schemasheets/schemamaker.py b/schemasheets/schemamaker.py index b2c0bf0..6ceacdd 100644 --- a/schemasheets/schemamaker.py +++ b/schemasheets/schemamaker.py @@ -190,7 +190,14 @@ def add_row(self, row: Dict[str, Any], table_config: TableConfig): logging.warning(f'Overwriting value for {k}, was {curr_val}, now {v}') raise ValueError(f'Cannot reset value for {k}, was {curr_val}, now {v}') if cc.settings.inner_key: - getattr(actual_element, cc.maps_to)[cc.settings.inner_key] = v + if isinstance(getattr(actual_element, cc.maps_to), list): + if '|' in v: + vs = v.split('|') + else: + vs = [v] + setattr(actual_element, cc.maps_to, [{cc.settings.inner_key: v} for v in vs]) + else: + getattr(actual_element, cc.maps_to)[cc.settings.inner_key] = v else: setattr(actual_element, cc.maps_to, v) elif cc.is_element_type: