Skip to content

Commit 466c013

Browse files
committed
More object canonicalisation
Fixes #92
1 parent ee40445 commit 466c013

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

src/hypothesis_jsonschema/_canonicalise.py

+6
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,13 @@ def canonicalish(schema: JSONType) -> Dict[str, Any]:
391391
):
392392
max_props = schema.get("maxProperties", math.inf)
393393
assert isinstance(max_props, (int, float))
394+
for k, v in list(schema["properties"].items()):
395+
if v == FALSEY:
396+
schema["properties"].pop(k)
394397
schema["maxProperties"] = min(max_props, len(schema["properties"]))
398+
if schema.get("maxProperties", math.inf) == 0:
399+
for k in ("properties", "patternProperties", "additionalProperties"):
400+
schema.pop(k, None)
395401
if "object" in type_ and schema.get("minProperties", 0) > schema.get(
396402
"maxProperties", math.inf
397403
):

tests/test_canonicalise.py

+21
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,27 @@ def test_canonicalises_to_empty(schema):
305305
{"type": "integer", "allOf": [{"multipleOf": 0.5}, {"multipleOf": 1e308}]},
306306
{"type": "integer", "multipleOf": 1e308},
307307
),
308+
(
309+
{
310+
"additionalProperties": {"not": {}},
311+
"properties": {"a": {"not": {}}},
312+
"type": "object",
313+
},
314+
{"maxProperties": 0, "type": "object"},
315+
),
316+
(
317+
{
318+
"additionalProperties": {"not": {}},
319+
"properties": {"a": {"not": {}}, "b": {}},
320+
"type": "object",
321+
},
322+
{
323+
"additionalProperties": {"not": {}},
324+
"properties": {"b": {}},
325+
"maxProperties": 1,
326+
"type": "object",
327+
},
328+
),
308329
],
309330
)
310331
def test_canonicalises_to_expected(schema, expected):

0 commit comments

Comments
 (0)