@@ -206,45 +206,85 @@ def list_connector_schemas(self, connector_id: str) -> List[Dict]:
206
206
207
207
try :
208
208
response = self ._make_request ("GET" , f"/connectors/{ connector_id } /schemas" )
209
- # Log the raw response format for debugging
210
- logger .debug (
211
- f"Schema response format for connector { connector_id } : { type (response )} "
212
- )
213
209
214
- schemas = response . get ( "data" , {}). get ( "schemas" , [])
215
- logger .debug (f"Schemas format: { type ( schemas ) } , value : { schemas } " )
210
+ # Debug the response format
211
+ logger .debug (f"Schema response for connector { connector_id } : { response } " )
216
212
217
- # Handle various schema response formats
218
- if schemas is None :
219
- schemas = []
220
- elif isinstance (schemas , str ):
221
- # Some APIs return a JSON string that needs to be parsed
222
- try :
223
- import json
224
-
225
- parsed = json .loads (schemas )
226
- if isinstance (parsed , list ):
227
- schemas = parsed
228
- else :
229
- logger .warning (f"Parsed schema is not a list: { parsed } " )
230
- schemas = []
231
- except Exception as e :
232
- logger .warning (f"Failed to parse schema string: { e } " )
233
- schemas = []
234
- elif not isinstance (schemas , list ):
235
- logger .warning (f"Unexpected schema type: { type (schemas )} " )
236
- schemas = []
213
+ # The API can return schemas in different formats
214
+ # Format 1: {'data': {'schemas': [...]}}
215
+ # Format 2: {'data': {'schemas': {'schema_name': {'name_in_destination': 'schema_name', 'enabled': True, 'tables': {...}}}}}
216
+ raw_schemas = response .get ("data" , {}).get ("schemas" , [])
237
217
238
- # Filter out non-dict entries
239
- schemas = [s for s in schemas if isinstance (s , dict )]
218
+ schemas = []
219
+
220
+ # Handle different response formats
221
+ if isinstance (raw_schemas , dict ):
222
+ # Handle nested object format
223
+ logger .info (
224
+ f"Converting nested schema format for connector { connector_id } "
225
+ )
226
+ for schema_name , schema_data in raw_schemas .items ():
227
+ # Convert to the expected format
228
+ schema_obj = {
229
+ "name" : schema_name ,
230
+ "name_in_destination" : schema_data .get (
231
+ "name_in_destination" , schema_name
232
+ ),
233
+ "enabled" : schema_data .get ("enabled" , True ),
234
+ "tables" : [],
235
+ }
236
+
237
+ # Convert tables from dict to list format
238
+ tables_dict = schema_data .get ("tables" , {})
239
+ if isinstance (tables_dict , dict ):
240
+ for table_name , table_data in tables_dict .items ():
241
+ table_obj = {
242
+ "name" : table_name ,
243
+ "name_in_destination" : table_data .get (
244
+ "name_in_destination" , table_name
245
+ ),
246
+ "enabled" : table_data .get ("enabled" , False ),
247
+ }
248
+
249
+ # Handle columns if present
250
+ columns_dict = table_data .get ("columns" , {})
251
+ columns = []
252
+ if isinstance (columns_dict , dict ):
253
+ for column_name , column_data in columns_dict .items ():
254
+ column_obj = {
255
+ "name" : column_name ,
256
+ "name_in_destination" : column_data .get (
257
+ "name_in_destination" , column_name
258
+ ),
259
+ "enabled" : column_data .get ("enabled" , True ),
260
+ }
261
+ columns .append (column_obj )
262
+
263
+ if columns :
264
+ table_obj ["columns" ] = columns
265
+
266
+ schema_obj ["tables" ].append (table_obj )
267
+
268
+ schemas .append (schema_obj )
269
+ elif isinstance (raw_schemas , list ):
270
+ # Already in the expected format
271
+ schemas = raw_schemas
272
+ else :
273
+ logger .warning (
274
+ f"Unexpected schema format type for connector { connector_id } : { type (raw_schemas )} "
275
+ )
276
+ schemas = []
240
277
241
278
self ._schema_cache [connector_id ] = schemas
242
279
logger .info (
243
- f"Retrieved { len (schemas )} schemas for connector { connector_id } "
280
+ f"Processed { len (schemas )} schemas for connector { connector_id } "
244
281
)
245
282
return schemas
246
283
except Exception as e :
247
- logger .warning (f"Error fetching schemas for connector { connector_id } : { e } " )
284
+ logger .warning (
285
+ f"Error fetching schemas for connector { connector_id } : { e } " ,
286
+ exc_info = True ,
287
+ )
248
288
return []
249
289
250
290
def list_users (self ) -> List [Dict ]:
0 commit comments