You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/validate.rst
+18-22Lines changed: 18 additions & 22 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -25,17 +25,20 @@ The simplest way to validate an instance under a given schema is to use the
25
25
The Validator Protocol
26
26
-----------------------
27
27
28
-
`jsonschema` defines a protocol that all validator classes should adhere
29
-
to.
28
+
`jsonschema` defines a `protocol <typing.Protocol>` that all validator classes adhere to.
29
+
30
+
.. hint::
31
+
32
+
If you are unfamiliar with protocols, either as a general notion or as specifically implemented by `typing.Protocol`, you can think of them as a set of attributes and methods that all objects satisfying the protocol have.
33
+
34
+
Here, in the context of `jsonschema`, the `Validator.iter_errors` method can be called on `jsonschema.validators.Draft202012Validator`, or `jsonschema.validators.Draft7Validator`, or indeed any validator class, as all of them have it, along with all of the other methods described below.
30
35
31
36
.. autoclass:: jsonschema.protocols.Validator
32
37
:noindex:
33
38
:members:
34
39
35
-
All of the `versioned validators <versioned-validators>` that are included with
36
-
`jsonschema` adhere to the protocol, and implementers of validator classes
37
-
that extend or complement the ones included should adhere to it as well. For
38
-
more information see `creating-validators`.
40
+
All of the `versioned validators <versioned-validators>` that are included with `jsonschema` adhere to the protocol, and any `extensions of these validators <jsonschema.validators.extend>` will as well.
41
+
For more information on `creating <jsonschema.validators.create>` or `extending <jsonschema.validators.extend>` validators see `creating-validators`.
39
42
40
43
Type Checking
41
44
-------------
@@ -119,10 +122,10 @@ existing `TypeChecker` or create a new one. You may then create a new
119
122
Versioned Validators
120
123
--------------------
121
124
122
-
`jsonschema` ships with validator classes for various versions of
123
-
the JSON Schema specification. For details on the methods and attributes
124
-
that each validator class provides see the `Validator` protocol,
125
-
which each included validator class implements.
125
+
`jsonschema` ships with validator classes for various versions of the JSON Schema specification.
126
+
For details on the methods and attributes that each validator class provides see the `Validator` protocol, which each included validator class implements.
127
+
128
+
Each of the below cover a specific release of the JSON Schema specification.
126
129
127
130
.. autoclass:: Draft202012Validator
128
131
:noindex:
@@ -168,11 +171,8 @@ Draft 2020-12 meta-schema, you could use:
168
171
Validating Formats
169
172
------------------
170
173
171
-
JSON Schema defines the :kw:`format` keyword which can be used to check
172
-
if primitive types (``string``\s, ``number``\s, ``boolean``\s) conform to
173
-
well-defined formats. By default, no validation is enforced, but optionally,
174
-
validation can be enabled by hooking in a format-checking object into an
175
-
`Validator`.
174
+
JSON Schema defines the :kw:`format` keyword which can be used to check if primitive types (``string``\s, ``number``\s, ``boolean``\s) conform to well-defined formats.
175
+
By default, no validation is enforced, but optionally, validation can be enabled by hooking in a format-checking object into a `Validator`.
176
176
177
177
.. doctest::
178
178
@@ -191,18 +191,14 @@ validation can be enabled by hooking in a format-checking object into an
191
191
:exclude-members: cls_checks
192
192
193
193
.. attribute:: checkers
194
-
A mapping of currently known formats to tuple of functions that
195
-
validate them and errors that should be caught. New checkers can be
196
-
added and removed either per-instance or globally for all checkers
197
-
using the `FormatChecker.checks` or `FormatChecker.cls_checks`
198
-
decorators respectively.
194
+
A mapping of currently known formats to tuple of functions that validate them and errors that should be caught.
195
+
New checkers can be added and removed either per-instance or globally for all checkers using the `FormatChecker.checks` decorator.
199
196
200
197
.. classmethod:: cls_checks(format, raises=())
201
198
202
199
Register a decorated function as *globally* validating a new format.
203
200
204
-
Any instance created after this function is called will pick up the
205
-
supplied checker.
201
+
Any instance created after this function is called will pick up the supplied checker.
206
202
207
203
:argument str format: the format that the decorated function will check
208
204
:argument Exception raises: the exception(s) raised
0 commit comments