Skip to content

Commit

Permalink
fix: Instances of oneOf are now handled by null-appending logic (#2245
Browse files Browse the repository at this point in the history
)

fix: Instance of `oneOf` are now handled by null-appending logic
  • Loading branch information
edgarrmondragon authored Feb 15, 2024
1 parent 5734e69 commit e3565ee
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
4 changes: 4 additions & 0 deletions singer_sdk/helpers/_typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ def append_type(type_dict: dict, new_type: str) -> dict:
result["anyOf"] = [result["anyOf"], new_type]
return result

if "oneOf" in result:
result["oneOf"].append(new_type)
return result

if "type" in result:
type_array = (
result["type"] if isinstance(result["type"], list) else [result["type"]]
Expand Down
31 changes: 31 additions & 0 deletions tests/core/test_typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
PropertiesList,
Property,
StringType,
append_type,
to_sql_type,
)

Expand Down Expand Up @@ -318,3 +319,33 @@ def test_conform_primitives():
)
def test_to_sql_type(jsonschema_type, expected):
assert isinstance(to_sql_type(jsonschema_type), expected)


@pytest.mark.parametrize(
"type_dict,expected",
[
pytest.param({"type": "string"}, {"type": ["string", "null"]}, id="string"),
pytest.param({"type": "integer"}, {"type": ["integer", "null"]}, id="integer"),
pytest.param({"type": "number"}, {"type": ["number", "null"]}, id="number"),
pytest.param({"type": "boolean"}, {"type": ["boolean", "null"]}, id="boolean"),
pytest.param(
{"type": "object", "properties": {}},
{"type": ["object", "null"], "properties": {}},
id="object",
),
pytest.param({"type": "array"}, {"type": ["array", "null"]}, id="array"),
pytest.param(
{"anyOf": [{"type": "integer"}, {"type": "number"}]},
{"anyOf": [{"type": "integer"}, {"type": "number"}, "null"]},
id="anyOf",
),
pytest.param(
{"oneOf": [{"type": "integer"}, {"type": "number"}]},
{"oneOf": [{"type": "integer"}, {"type": "number"}, "null"]},
id="oneOf",
),
],
)
def test_append_null(type_dict: dict, expected: dict):
result = append_type(type_dict, "null")
assert result == expected

0 comments on commit e3565ee

Please sign in to comment.