File tree Expand file tree Collapse file tree 2 files changed +9
-9
lines changed Expand file tree Collapse file tree 2 files changed +9
-9
lines changed Original file line number Diff line number Diff line change @@ -76,18 +76,19 @@ def test_if_a_version_is_not_provided_it_is_not_registered(self):
76
76
validators .create (meta_schema = {u"id" : "id" })
77
77
self .assertFalse (validates .called )
78
78
79
- def test_if_validates_registers_meta_schema_id (self ):
79
+ def test_validates_registers_meta_schema_id (self ):
80
80
meta_schema_key = "meta schema id"
81
81
my_meta_schema = {u"id" : meta_schema_key }
82
82
83
83
validators .create (
84
84
meta_schema = my_meta_schema ,
85
85
version = "my version" ,
86
+ id_of = lambda s : s .get ("id" , "" ),
86
87
)
87
88
88
89
self .assertIn (meta_schema_key , validators .meta_schemas )
89
90
90
- def test_if_validates_registers_meta_schema_draft6_id (self ):
91
+ def test_validates_registers_meta_schema_draft6_id (self ):
91
92
meta_schema_key = "meta schema $id"
92
93
my_meta_schema = {u"$id" : meta_schema_key }
93
94
@@ -1052,6 +1053,7 @@ def test_custom_validator(self):
1052
1053
Validator = validators .create (
1053
1054
meta_schema = {"id" : "meta schema id" },
1054
1055
version = "12" ,
1056
+ id_of = lambda s : s .get ("id" , "" ),
1055
1057
)
1056
1058
schema = {"$schema" : "meta schema id" }
1057
1059
self .assertIs (
Original file line number Diff line number Diff line change @@ -36,9 +36,7 @@ def validates(version):
36
36
Register the decorated validator for a ``version`` of the specification.
37
37
38
38
Registered validators and their meta schemas will be considered when
39
- parsing ``$schema`` properties' URIs. Meta schemas can use either
40
- ``id`` or ``$id`` depending on whether they follow pre-draft6 or draft6
41
- and later, respectively.
39
+ parsing ``$schema`` properties' URIs.
42
40
43
41
Arguments:
44
42
@@ -54,10 +52,9 @@ def validates(version):
54
52
55
53
def _validates (cls ):
56
54
validators [version ] = cls
57
- if u"id" in cls .META_SCHEMA :
58
- meta_schemas [cls .META_SCHEMA [u"id" ]] = cls
59
- elif u"$id" in cls .META_SCHEMA :
60
- 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
61
58
return cls
62
59
return _validates
63
60
@@ -208,6 +205,7 @@ class Validator(object):
208
205
VALIDATORS = dict (validators )
209
206
META_SCHEMA = dict (meta_schema )
210
207
TYPE_CHECKER = type_checker
208
+ ID_OF = staticmethod (id_of )
211
209
212
210
_DEFAULT_TYPES = dict (default_types )
213
211
You can’t perform that action at this time.
0 commit comments