Maybe it's a problem on layer 8, but it seems that order of array-content is non deterministic after patch, even when using the same index multiple times.
To Reproduce
Create a new resource like so:
curl 'http://localhost:8090/api/v1/dataresources/' -i -X POST \
-H 'Content-Type: application/json' \
-d '{
"creators" : [{
"familyName" : "Doe",
"givenName" : "John",
"affiliations" : [ "test1", "test2" ]
}],
"titles" : [{
"value" : "Most basic resource for testing"
}],
"resourceType" : {
"value" : "testingSample",
"typeGeneral" : "DATASET"
}
}'
This results in first inconsistency as affiliations will be ["test2","test1"]
.
Now add another entry to the array (replace ID and ETAG with values of the step before):
curl 'http://127.0.0.1:8090/api/v1/dataresources/<ID>' -i -X PATCH \
-H 'Content-Type: application/json-patch+json' \
-H 'If-Match: <ETAG>' \
-d '[{
"op" : "add",
"path" : "/creators/0/affiliations/0",
"value" : "test3"
}]'
Fetch the changed resource:
curl 'http://127.0.0.1:8090/api/v1/dataresources/<ID>' -i -X GET
Now affiliations is ["test2","test3","test1"]
, the insertion happened between elements 0 and 1.
Repeating the previous steps (patch, get), results in:
["test4","test2","test3","test1"]
, this is the only result that is as expected (at least for my understanding).
["test4","test5","test2","test3","test1"]
, again between elements 0 and 1.
["test4","test5","test2","test3","test6","test1"]
, insertion between elements 3 and 4.
Expected behavior
Adding [ "test1", "test2" ]
leads to [ "test1", "test2" ]
added to resource.
Adding an entry respects the path given, for example
{ "affiliations": [ "test1", "test2" ] }
with patch:
[{ "op": "add", "path": "/affiliations/0", "value": "test3" }]
leads to:
{ "affiliations": [ "test3", "test1", "test2" ] }
whereas patch:
[{ "op": "add", "path": "/affiliations/1", "value": "test3" }]
leads to:
{ "affiliations": [ "test1", "test3", "test2" ] }
and patch:
[{ "op": "add", "path": "/affiliations/2", "value": "test3" }]
as well as patch:
[{ "op": "add", "path": "/affiliations/-", "value": "test3" }]
leads to:
{ "affiliations": [ "test1", "test2", "test3" ] }
according to Specification:
An element to add to an existing array - whereupon the supplied value is added to the array at the indicated location. Any elements at or above the specified index are shifted one position to the right.
Version
Tested version 1.4.1-SNAPSHOT as well as 1.5.4-SNAPSHOT with no obvious difference.