Skip to content

Commit 79daf05

Browse files
committed
Emit fully absolute URIs from jsonschema_suite remotes.
This was I believe just an oversight on my part (or I never noticed it before) -- but there's no reason a user of this should need to know the base URI is http://localhost:1234/, the whole point of the command is to just give you the URIs + schemas to configure. I don't know how many people use this command rather than reading directly off the remotes/ directory, but I do, so it's at least 1 person.
1 parent dfcea62 commit 79daf05

File tree

2 files changed

+33
-6
lines changed

2 files changed

+33
-6
lines changed

README.md

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,22 @@ If your implementation supports multiple versions, run the above procedure for e
131131

132132
1. The suite, notably in its `refRemote.json` file in each draft, expects a number of remote references to be configured.
133133
These are JSON documents, identified by URI, which are used by the suite to test the behavior of the `$ref` keyword (and related keywords).
134-
Depending on your implementation, you may configure how to "register" these either by retrieving them from the `remotes/` directory at the root of the repository, *or* you may execute `bin/jsonschema_suite remotes` using the executable in the `bin/` directory, which will output a JSON object containing all of the remotes combined.
134+
Depending on your implementation, you may configure how to "register" these either by retrieving them from the `remotes/` directory at the root of the repository, *or* you may execute `bin/jsonschema_suite remotes` using the executable in the `bin/` directory, which will output a JSON object containing all of the remotes combined, e.g.:
135+
136+
```
137+
138+
$ bin/jsonschema_suite remotes
139+
```
140+
```json
141+
{
142+
"http://localhost:1234/baseUriChange/folderInteger.json": {
143+
"type": "integer"
144+
},
145+
"http://localhost:1234/baseUriChangeFolder/folderInteger.json": {
146+
"type": "integer"
147+
}
148+
}
149+
```
135150
136151
2. Test cases found within [special subdirectories](#subdirectories-within-each-draft) may require additional configuration to run.
137152
In particular, tests within the `optional/format` subdirectory may require implementations to change the way they treat the `"format"`keyword (particularly on older drafts which did not have a notion of vocabularies).

bin/jsonschema_suite

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#! /usr/bin/env python3
22
from pathlib import Path
3+
from urllib.parse import urljoin
34
import argparse
4-
import errno
55
import json
66
import os
77
import random
@@ -30,7 +30,9 @@ else:
3030

3131
ROOT_DIR = Path(__file__).parent.parent
3232
SUITE_ROOT_DIR = ROOT_DIR / "tests"
33+
3334
REMOTES_DIR = ROOT_DIR / "remotes"
35+
REMOTES_BASE_URL = "http://localhost:1234/"
3436

3537
TESTSUITE_SCHEMA = json.loads((ROOT_DIR / "test-schema.json").read_text())
3638

@@ -68,6 +70,16 @@ def collect(root_dir):
6870
return root_dir.glob("**/*.json")
6971

7072

73+
def url_for_path(path):
74+
"""
75+
Return the assumed remote URL for a file in the remotes/ directory.
76+
77+
Tests in the refRemote.json file reference this URL, and assume the
78+
corresponding contents are available at the URL.
79+
"""
80+
return urljoin(REMOTES_BASE_URL, str(path.relative_to(REMOTES_DIR)))
81+
82+
7183
class SanityTests(unittest.TestCase):
7284
@classmethod
7385
def setUpClass(cls):
@@ -243,10 +255,10 @@ def main(arguments):
243255

244256
json.dump(selected_cases, sys.stdout, indent=4, sort_keys=True)
245257
elif arguments.command == "remotes":
246-
remotes = {}
247-
for path in collect(REMOTES_DIR):
248-
relative_path = os.path.relpath(path, REMOTES_DIR)
249-
remotes[relative_path] = json.loads(path.read_text())
258+
remotes = {
259+
url_for_path(path): json.loads(path.read_text())
260+
for path in collect(REMOTES_DIR)
261+
}
250262
json.dump(remotes, sys.stdout, indent=4, sort_keys=True)
251263
elif arguments.command == "dump_remotes":
252264
if arguments.update:

0 commit comments

Comments
 (0)