Skip to content

Commit

Permalink
fix: missing array detection
Browse files Browse the repository at this point in the history
  • Loading branch information
yshalenyk committed Jun 14, 2024
1 parent c6c8616 commit fb37a17
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
2 changes: 2 additions & 0 deletions nightingale/mapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,8 @@ def set_nested_value(nested_dict, keys, value, schema, add_new=False):
nested_dict[-1][last_key] = []
nested_dict[-1][last_key].append(value)
else:
if not nested_dict:
nested_dict.append({})
nested_dict[-1][last_key] = value
else:
if last_key in nested_dict:
Expand Down
5 changes: 5 additions & 0 deletions nightingale/mapping/v1/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,11 @@ def read_schema_sheet(self):
_, path, title, description, type, range, values, links, _, _ = row
if not path:
continue
path = "/" + path

if path in schema and type == "object":
# this is a nested object inside arrray we are interested in parrent array path
continue
schema[path] = {
"title": title,
"description": description,
Expand Down
8 changes: 4 additions & 4 deletions tests/test_mapping_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,15 +153,15 @@ def test_read_schema_sheet(mock_load_workbook, mock_workbook, mock_config):
schema = mapping.read_schema_sheet()

expected_schema = {
"array_path": {
"/array_path": {
"title": "title1",
"description": "description1",
"type": "array",
"range": "range1",
"values": "values1",
"links": "links1",
},
"path1": {
"/path1": {
"title": "title2",
"description": "description2",
"type": "string",
Expand Down Expand Up @@ -463,8 +463,8 @@ def test_is_array_path(mock_load_workbook, mock_workbook, mock_config):
mapping = Mapping(mock_config)
mapping.schema = mapping.read_schema_sheet()

assert mapping.is_array_path("array_path") is True
assert mapping.is_array_path("path2") is False
assert mapping.is_array_path("/array_path") is True
assert mapping.is_array_path("/path2") is False


if __name__ == "__main__":
Expand Down

0 comments on commit fb37a17

Please sign in to comment.