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 11v4.17.0
22=======
33
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.
49* The ``jsonschema `` CLI (along with ``jsonschema.cli `` the module) are now
510 deprecated. Use ``check-jsonschema `` instead, which can be installed via
611 ``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):
14831483 else :
14841484 self .Validator .check_schema ({"enum" : [12 , 12 ]})
14851485
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+
14861496
14871497class ValidatorTestMixin (MetaSchemaTestsMixin , object ):
14881498 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):
215215 )
216216
217217 @classmethod
218- def check_schema (cls , schema ):
218+ def check_schema (cls , schema , format_checker = _UNSET ):
219219 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 ):
221227 raise exceptions .SchemaError .create_from (error )
222228
223229 def evolve (self , ** changes ):
You can’t perform that action at this time.
0 commit comments