|
| 1 | +#!/bin/sh |
| 2 | + |
| 3 | +set -o errexit |
| 4 | +set -o nounset |
| 5 | + |
| 6 | +TMP="$(mktemp -d)" |
| 7 | +clean() { rm -rf "$TMP"; } |
| 8 | +trap clean EXIT |
| 9 | + |
| 10 | +cat << 'EOF' > "$TMP/schema.json" |
| 11 | +{ |
| 12 | + "$schema": "https://json-schema.org/draft/2020-12/schema", |
| 13 | + "$ref": "https://example.com/my-schema" |
| 14 | +} |
| 15 | +EOF |
| 16 | + |
| 17 | +cat << 'EOF' > "$TMP/zz-meta.json" |
| 18 | +{ |
| 19 | + "$schema": "https://json-schema.org/draft/2020-12/schema", |
| 20 | + "$id": "https://example.com/my-meta", |
| 21 | + "$vocabulary": { |
| 22 | + "https://json-schema.org/draft/2020-12/vocab/core": true, |
| 23 | + "https://json-schema.org/draft/2020-12/vocab/applicator": true, |
| 24 | + "https://json-schema.org/draft/2020-12/vocab/validation": true |
| 25 | + } |
| 26 | +} |
| 27 | +EOF |
| 28 | + |
| 29 | +cat << 'EOF' > "$TMP/aa-schema.json" |
| 30 | +{ |
| 31 | + "$schema": "https://example.com/my-meta", |
| 32 | + "$id": "https://example.com/my-schema", |
| 33 | + "type": "string" |
| 34 | +} |
| 35 | +EOF |
| 36 | + |
| 37 | +cat << 'EOF' > "$TMP/instance.json" |
| 38 | +"hello" |
| 39 | +EOF |
| 40 | + |
| 41 | +"$1" validate "$TMP/schema.json" "$TMP/instance.json" \ |
| 42 | + --resolve "$TMP/zz-meta.json" \ |
| 43 | + --resolve "$TMP/aa-schema.json" --debug 2>"$TMP/stderr.txt" |
| 44 | + |
| 45 | +cat << EOF > "$TMP/expected.txt" |
| 46 | +debug: Detecting schema resources from file: $(realpath "$TMP")/zz-meta.json |
| 47 | +debug: Importing schema into the resolution context: file://$(realpath "$TMP")/zz-meta.json |
| 48 | +debug: Importing schema into the resolution context: https://example.com/my-meta |
| 49 | +debug: Detecting schema resources from file: $(realpath "$TMP")/aa-schema.json |
| 50 | +debug: Importing schema into the resolution context: file://$(realpath "$TMP")/aa-schema.json |
| 51 | +debug: Importing schema into the resolution context: https://example.com/my-schema |
| 52 | +ok: $(realpath "$TMP")/instance.json |
| 53 | + matches $(realpath "$TMP")/schema.json |
| 54 | +EOF |
| 55 | + |
| 56 | +diff "$TMP/stderr.txt" "$TMP/expected.txt" |
0 commit comments