Starcounter-Jack / JSON-Patch

Lean and mean Javascript implementation of the JSON-Patch standard (RFC 6902). Update JSON documents using delta patches.
MIT License
1.78k stars 215 forks source link

auto add tests to "add/remove" operations like for "replace" #316

Closed eladonline closed 1 year ago

eladonline commented 1 year ago

Hey would be really nice to have this feature as in our app we allow to replace the source document and apllying the current patches on it therfore when in the new doc if you have order change for any array it can lead to unwated results if patches add to some index ex:

document = {endpoint:{method:{parameters:[{id:"foo"}]}}}

// I want  to add to "foo" some description in index 0
patches = {op:add, path:"endpoint/method/parameters/0/description", value:"desc..."}

// now for some reason I changed the doc and now foo`s index is 1 
document = {endpoint:{method:{parameters:[{id:"bar"},{id:"foo"}]}}}

// now the old patches add description to "bar" 
patches = {op:add, path:"endpoint/method/parameters/0/description", value:"desc..."}

this situation can be resolved by adding test to verify parameter 0 is "foo"