diff --git a/airbyte_cdk/sources/declarative/parsers/manifest_component_transformer.py b/airbyte_cdk/sources/declarative/parsers/manifest_component_transformer.py index e11a0af515..97c63c69bf 100644 --- a/airbyte_cdk/sources/declarative/parsers/manifest_component_transformer.py +++ b/airbyte_cdk/sources/declarative/parsers/manifest_component_transformer.py @@ -192,10 +192,10 @@ def propagate_types_and_parameters( @staticmethod def _is_json_schema_object(propagated_component: Mapping[str, Any]) -> bool: - return propagated_component.get("type") == "object" or propagated_component.get("type") == [ - "null", - "object", - ] + # Component types are always strings: a list is a JSON schema type union and a dict is a + # `properties` map that has a property named `type`. + component_type = propagated_component.get("type") + return component_type == "object" or isinstance(component_type, (list, dict)) @staticmethod def _has_nested_components(propagated_component: Dict[str, Any]) -> bool: diff --git a/unit_tests/sources/declarative/parsers/test_manifest_component_transformer.py b/unit_tests/sources/declarative/parsers/test_manifest_component_transformer.py index c741fa94a1..7f5977d567 100644 --- a/unit_tests/sources/declarative/parsers/test_manifest_component_transformer.py +++ b/unit_tests/sources/declarative/parsers/test_manifest_component_transformer.py @@ -405,7 +405,36 @@ def test_only_propagate_parameters_to_components(): assert actual_component == expected_component -def test_do_not_propagate_parameters_on_json_schema_object(): +@pytest.mark.parametrize( + "schema", + [ + pytest.param( + { + "type": "object", + "$schema": "http://json-schema.org/schema#", + "properties": {"id": {"type": "string"}}, + }, + id="object", + ), + pytest.param( + {"type": ["null", "object"], "properties": {"id": {"type": ["null", "string"]}}}, + id="null_object", + ), + pytest.param( + {"type": ["object", "null"], "properties": {"id": {"type": ["null", "string"]}}}, + id="object_null", + ), + pytest.param( + {"type": ["object"], "properties": {"id": {"type": ["integer"]}}}, + id="object_only", + ), + pytest.param( + {"properties": {"type": {"type": "string"}, "id": {"type": "string"}}}, + id="no_root_type_with_type_property", + ), + ], +) +def test_do_not_propagate_parameters_on_json_schema_object(schema): component = { "type": "DeclarativeStream", "streams": [ @@ -413,11 +442,7 @@ def test_do_not_propagate_parameters_on_json_schema_object(): "type": "DeclarativeStream", "schema_loader": { "type": "InlineSchemaLoader", - "schema": { - "type": "object", - "$schema": "http://json-schema.org/schema#", - "properties": {"id": {"type": "string"}}, - }, + "schema": schema, }, "$parameters": { "name": "roasters", @@ -438,11 +463,7 @@ def test_do_not_propagate_parameters_on_json_schema_object(): "type": "InlineSchemaLoader", "name": "roasters", "primary_key": "id", - "schema": { - "type": "object", - "$schema": "http://json-schema.org/schema#", - "properties": {"id": {"type": "string"}}, - }, + "schema": schema, "$parameters": { "name": "roasters", "primary_key": "id",