...
For example: if there is a list named "Items" containing 10 items named Item 1, Item 2, ......, Item 10. Then when fetching this list using get a node API a total of 10 individual lists are returned where each list contains one Item, i.e. List 1→Item 1, List 2→ Item 2, ......., List 10→ Item 10.
Code Block |
---|
title | Data Originally Stored |
---|
collapse | true |
---|
| {
"book-store:bookstore": {
"bookstore-name": "Easons",
"categories": [
{
"code": "1",
"name": "Children",
"books": [
{
"title": "Matilda",
"lang": "English",
"price": 20
},
{
"title": "The Gruffalo",
"lang": "English",
"price": 15
}
]
}
]
}
} |
| Response when querying the list directly. Code Block |
---|
title | Current output |
---|
collapse | true |
---|
| [
{
"books": {
"title": "Matilda",
"lang": "English",
"price": 20
}
},
{
"books": {
"title": "The Gruffalo",
"lang": "English",
"price": 15
}
}
] |
|
Code Block |
---|
title | Expected Result |
---|
collapse | true |
---|
| [
{
"books": [
{
"title": "Matilda",
"lang": "English",
"price": 20
},
{
"title": "The Gruffalo",
"lang": "English",
"price": 15
}
]
}
] |
| This behavior extends to list items stored under root node as well. So, this case needs to be taken into consideration as well |
Initial setup to try the sample requests up ahead
...
|
|
| Notes |
---|
Code Block |
---|
title | Original JSON data: |
---|
collapse | true |
---|
| {
"code": 1,
"name": "Children",
"books": [
{
"title": "Matilda",
"lang": "English",
"authors": ["Roald Dahl"],
"editions": [1988, 2000],
"price": 20
}
]
} |
|
Code Block |
---|
title | JSON with updates |
---|
collapse | true |
---|
| {
"code": 1,
"name": "Kids",
"books": [
{
"title": "Matilda",
"editions":
[1988, 2000, 2024],
"price": 25
}
]
} |
|
Code Block |
---|
title | JSON data after update |
---|
collapse | true |
---|
| {
"code": "1",
"name": "Children",
"books": [
{
"title": "Matilda",
"lang": "English",
"authors": ["Roald Dahl"],
"editions":
[1988, 2000, 2024],
"price": 25
}
]
} |
| - It can be seen that the leaf data belonging to parent node i.e. code=1 is sent as part of JSON body. Where name is changed from Children to Kids
- And the fields editions and price, of child node, i.e. title=Matilda are modified.
- But after the request is executed only the child node is updated.
- The expected behavior should be to throw an exception as the Update a node API requires parent node xpath to update any child data. Which in this case should be "/bookstore" because the request is also updating the node with key "code=1"
- This situation can mainly occur due to user error, where user provides updated parent data along with parent node xpath as part of the request.
|
Code Block |
---|
title | Curl request to replicate the scenario |
---|
collapse | true |
---|
| curl --location --globoff --request PATCH 'http://localhost:8883/cps/api/v2/dataspaces/my-dataspace/anchors/bookstore/nodes?xpath=%2Fbookstore%2Fcategories[%40code%3D1]' --header 'Content-Type: application/json' --header 'Accept: application/json' --header 'Authorization: ••••••' --data '{
"code": 1,
"name": "Kids",
"books": [
{
"title": "Matilda",
"editions":
[1988, 2000, 2024],
"price": 25
}
]
}' |
|
Problem Description 2
Update operation can only be done on one node at a time and when trying to update parent child in one request, then only the parent node is updated.
...