Skip to content

Commit dca5999

Browse files
committed
Merge pull request python-jsonschema#153 from asottile/faq_defaulting_validator
Update FAQ with example of using defaulting validator.
2 parents 1ca7d21 + 73f774e commit dca5999

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

docs/faq.rst

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,18 @@ started:
4747
DefaultValidatingDraft4Validator = extend_with_default(Draft4Validator)
4848
4949
50+
# Example usage:
51+
obj = {}
52+
schema = {'properties': {'foo': {'default': 'bar'}}}
53+
# Note jsonschem.validate(obj, schema, cls=DefaultValidatingDraft4Validator)
54+
# will not work because the metaschema contains `default` directives.
55+
DefaultValidatingDraft4Validator(schema).validate(obj)
56+
assert obj == {'foo': 'bar'}
57+
58+
5059
See the above-linked document for more info on how this works, but basically,
5160
it just extends the :validator:`properties` validator on a
52-
:class:`Draft4Validator` to then go ahed and update all the defaults.
61+
:class:`Draft4Validator` to then go ahead and update all the defaults.
5362

5463
If you're interested in a more interesting solution to a larger class of these
5564
types of transformations, keep an eye on `Seep

0 commit comments

Comments
 (0)