Skip to content

Add dependentRequired and dependentSchemas for draft 2019-09 - #236

Open
chinmayajha wants to merge 1 commit into
horejsek:masterfrom
chinmayajha:draft2019-dependent-keywords
Open

chinmayajha wants to merge 1 commit into
horejsek:masterfrom
chinmayajha:draft2019-dependent-keywords

Conversation

@chinmayajha

Copy link
Copy Markdown

Draft 2019-09 split dependencies into dependentRequired and dependentSchemas, but neither is implemented, so both are silently ignored:

import fastjsonschema

schema = {
    '$schema': 'https://json-schema.org/draft/2019-09/schema',
    'dependentRequired': {'bar': ['foo']},
}
fastjsonschema.validate(schema, {'bar': 1})
# returns {'bar': 1}, should fail because foo is missing

Both keywords work like the two shapes dependencies already handles (a list of names, or a schema), so the draft 04 code moves into _generate_dependencies(rule) and the draft 2019 generator calls it for each keyword. The error rule is the keyword name. Like dependencies, they are inserted before properties so a default value can't trigger them. Drafts 04, 06 and 07 still ignore them. Schemas without $schema use the 2019 generator, so they get the new checks too.

dependentRequired.json and dependentSchemas.json from the test suite now pass, so I removed them from the draft 2019 ignore list. I also added a test in tests/test_object.py that a default doesn't trigger either keyword. The full suite passes and pylint is unchanged. CHANGELOG has an entry under UNRELEASED.

@chinmayajha

Copy link
Copy Markdown
Author

@horejsek same for this one, the workflows need approval before CI runs.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant