Skip to content

Commit 7a8634e

Browse files
committed
Fix bug in current registration of validators
1 parent 9632422 commit 7a8634e

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

jsonschema/tests/test_validators.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1030,6 +1030,7 @@ def test_custom_validator(self):
10301030
Validator = validators.create(
10311031
meta_schema={"id": "meta schema id"},
10321032
version="12",
1033+
id_of=lambda s: s.get("id", ""),
10331034
)
10341035
schema = {"$schema": "meta schema id"}
10351036
self.assertIs(

jsonschema/validators.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,9 @@ def validates(version):
5252

5353
def _validates(cls):
5454
validators[version] = cls
55-
if u"id" in cls.META_SCHEMA:
56-
meta_schemas[cls.META_SCHEMA[u"id"]] = cls
55+
meta_schema_id = cls.ID_OF(cls.META_SCHEMA)
56+
if meta_schema_id:
57+
meta_schemas[meta_schema_id] = cls
5758
return cls
5859
return _validates
5960

@@ -204,6 +205,7 @@ class Validator(object):
204205
VALIDATORS = dict(validators)
205206
META_SCHEMA = dict(meta_schema)
206207
TYPE_CHECKER = type_checker
208+
ID_OF = staticmethod(id_of)
207209

208210
_DEFAULT_TYPES = dict(default_types)
209211

0 commit comments

Comments
 (0)