File tree Expand file tree Collapse file tree 2 files changed +38
-0
lines changed Expand file tree Collapse file tree 2 files changed +38
-0
lines changed Original file line number Diff line number Diff line change @@ -67,6 +67,7 @@ def setup(app):
67
67
68
68
doctest_global_setup = """
69
69
from jsonschema import *
70
+ import jsonschema.validators
70
71
"""
71
72
72
73
Original file line number Diff line number Diff line change @@ -1141,6 +1141,43 @@ def validator_for(schema, default=_UNSET):
1141
1141
1142
1142
If unprovided, the default is to return the latest supported
1143
1143
draft.
1144
+
1145
+ Examples:
1146
+
1147
+ The :kw:`$schema` JSON Schema keyword will control which validator
1148
+ class is returned:
1149
+
1150
+ >>> schema = {
1151
+ ... "$schema": "https://json-schema.org/draft/2020-12/schema",
1152
+ ... "type": "integer",
1153
+ ... }
1154
+ >>> jsonschema.validators.validator_for(schema)
1155
+ <class 'jsonschema.validators.Draft202012Validator'>
1156
+
1157
+
1158
+ Here, a draft 7 schema instead will return the draft 7 validator:
1159
+
1160
+ >>> schema = {
1161
+ ... "$schema": "http://json-schema.org/draft-07/schema#",
1162
+ ... "type": "integer",
1163
+ ... }
1164
+ >>> jsonschema.validators.validator_for(schema)
1165
+ <class 'jsonschema.validators.Draft7Validator'>
1166
+
1167
+
1168
+ Schemas with no ``$schema`` keyword will fallback to the default
1169
+ argument:
1170
+
1171
+ >>> schema = {"type": "integer"}
1172
+ >>> jsonschema.validators.validator_for(
1173
+ ... schema, default=Draft7Validator,
1174
+ ... )
1175
+ <class 'jsonschema.validators.Draft7Validator'>
1176
+
1177
+ or if none is provided, to the latest version supported.
1178
+ Always including the keyword when authoring schemas is highly
1179
+ recommended.
1180
+
1144
1181
"""
1145
1182
1146
1183
DefaultValidator = _LATEST_VERSION if default is _UNSET else default
You can’t perform that action at this time.
0 commit comments