Skip to content

Commit d98ab06

Browse files
gazpachokingJulian
authored andcommitted
Fix #95, array indexes in json reference fragments now work
1 parent 6fde6a2 commit d98ab06

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

jsonschema.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@
2525
import textwrap
2626

2727
try:
28-
from collections import MutableMapping
28+
from collections import MutableMapping, Sequence
2929
except ImportError:
30-
from collections.abc import MutableMapping
30+
from collections.abc import MutableMapping, Sequence
3131

3232
try:
3333
import requests
@@ -1191,13 +1191,19 @@ def resolve_fragment(self, document, fragment):
11911191
for part in parts:
11921192
part = part.replace("~1", "/").replace("~0", "~")
11931193

1194-
if part not in document:
1194+
if isinstance(document, Sequence):
1195+
# Array indexes should be turned into integers
1196+
try:
1197+
part = int(part)
1198+
except ValueError:
1199+
pass
1200+
try:
1201+
document = document[part]
1202+
except (TypeError, LookupError):
11951203
raise RefResolutionError(
11961204
"Unresolvable JSON pointer: %r" % fragment
11971205
)
11981206

1199-
document = document[part]
1200-
12011207
return document
12021208

12031209
def resolve_remote(self, uri):

0 commit comments

Comments
 (0)