Skip to content

Commit

Permalink
fix: Handle missing type value when checking JSON schema types (#1526)
Browse files Browse the repository at this point in the history
  • Loading branch information
edgarrmondragon authored Mar 24, 2023
1 parent 97b4906 commit f943fa3
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
10 changes: 5 additions & 5 deletions singer_sdk/helpers/_typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ def is_boolean_type(property_schema: dict) -> bool | None:
return None # Could not detect data type
for property_type in property_schema.get("anyOf", [property_schema.get("type")]):
if isinstance(property_type, dict):
property_type = property_type.get("type")
property_type = property_type.get("type", [])
if "boolean" in property_type or property_type == "boolean":
return True
return False
Expand All @@ -264,7 +264,7 @@ def is_integer_type(property_schema: dict) -> bool | None:
return None # Could not detect data type
for property_type in property_schema.get("anyOf", [property_schema.get("type")]):
if isinstance(property_type, dict):
property_type = property_type.get("type")
property_type = property_type.get("type", [])
if "integer" in property_type or property_type == "integer":
return True
return False
Expand All @@ -276,7 +276,7 @@ def is_string_type(property_schema: dict) -> bool | None:
return None # Could not detect data type
for property_type in property_schema.get("anyOf", [property_schema.get("type")]):
if isinstance(property_type, dict):
property_type = property_type.get("type")
property_type = property_type.get("type", [])
if "string" in property_type or property_type == "string":
return True
return False
Expand All @@ -288,7 +288,7 @@ def is_null_type(property_schema: dict) -> bool | None:
return None # Could not detect data type
for property_type in property_schema.get("anyOf", [property_schema.get("type")]):
if isinstance(property_type, dict):
property_type = property_type.get("type")
property_type = property_type.get("type", [])
if "null" in property_type or property_type == "null":
return True
return False
Expand All @@ -300,7 +300,7 @@ def is_number_type(property_schema: dict) -> bool | None:
return None # Could not detect data type
for property_type in property_schema.get("anyOf", [property_schema.get("type")]):
if isinstance(property_type, dict):
property_type = property_type.get("type")
property_type = property_type.get("type", [])
if "number" in property_type or property_type == "number":
return True
return False
Expand Down
12 changes: 12 additions & 0 deletions tests/core/test_jsonschema_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -751,6 +751,18 @@ def test_custom_type():
[is_number_type],
[True],
),
(
[
{
"anyOf": [
{"enum": ["developer", "team", "enterprise"]},
{"type": "string"},
],
},
],
[is_string_type],
[True],
),
],
)
def test_type_check_variations(property_schemas, type_check_functions, results):
Expand Down

0 comments on commit f943fa3

Please sign in to comment.