Skip to content

Commit 0ee84d5

Browse files
committed
Fix complex type resolving
1 parent 1bda3d4 commit 0ee84d5

File tree

2 files changed

+14
-23
lines changed

2 files changed

+14
-23
lines changed

airbyte_cdk/sources/declarative/schema/dynamic_schema_loader.py

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,9 @@ def get_json_schema(self) -> Mapping[str, Any]:
154154
transformed_properties = self._transform(properties, {})
155155

156156
return {
157-
"$schema": "http://json-schema.org/draft-07/schema#",
157+
"$schema": "https://json-schema.org/draft-07/schema#",
158158
"type": "object",
159+
"additionalProperties": True,
159160
"properties": transformed_properties,
160161
}
161162

@@ -220,25 +221,14 @@ def _get_type(
220221
)
221222

222223
def _resolve_complex_type(self, complex_type: ComplexFieldType) -> Mapping[str, Any]:
223-
types = [complex_type]
224-
resolved_type: MutableMapping[str, Any] = {}
225-
226-
while types:
227-
current_type = types.pop()
228-
if not current_type.items:
229-
resolved_type = self._get_airbyte_type(current_type.field_type)
230-
else:
231-
field_type = self._get_airbyte_type(current_type.field_type)
232-
233-
if isinstance(current_type.items, str):
234-
items_type = current_type.items
235-
else:
236-
types.append(current_type.items)
237-
continue # Skip the following lines until the stack is resolved
238-
field_type["items"] = self._get_airbyte_type(items_type)
239-
resolved_type = field_type
240-
241-
return resolved_type
224+
if not complex_type.items:
225+
return self._get_airbyte_type(complex_type.field_type)
226+
227+
field_type = self._get_airbyte_type(complex_type.field_type)
228+
field_type["items"] = self._get_airbyte_type(complex_type.items) if isinstance(complex_type.items, str) else self._resolve_complex_type(
229+
complex_type.items)
230+
231+
return field_type
242232

243233
def _replace_type_if_not_valid(
244234
self,

unit_tests/sources/declarative/schema/test_dynamic_schema_loader.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@
8787
"types_mapping": [
8888
{"target_type": "string", "current_type": "singleLineText"},
8989
{
90-
"target_type": {"field_type": "array", "items": "integer"},
90+
"target_type": {"field_type": "array", "items": {"field_type": "array", "items": "integer"}},
9191
"current_type": "formula",
9292
"condition": "{{ raw_schema['result']['type'] == 'customInteger' }}",
9393
},
@@ -321,7 +321,8 @@ def test_dynamic_schema_loader_with_type_conditions():
321321
]["types_mapping"].append({"target_type": "array", "current_type": "formula"})
322322

323323
expected_schema = {
324-
"$schema": "http://json-schema.org/draft-07/schema#",
324+
"$schema": "https://json-schema.org/draft-07/schema#",
325+
"additionalProperties": True,
325326
"type": "object",
326327
"properties": {
327328
"id": {"type": ["null", "integer"]},
@@ -331,7 +332,7 @@ def test_dynamic_schema_loader_with_type_conditions():
331332
"currency": {"type": ["null", "number"]},
332333
"salary": {"type": ["null", "number"]},
333334
"working_days": {"type": ["null", "array"]},
334-
"avg_salary": {"type": ["null", "array"], "items": {"type": ["null", "integer"]}},
335+
"avg_salary": {"type": ["null", "array"], "items": {"type": ["null", "array"], "items": {"type": ["null", "integer"]}}},
335336
},
336337
}
337338
source = ConcurrentDeclarativeSource(

0 commit comments

Comments
 (0)