Skip to content

Commit 92b05d6

Browse files
committed
Fix exception when additionalProperties is boolean
jsonschema draft 4 allows additionalProperties to be true and false, in addition to containing a subschema. Related to: #30
1 parent 60b2f02 commit 92b05d6

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

jsonmerge/strategies.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,8 @@ def merge(self, walk, base, head, schema, meta, objclass_menu=None, objClass='_d
262262

263263
if subschema.is_undef():
264264
p = schema.get('additionalProperties')
265-
if not p.is_undef():
265+
# additionalProperties can be boolean in draft 4
266+
if not p.is_undef() and walk.is_type(p, "object"):
266267
subschema = p
267268

268269
base[k] = walk.descend(subschema, base.get(k), v, meta)
@@ -281,8 +282,9 @@ def descend_keyword(keyword):
281282
descend_keyword("properties")
282283
descend_keyword("patternProperties")
283284

285+
# additionalProperties can be boolean in draft 4
284286
p = schema.get("additionalProperties")
285-
if not p.is_undef():
287+
if not p.is_undef() and walk.is_type(p, "object"):
286288
schema2["additionalProperties"] = walk.descend(p, meta)
287289

288290
return schema2

tests/test_jsonmerge.py

+23
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,17 @@ def test_merge_append_additional(self):
338338

339339
self.assertEqual(base, {'a': ["a", "b"], 'b': 'c'})
340340

341+
def test_merge_additional_bool(self):
342+
343+
schema = {'additionalProperties': True}
344+
345+
base = {}
346+
head = {'a': 'a'}
347+
348+
base = jsonmerge.merge(base, head, schema)
349+
350+
self.assertEqual(base, {'a': 'a'})
351+
341352
def test_example(self):
342353

343354
head1 = {
@@ -1857,6 +1868,18 @@ def test_merge_append_additional(self):
18571868

18581869
self.assertEqual(schema2, expected)
18591870

1871+
def test_merge_additional_bool(self):
1872+
1873+
schema = {'additionalProperties': True}
1874+
1875+
base = {}
1876+
head = {'a': 'a'}
1877+
1878+
merger = jsonmerge.Merger(schema)
1879+
schema2 = merger.get_schema()
1880+
1881+
self.assertEqual(schema2, schema)
1882+
18601883
def test_oneof(self):
18611884

18621885
schema = {

0 commit comments

Comments
 (0)