File tree 3 files changed +30
-1
lines changed
3 files changed +30
-1
lines changed Original file line number Diff line number Diff line change 2
2
Changelog
3
3
=========
4
4
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
+
5
10
v0.26.1
6
11
-------
7
12
Original file line number Diff line number Diff line change @@ -91,7 +91,14 @@ class PointerToNowhere(Unresolvable):
91
91
resource : Resource [Any ]
92
92
93
93
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
95
102
96
103
97
104
@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):
723
723
resource = resource ,
724
724
)
725
725
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
+
726
743
def test_lookup_non_existent_anchor (self ):
727
744
root = ID_AND_CHILDREN .create_resource ({"anchors" : {}})
728
745
resolver = Registry ().with_resource ("urn:example" , root ).resolver ()
You can’t perform that action at this time.
0 commit comments