Skip to content

Commit

Permalink
Fix validate not checking the metaschema without -m given no inst…
Browse files Browse the repository at this point in the history
…ances (#82)

See: asyncapi/spec-json-schemas#549
Signed-off-by: Juan Cruz Viotti <jv@jviotti.com>
  • Loading branch information
jviotti committed Jun 12, 2024
1 parent 5073041 commit 37f2d54
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/command_validate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ auto intelligence::jsonschema::cli::validate(

const auto schema{sourcemeta::jsontoolkit::from_file(schema_path)};

if (options.contains("m") || options.contains("metaschema")) {
if (options.contains("m") || options.contains("metaschema") ||
options.at("").size() < 2) {
const auto metaschema_template{sourcemeta::jsontoolkit::compile(
sourcemeta::jsontoolkit::metaschema(schema, custom_resolver),
sourcemeta::jsontoolkit::default_schema_walker, custom_resolver,
Expand Down
1 change: 1 addition & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ add_jsonschema_test_unix(validate_non_supported)
add_jsonschema_test_unix(validate_pass_with_metaschema)
add_jsonschema_test_unix(validate_pass_only_metaschema)
add_jsonschema_test_unix(validate_fail_only_metaschema)
add_jsonschema_test_unix(validate_fail_only_metaschema_without_option)
add_jsonschema_test_unix(bundle_non_remote)
add_jsonschema_test_unix(bundle_remote_single_schema)
add_jsonschema_test_unix(bundle_remote_no_http)
Expand Down
29 changes: 29 additions & 0 deletions test/validate_fail_only_metaschema_without_option.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/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-04/schema#",
"properties": {
"foo": {
"type": 1
}
}
}
EOF

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

if [ "$CODE" = "0" ]
then
echo "FAIL" 1>&2
exit 1
else
echo "PASS" 1>&2
fi

0 comments on commit 37f2d54

Please sign in to comment.