File tree 4 files changed +12
-22
lines changed
4 files changed +12
-22
lines changed Original file line number Diff line number Diff line change @@ -142,7 +142,10 @@ def id(self) -> URI | None:
142
142
"""
143
143
Retrieve this resource's (specification-specific) identifier.
144
144
"""
145
- return self ._specification .id_of (self .contents )
145
+ id = self ._specification .id_of (self .contents )
146
+ if id is None :
147
+ return
148
+ return id .rstrip ("#" )
146
149
147
150
def subresources (self ) -> Iterable [Resource [D ]]:
148
151
"""
Original file line number Diff line number Diff line change @@ -36,25 +36,23 @@ class UnknownDialect(Exception):
36
36
def _dollar_id (contents : Schema ) -> URI | None :
37
37
if isinstance (contents , bool ):
38
38
return
39
- id = contents .get ("$id" )
40
- if id is not None :
41
- return id .rstrip ("#" )
39
+ return contents .get ("$id" )
42
40
43
41
44
42
def _legacy_dollar_id (contents : Schema ) -> URI | None :
45
43
if isinstance (contents , bool ) or "$ref" in contents :
46
44
return
47
45
id = contents .get ("$id" )
48
46
if id is not None and not id .startswith ("#" ):
49
- return id . rstrip ( "#" )
47
+ return id
50
48
51
49
52
50
def _legacy_id (contents : ObjectSchema ) -> URI | None :
53
51
if "$ref" in contents :
54
52
return
55
53
id = contents .get ("id" )
56
54
if id is not None and not id .startswith ("#" ):
57
- return id . rstrip ( "#" )
55
+ return id
58
56
59
57
60
58
def _anchor (
Original file line number Diff line number Diff line change @@ -610,6 +610,11 @@ def test_id_delegates_to_specification(self):
610
610
)
611
611
assert resource .id () == "urn:fixedID"
612
612
613
+ def test_id_strips_empty_fragment (self ):
614
+ uri = "http://example.com/"
615
+ root = ID_AND_CHILDREN .create_resource ({"ID" : uri + "#" })
616
+ assert root .id () == uri
617
+
613
618
def test_subresources_delegates_to_specification (self ):
614
619
resource = ID_AND_CHILDREN .create_resource ({"children" : [{}, 12 ]})
615
620
assert list (resource .subresources ()) == [
Original file line number Diff line number Diff line change @@ -65,22 +65,6 @@ def test_id_of_mapping(id, specification):
65
65
assert specification .id_of ({id : uri }) == uri
66
66
67
67
68
- @pytest .mark .parametrize (
69
- "id, specification" ,
70
- [
71
- ("$id" , referencing .jsonschema .DRAFT202012 ),
72
- ("$id" , referencing .jsonschema .DRAFT201909 ),
73
- ("$id" , referencing .jsonschema .DRAFT7 ),
74
- ("$id" , referencing .jsonschema .DRAFT6 ),
75
- ("id" , referencing .jsonschema .DRAFT4 ),
76
- ("id" , referencing .jsonschema .DRAFT3 ),
77
- ],
78
- )
79
- def test_id_of_empty_fragment (id , specification ):
80
- uri = "http://example.com/some-schema"
81
- assert specification .id_of ({id : uri + "#" }) == uri
82
-
83
-
84
68
@pytest .mark .parametrize (
85
69
"specification" ,
86
70
[
You can’t perform that action at this time.
0 commit comments