From f943fa3814efb4a309a72fe8ca2c1ee14873bbdd Mon Sep 17 00:00:00 2001 From: "Edgar R. M" Date: Fri, 24 Mar 2023 09:09:45 -0600 Subject: [PATCH] fix: Handle missing `type` value when checking JSON schema types (#1526) --- singer_sdk/helpers/_typing.py | 10 +++++----- tests/core/test_jsonschema_helpers.py | 12 ++++++++++++ 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/singer_sdk/helpers/_typing.py b/singer_sdk/helpers/_typing.py index 673a58deb..1fe89dc38 100644 --- a/singer_sdk/helpers/_typing.py +++ b/singer_sdk/helpers/_typing.py @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 diff --git a/tests/core/test_jsonschema_helpers.py b/tests/core/test_jsonschema_helpers.py index 6a4ef0ba6..f670a6cfc 100644 --- a/tests/core/test_jsonschema_helpers.py +++ b/tests/core/test_jsonschema_helpers.py @@ -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):