Closed ahuff44 closed 7 years ago
Theoretically, what you want could be done with a schema like this:
schema = {
"oneOf": [
{
"type": "array",
"mergeStrategy": "append"
},
{
"type": "object",
"additionalProperties": {
"$ref": "#"
}
},
{
"type": "string"
},
{
"type": "number"
},
]
}
This seems to work correctly for validation with current jsonschema
(even though self-referential schemas are technically undefined behavior). Unfortunately, oneOf
keyword is not currently supported at all in jsonmerge
, so this does not work for merging right now.
I'll look into implementing a basic support for oneOf
that will work with the schema above. It should be relatively straightforward compared to anyOf
and allOf
.
For a quick-and-dirty fix, modify the WalkInstance.default_strategy
method. I don't think you can achieve what you want with a custom merge strategy.
The oneOf
recipe mentioned above should now work with jsonmerge
from the master branch.
I want the following assertion to pass:
I know that this is possible with
but in my case, I trying to write a general system where the array key isn't necessarily a top-level key named "a"; I want to merge any and all arrays using
"append"
instead of"overwrite"
.Is this possible somehow? Ideally I would be able to set
schema
like so: (this obviously does not currently work)It seems like the best route would be to create a custom merge strategy, but I'm hoping there's an easier solution that I've overlooked