From 4fb6ad247aee44cf0bfec8d2a430e180ea01c121 Mon Sep 17 00:00:00 2001 From: Junjie Mao Date: Fri, 18 Feb 2022 22:29:41 +0800 Subject: [PATCH] config_tools: do not create leaf nodes without default values Today the default value populator will always create a node if it is required by the schema but not provided in the given XML file. This could hide issues in a given scenario XML if a node does not have default values (i.e. require user's inputs) but accepts empty text. This patch avoids the creation of nodes without a default value so that, at validation stage, missing of essential data is always reported. Tracked-On: #6690 Signed-off-by: Junjie Mao --- misc/config_tools/scenario_config/default_populator.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/misc/config_tools/scenario_config/default_populator.py b/misc/config_tools/scenario_config/default_populator.py index d61398241..bb81847ab 100755 --- a/misc/config_tools/scenario_config/default_populator.py +++ b/misc/config_tools/scenario_config/default_populator.py @@ -14,9 +14,14 @@ class DefaultValuePopulator(ScenarioTransformer): element_name = xsd_element_node.get("name") default_value = xsd_element_node.get("default") + # If the node is neither of a complex type (i.e. it does not have an child node) nor has a default value, do not + # create the node at all. Users are required to fill in proper values in such nodes, and missing any of them + # shall trigger a validation error. + if self.complex_type_of_element(xsd_element_node) is None and default_value is None: + return [] + new_node = etree.Element(element_name) - if default_value is not None: - new_node.text = default_value + new_node.text = default_value if new_node_index is not None: xml_parent_node.insert(new_node_index, new_node)