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 traces when involving anyOf #258

Merged
merged 1 commit into from
Mar 17, 2025
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
Expand Up @@ -2,4 +2,4 @@ vendorpull https://github.com/sourcemeta/vendorpull dea311b5bfb53b6926a414026795
core https://github.com/sourcemeta/core 64063dc926a074dd9b7add8478d891dd39a8fc9f
hydra https://github.com/sourcemeta/hydra a67b879df800e834ed8a2d056f98398f7211d870
jsonbinpack https://github.com/sourcemeta/jsonbinpack c7bb7f4d903c3b6925b62ce2bb5b8d360e01ce84
blaze https://github.com/sourcemeta/blaze 3e6b69ab55ed85edfde5d0a05d990a9524c5877f
blaze https://github.com/sourcemeta/blaze a453075f2013ea8fc27d0dded1da6521dbc8474e
1 change: 1 addition & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ add_jsonschema_test_unix(test/fail_not_object)
add_jsonschema_test_unix(test/fail_no_schema)
add_jsonschema_test_unix(test/fail_schema_non_string)
add_jsonschema_test_unix(test/fail_no_tests)
add_jsonschema_test_unix(test/fail_anyof)
add_jsonschema_test_unix(test/fail_tests_non_array)
add_jsonschema_test_unix(test/fail_test_case_non_object)
add_jsonschema_test_unix(test/fail_test_case_no_data)
Expand Down
9 changes: 0 additions & 9 deletions test/metaschema/fail_directory.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,6 @@ test "$CODE" = "2" || exit 1
cat << EOF > "$TMP/expected.txt"
fail: $(realpath "$TMP")/schemas/schema_2.json
error: Schema validation failure
The integer value 1 was expected to equal one of the following values: "array", "boolean", "integer", "null", "number", "object", and "string"
at instance location "/type"
at evaluate path "/properties/type/anyOf/0/\$ref/enum"
The integer value was expected to validate against the statically referenced schema
at instance location "/type"
at evaluate path "/properties/type/anyOf/0/\$ref"
The value was expected to be of type array but it was of type integer
at instance location "/type"
at evaluate path "/properties/type/anyOf/1/type"
The integer value was expected to validate against at least one of the 2 given subschemas
at instance location "/type"
at evaluate path "/properties/type/anyOf"
Expand Down
9 changes: 0 additions & 9 deletions test/metaschema/fail_single.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,6 @@ test "$CODE" = "2" || exit 1
cat << EOF > "$TMP/expected.txt"
fail: $(realpath "$TMP")/schema.json
error: Schema validation failure
The integer value 1 was expected to equal one of the following values: "array", "boolean", "integer", "null", "number", "object", and "string"
at instance location "/type"
at evaluate path "/properties/type/anyOf/0/\$ref/enum"
The integer value was expected to validate against the statically referenced schema
at instance location "/type"
at evaluate path "/properties/type/anyOf/0/\$ref"
The value was expected to be of type array but it was of type integer
at instance location "/type"
at evaluate path "/properties/type/anyOf/1/type"
The integer value was expected to validate against at least one of the 2 given subschemas
at instance location "/type"
at evaluate path "/properties/type/anyOf"
Expand Down
9 changes: 0 additions & 9 deletions test/metaschema/fail_yaml.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,6 @@ test "$CODE" = "2" || exit 1
cat << EOF > "$TMP/expected.txt"
fail: $(realpath "$TMP")/schema.yaml
error: Schema validation failure
The integer value 1 was expected to equal one of the following values: "array", "boolean", "integer", "null", "number", "object", and "string"
at instance location "/type"
at evaluate path "/properties/type/anyOf/0/\$ref/enum"
The integer value was expected to validate against the statically referenced schema
at instance location "/type"
at evaluate path "/properties/type/anyOf/0/\$ref"
The value was expected to be of type array but it was of type integer
at instance location "/type"
at evaluate path "/properties/type/anyOf/1/type"
The integer value was expected to validate against at least one of the 2 given subschemas
at instance location "/type"
at evaluate path "/properties/type/anyOf"
Expand Down
56 changes: 56 additions & 0 deletions test/test/fail_anyof.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#!/bin/sh

set -o errexit
set -o nounset

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

cat << 'EOF' > "$TMP/schema.json"
{
"id": "https://example.com",
"$schema": "http://json-schema.org/draft-04/schema#",
"allOf": [
{
"anyOf": [
{ "required": [ "foo" ] },
{ "required": [ "bar" ] }
]
},
{
"type": "integer"
}
]
}
EOF

cat << 'EOF' > "$TMP/test.json"
{
"target": "https://example.com",
"tests": [
{
"valid": true,
"data": { "bar": 1 }
}
]
}
EOF

"$1" test "$TMP/test.json" --resolve "$TMP/schema.json" 1> "$TMP/output.txt" 2>&1 \
&& CODE="$?" || CODE="$?"
test "$CODE" = "1" || exit 1

cat "$TMP/output.txt"

cat << EOF > "$TMP/expected.txt"
$(realpath "$TMP")/test.json:
1/1 FAIL <no description>

error: Schema validation failure
The value was expected to be of type integer but it was of type object
at instance location ""
at evaluate path "/allOf/1/type"
EOF

diff "$TMP/output.txt" "$TMP/expected.txt"
3 changes: 2 additions & 1 deletion vendor/blaze/src/compiler/compile_output_error.cc

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