Skip to content
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

Improve error message when compiling a $ref inside an unknown keyword #148

Merged
merged 1 commit into from
Aug 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion DEPENDENCIES
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
vendorpull https://github.com/sourcemeta/vendorpull dea311b5bfb53b6926a4140267959ae334d3ecf4
noa https://github.com/sourcemeta/noa 7e26abce7a4e31e86a16ef2851702a56773ca527
jsontoolkit https://github.com/sourcemeta/jsontoolkit 2b44aee9b2be18a03b375c0b1f15c7623db8b922
jsontoolkit https://github.com/sourcemeta/jsontoolkit e7a8f35b0b85cd87b5fa587b2ae767ed939a0b4d
hydra https://github.com/sourcemeta/hydra 3c53d3fdef79e9ba603d48470a508cc45472a0dc
1 change: 1 addition & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ add_jsonschema_test_unix(compile/pass_2)
add_jsonschema_test_unix(compile/fail_no_schema)
add_jsonschema_test_unix(compile/fail_schema_invalid_json)
add_jsonschema_test_unix(compile/fail_unknown_metaschema)
add_jsonschema_test_unix(compile/fail_ref_from_unknown_keyword)

# Identify
add_jsonschema_test_unix(identify/fail_resolve_from_no_match)
Expand Down
35 changes: 35 additions & 0 deletions test/compile/fail_ref_from_unknown_keyword.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/bin/sh

set -o errexit
set -o nounset

TMP="$(mktemp -d)"
clean() { rm -rf "$TMP"; }
trap clean EXIT

cat << 'EOF' > "$TMP/schema.json"
{
"$schema": "http://json-schema.org/draft-07/schema#",
"properties": {
"foo": { "$ref": "#/$defs/bar" },
"baz": { "type": "string" }
},
"$defs": {
"bar": {
"$ref": "#/properties/baz"
}
}
}
EOF

"$1" compile "$TMP/schema.json" 2>"$TMP/stderr.txt" \
&& CODE="$?" || CODE="$?"
test "$CODE" = "1" || exit 1

cat << 'EOF' > "$TMP/expected.txt"
error: The schema location is inside of an unknown keyword
#/properties/baz
at schema location "/$defs/bar/$ref"
EOF

diff "$TMP/stderr.txt" "$TMP/expected.txt"
8 changes: 7 additions & 1 deletion vendor/jsontoolkit/src/jsonschema/default_compiler_draft4.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.