diff options
author | Harald Nezbeda <hn@nezhar.com> | 2021-06-25 08:41:19 +0200 |
---|---|---|
committer | Harald Nezbeda <hn@nezhar.com> | 2021-07-20 17:08:47 +0200 |
commit | df1953ff50c16d7bad396b4e38677bbc0502c182 (patch) | |
tree | 72f22f9c2a564a585c42ba1fda31b399eb8e0361 /jsonschema/_legacy_validators.py | |
parent | f8555cd4a7458b0dd8c39f869d18c1b3cc67e816 (diff) | |
download | jsonschema-df1953ff50c16d7bad396b4e38677bbc0502c182.tar.gz |
Julian/jsonschema#782: Load dependencies from legacy validators
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]}): |