File tree Expand file tree Collapse file tree 3 files changed +23
-2
lines changed Expand file tree Collapse file tree 3 files changed +23
-2
lines changed Original file line number Diff line number Diff line change 1
1
v4.17.0
2
2
=======
3
3
4
+ * The ``check_schema `` method on ``jsonschema.protocols.Validator `` instances
5
+ now *enables * format validation by default when run. This can catch some
6
+ additional invalid schemas (e.g. containing invalid regular expressions)
7
+ where the issue is indeed uncovered by validating against the metaschema
8
+ with format validation enabled as an assertion.
4
9
* The ``jsonschema `` CLI (along with ``jsonschema.cli `` the module) are now
5
10
deprecated. Use ``check-jsonschema `` instead, which can be installed via
6
11
``pip install check-jsonschema `` and found
Original file line number Diff line number Diff line change @@ -1483,6 +1483,16 @@ def test_enum_allows_non_unique_items(self):
1483
1483
else :
1484
1484
self .Validator .check_schema ({"enum" : [12 , 12 ]})
1485
1485
1486
+ def test_schema_with_invalid_regex (self ):
1487
+ with self .assertRaises (exceptions .SchemaError ):
1488
+ self .Validator .check_schema ({"pattern" : "*notaregex" })
1489
+
1490
+ def test_schema_with_invalid_regex_with_disabled_format_validation (self ):
1491
+ self .Validator .check_schema (
1492
+ {"pattern" : "*notaregex" },
1493
+ format_checker = None ,
1494
+ )
1495
+
1486
1496
1487
1497
class ValidatorTestMixin (MetaSchemaTestsMixin , object ):
1488
1498
def test_it_implements_the_validator_protocol (self ):
Original file line number Diff line number Diff line change @@ -215,9 +215,15 @@ def __attrs_post_init__(self):
215
215
)
216
216
217
217
@classmethod
218
- def check_schema (cls , schema ):
218
+ def check_schema (cls , schema , format_checker = _UNSET ):
219
219
Validator = validator_for (cls .META_SCHEMA , default = cls )
220
- for error in Validator (cls .META_SCHEMA ).iter_errors (schema ):
220
+ if format_checker is _UNSET :
221
+ format_checker = Validator .FORMAT_CHECKER
222
+ validator = Validator (
223
+ schema = cls .META_SCHEMA ,
224
+ format_checker = format_checker ,
225
+ )
226
+ for error in validator .iter_errors (schema ):
221
227
raise exceptions .SchemaError .create_from (error )
222
228
223
229
def evolve (self , ** changes ):
You can’t perform that action at this time.
0 commit comments