Skip to content

Commit

Permalink
Improve error message when compiling a $ref inside an unknown keywo…
Browse files Browse the repository at this point in the history
…rd (#148)

Signed-off-by: Juan Cruz Viotti <[email protected]>
  • Loading branch information
jviotti authored Aug 13, 2024
1 parent cb66c9f commit 446a4d0
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 2 deletions.
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.

0 comments on commit 446a4d0

Please sign in to comment.