Skip to content

Commit

Permalink
Support piping bundle output to a resolve directory (#98)
Browse files Browse the repository at this point in the history
Signed-off-by: Juan Cruz Viotti <[email protected]>
  • Loading branch information
jviotti authored Jun 18, 2024
1 parent 4ddb051 commit 9fd98e8
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -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));
Expand Down
1 change: 1 addition & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
44 changes: 44 additions & 0 deletions test/bundle_into_resolve_directory.sh
Original file line number Diff line number Diff line change
@@ -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"

0 comments on commit 9fd98e8

Please sign in to comment.