From af86fb6b7ab445651a4e85e3bf5e3b6604bd17d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Edgar=20Ram=C3=ADrez=20Mondrag=C3=B3n?= Date: Wed, 4 Oct 2023 17:08:49 -0600 Subject: [PATCH] Add failing tests --- singer_sdk/helpers/_flattening.py | 79 +++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) diff --git a/singer_sdk/helpers/_flattening.py b/singer_sdk/helpers/_flattening.py index 397044bb6f..592111f35f 100644 --- a/singer_sdk/helpers/_flattening.py +++ b/singer_sdk/helpers/_flattening.py @@ -185,6 +185,85 @@ def flatten_schema( } } } + + >>> nullable_leaves_schema = { + ... "type": "object", + ... "properties": { + ... "id": { + ... "type": "string" + ... }, + ... "foo": { + ... "type": ["object", "null"], + ... "properties": { + ... "bar": { + ... "type": ["object", "null"], + ... "properties": { + ... "baz": { + ... "type": ["object", "null"], + ... "properties": { + ... "qux": { + ... "type": "string" + ... } + ... } + ... } + ... } + ... } + ... } + ... } + ... } + ... } + >>> print(json.dumps(flatten_schema(nullable_leaves_schema, 0), indent=2)) + { + "type": "object", + "properties": { + "id": { + "type": "string" + }, + "foo": { + "type": [ + "object", + "null" + ], + "properties": { + "bar": { + "type": [ + "object", + "null" + ], + "properties": { + "baz": { + "type": [ + "object", + "null" + ], + "properties": { + "qux": { + "type": "string" + } + } + } + } + } + } + } + } + } + + >>> print(json.dumps(flatten_schema(nullable_leaves_schema, 1), indent=2)) + { + "type": "object", + "properties": { + "id": { + "type": "string" + }, + "foo__bar": { + "type": [ + "string", + "null + ] + } + } + } """ new_schema = deepcopy(schema) new_schema["properties"] = _flatten_schema(