-
Notifications
You must be signed in to change notification settings - Fork 23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
API V2: Inconsistent 'add' behavior for empty arrays #224
Comments
Should we always support an array value in So, perhaps we should support the entire matrix of:
I think this may all be fairly clear for flat array properties. But I suppose a model might have some property that is an array of arrays. Then anything added to such a property must itself be an array and we get ambiguity when faced with empty arrays where the property currently is Perhaps this suggests that initialization of an |
In that case, the issue is that we have little control about how Json Patch diffs are generated; so we need to stay as close as possible to the Json Patch semantics. This means that supporting only "replace" is not really an option. AFAIK, in Json Patch, "add" is always an append, i.e. it never removes anything ("replace" is "remove" + "add"). Adding an array of values at a specific index would create a multi-dimensional array: {
"array": [1, 2]
} {
"op": "add",
"path": "/array/-",
"value": [3, 4]
} should result in: {
"array": [1, 2, [3, 4]]
} (Which may or may not be valid in EMF, depending on the Ecore model). The general issue with the JsonPatchHelper is that it was implemented in a simplified way; we wanted to support all "necessary" model operations, but not all "possible" operations. However, since we now more heavily rely on generic Json Patch Diff libraries, which may produce more different operations (and don't know anything about the underlying EMF Model), we need to fill the gaps. So we need:
I don't think it is necessary to handle all possible combinations. Especially, index + list would (should) work exclusively for EMF Multi-dimensional collections, just like it does with native Json Patch. Initializing an EMF Collection with an empty array would be a no-op (Except maybe in some custom cases, where the list isn't initialized automatically by EMF?). The reason EMF empty lists appear as undefined in Json is because the Codec doesn't serialize default values (But IMO it should serialize everything, because the client may not know anything about the EMF default values to fill the gaps by itself). |
Empty arrays are handled differently in EMF and Json. For example, these 2 models are equivalent in EMF (because lists are never "null"; they default to an empty collection), but different in Json:
{ "array": [] }
In the first case, we can add an array value with this patch:
In the second case, we need to add the entire array to the root node:
The JsonPatchHelper doesn't support the latter case (index-less "add" operation with a full array value). We should support direct feature edition (
/array
instead of/array/-
) for arrays , and expect an array value in that case ([value1, value2]
instead ofvalue1
).The text was updated successfully, but these errors were encountered: