Skip to content

Commit 9a4b90d

Browse files
committed
[WIP] Improve error traces when involving anyOf
Signed-off-by: Juan Cruz Viotti <jv@jviotti.com>
1 parent 3fb1b68 commit 9a4b90d

File tree

2 files changed

+57
-0
lines changed

2 files changed

+57
-0
lines changed

test/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ add_jsonschema_test_unix(test/fail_not_object)
116116
add_jsonschema_test_unix(test/fail_no_schema)
117117
add_jsonschema_test_unix(test/fail_schema_non_string)
118118
add_jsonschema_test_unix(test/fail_no_tests)
119+
add_jsonschema_test_unix(test/fail_anyof)
119120
add_jsonschema_test_unix(test/fail_tests_non_array)
120121
add_jsonschema_test_unix(test/fail_test_case_non_object)
121122
add_jsonschema_test_unix(test/fail_test_case_no_data)

test/test/fail_anyof.sh

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
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+
"id": "https://example.com",
13+
"$schema": "http://json-schema.org/draft-04/schema#",
14+
"allOf": [
15+
{
16+
"anyOf": [
17+
{ "required": [ "foo" ] },
18+
{ "required": [ "bar" ] }
19+
]
20+
},
21+
{
22+
"type": "integer"
23+
}
24+
]
25+
}
26+
EOF
27+
28+
cat << 'EOF' > "$TMP/test.json"
29+
{
30+
"target": "https://example.com",
31+
"tests": [
32+
{
33+
"valid": true,
34+
"data": { "bar": 1 }
35+
}
36+
]
37+
}
38+
EOF
39+
40+
"$1" test "$TMP/test.json" --resolve "$TMP/schema.json" 1> "$TMP/output.txt" 2>&1 \
41+
&& CODE="$?" || CODE="$?"
42+
test "$CODE" = "1" || exit 1
43+
44+
cat "$TMP/output.txt"
45+
46+
cat << EOF > "$TMP/expected.txt"
47+
$(realpath "$TMP")/test.json:
48+
1/1 FAIL <no description>
49+
50+
error: Schema validation failure
51+
The value was expected to be of type integer but it was of type object
52+
at instance location ""
53+
at evaluate path "/allOf/1/type"
54+
EOF
55+
56+
diff "$TMP/output.txt" "$TMP/expected.txt"

0 commit comments

Comments
 (0)