avian2 / jsonmerge

Merge a series of JSON documents.
MIT License
214 stars 25 forks source link

fix for handling additionalProperties keyword and update test #19

Closed nxkb closed 8 years ago

nxkb commented 8 years ago

Hello! I came across an issue when trying to merge 2 jsons where the values of arbitrary keys needed to be appended.

The schema for additional properties is slightly different than for pattern properties because it matches all additional properties and so it doesn't need to specify a rule to match, but goes straight into the details of the property.

'patternProperties': {
    'a.*': {'mergeStrategy'},
'additionalProperties': {
    'mergeStrategy': 'append'
}

I just made a small change so that for additional properties it would use the json object directly and not try to match the property.

I didn't find a relevant example in the json schema docs, but heres one from another site: http://spacetelescope.github.io/understanding-json-schema/reference/object.html?highlight=additionalproperties

btw this was my case, and desired output:

schema = {'mergeStrategy': 'objectMerge',
                  'additionalProperties': {
                      'mergeStrategy': 'append'
a = {'randomKey': [1, 2, 3]}
b = {'randomKey': [4,5],
       'anotherRandomKey': [1]}
...
merged = {'randomKey': [1, 2, 3, 4, 5],
          'anotherRandomKey': [1]}

please pull! thanks! Nick

avian2 commented 8 years ago

Right. This is the relevant paragraph of JSON schema definition:

http://json-schema.org/latest/json-schema-validation.html#anchor65

I see some unrelated Travis tests are failing - probably because of the updated jsonschema package. I'll try to fix them first before merging your changes.

avian2 commented 8 years ago

Merged. Thanks.