Skip to content

Commit

Permalink
Refactor JSON schema type handling in KlaviyoStream to enforce string…
Browse files Browse the repository at this point in the history
… type for empty objects and simplify type definitions. This change improves schema consistency and clarity. (#7)
  • Loading branch information
butkeraites-hotglue authored Nov 29, 2024
1 parent 5adf984 commit 5a7f62e
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions tap_klaviyo/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,15 +124,17 @@ def get_jsonschema_type(self, obj):
return th.ArrayType(self.get_jsonschema_type(obj[0]))
else:
return th.ArrayType(
th.CustomType({"type": ["number", "string", "object"]})
th.CustomType({"type": ["string"]})
)
if dtype == dict:
obj_props = []
for key in obj.keys():
obj_props.append(th.Property(key, self.get_jsonschema_type(obj[key])))
if not obj_props:
return th.CustomType({"type": ["string"]})
return th.ObjectType(*obj_props)
else:
return th.CustomType({"type": ["number", "string", "object"]})
return th.CustomType({"type": ["string"]})

def get_schema(self) -> dict:
"""Dynamically detect the json schema for the stream.
Expand Down

0 comments on commit 5a7f62e

Please sign in to comment.