Versions Compared

Key

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

...

Expand
titlexpath with incorrect JSON payload

xpath: /bookstore/categories[@code=1]

Incorrect JSON payload:

Code Block
languagenone
{
  "code": 1,                      //parent node data should not be in the payload
  "name": "Kids",                      
  "books": [
    {
      "title": "Matilda",
      "editions": [1988, 2000, 2024],
      "price": 25
    }
  ]
}

...

Expand
titleData fetched from DB after partial update
Code Block
{
    "code": "1",
    "name": "Children",                        //not updated
    "books": [
      {
	 	"title": "Matilda",
        "lang": "English",
        "editions": [1988, 2000, 2024],       //updated
		"price": 25							  //updated
       }
    ]
  }

Proposed Solution for Scenario 1:

  • The proposed solution is to drop the support for using parent node xpath in the request and instead the exact xpath of the data node being updated should be provided in the request.

    • throw an exception when the parent node is provided in the payload

  • Apart from this based on the RESTful rules, an additional check should be put in place to first fetch the existing data from the database and verify that it exists and is valid before performing the PATCH operation.

Scenario 2: API does not update child nodes

...

Expand
titleOriginal Data
Code Block
languagejson
{
  "categories": {
    "code": "1",
    "name": "Children",
    "books": [
      {
	 	"title": "Matilda",
        "lang": "English",
        "price": 200,
        "editions": [1988,2000]
      }
    ]
  }
}

...

Expand
titleData fetched from DB after partial update
Code Block
{
  "categories": {
    "code": "1",
    "name": "Kids",                 //updated
    "books": [
      {
        "title": "Matilda", 
     	"lang": "English",
        "price": 200,              //not updated
		"editions": [1988,2000]    //not updated    
		}
    ]
  }
}

Expected Behavior

The expected behavior should be as follows:

...

Scenario 1

  • throw an exception when the parent node is provided in the payload

  • modify the API so that it accepts the xpath of data node being updated and handles the payload present under the data node to be updated.

  • add support for multiple data nodes

Scenario 2

Proposed Solution for Scenario 2

  • Solution 1: Limit the update operation to one Data Node at a time

    • throw an exception if more than one data nodes are present in the payloadadd

  • Solution 2: Add support to update multiple data nodes

Proposed/Accepted Solution

...