diff --git a/src/hypothesis_jsonschema/_canonicalise.py b/src/hypothesis_jsonschema/_canonicalise.py index a11c9be..47d7de5 100644 --- a/src/hypothesis_jsonschema/_canonicalise.py +++ b/src/hypothesis_jsonschema/_canonicalise.py @@ -461,6 +461,8 @@ def canonicalish(schema: JSONType) -> Dict[str, Any]: # TODO: else merge schema-dependencies of required properties # into the base schema after adding required back in and being # careful to avoid an infinite loop... + if not schema["dependencies"]: + schema.pop("dependencies") schema["required"] = sorted(reqs) max_ = schema.get("maxProperties", float("inf")) assert isinstance(max_, (int, float)) diff --git a/tests/test_canonicalise.py b/tests/test_canonicalise.py index 6471507..6fd4d83 100644 --- a/tests/test_canonicalise.py +++ b/tests/test_canonicalise.py @@ -53,6 +53,14 @@ def test_canonicalises_to_equivalent_fixpoint(schema_strategy, data): jsonschema.validators.validator_for(schema).check_schema(schema) +def test_dependencies_canonicalises_to_fixpoint(): + """Check that an object drawn from an arbitrary schema is valid.""" + cc = canonicalish( + {"required": [""], "properties": {"": {}}, "dependencies": {"": [""]}} + ) + assert cc == canonicalish(cc) + + @pytest.mark.parametrize( "schema", [