Skip to content

Commit 69eb0cf

Browse files
refactor code
1 parent f4ca661 commit 69eb0cf

File tree

1 file changed

+40
-25
lines changed

1 file changed

+40
-25
lines changed

airbyte_cdk/sources/declarative/parsers/manifest_component_transformer.py

Lines changed: 40 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -130,27 +130,39 @@ def propagate_types_and_parameters(
130130
else {**current_parameters, **component_parameters}
131131
)
132132

133-
# When processing request parameters which is an object that does not have a type, so $parameters will not be passes to the object.
134-
# But request parameters can have PropertyChunking object that needs to be updated with paranet $parameters.
135-
# When there is a PropertyChunking object _process_property_chunking_property() is called to update PropertyChunking object with $parameters
136-
# and set updated object to propagated_component, then it's returned without propagation.
137-
if "type" not in propagated_component and self._is_property_chunking_component(
138-
propagated_component
139-
):
140-
propagated_component = self._process_property_chunking_property(
141-
propagated_component,
142-
parent_field_identifier,
143-
current_parameters,
144-
use_parent_parameters,
145-
)
146-
147133
# When there is no resolved type, we're not processing a component (likely a regular object) and don't need to propagate parameters
148134
# When the type refers to a json schema, we're not processing a component as well. This check is currently imperfect as there could
149135
# be json_schema are not objects but we believe this is not likely in our case because:
150136
# * records are Mapping so objects hence SchemaLoader root should be an object
151137
# * connection_specification is a Mapping
138+
if self._is_json_schema_object(propagated_component):
139+
return propagated_component
152140

153-
if "type" not in propagated_component or self._is_json_schema_object(propagated_component):
141+
# For objects that don't have type check if their object fields have nested components which should have parameters in it.
142+
# For example, QueryProperties in requester.request_parameters:
143+
# requester:
144+
# $ref: "#/definitions/base_requester"
145+
# path: /path/to/entity/{{ parameters.entity }}
146+
# request_parameters:
147+
# archived: 'false'
148+
# properties:
149+
# type: QueryProperties
150+
# property_list:
151+
# retriever:
152+
# type: SimpleRetriever
153+
# requester:
154+
# $ref: "#/definitions/base_requester"
155+
# path: /path/to//{{ parameters.entity }}/properties
156+
# ....
157+
# Update propagated_component value with components if needed and return propagated_component.
158+
if "type" not in propagated_component:
159+
if self._has_nested_components(propagated_component):
160+
propagated_component = self._process_nested_components(
161+
propagated_component,
162+
parent_field_identifier,
163+
current_parameters,
164+
use_parent_parameters,
165+
)
154166
return propagated_component
155167

156168
# Parameters should be applied to the current component fields with the existing field taking precedence over parameters if
@@ -196,31 +208,34 @@ def propagate_types_and_parameters(
196208

197209
@staticmethod
198210
def _is_json_schema_object(propagated_component: Mapping[str, Any]) -> bool:
199-
return propagated_component.get("type") == "object"
211+
return propagated_component.get("type") == "object" or propagated_component.get("type") == [
212+
"null",
213+
"object",
214+
]
200215

201216
@staticmethod
202-
def _is_property_chunking_component(propagated_component: Mapping[str, Any]) -> bool:
203-
has_property_chunking = False
217+
def _has_nested_components(propagated_component: Mapping[str, Any]) -> bool:
218+
has_nested_components = False
204219
for k, v in propagated_component.items():
205-
if isinstance(v, dict) and v.get("type") == "QueryProperties":
206-
has_property_chunking = True
207-
return has_property_chunking
220+
if isinstance(v, dict) and v.get("type"):
221+
has_nested_components = True
222+
return has_nested_components
208223

209-
def _process_property_chunking_property(
224+
def _process_nested_components(
210225
self,
211226
propagated_component: Dict[str, Any],
212227
parent_field_identifier: str,
213228
current_parameters: Mapping[str, Any],
214229
use_parent_parameters: Optional[bool] = None,
215230
) -> Dict[str, Any]:
216231
for k, v in propagated_component.items():
217-
if isinstance(v, dict) and v.get("type") == "QueryProperties":
218-
property_chunking_with_parameters = self.propagate_types_and_parameters(
232+
if isinstance(v, dict) and v.get("type"):
233+
nested_component_with_parameters = self.propagate_types_and_parameters(
219234
parent_field_identifier,
220235
v,
221236
current_parameters,
222237
use_parent_parameters=use_parent_parameters,
223238
)
224-
propagated_component[k] = property_chunking_with_parameters
239+
propagated_component[k] = nested_component_with_parameters
225240

226241
return propagated_component

0 commit comments

Comments
 (0)