diff --git a/src/command_validate.cc b/src/command_validate.cc index dde0fa04..634b2178 100644 --- a/src/command_validate.cc +++ b/src/command_validate.cc @@ -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, diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 9b2dd753..90bf2666 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -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) diff --git a/test/validate_fail_only_metaschema_without_option.sh b/test/validate_fail_only_metaschema_without_option.sh new file mode 100755 index 00000000..279e829d --- /dev/null +++ b/test/validate_fail_only_metaschema_without_option.sh @@ -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