diff options
Diffstat (limited to 'jsonschema/_legacy_validators.py')
-rw-r--r-- | jsonschema/_legacy_validators.py | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/jsonschema/_legacy_validators.py b/jsonschema/_legacy_validators.py index b337151..8e46190 100644 --- a/jsonschema/_legacy_validators.py +++ b/jsonschema/_legacy_validators.py @@ -27,6 +27,32 @@ def dependencies_draft3(validator, dependencies, instance, schema): yield ValidationError(message % (each, property)) +def dependencies_draft4_draft6_draft7(validator, dependencies, instance, schema): + """ + Support for the ``dependencies`` validator from pre-draft 2019-09. + + In later drafts, the validator was split into separate ``dependentRequired`` + and ``dependentSchemas`` validators. + """ + if not validator.is_type(instance, "object"): + return + + for property, dependency in dependencies.items(): + if property not in instance: + continue + + if validator.is_type(dependency, "array"): + for each in dependency: + if each not in instance: + message = "%r is a dependency of %r" + yield ValidationError(message % (each, property)) + else: + for error in validator.descend( + instance, dependency, schema_path=property, + ): + yield error + + def disallow_draft3(validator, disallow, instance, schema): for disallowed in _utils.ensure_list(disallow): if validator.is_valid(instance, {"type": [disallowed]}): |