Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions src/input.h
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,8 @@ inline auto for_each_json(const std::vector<std::string_view> &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<std::string> seen_configurations;
for (const auto &entry : arguments) {
Expand All @@ -328,13 +330,14 @@ inline auto for_each_json(const std::vector<std::string_view> &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<std::ptrdiff_t>(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;
}

Expand Down
1 change: 1 addition & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
56 changes: 56 additions & 0 deletions test/validate/pass_resolve_custom_metaschema_ordering.sh
Original file line number Diff line number Diff line change
@@ -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"