1818from airbyte_cdk .sources .source import ExperimentalClassWarning
1919from airbyte_cdk .sources .types import Config , StreamSlice , StreamState
2020
21- AIRBYTE_DATA_TYPES : Mapping [str , Mapping [str , Any ]] = {
21+ AIRBYTE_DATA_TYPES : Mapping [str , MutableMapping [str , Any ]] = {
2222 "string" : {"type" : ["null" , "string" ]},
2323 "boolean" : {"type" : ["null" , "boolean" ]},
2424 "date" : {"type" : ["null" , "string" ], "format" : "date" },
@@ -222,11 +222,11 @@ def _replace_type_if_not_valid(
222222 self ,
223223 field_type : Union [List [str ], str ],
224224 raw_schema : MutableMapping [str , Any ],
225- ) -> Tuple [Union [List [str ], str ], List [str ]]:
225+ ) -> Tuple [Union [List [str ], str ], List [Union [ List [ str ], str ] ]]:
226226 """
227227 Replaces a field type if it matches a type mapping in `types_map`.
228228 """
229- additional_types : List [str ] = []
229+ additional_types : List [Union [ List [ str ], str ] ] = []
230230 if self .schema_type_identifier .types_mapping :
231231 for types_map in self .schema_type_identifier .types_mapping :
232232 # conditional is optional param, setting to true if not provided
@@ -255,9 +255,8 @@ def _replace_type_if_not_valid(
255255 return types_map .target_type , additional_types
256256 return field_type , additional_types
257257
258- @staticmethod
259258 def _get_airbyte_type (
260- field_type : str , additional_types : Optional [List [str ]] = None
259+ self , field_type : str , additional_types : Optional [List [Union [ List [ str ], str ] ]] = None
261260 ) -> Mapping [str , Any ]:
262261 """
263262 Maps a field type to its corresponding Airbyte type definition.
@@ -271,8 +270,22 @@ def _get_airbyte_type(
271270 airbyte_type = deepcopy (AIRBYTE_DATA_TYPES [field_type ])
272271
273272 if field_type == "array" and additional_types :
274- airbyte_type ["items" ] = deepcopy (AIRBYTE_DATA_TYPES [additional_types [0 ]])
275-
273+ if (
274+ isinstance (additional_types [0 ], list )
275+ and len (additional_types [0 ]) == 2
276+ and all (isinstance (item , str ) for item in additional_types [0 ])
277+ ):
278+ first_type = self ._get_airbyte_type (additional_types [0 ][0 ])
279+ second_type = self ._get_airbyte_type (additional_types [0 ][1 ])
280+ items_type = {"oneOf" : [first_type , second_type ]}
281+ elif isinstance (additional_types [0 ], str ):
282+ items_type = deepcopy (AIRBYTE_DATA_TYPES [additional_types [0 ]]) # type: ignore[arg-type]
283+ else :
284+ raise ValueError (
285+ f"Invalid data type. Available string or two items list of string. Got { additional_types [0 ]} ."
286+ )
287+
288+ airbyte_type ["items" ] = items_type
276289 return airbyte_type
277290
278291 def _extract_data (
0 commit comments