Running the following will produce an incorrect JsonPatchError:
const jsonpatch = require('fast-json-patch')
var original = {
myObj: {
arrKey: []
}
}
var patch = [
{ value: 1234, path: '/id', op: 'add' },
{ value: 12,
path: '/myObj/arrKey/1',
op: 'add' }
]
var validationErrors = jsonpatch.validate(patch, original)
if (validationErrors !== undefined) {
console.log(validationErrors)
}
Output:
{ [OPERATION_VALUE_OUT_OF_BOUNDS: The specified index MUST NOT be greater than the number of elements in the array]
message:
'The specified index MUST NOT be greater than the number of elements in the array',
name: 'OPERATION_VALUE_OUT_OF_BOUNDS',
index: 0,
operation: '/myObj/arrKey/1',
tree: { value: 12, path: '/myObj/arrKey/1', op: 'add' } }
The operation references the path, and the tree references the actual operation. Additionally, the index is wrong, as it does not reflect the index of the patch that is invalid.
All other JSONPatchErrors have the operation referencing the invalid patch operation, index that reflects the position of the invalid patch in an array of patches, and tree that displays the corresponding object that is being patched.
Expected:
{ [OPERATION_VALUE_OUT_OF_BOUNDS: The specified index MUST NOT be greater than the number of elements in the array]
message: 'The specified index MUST NOT be greater than the number of elements in the array',
name: 'OPERATION_VALUE_OUT_OF_BOUNDS',
index: 1,
operation:{ value: 12, path: '/myObj/arrKey/1', op: 'add' } ,
tree: { cost: { others: [] } } }
Running the following will produce an incorrect JsonPatchError:
Output:
The operation references the path, and the tree references the actual operation. Additionally, the index is wrong, as it does not reflect the index of the patch that is invalid.
All other JSONPatchErrors have the operation referencing the invalid patch operation, index that reflects the position of the invalid patch in an array of patches, and tree that displays the corresponding object that is being patched.
Expected:
Version Information: