Skip to content

Commit 3dd3fe5

Browse files
committed
Merge not schemas
1 parent 03b3b43 commit 3dd3fe5

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

src/hypothesis_jsonschema/_canonicalise.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -757,8 +757,10 @@ def merged(schemas: List[Any]) -> Optional[Schema]:
757757
if m == out["contains"] or m == s["contains"]:
758758
out["contains"] = m
759759
s.pop("contains")
760+
if "not" in out and "not" in s and out["not"] != s["not"]:
761+
out["not"] = {"anyOf": [out["not"], s.pop("not")]}
762+
760763
# TODO: merge `items` schemas or lists-of-schemas
761-
# TODO: merge `not` schemas as {not: anyOf: [not1, not2]}
762764
# TODO: merge if/then/else schemas to the chained form
763765
# or maybe canonicalise them to an anyOf instead?
764766
# TODO: merge dependencies

tests/test_canonicalise.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,10 @@ def test_canonicalises_to_expected(schema, expected):
342342
],
343343
{"type": "array", "contains": {"type": "integer"}, "minItems": 1},
344344
),
345+
(
346+
[{"not": {"enum": [1, 2, 3]}}, {"not": {"enum": ["a", "b", "c"]}}],
347+
{"not": {"anyOf": [{"enum": ["a", "b", "c"]}, {"enum": [1, 2, 3]}]}},
348+
),
345349
]
346350
+ [
347351
([{lo: 0, hi: 9}, {lo: 1, hi: 10}], {lo: 1, hi: 9})

0 commit comments

Comments
 (0)