Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -405,19 +405,44 @@ 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": [
{
"type": "DeclarativeStream",
"schema_loader": {
"type": "InlineSchemaLoader",
"schema": {
"type": "object",
"$schema": "http://json-schema.org/schema#",
"properties": {"id": {"type": "string"}},
},
"schema": schema,
},
"$parameters": {
"name": "roasters",
Expand All @@ -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",
Expand Down
Loading