From 64f2fd08acb0492c71fa0fdfc61f62f1eca00aeb Mon Sep 17 00:00:00 2001 From: Ben Webb Date: Thu, 9 Nov 2017 10:27:52 +0000 Subject: [PATCH 1/2] [#180] Support lists under items in schema --- flattentool/schema.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/flattentool/schema.py b/flattentool/schema.py index 81ecfa68..97e7c83e 100644 --- a/flattentool/schema.py +++ b/flattentool/schema.py @@ -147,7 +147,11 @@ def parse_schema_dict(self, parent_path, schema_dict, parent_id_fields=None, tit elif 'array' in property_type_set: flattened_key = parent_path.replace('/0/', '/')+property_name self.flattened[flattened_key] = "array" - type_set = get_property_type_set(property_schema_dict['items']) + if isinstance(property_schema_dict['items'], list): + # If we have a list under items, just use the first one + type_set = get_property_type_set(property_schema_dict['items'][0]) + else: + type_set = get_property_type_set(property_schema_dict['items']) if 'string' in type_set or not type_set: self.flattened[flattened_key] = "string_array" yield property_name, title From e774c9fa1025ace8524d0a3e323c46be1d020d41 Mon Sep 17 00:00:00 2001 From: Ben Webb Date: Tue, 14 Nov 2017 16:58:06 +0000 Subject: [PATCH 2/2] [#180] Test that we support lists under items in schema --- flattentool/tests/test_schema_parser.py | 27 +++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/flattentool/tests/test_schema_parser.py b/flattentool/tests/test_schema_parser.py index da72707b..3abce057 100644 --- a/flattentool/tests/test_schema_parser.py +++ b/flattentool/tests/test_schema_parser.py @@ -282,6 +282,33 @@ def test_simple_array(type_): assert set(parser.main_sheet) == set(['Atest']) +@pytest.mark.parametrize('type_', ['string', 'number']) +def test_double_array(type_): + """ + Make sure we handle an array under items, used for e.g. co-ordinates. + + """ + parser = SchemaParser( + root_schema_dict={ + 'properties': { + 'Atest': { + 'type': 'array', + 'items': [ + { + 'type': type_ + }, + { + 'type': type_ + } + ] + } + } + } + ) + parser.parse() + assert set(parser.main_sheet) == set(['Atest']) + + @pytest.mark.parametrize('type_', ['string', 'number']) def test_nested_simple_array(type_): parser = SchemaParser(