diff --git a/src/utils.cc b/src/utils.cc index 19cc0c28..a0534504 100644 --- a/src/utils.cc +++ b/src/utils.cc @@ -53,6 +53,10 @@ auto handle_json_entry( return prefix == canonical || path_starts_with(canonical, prefix); })) { + if (std::filesystem::is_empty(canonical)) { + continue; + } + // TODO: Print a verbose message for what is getting parsed result.emplace_back(canonical, sourcemeta::jsontoolkit::from_file(canonical)); @@ -75,6 +79,10 @@ auto handle_json_entry( return prefix == canonical || path_starts_with(canonical, prefix); })) { + if (std::filesystem::is_empty(canonical)) { + return; + } + // TODO: Print a verbose message for what is getting parsed result.emplace_back(canonical, sourcemeta::jsontoolkit::from_file(canonical)); diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index ae3945a4..252980ee 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -38,6 +38,7 @@ add_jsonschema_test_unix(validate_fail_no_schema) add_jsonschema_test_unix(validate_fail_no_instance) add_jsonschema_test_unix(validate_non_supported) add_jsonschema_test_unix(bundle_non_remote) +add_jsonschema_test_unix(bundle_into_resolve_directory) add_jsonschema_test_unix(bundle_remote_single_schema) add_jsonschema_test_unix(bundle_remote_no_http) add_jsonschema_test_unix(bundle_remote_directory) diff --git a/test/bundle_into_resolve_directory.sh b/test/bundle_into_resolve_directory.sh new file mode 100755 index 00000000..087d80fe --- /dev/null +++ b/test/bundle_into_resolve_directory.sh @@ -0,0 +1,44 @@ +#!/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", + "$id": "https://example.com", + "$ref": "nested" +} +EOF + +mkdir "$TMP/schemas" +cat << 'EOF' > "$TMP/schemas/remote.json" +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://example.com/nested", + "type": "string" +} +EOF + +"$1" bundle "$TMP/schema.json" --resolve "$TMP/schemas" > "$TMP/schemas/result.json" + +cat << 'EOF' > "$TMP/expected.json" +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://example.com", + "$ref": "nested", + "$defs": { + "https://example.com/nested": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://example.com/nested", + "type": "string" + } + } +} +EOF + +diff "$TMP/schemas/result.json" "$TMP/expected.json"