diff --git a/src/common/providers/address_resolver/path_items.py b/src/common/providers/address_resolver/path_items.py index 895874afe..ab0d4d23b 100644 --- a/src/common/providers/address_resolver/path_items.py +++ b/src/common/providers/address_resolver/path_items.py @@ -130,6 +130,13 @@ def get_child( f"Invalid attribute '{self.path}'. Valid attributes are '{list(entity.keys())}'." ) from ex else: + try: + int(self.path) + raise NotFoundException( + "'myList.0' is an invalid syntax for accessing items in a list. Use 'myList[0]' instead" + ) from ex + except ValueError: + pass raise NotFoundException(f"Invalid index '{self.path}'. Valid indices are < {len(entity)}.") from ex return result, self.path diff --git a/src/common/tree/tree_node.py b/src/common/tree/tree_node.py index 71bc92f94..df22f076f 100644 --- a/src/common/tree/tree_node.py +++ b/src/common/tree/tree_node.py @@ -95,6 +95,8 @@ def node_id(self): return self.uid if not self.storage_contained and not self.is_array(): return self.uid + if self.parent.is_array(): + return f"{self.parent.node_id}[{self.key}]" return ".".join((self.parent.node_id, self.key)) def path(self): diff --git a/src/tests/bdd/document/add_contained.feature b/src/tests/bdd/document/add_contained.feature index 6b70763f6..2681cc80f 100644 --- a/src/tests/bdd/document/add_contained.feature +++ b/src/tests/bdd/document/add_contained.feature @@ -89,5 +89,5 @@ Feature: Explorer - Add contained node Then the response status should be "OK" And the response should contain """ - {"uid": "1.meAgain.1.meAgain.0"} + {"uid": "1.meAgain[1].meAgain[0]"} """ diff --git a/src/tests/bdd/document/add_document.feature b/src/tests/bdd/document/add_document.feature index 8ffb2c426..7f49d33b6 100644 --- a/src/tests/bdd/document/add_document.feature +++ b/src/tests/bdd/document/add_document.feature @@ -386,6 +386,10 @@ Feature: Add document with document_service } """ Then the response status should be "OK" + And the response should contain + """ + {"uid": "11.phases[1]"} + """ Given i access the resource url "/api/documents/data-source-name/root_package/EntityPackage/operation1?depth=3" When I make a "GET" request Then the response status should be "OK" @@ -449,7 +453,7 @@ Feature: Add document with document_service And the response should contain """ { - "uid": "11.phases.0.containedResults.0" + "uid": "11.phases[0].containedResults[0]" } """ # todo update document add use case such that id contains bracket notation for lists: 11.phases[0].containedResults[0] diff --git a/src/tests/bdd/document/add_documentwith_optional_attributes.feature b/src/tests/bdd/document/add_documentwith_optional_attributes.feature index b347def84..36e29f91f 100644 --- a/src/tests/bdd/document/add_documentwith_optional_attributes.feature +++ b/src/tests/bdd/document/add_documentwith_optional_attributes.feature @@ -202,7 +202,7 @@ Feature: Add document with optional attributes And the response should contain """ { - "uid": "workComputerId.letterKeys.0" + "uid": "workComputerId.letterKeys[0]" } """ Given i access the resource url "/api/documents/data-source-name/$workComputerId.letterKeys" diff --git a/src/tests/bdd/document/update_list.feature b/src/tests/bdd/document/update_list.feature index 405eb7ea5..465149d63 100644 --- a/src/tests/bdd/document/update_list.feature +++ b/src/tests/bdd/document/update_list.feature @@ -139,7 +139,7 @@ Feature: Add document with optional attributes And the response should contain """ { - "uid": "workComputerId.letterKeys.0" + "uid": "workComputerId.letterKeys[0]" } """ Given i access the resource url "/api/documents/data-source-name/$workComputerId.letterKeys" diff --git a/src/tests/unit/common/tree/test_tree_node_helpers.py b/src/tests/unit/common/tree/test_tree_node_helpers.py index 58ba5e52a..221979cb8 100644 --- a/src/tests/unit/common/tree/test_tree_node_helpers.py +++ b/src/tests/unit/common/tree/test_tree_node_helpers.py @@ -288,7 +288,7 @@ def test_node_id(self): self.assertEqual(nested_2.node_id, "1.nested.nested") self.assertEqual(reference.node_id, "1.nested.nested.reference") self.assertEqual(list_node.node_id, "1.list") - self.assertEqual(item_1.node_id, "1.list.0") + self.assertEqual(item_1.node_id, "1.list[0]") def test_search(self): document_1 = {