44
55import copy
66import typing
7- from typing import Any , Mapping
7+ from typing import Any , Mapping , Optional
88
99PARAMETERS_STR = "$parameters"
1010
@@ -94,6 +94,7 @@ def propagate_types_and_parameters(
9494 parent_field_identifier : str ,
9595 declarative_component : Mapping [str , Any ],
9696 parent_parameters : Mapping [str , Any ],
97+ use_parent_parameters : Optional [bool ] = None ,
9798 ) -> Mapping [str , Any ]:
9899 """
99100 Recursively transforms the specified declarative component and subcomponents to propagate parameters and insert the
@@ -103,6 +104,7 @@ def propagate_types_and_parameters(
103104 :param declarative_component: The current component that is having type and parameters added
104105 :param parent_field_identifier: The name of the field of the current component coming from the parent component
105106 :param parent_parameters: The parameters set on parent components defined before the current component
107+ :param use_parent_parameters: If set, parent parameters will be used as the source of truth when key names are the same
106108 :return: A deep copy of the transformed component with types and parameters persisted to it
107109 """
108110 propagated_component = dict (copy .deepcopy (declarative_component ))
@@ -130,7 +132,7 @@ def propagate_types_and_parameters(
130132 # level take precedence
131133 current_parameters = dict (copy .deepcopy (parent_parameters ))
132134 component_parameters = propagated_component .pop (PARAMETERS_STR , {})
133- current_parameters = {** current_parameters , ** component_parameters }
135+ current_parameters = {** component_parameters , ** current_parameters } if use_parent_parameters else { ** current_parameters , ** component_parameters }
134136
135137 # Parameters should be applied to the current component fields with the existing field taking precedence over parameters if
136138 # both exist
@@ -145,7 +147,7 @@ def propagate_types_and_parameters(
145147 excluded_parameter = current_parameters .pop (field_name , None )
146148 parent_type_field_identifier = f"{ propagated_component .get ('type' )} .{ field_name } "
147149 propagated_component [field_name ] = self .propagate_types_and_parameters (
148- parent_type_field_identifier , field_value , current_parameters
150+ parent_type_field_identifier , field_value , current_parameters , use_parent_parameters = use_parent_parameters
149151 )
150152 if excluded_parameter :
151153 current_parameters [field_name ] = excluded_parameter
@@ -158,7 +160,7 @@ def propagate_types_and_parameters(
158160 f"{ propagated_component .get ('type' )} .{ field_name } "
159161 )
160162 field_value [i ] = self .propagate_types_and_parameters (
161- parent_type_field_identifier , element , current_parameters
163+ parent_type_field_identifier , element , current_parameters , use_parent_parameters = use_parent_parameters
162164 )
163165 if excluded_parameter :
164166 current_parameters [field_name ] = excluded_parameter
0 commit comments