Skip to content

Commit 14d05dc

Browse files
authored
Merge pull request #585 from json-schema-org/absolute-uri
Emit fully absolute URIs from `jsonschema_suite remotes`.
2 parents b3c8672 + b643e11 commit 14d05dc

File tree

2 files changed

+37
-6
lines changed

2 files changed

+37
-6
lines changed

README.md

+20-1
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,26 @@ 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*:
135+
136+
* by directly retrieving them off the filesystem from the `remotes/` directory, in which case you should load each schema with a retrieval URI of `http://localhost:1234` followed by the relative path from the remotes directory -- e.g. a `$ref` to `http://localhost:1234/foo/bar/baz.json` is expected to resolve to the contents of the file at `remotes/foo/bar/baz.json`
137+
138+
* or alternatively, by executing `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.:
139+
140+
```
141+
142+
$ bin/jsonschema_suite remotes
143+
```
144+
```json
145+
{
146+
"http://localhost:1234/baseUriChange/folderInteger.json": {
147+
"type": "integer"
148+
},
149+
"http://localhost:1234/baseUriChangeFolder/folderInteger.json": {
150+
"type": "integer"
151+
}
152+
}
153+
```
135154
136155
2. Test cases found within [special subdirectories](#subdirectories-within-each-draft) may require additional configuration to run.
137156
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

+17-5
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)