File tree Expand file tree Collapse file tree 3 files changed +30
-1
lines changed Expand file tree Collapse file tree 3 files changed +30
-1
lines changed Original file line number Diff line number Diff line change 22Changelog
33=========
44
5+ v0.26.2
6+ -------
7+
8+ * Also suggest a proper JSON Pointer for users who accidentally use ``#/ `` and intend to refer to the entire resource.
9+
510v0.26.1
611-------
712
Original file line number Diff line number Diff line change @@ -91,7 +91,14 @@ class PointerToNowhere(Unresolvable):
9191 resource : Resource [Any ]
9292
9393 def __str__ (self ):
94- return f"{ self .ref !r} does not exist within { self .resource .contents !r} "
94+ msg = f"{ self .ref !r} does not exist within { self .resource .contents !r} "
95+ if self .ref == "/" :
96+ msg += (
97+ ". The pointer '/' is a valid JSON Pointer but it points to "
98+ "an empty string property ''. If you intended to point "
99+ "to the entire resource, you should use '#'."
100+ )
101+ return msg
95102
96103
97104@frozen
Original file line number Diff line number Diff line change @@ -723,6 +723,23 @@ def test_lookup_non_existent_pointer_to_array_index(self):
723723 resource = resource ,
724724 )
725725
726+ def test_lookup_pointer_to_empty_string (self ):
727+ resolver = Registry ().resolver_with_root (Resource .opaque ({"" : {}}))
728+ assert resolver .lookup ("#/" ).contents == {}
729+
730+ def test_lookup_non_existent_pointer_to_empty_string (self ):
731+ resource = Resource .opaque ({"foo" : {}})
732+ resolver = Registry ().resolver_with_root (resource )
733+ with pytest .raises (
734+ exceptions .Unresolvable ,
735+ match = "^'/' does not exist within {'foo': {}}.*'#'" ,
736+ ) as e :
737+ resolver .lookup ("#/" )
738+ assert e .value == exceptions .PointerToNowhere (
739+ ref = "/" ,
740+ resource = resource ,
741+ )
742+
726743 def test_lookup_non_existent_anchor (self ):
727744 root = ID_AND_CHILDREN .create_resource ({"anchors" : {}})
728745 resolver = Registry ().with_resource ("urn:example" , root ).resolver ()
You can’t perform that action at this time.
0 commit comments