Skip to content

Commit

Permalink
Simplify indexing output a bit (#110)
Browse files Browse the repository at this point in the history
Signed-off-by: Juan Cruz Viotti <[email protected]>
  • Loading branch information
jviotti authored Jan 9, 2025
1 parent 2387175 commit 511a188
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 21 deletions.
19 changes: 8 additions & 11 deletions src/index/index.cc
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,7 @@ static auto index(sourcemeta::jsontoolkit::FlatFileSchemaResolver &resolver,
.canonicalize()};
const auto collection_base_uri_string{collection_base_uri.recompose()};

std::cerr << "-- Processing collection: " << schema_entry.first << "\n";
std::cerr << "Base directory: " << collection_path.string() << "\n";
std::cerr << "Base URI: " << collection_base_uri_string << "\n";
std::cerr << "Discovering schemas at: " << collection_path.string() << "\n";

const std::optional<std::string> default_dialect{
schema_entry.second.defines("defaultDialect")
Expand All @@ -104,7 +102,7 @@ static auto index(sourcemeta::jsontoolkit::FlatFileSchemaResolver &resolver,
continue;
}

std::cerr << "Found schema: " << entry.path().string() << "\n";
std::cerr << "-- Found schema: " << entry.path().string() << "\n";

// Calculate a default identifier for the schema through their file system
// location, to accomodate for schema collections that purely rely on
Expand All @@ -124,11 +122,11 @@ static auto index(sourcemeta::jsontoolkit::FlatFileSchemaResolver &resolver,
default_identifier.str())};
auto identifier_uri{
sourcemeta::jsontoolkit::URI{current_identifier}.canonicalize()};
std::cerr << "Current identifier: " << identifier_uri.recompose() << "\n";
std::cerr << identifier_uri.recompose();
identifier_uri.relative_to(collection_base_uri);
if (identifier_uri.is_absolute()) {
std::cout << "Cannot resolve the schema identifier against the "
"collection base\n";
std::cout << "\nerror: Cannot resolve the schema identifier against "
"the collection base\n";
return EXIT_FAILURE;
}

Expand All @@ -139,7 +137,7 @@ static auto index(sourcemeta::jsontoolkit::FlatFileSchemaResolver &resolver,
// extension, as we want to use the non-extension URI to
// potentially metadata about schemas, etc
"json")};
std::cerr << "Rebased identifier: " << new_identifier << "\n";
std::cerr << " => " << new_identifier << "\n";
resolver.reidentify(current_identifier, new_identifier);
}
}
Expand Down Expand Up @@ -219,9 +217,8 @@ static auto index_main(const std::string_view &program,
const auto configuration_path{std::filesystem::canonical(arguments[0])};
const auto output{std::filesystem::weakly_canonical(arguments[1])};

std::cerr << "-- Using configuration: " << configuration_path.string()
<< "\n";
std::cerr << "-- Writing output to: " << output.string() << "\n";
std::cerr << "Using configuration: " << configuration_path.string() << "\n";
std::cerr << "Writing output to: " << output.string() << "\n";

const auto configuration_schema{sourcemeta::jsontoolkit::parse(
std::string{sourcemeta::registry::SCHEMA_CONFIGURATION})};
Expand Down
4 changes: 2 additions & 2 deletions test/cli/common/index/invalid-configuration.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ EOF
test "$CODE" = "1" || exit 1

cat << EOF > "$TMP/expected.txt"
-- Using configuration: $(realpath "$TMP")/configuration.json
-- Writing output to: $(realpath "$TMP")/output
Using configuration: $(realpath "$TMP")/configuration.json
Writing output to: $(realpath "$TMP")/output
error: Invalid configuration
The object value was expected to define properties "port", "schemas", and "url" but did not define the property "url"
at instance location ""
Expand Down
13 changes: 5 additions & 8 deletions test/cli/common/index/invalid-schema.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,11 @@ EOF
test "$CODE" = "1" || exit 1

cat << EOF > "$TMP/expected.txt"
-- Using configuration: $(realpath "$TMP")/configuration.json
-- Writing output to: $(realpath "$TMP")/output
-- Processing collection: example/schemas
Base directory: $(realpath "$TMP")/schemas
Base URI: https://example.com/
Found schema: $(realpath "$TMP")/schemas/test.json
Current identifier: https://example.com/test.json
Rebased identifier: https://sourcemeta.com/example/schemas/test.json
Using configuration: $(realpath "$TMP")/configuration.json
Writing output to: $(realpath "$TMP")/output
Discovering schemas at: $(realpath "$TMP")/schemas
-- Found schema: $(realpath "$TMP")/schemas/test.json
https://example.com/test.json => https://sourcemeta.com/example/schemas/test.json
-- Processing schema: https://sourcemeta.com/example/schemas/test.json
Schema output: $(realpath "$TMP")/output/schemas/example/schemas/test.json
Compiling metaschema: http://json-schema.org/draft-07/schema#
Expand Down

0 comments on commit 511a188

Please sign in to comment.