diff --git a/src/input.h b/src/input.h index fd5f3de5..3957e487 100644 --- a/src/input.h +++ b/src/input.h @@ -309,6 +309,8 @@ inline auto for_each_json(const std::vector &arguments, ? configuration.value().absolute_path : current_path, blacklist, extensions, result, options); + std::sort(result.begin(), result.end(), + [](const auto &left, const auto &right) { return left < right; }); } else { std::unordered_set seen_configurations; for (const auto &entry : arguments) { @@ -328,13 +330,14 @@ inline auto for_each_json(const std::vector &arguments, const auto extensions{parse_extensions(options, std::nullopt)}; for (const auto &entry : arguments) { + const auto before{result.size()}; handle_json_entry(entry, blacklist, extensions, result, options); + std::sort( + result.begin() + static_cast(before), result.end(), + [](const auto &left, const auto &right) { return left < right; }); } } - std::sort(result.begin(), result.end(), - [](const auto &left, const auto &right) { return left < right; }); - return result; } diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index a145842f..0c340c4a 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -110,6 +110,7 @@ add_jsonschema_test_unix(validate/fail_resolve_invalid_id) add_jsonschema_test_unix(validate/fail_resolve_invalid_recursive_ref) add_jsonschema_test_unix(validate/fail_resolve_missing_core_vocabulary) add_jsonschema_test_unix(validate/fail_resolve_relative_metaschema) +add_jsonschema_test_unix(validate/pass_resolve_custom_metaschema_ordering) add_jsonschema_test_unix(validate/pass_jsonl_bigint) add_jsonschema_test_unix(validate/fail_trace) add_jsonschema_test_unix(validate/fail_trace_fast) diff --git a/test/validate/pass_resolve_custom_metaschema_ordering.sh b/test/validate/pass_resolve_custom_metaschema_ordering.sh new file mode 100755 index 00000000..2add0be8 --- /dev/null +++ b/test/validate/pass_resolve_custom_metaschema_ordering.sh @@ -0,0 +1,56 @@ +#!/bin/sh + +set -o errexit +set -o nounset + +TMP="$(mktemp -d)" +clean() { rm -rf "$TMP"; } +trap clean EXIT + +cat << 'EOF' > "$TMP/schema.json" +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$ref": "https://example.com/my-schema" +} +EOF + +cat << 'EOF' > "$TMP/zz-meta.json" +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://example.com/my-meta", + "$vocabulary": { + "https://json-schema.org/draft/2020-12/vocab/core": true, + "https://json-schema.org/draft/2020-12/vocab/applicator": true, + "https://json-schema.org/draft/2020-12/vocab/validation": true + } +} +EOF + +cat << 'EOF' > "$TMP/aa-schema.json" +{ + "$schema": "https://example.com/my-meta", + "$id": "https://example.com/my-schema", + "type": "string" +} +EOF + +cat << 'EOF' > "$TMP/instance.json" +"hello" +EOF + +"$1" validate "$TMP/schema.json" "$TMP/instance.json" \ + --resolve "$TMP/zz-meta.json" \ + --resolve "$TMP/aa-schema.json" --debug 2>"$TMP/stderr.txt" + +cat << EOF > "$TMP/expected.txt" +debug: Detecting schema resources from file: $(realpath "$TMP")/zz-meta.json +debug: Importing schema into the resolution context: file://$(realpath "$TMP")/zz-meta.json +debug: Importing schema into the resolution context: https://example.com/my-meta +debug: Detecting schema resources from file: $(realpath "$TMP")/aa-schema.json +debug: Importing schema into the resolution context: file://$(realpath "$TMP")/aa-schema.json +debug: Importing schema into the resolution context: https://example.com/my-schema +ok: $(realpath "$TMP")/instance.json + matches $(realpath "$TMP")/schema.json +EOF + +diff "$TMP/stderr.txt" "$TMP/expected.txt"