File tree Expand file tree Collapse file tree 4 files changed +12
-22
lines changed Expand file tree Collapse file tree 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:
142142 """
143143 Retrieve this resource's (specification-specific) identifier.
144144 """
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 ("#" )
146149
147150 def subresources (self ) -> Iterable [Resource [D ]]:
148151 """
Original file line number Diff line number Diff line change @@ -36,25 +36,23 @@ class UnknownDialect(Exception):
3636def _dollar_id (contents : Schema ) -> URI | None :
3737 if isinstance (contents , bool ):
3838 return
39- id = contents .get ("$id" )
40- if id is not None :
41- return id .rstrip ("#" )
39+ return contents .get ("$id" )
4240
4341
4442def _legacy_dollar_id (contents : Schema ) -> URI | None :
4543 if isinstance (contents , bool ) or "$ref" in contents :
4644 return
4745 id = contents .get ("$id" )
4846 if id is not None and not id .startswith ("#" ):
49- return id . rstrip ( "#" )
47+ return id
5048
5149
5250def _legacy_id (contents : ObjectSchema ) -> URI | None :
5351 if "$ref" in contents :
5452 return
5553 id = contents .get ("id" )
5654 if id is not None and not id .startswith ("#" ):
57- return id . rstrip ( "#" )
55+ return id
5856
5957
6058def _anchor (
Original file line number Diff line number Diff line change @@ -610,6 +610,11 @@ def test_id_delegates_to_specification(self):
610610 )
611611 assert resource .id () == "urn:fixedID"
612612
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+
613618 def test_subresources_delegates_to_specification (self ):
614619 resource = ID_AND_CHILDREN .create_resource ({"children" : [{}, 12 ]})
615620 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):
6565 assert specification .id_of ({id : uri }) == uri
6666
6767
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-
8468@pytest .mark .parametrize (
8569 "specification" ,
8670 [
You can’t perform that action at this time.
0 commit comments