Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support lists under items in schema #181

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 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
6 changes: 5 additions & 1 deletion flattentool/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
27 changes: 27 additions & 0 deletions flattentool/tests/test_schema_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down