Skip to content

Commit

Permalink
Support JSON Schema Draft 6 on test and validate (#70)
Browse files Browse the repository at this point in the history
Signed-off-by: Juan Cruz Viotti <[email protected]>
  • Loading branch information
jviotti authored Jun 7, 2024
1 parent 4e3d386 commit c4beb63
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 3 deletions.
2 changes: 1 addition & 1 deletion README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ schemas**, both during local development and when running on CI/CD pipelines.
>
> **Current Limitations:**
>
> - The `validate` and `test` commands only support JSON Schema Draft 4
> - The `validate` and `test` commands only support JSON Schema Draft 4 and Draft 6
> - It is not possible to collect annotations with the `validate` command
What our users are saying
Expand Down
6 changes: 4 additions & 2 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@ add_jsonschema_test_unix(format_multi_extension)
add_jsonschema_test_unix(format_check_single_fail)
add_jsonschema_test_unix(format_check_single_pass)
add_jsonschema_test_unix(frame)
add_jsonschema_test_unix(validate_pass)
add_jsonschema_test_unix(validate_fail)
add_jsonschema_test_unix(validate_pass_draft4)
add_jsonschema_test_unix(validate_fail_draft4)
add_jsonschema_test_unix(validate_pass_draft6)
add_jsonschema_test_unix(validate_fail_draft6)
add_jsonschema_test_unix(validate_fail_remote_no_http)
add_jsonschema_test_unix(validate_non_supported)
add_jsonschema_test_unix(validate_pass_with_metaschema)
Expand Down
File renamed without changes.
34 changes: 34 additions & 0 deletions test/validate_fail_draft6.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/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-06/schema#",
"type": "object",
"properties": {
"foo": {
"type": "string"
}
}
}
EOF

cat << 'EOF' > "$TMP/instance.json"
{ "foo": 1 }
EOF

"$1" validate "$TMP/schema.json" "$TMP/instance.json" && CODE="$?" || CODE="$?"

if [ "$CODE" = "0" ]
then
echo "FAIL" 1>&2
exit 1
else
echo "PASS" 1>&2
fi
File renamed without changes.
25 changes: 25 additions & 0 deletions test/validate_pass_draft6.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/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-06/schema#",
"properties": {
"foo": {
"type": "string"
}
}
}
EOF

cat << 'EOF' > "$TMP/instance.json"
{ "foo": "bar" }
EOF

"$1" validate "$TMP/schema.json" "$TMP/instance.json"

0 comments on commit c4beb63

Please sign in to comment.