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
24 changes: 13 additions & 11 deletions src/command_bundle.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "command.h"
#include "configuration.h"
#include "error.h"
#include "logger.h"
#include "resolver.h"
#include "utils.h"

Expand All @@ -35,17 +36,18 @@ auto sourcemeta::jsonschema::bundle(const sourcemeta::core::Options &options)
.recompose());

if (options.contains("without-id")) {
std::cerr << "warning: You are opting in to remove schema identifiers in "
"the bundled schema.\n";
std::cerr << "The only legit use case of this advanced feature we know of "
"is to workaround\n";
std::cerr << "non-compliant JSON Schema implementations such as Visual "
"Studio Code.\n";
std::cerr << "Otherwise, this is not needed and may harm other use "
"cases. For example,\n";
std::cerr << "you will be unable to reference the resulting schema from "
"other schemas\n";
std::cerr << "using the --resolve/-r option.\n";
sourcemeta::jsonschema::LOG_WARNING()
<< "You are opting in to remove schema identifiers in "
"the bundled schema.\n"
<< "The only legit use case of this advanced feature we know of "
"is to workaround\n"
<< "non-compliant JSON Schema implementations such as Visual "
"Studio Code.\n"
<< "Otherwise, this is not needed and may harm other use "
"cases. For example,\n"
<< "you will be unable to reference the resulting schema from "
"other schemas\n"
<< "using the --resolve/-r option.\n";
sourcemeta::core::for_editor(schema,
sourcemeta::core::schema_official_walker,
custom_resolver, dialect);
Expand Down
4 changes: 2 additions & 2 deletions src/command_lint.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ static auto disable_lint_rules(sourcemeta::core::SchemaTransformer &bundle,
sourcemeta::jsonschema::LOG_VERBOSE(options)
<< "Disabling rule: " << *iterator << "\n";
} else {
sourcemeta::jsonschema::LOG_VERBOSE(options)
<< "warning: Cannot exclude unknown rule: " << *iterator << "\n";
sourcemeta::jsonschema::LOG_WARNING()
<< "Cannot exclude unknown rule: " << *iterator << "\n";
}
}
}
Expand Down
7 changes: 4 additions & 3 deletions src/command_validate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,9 @@ auto get_schema_template(const sourcemeta::core::JSON &bundled,
if (precompiled_result.has_value()) {
return precompiled_result.value();
} else {
std::cerr << "warning: Failed to parse pre-compiled schema template. "
"Compiling from scratch\n";
sourcemeta::jsonschema::LOG_WARNING()
<< "Failed to parse pre-compiled schema template. "
"Compiling from scratch\n";
}
}

Expand Down Expand Up @@ -285,7 +286,7 @@ auto sourcemeta::jsonschema::validate(const sourcemeta::core::Options &options)
}

if (index == 0) {
LOG_VERBOSE(options) << "warning: The JSONL file is empty\n";
sourcemeta::jsonschema::LOG_WARNING() << "The JSONL file is empty\n";
}
} else {
sourcemeta::core::PointerPositionTracker tracker;
Expand Down
10 changes: 8 additions & 2 deletions src/logger.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@

#include <sourcemeta/core/options.h>

#include <fstream> // std::ofstream
#include <ostream> // std::ostream
#include <fstream> // std::ofstream
#include <iostream> // std::cerr
#include <ostream> // std::ostream

namespace sourcemeta::jsonschema {

Expand All @@ -18,6 +19,11 @@ inline auto LOG_VERBOSE(const sourcemeta::core::Options &options)
return null_stream;
}

inline auto LOG_WARNING() -> std::ostream & {
std::cerr << "warning: ";
return std::cerr;
}

} // namespace sourcemeta::jsonschema

#endif
7 changes: 3 additions & 4 deletions src/resolver.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,9 @@ class CustomResolver {
<< identifier << "\n";
});
if (!result) {
std::cerr
<< "warning: No schema resources were imported from this file\n";
std::cerr << " at " << entry.first.string() << "\n";
std::cerr << "Are you sure this schema sets any identifiers?\n";
LOG_WARNING() << "No schema resources were imported from this file\n"
<< " at " << entry.first.string() << "\n"
<< "Are you sure this schema sets any identifiers?\n";
}
}
}
Expand Down
1 change: 1 addition & 0 deletions test/validate/pass_jsonl_empty.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ touch "$TMP/instance.jsonl"
"$1" validate "$TMP/schema.json" "$TMP/instance.jsonl" 2> "$TMP/output.txt" 1>&2

cat << EOF > "$TMP/expected.txt"
warning: The JSONL file is empty
EOF

diff "$TMP/output.txt" "$TMP/expected.txt"