Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...




Notes


Code Block
titleOriginal JSON data:
collapsetrue
{
  "code": 1,
  "name": "Children",
  "books": [
    {
      "title": "Matilda",
      "lang": "English",
      "authors": ["Roald Dahl"],
      "editions": [1988, 2000],
      "price": 20
    }
  ]
}




Code Block
titleJSON with updates
collapsetrue
{
  "code": 1,
  "name": "Kids",
  "books": [
    {
      "title": "Matilda",
      "editions": 
		[1988, 2000, 2024],
      "price": 25
    }
  ]
}



Code Block
titleJSON data after update
collapsetrue
{
    "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.

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.


Code Block
title
Original JSON data
Curl request to replicate the scenario
collapsetrue
{
curl --location 
"categories": { "code": "1",
--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": "
Children
Kids", 
"books": [
{
"title": "Matilda",
      "lang
"editions": 
"English", "price": 200, "authors":["Roald Dahl"], "editions": [1988,2000] } ] } }
[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.

Notes Code BlocktitleOriginal JSON data





Code Block
titleOriginal JSON to be updateddata
collapsetrue
{
  "categories": {
    "code": "1",
    "name": "KidsChildren",
    "books": [
      {
	   	"title": "Matilda",
        "titlelang": "MatildaEnglish",
	 	
        "price": 20200,
		"editions":  		[1988, 2000, 2022]    "authors":["Roald Dahl"],
 }     ]  "editions": [1988,2000]
      }
    ]
  }
}



Code Block
titleUpdated JSON datato be updated
collapsetrue
{
  "categories": {
    "code": "1",
    "name": "Kids",
    "books": [
      {
        "title": "Matilda",
	      	"lang": "English",
	"price": 20,
		"editions": 
		[1988, 2000, 2022]
      }
"price": 200,    ]
  }
}



Code Block
titleUpdated JSON data
collapsetrue
{
  "authorscategories": ["Roald Dahl"],
		"editions": [1988,2000]        }
    ]
  }
}
  • The request is executed successfully but only a partial update takes place in the database.
  • So, either the API should reject any request containing multiple nodes or support updating multiple nodes at once.

Replace a node with descendants

Problem Description

If a replace operation is performed on a list, where a new list item is also added to the list, then it results in a 200-response code, with a partial replace operation.

 {
    "code": "1",
    "name": "Kids",
    "books": [
      {
        "title": "Matilda", 
     	"lang": "English",
        "price": 200,
        "authors": ["Roald Dahl"],
		"editions": [1988,2000]        }
    ]
  }
}


  • The request is executed successfully but only a partial update takes place in the database.
  • So, either the API should reject any request containing multiple nodes or support updating multiple nodes at once.


Code Block
titleCurl request to replicate the scenario
collapsetrue
curl --location --request PATCH 'http://localhost:8883/cps/api/v2/dataspaces/my-dataspace/anchors/bookstore/nodes?xpath=%2Fbookstore' --header 'Content-Type: application/json' --header 'Accept: application/json' --header 'Authorization: ••••••' --data '{
  "categories": {
    "code": 1,
    "name": "Kids",
    "books": [
      {
        "title": "Matilda",
	 	"price": 20,
		"editions": 
		[1988, 2000, 2022]
      }
    ]
  }
}'


Replace a node with descendants

Problem Description

If a replace operation is performed on a list, where a new list item is also added to the list, then it results in a 200-response code, with a partial replace operation.

Data to replace{ "books": [ { "title": "Matilda", "lang": "English", "authors": ["Roald Dahl"], "editions": [2024] }, The GruffaloJuliaDonaldson1999], "price": 15 ]}["book-store:books":{ MatildaRoaldDahl2024] } ]
  • This is a user error as request here is itself wrong, because it tries to add a new list element.
  • CPS provides a separate endpoint to Add a list element
  • So, such a scenario should be handled by the API instead of returning a successful response.



    Notes


    Code Block
    titleOriginal JSON data
    collapsetrue
    [
      {
        "book-store:books": {
    	  "title": "Matilda",
          "lang": "English",
          "price": 20,
          "authors": ["Roald Dahl"],
          "editions": [1988,2000]
        }
      }
    ]



    Code Block
    titleData to replace
    collapsetrue
    {
      "books": [
        {
          "title": "Matilda",
          "lang": "English",
          "authors": ["Roald Dahl"],
          "editions": [2024]
        },
        {
          "title": "The Gruffalo",
          "lang": "English",
          "authors": ["Julia Donaldson"],
          "editions": [1999],
          "price": 15
        }
      ]
    }



    Code Block
    titleResult after Replace operation
    collapsetrue
    [
      {
        "book-store:books": {
    	  "title": "Matilda",
          "lang": "English",
          "price": 20,
          "authors": ["Roald Dahl"],
          "editions": [1988,20002024]
        }
      }
    ]]


    • This is a user error as request here is itself wrong, because it tries to add a new list element.
    • CPS provides a separate endpoint to Add a list element
    • So, such a scenario should be handled by the API instead of returning a successful response.


    Code Block
    title
    Curel request to replicate the scenario
    collapsetrue
    curl --location 
    --globoff --request PUT '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 '{
      "books": [
        {
          "title": "
    Matilda",
          "lang": "English",
          "authors": ["
    Roald 
    Dahl"],
          "editions": [
    2024]
        }
    ,
    
     
    Code Block
    titleResult after Replace operation
    collapsetrue
       {
        
     
     "title": "
    The Gruffalo",
          "lang": "English",
          "authors": ["
    Julia 
    Donaldson"],
          "editions": [
    1999],
          "price": 15
        }
      
    ]
    }'