summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulian Berman <Julian@GrayVines.com>2022-08-17 14:09:27 +0300
committerJulian Berman <Julian@GrayVines.com>2022-08-17 14:09:27 +0300
commita65806d59069c7e4295b9143ff1d232a67747c21 (patch)
tree83fa5ec3678c3f8d9f7b5840428110ee921d3235
parent263d4ee47cf72eecc932684b3a4e4dd1c05cb8dd (diff)
parent5d6a9931ff0d606b273c36a20bd0444a2a61ea24 (diff)
downloadjsonschema-a65806d59069c7e4295b9143ff1d232a67747c21.tar.gz
Merge commit '5d6a9931ff0d606b273c36a20bd0444a2a61ea24'
* commit '5d6a9931ff0d606b273c36a20bd0444a2a61ea24': Squashed 'json/' changes from b3c8672a3..14d05dcea
-rw-r--r--json/README.md21
-rwxr-xr-xjson/bin/jsonschema_suite22
2 files changed, 37 insertions, 6 deletions
diff --git a/json/README.md b/json/README.md
index efbed38..88b65c9 100644
--- a/json/README.md
+++ b/json/README.md
@@ -131,7 +131,26 @@ If your implementation supports multiple versions, run the above procedure for e
1. The suite, notably in its `refRemote.json` file in each draft, expects a number of remote references to be configured.
These are JSON documents, identified by URI, which are used by the suite to test the behavior of the `$ref` keyword (and related keywords).
- 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.
+ Depending on your implementation, you may configure how to "register" these *either*:
+
+ * 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`
+
+ * 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.:
+
+ ```
+
+ $ bin/jsonschema_suite remotes
+ ```
+ ```json
+ {
+ "http://localhost:1234/baseUriChange/folderInteger.json": {
+ "type": "integer"
+ },
+ "http://localhost:1234/baseUriChangeFolder/folderInteger.json": {
+ "type": "integer"
+ }
+ }
+ ```
2. Test cases found within [special subdirectories](#subdirectories-within-each-draft) may require additional configuration to run.
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).
diff --git a/json/bin/jsonschema_suite b/json/bin/jsonschema_suite
index 000103c..85642b1 100755
--- a/json/bin/jsonschema_suite
+++ b/json/bin/jsonschema_suite
@@ -1,7 +1,7 @@
#! /usr/bin/env python3
from pathlib import Path
+from urllib.parse import urljoin
import argparse
-import errno
import json
import os
import random
@@ -30,7 +30,9 @@ else:
ROOT_DIR = Path(__file__).parent.parent
SUITE_ROOT_DIR = ROOT_DIR / "tests"
+
REMOTES_DIR = ROOT_DIR / "remotes"
+REMOTES_BASE_URL = "http://localhost:1234/"
TESTSUITE_SCHEMA = json.loads((ROOT_DIR / "test-schema.json").read_text())
@@ -68,6 +70,16 @@ def collect(root_dir):
return root_dir.glob("**/*.json")
+def url_for_path(path):
+ """
+ Return the assumed remote URL for a file in the remotes/ directory.
+
+ Tests in the refRemote.json file reference this URL, and assume the
+ corresponding contents are available at the URL.
+ """
+ return urljoin(REMOTES_BASE_URL, str(path.relative_to(REMOTES_DIR)))
+
+
class SanityTests(unittest.TestCase):
@classmethod
def setUpClass(cls):
@@ -243,10 +255,10 @@ def main(arguments):
json.dump(selected_cases, sys.stdout, indent=4, sort_keys=True)
elif arguments.command == "remotes":
- remotes = {}
- for path in collect(REMOTES_DIR):
- relative_path = os.path.relpath(path, REMOTES_DIR)
- remotes[relative_path] = json.loads(path.read_text())
+ remotes = {
+ url_for_path(path): json.loads(path.read_text())
+ for path in collect(REMOTES_DIR)
+ }
json.dump(remotes, sys.stdout, indent=4, sort_keys=True)
elif arguments.command == "dump_remotes":
if arguments.update: