From 812903e7cbb58a6e020bd04e86c8fb1478870832 Mon Sep 17 00:00:00 2001 From: Juan Cruz Viotti Date: Mon, 28 Oct 2024 17:15:33 -0400 Subject: [PATCH] Fix segmentation error during validation reporting in `metaschema` See: https://github.com/sourcemeta/jsonschema/issues/182 Signed-off-by: Juan Cruz Viotti --- src/command_metaschema.cc | 2 +- test/metaschema/fail_directory.sh | 4 ++-- test/metaschema/fail_single.sh | 4 ++-- test/metaschema/pass_2020_12.sh | 7 ++++++- 4 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/command_metaschema.cc b/src/command_metaschema.cc index 9c19f43..fb6c53f 100644 --- a/src/command_metaschema.cc +++ b/src/command_metaschema.cc @@ -44,7 +44,7 @@ auto sourcemeta::jsonschema::cli::metaschema( cache.insert({dialect.value(), metaschema_template}); } - sourcemeta::blaze::ErrorTraceOutput output{metaschema}; + sourcemeta::blaze::ErrorTraceOutput output{entry.second}; if (sourcemeta::blaze::evaluate(cache.at(dialect.value()), entry.second, std::ref(output))) { log_verbose(options) diff --git a/test/metaschema/fail_directory.sh b/test/metaschema/fail_directory.sh index 599d01a..7aff7e9 100755 --- a/test/metaschema/fail_directory.sh +++ b/test/metaschema/fail_directory.sh @@ -29,13 +29,13 @@ test "$CODE" = "1" || exit 1 cat << EOF > "$TMP/expected.txt" fail: $(realpath "$TMP")/schemas/schema_2.json error: Schema validation failure - The string value "object" was expected to equal one of the following values: "array", "boolean", "integer", "null", "number", "object", and "string" + 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 value was expected to consist of an array of at least 1 item at instance location "/type" at evaluate path "/properties/type/anyOf/1/type" - The string value was expected to validate against at least one of the 2 given subschemas + 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" The object value was expected to validate against the 33 defined properties subschemas diff --git a/test/metaschema/fail_single.sh b/test/metaschema/fail_single.sh index 8125c72..f417d08 100755 --- a/test/metaschema/fail_single.sh +++ b/test/metaschema/fail_single.sh @@ -20,13 +20,13 @@ test "$CODE" = "1" || exit 1 cat << EOF > "$TMP/expected.txt" fail: $(realpath "$TMP")/schema.json error: Schema validation failure - The string value "object" was expected to equal one of the following values: "array", "boolean", "integer", "null", "number", "object", and "string" + 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 value was expected to consist of an array of at least 1 item at instance location "/type" at evaluate path "/properties/type/anyOf/1/type" - The string value was expected to validate against at least one of the 2 given subschemas + 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" The object value was expected to validate against the 33 defined properties subschemas diff --git a/test/metaschema/pass_2020_12.sh b/test/metaschema/pass_2020_12.sh index b2a93e9..c571eca 100755 --- a/test/metaschema/pass_2020_12.sh +++ b/test/metaschema/pass_2020_12.sh @@ -10,7 +10,12 @@ trap clean EXIT cat << 'EOF' > "$TMP/schema.json" { "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "string" + "type": "string", + "$defs": { + "foo": { + "type": [ "string", "null" ] + } + } } EOF