-
Notifications
You must be signed in to change notification settings - Fork 27
Improve error handling on --resolve meta-schema errors
#673
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| #!/bin/sh | ||
|
|
||
| set -o errexit | ||
| set -o nounset | ||
|
|
||
| TMP="$(mktemp -d)" | ||
| clean() { rm -rf "$TMP"; } | ||
| trap clean EXIT | ||
|
|
||
| cat << 'EOF' > "$TMP/schema.json" | ||
| { | ||
| "$schema": "https://json-schema.org/draft/2020-12/schema", | ||
| "type": "object" | ||
| } | ||
| EOF | ||
|
|
||
| cat << 'EOF' > "$TMP/resolve.json" | ||
| { | ||
| "$schema": "https://json-schema.org/draft/2020-12/schema", | ||
| "$id": "not a valid uri ::", | ||
| "type": "string" | ||
| } | ||
| EOF | ||
|
|
||
| cat << 'EOF' > "$TMP/instance.json" | ||
| { "foo": "bar" } | ||
| EOF | ||
|
|
||
| "$1" validate "$TMP/schema.json" "$TMP/instance.json" \ | ||
| --resolve "$TMP/resolve.json" 2>"$TMP/stderr.txt" \ | ||
| && EXIT_CODE="$?" || EXIT_CODE="$?" | ||
| test "$EXIT_CODE" = "1" || exit 1 | ||
|
|
||
| cat << EOF > "$TMP/expected.txt" | ||
| error: The identifier is not a valid URI | ||
| at value not a valid uri :: | ||
| at keyword \$id | ||
| at file path $(realpath "$TMP")/resolve.json | ||
|
|
||
| Are you sure the input is a valid JSON Schema and it is valid according to its meta-schema? | ||
| EOF | ||
|
|
||
| diff "$TMP/stderr.txt" "$TMP/expected.txt" | ||
|
|
||
| "$1" validate "$TMP/schema.json" "$TMP/instance.json" \ | ||
| --resolve "$TMP/resolve.json" --json >"$TMP/stdout.txt" \ | ||
| && EXIT_CODE="$?" || EXIT_CODE="$?" | ||
| test "$EXIT_CODE" = "1" || exit 1 | ||
|
|
||
| cat << EOF > "$TMP/expected.txt" | ||
| { | ||
| "error": "The identifier is not a valid URI", | ||
| "value": "not a valid uri ::", | ||
| "keyword": "\$id", | ||
| "filePath": "$(realpath "$TMP")/resolve.json" | ||
| } | ||
| EOF | ||
|
|
||
| diff "$TMP/stdout.txt" "$TMP/expected.txt" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| #!/bin/sh | ||
|
|
||
| set -o errexit | ||
| set -o nounset | ||
|
|
||
| TMP="$(mktemp -d)" | ||
| clean() { rm -rf "$TMP"; } | ||
| trap clean EXIT | ||
|
|
||
| cat << 'EOF' > "$TMP/schema.json" | ||
| { | ||
| "$schema": "https://json-schema.org/draft/2020-12/schema", | ||
| "type": "object" | ||
| } | ||
| EOF | ||
|
|
||
| cat << 'EOF' > "$TMP/resolve.json" | ||
| { | ||
| "$schema": "https://json-schema.org/draft/2019-09/schema", | ||
| "$id": "https://example.com/bad-recref", | ||
| "$recursiveRef": "not-hash" | ||
| } | ||
| EOF | ||
|
|
||
| cat << 'EOF' > "$TMP/instance.json" | ||
| { "foo": "bar" } | ||
| EOF | ||
|
|
||
| "$1" validate "$TMP/schema.json" "$TMP/instance.json" \ | ||
| --resolve "$TMP/resolve.json" 2>"$TMP/stderr.txt" \ | ||
| && EXIT_CODE="$?" || EXIT_CODE="$?" | ||
| test "$EXIT_CODE" = "1" || exit 1 | ||
|
|
||
| cat << EOF > "$TMP/expected.txt" | ||
| error: Invalid recursive reference | ||
| at identifier https://example.com/bad-recref | ||
| at file path $(realpath "$TMP")/resolve.json | ||
| at location "/\$recursiveRef" | ||
| EOF | ||
|
|
||
| diff "$TMP/stderr.txt" "$TMP/expected.txt" | ||
|
|
||
| "$1" validate "$TMP/schema.json" "$TMP/instance.json" \ | ||
| --resolve "$TMP/resolve.json" --json >"$TMP/stdout.txt" \ | ||
| && EXIT_CODE="$?" || EXIT_CODE="$?" | ||
| test "$EXIT_CODE" = "1" || exit 1 | ||
|
|
||
| cat << EOF > "$TMP/expected.txt" | ||
| { | ||
| "error": "Invalid recursive reference", | ||
| "identifier": "https://example.com/bad-recref", | ||
| "filePath": "$(realpath "$TMP")/resolve.json", | ||
| "location": "/\$recursiveRef" | ||
| } | ||
| EOF | ||
|
|
||
| diff "$TMP/stdout.txt" "$TMP/expected.txt" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| #!/bin/sh | ||
|
|
||
| set -o errexit | ||
| set -o nounset | ||
|
|
||
| TMP="$(mktemp -d)" | ||
| clean() { rm -rf "$TMP"; } | ||
| trap clean EXIT | ||
|
|
||
| cat << 'EOF' > "$TMP/schema.json" | ||
| { | ||
| "$schema": "https://json-schema.org/draft/2020-12/schema", | ||
| "type": "object" | ||
| } | ||
| EOF | ||
|
|
||
| cat << 'EOF' > "$TMP/meta.json" | ||
| { | ||
| "$schema": "https://json-schema.org/draft/2020-12/schema", | ||
| "$id": "https://example.com/my-meta", | ||
| "$vocabulary": { | ||
| "https://example.com/fake-vocab": true | ||
| } | ||
| } | ||
| EOF | ||
|
|
||
| cat << 'EOF' > "$TMP/resolve.json" | ||
| { | ||
| "$schema": "https://example.com/my-meta", | ||
| "$id": "https://example.com/my-schema", | ||
| "type": "string" | ||
| } | ||
| EOF | ||
|
|
||
| cat << 'EOF' > "$TMP/instance.json" | ||
| { "foo": "bar" } | ||
| EOF | ||
|
|
||
| "$1" validate "$TMP/schema.json" "$TMP/instance.json" \ | ||
| --resolve "$TMP/meta.json" --resolve "$TMP/resolve.json" 2>"$TMP/stderr.txt" \ | ||
| && EXIT_CODE="$?" || EXIT_CODE="$?" | ||
| test "$EXIT_CODE" = "1" || exit 1 | ||
|
|
||
| cat << EOF > "$TMP/expected.txt" | ||
| error: The core vocabulary must always be present | ||
| at file path $(realpath "$TMP")/resolve.json | ||
| EOF | ||
|
|
||
| diff "$TMP/stderr.txt" "$TMP/expected.txt" | ||
|
|
||
| "$1" validate "$TMP/schema.json" "$TMP/instance.json" \ | ||
| --resolve "$TMP/meta.json" --resolve "$TMP/resolve.json" --json >"$TMP/stdout.txt" \ | ||
| && EXIT_CODE="$?" || EXIT_CODE="$?" | ||
| test "$EXIT_CODE" = "1" || exit 1 | ||
|
|
||
| cat << EOF > "$TMP/expected.txt" | ||
| { | ||
| "error": "The core vocabulary must always be present", | ||
| "filePath": "$(realpath "$TMP")/resolve.json" | ||
| } | ||
| EOF | ||
|
|
||
| diff "$TMP/stdout.txt" "$TMP/expected.txt" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| #!/bin/sh | ||
|
|
||
| set -o errexit | ||
| set -o nounset | ||
|
|
||
| TMP="$(mktemp -d)" | ||
| clean() { rm -rf "$TMP"; } | ||
| trap clean EXIT | ||
|
|
||
| cat << 'EOF' > "$TMP/schema.json" | ||
| { | ||
| "$schema": "https://json-schema.org/draft/2020-12/schema", | ||
| "type": "object" | ||
| } | ||
| EOF | ||
|
|
||
| cat << 'EOF' > "$TMP/resolve.json" | ||
| { | ||
| "$schema": "relative/path", | ||
| "$id": "https://example.com/relative-test", | ||
| "type": "string" | ||
| } | ||
| EOF | ||
|
|
||
| cat << 'EOF' > "$TMP/instance.json" | ||
| { "foo": "bar" } | ||
| EOF | ||
|
|
||
| "$1" validate "$TMP/schema.json" "$TMP/instance.json" \ | ||
| --resolve "$TMP/resolve.json" 2>"$TMP/stderr.txt" \ | ||
| && EXIT_CODE="$?" || EXIT_CODE="$?" | ||
| test "$EXIT_CODE" = "1" || exit 1 | ||
|
|
||
| cat << EOF > "$TMP/expected.txt" | ||
| error: Relative meta-schema URIs are not valid according to the JSON Schema specification | ||
| at identifier relative/path | ||
| at file path $(realpath "$TMP")/resolve.json | ||
| EOF | ||
|
|
||
| diff "$TMP/stderr.txt" "$TMP/expected.txt" | ||
|
|
||
| "$1" validate "$TMP/schema.json" "$TMP/instance.json" \ | ||
| --resolve "$TMP/resolve.json" --json >"$TMP/stdout.txt" \ | ||
| && EXIT_CODE="$?" || EXIT_CODE="$?" | ||
| test "$EXIT_CODE" = "1" || exit 1 | ||
|
|
||
| cat << EOF > "$TMP/expected.txt" | ||
| { | ||
| "error": "Relative meta-schema URIs are not valid according to the JSON Schema specification", | ||
| "identifier": "relative/path", | ||
| "filePath": "$(realpath "$TMP")/resolve.json" | ||
| } | ||
| EOF | ||
|
|
||
| diff "$TMP/stdout.txt" "$TMP/expected.txt" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| #!/bin/sh | ||
|
|
||
| set -o errexit | ||
| set -o nounset | ||
|
|
||
| TMP="$(mktemp -d)" | ||
| clean() { rm -rf "$TMP"; } | ||
| trap clean EXIT | ||
|
|
||
| cat << 'EOF' > "$TMP/schema.json" | ||
| { | ||
| "$schema": "https://json-schema.org/draft/2020-12/schema", | ||
| "type": "object" | ||
| } | ||
| EOF | ||
|
|
||
| cat << 'EOF' > "$TMP/resolve.json" | ||
| { | ||
| "$schema": "https://example.com/unknown-metaschema", | ||
| "$id": "https://example.com/resolve", | ||
| "type": "string" | ||
| } | ||
| EOF | ||
|
|
||
| cat << 'EOF' > "$TMP/instance.json" | ||
| { "foo": "bar" } | ||
| EOF | ||
|
|
||
| "$1" validate "$TMP/schema.json" "$TMP/instance.json" \ | ||
| --resolve "$TMP/resolve.json" 2>"$TMP/stderr.txt" \ | ||
| && EXIT_CODE="$?" || EXIT_CODE="$?" | ||
| test "$EXIT_CODE" = "1" || exit 1 | ||
|
|
||
| cat << EOF > "$TMP/expected.txt" | ||
| error: Could not resolve the metaschema of the schema | ||
| at identifier https://example.com/unknown-metaschema | ||
| at file path $(realpath "$TMP")/resolve.json | ||
|
|
||
| This is likely because you forgot to import such schema using \`--resolve/-r\` | ||
| EOF | ||
|
|
||
| diff "$TMP/stderr.txt" "$TMP/expected.txt" | ||
|
|
||
| "$1" validate "$TMP/schema.json" "$TMP/instance.json" \ | ||
| --resolve "$TMP/resolve.json" --json >"$TMP/stdout.txt" \ | ||
| && EXIT_CODE="$?" || EXIT_CODE="$?" | ||
| test "$EXIT_CODE" = "1" || exit 1 | ||
|
|
||
| cat << EOF > "$TMP/expected.txt" | ||
| { | ||
| "error": "Could not resolve the metaschema of the schema", | ||
| "identifier": "https://example.com/unknown-metaschema", | ||
| "filePath": "$(realpath "$TMP")/resolve.json" | ||
| } | ||
| EOF | ||
|
|
||
| diff "$TMP/stdout.txt" "$TMP/expected.txt" |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.