@@ -50,20 +50,30 @@ class Validator(Protocol):
50
50
"""
51
51
The protocol to which all validator classes should adhere.
52
52
53
- :argument schema: the schema that the validator object
54
- will validate with. It is assumed to be valid, and providing
55
- an invalid schema can lead to undefined behavior. See
56
- `Validator.check_schema` to validate a schema first.
57
- :argument resolver: an instance of `jsonschema.RefResolver` that will be
58
- used to resolve :kw:`$ref` properties (JSON references). If
59
- unprovided, one will be created.
60
- :argument format_checker: an instance of `jsonschema.FormatChecker`
61
- whose `jsonschema.FormatChecker.conforms` method will be called to
62
- check and see if instances conform to each :kw:`format`
63
- property present in the schema. If unprovided, no validation
64
- will be done for :kw:`format`. Certain formats require
65
- additional packages to be installed (ipv5, uri, color, date-time).
66
- The required packages can be found at the bottom of this page.
53
+ Arguments:
54
+
55
+ schema:
56
+
57
+ The schema that the validator object will validate with.
58
+ It is assumed to be valid, and providing
59
+ an invalid schema can lead to undefined behavior. See
60
+ `Validator.check_schema` to validate a schema first.
61
+
62
+ resolver:
63
+
64
+ a resolver that will be used to resolve :kw:`$ref`
65
+ properties (JSON references). If unprovided, one will be created.
66
+
67
+ format_checker:
68
+
69
+ if provided, a checker which will be used to assert about
70
+ :kw:`format` properties present in the schema. If unprovided,
71
+ *no* format validation is done, and the presence of format
72
+ within schemas is strictly informational. Certain formats
73
+ require additional packages to be installed in order to assert
74
+ against instances. Ensure you've installed `jsonschema` with
75
+ its `extra (optional) dependencies <index:extras>` when
76
+ invoking ``pip``.
67
77
"""
68
78
69
79
#: An object representing the validator's meta schema (the schema that
@@ -99,25 +109,45 @@ def check_schema(cls, schema: dict) -> None:
99
109
"""
100
110
Validate the given schema against the validator's `META_SCHEMA`.
101
111
102
- :raises: `jsonschema.exceptions.SchemaError` if the schema
103
- is invalid
112
+ Raises:
113
+
114
+ `jsonschema.exceptions.SchemaError`
115
+
116
+ if the schema is invalid
104
117
"""
105
118
106
119
def is_type (self , instance : Any , type : str ) -> bool :
107
120
"""
108
121
Check if the instance is of the given (JSON Schema) type.
109
122
110
- :type type: str
111
- :rtype: bool
112
- :raises: `jsonschema.exceptions.UnknownType` if ``type``
113
- is not a known type.
123
+ Arguments:
124
+
125
+ instance:
126
+
127
+ the value to check
128
+
129
+ type:
130
+
131
+ the name of a known (JSON Schema) type
132
+
133
+ Returns:
134
+
135
+ whether the instance is of the given type
136
+
137
+ Raises:
138
+
139
+ `jsonschema.exceptions.UnknownType`
140
+
141
+ if ``type`` is not a known type
114
142
"""
115
143
116
144
def is_valid (self , instance : Any ) -> bool :
117
145
"""
118
146
Check if the instance is valid under the current `schema`.
119
147
120
- :rtype: bool
148
+ Returns:
149
+
150
+ whether the instance is valid or not
121
151
122
152
>>> schema = {"maxItems" : 2}
123
153
>>> Draft202012Validator(schema).is_valid([2, 3, 4])
@@ -128,9 +158,6 @@ def iter_errors(self, instance: Any) -> Iterable[ValidationError]:
128
158
r"""
129
159
Lazily yield each of the validation errors in the given instance.
130
160
131
- :rtype: an `collections.abc.Iterable` of
132
- `jsonschema.exceptions.ValidationError`\s
133
-
134
161
>>> schema = {
135
162
... "type" : "array",
136
163
... "items" : {"enum" : [1, 2, 3]},
@@ -147,8 +174,11 @@ def validate(self, instance: Any) -> None:
147
174
"""
148
175
Check if the instance is valid under the current `schema`.
149
176
150
- :raises: `jsonschema.exceptions.ValidationError` if the
151
- instance is invalid
177
+ Raises:
178
+
179
+ `jsonschema.exceptions.ValidationError`
180
+
181
+ if the instance is invalid
152
182
153
183
>>> schema = {"maxItems" : 2}
154
184
>>> Draft202012Validator(schema).validate([2, 3, 4])
0 commit comments