Skip to content

Fix #95, array indexes in json reference fragments now work #97

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions jsonschema.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@
import textwrap

try:
from collections import MutableMapping
from collections import MutableMapping, Sequence
except ImportError:
from collections.abc import MutableMapping
from collections.abc import MutableMapping, Sequence

try:
import requests
Expand Down Expand Up @@ -1191,13 +1191,19 @@ def resolve_fragment(self, document, fragment):
for part in parts:
part = part.replace("~1", "/").replace("~0", "~")

if part not in document:
if isinstance(document, Sequence):
# Array indexes should be turned into integers
try:
part = int(part)
except ValueError:
pass
try:
document = document[part]
except (TypeError, LookupError):
raise RefResolutionError(
"Unresolvable JSON pointer: %r" % fragment
)

document = document[part]

return document

def resolve_remote(self, uri):
Expand Down
4 changes: 4 additions & 0 deletions tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@ def add_test_methods(test_class):
re.sub(r"[\W ]+", "_", test["description"]),
)

# Make sure method name is unique
while hasattr(test_class, test_name):
test_name += 'I'

if not PY3:
test_name = test_name.encode("utf-8")
a_test.__name__ = test_name
Expand Down