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
2 changes: 1 addition & 1 deletion DEPENDENCIES
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
vendorpull https://github.com/sourcemeta/vendorpull 1dcbac42809cf87cb5b045106b863e17ad84ba02
core https://github.com/sourcemeta/core 8b34af868820407091f108486798b4c73dec6631
core https://github.com/sourcemeta/core eababe4f4a967bfa546146c8531b8668913a3880
jsonbinpack https://github.com/sourcemeta/jsonbinpack abd40e41050d14d74af1fddb5c397de5cca3b13c
blaze https://github.com/sourcemeta/blaze bfdc479b5ae0c17a356be5f42dcc713ab31f976a
hydra https://github.com/sourcemeta/hydra af9f2c54709d620872ead0c3f8f683c15a0fa702
72 changes: 46 additions & 26 deletions src/command_bundle.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,36 +25,56 @@ auto sourcemeta::jsonschema::bundle(const sourcemeta::core::Options &options)
const auto configuration_path{find_configuration(schema_path)};
const auto &configuration{read_configuration(options, configuration_path)};
const auto dialect{default_dialect(options, configuration)};
const auto &custom_resolver{
resolver(options, options.contains("http"), dialect, configuration)};
auto schema{sourcemeta::core::read_yaml_or_json(schema_path)};

sourcemeta::core::bundle(schema, sourcemeta::core::schema_official_walker,
custom_resolver, dialect,
sourcemeta::core::URI::from_path(
sourcemeta::core::weakly_canonical(schema_path))
.recompose());

if (options.contains("without-id")) {
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);
try {
const auto &custom_resolver{
resolver(options, options.contains("http"), dialect, configuration)};
sourcemeta::core::bundle(
schema, sourcemeta::core::schema_official_walker, custom_resolver,
dialect,
sourcemeta::core::URI::from_path(
sourcemeta::core::weakly_canonical(schema_path))
.recompose());

if (options.contains("without-id")) {
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);
}

sourcemeta::core::format(schema, sourcemeta::core::schema_official_walker,
custom_resolver, dialect);
} catch (const sourcemeta::core::SchemaReferenceError &error) {
throw FileError<sourcemeta::core::SchemaReferenceError>(
schema_path, std::string{error.identifier()}, error.location(),
error.what());
} catch (
const sourcemeta::core::SchemaRelativeMetaschemaResolutionError &error) {
throw FileError<sourcemeta::core::SchemaRelativeMetaschemaResolutionError>(
schema_path, error);
} catch (const sourcemeta::core::SchemaResolutionError &error) {
throw FileError<sourcemeta::core::SchemaResolutionError>(schema_path,
error);
} catch (const sourcemeta::core::SchemaUnknownBaseDialectError &) {
throw FileError<sourcemeta::core::SchemaUnknownBaseDialectError>(
schema_path);
} catch (const sourcemeta::core::SchemaError &error) {
throw FileError<sourcemeta::core::SchemaError>(schema_path, error.what());
}

sourcemeta::core::format(schema, sourcemeta::core::schema_official_walker,
custom_resolver, dialect);
sourcemeta::core::prettify(schema, std::cout);
std::cout << "\n";
}
38 changes: 27 additions & 11 deletions src/command_compile.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ auto sourcemeta::jsonschema::compile(const sourcemeta::core::Options &options)
const auto configuration_path{find_configuration(schema_path)};
const auto &configuration{read_configuration(options, configuration_path)};
const auto dialect{default_dialect(options, configuration)};
const auto &custom_resolver{
resolver(options, options.contains("http"), dialect, configuration)};

const auto schema{sourcemeta::core::read_yaml_or_json(schema_path)};

Expand All @@ -34,15 +32,33 @@ auto sourcemeta::jsonschema::compile(const sourcemeta::core::Options &options)
}

const auto fast_mode{options.contains("fast")};
const auto schema_template{sourcemeta::blaze::compile(
schema, sourcemeta::core::schema_official_walker, custom_resolver,
sourcemeta::blaze::default_schema_compiler,
fast_mode ? sourcemeta::blaze::Mode::FastValidation
: sourcemeta::blaze::Mode::Exhaustive,
dialect,
sourcemeta::core::URI::from_path(
sourcemeta::core::weakly_canonical(schema_path))
.recompose())};

sourcemeta::blaze::Template schema_template;
try {
const auto &custom_resolver{
resolver(options, options.contains("http"), dialect, configuration)};
schema_template = sourcemeta::blaze::compile(
schema, sourcemeta::core::schema_official_walker, custom_resolver,
sourcemeta::blaze::default_schema_compiler,
fast_mode ? sourcemeta::blaze::Mode::FastValidation
: sourcemeta::blaze::Mode::Exhaustive,
dialect,
sourcemeta::core::URI::from_path(
sourcemeta::core::weakly_canonical(schema_path))
.recompose());
} catch (
const sourcemeta::core::SchemaRelativeMetaschemaResolutionError &error) {
throw FileError<sourcemeta::core::SchemaRelativeMetaschemaResolutionError>(
schema_path, error);
} catch (const sourcemeta::core::SchemaResolutionError &error) {
throw FileError<sourcemeta::core::SchemaResolutionError>(schema_path,
error);
} catch (const sourcemeta::core::SchemaUnknownBaseDialectError &) {
throw FileError<sourcemeta::core::SchemaUnknownBaseDialectError>(
schema_path);
} catch (const sourcemeta::core::SchemaError &error) {
throw FileError<sourcemeta::core::SchemaError>(schema_path, error.what());
}

const auto template_json{sourcemeta::blaze::to_json(schema_template)};
if (options.contains("minify")) {
Expand Down
78 changes: 47 additions & 31 deletions src/command_fmt.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,42 +33,58 @@ auto sourcemeta::jsonschema::fmt(const sourcemeta::core::Options &options)
LOG_VERBOSE(options) << "Formatting: " << entry.first.string() << "\n";
}

const auto configuration_path{find_configuration(entry.first)};
const auto &configuration{read_configuration(options, configuration_path)};
const auto dialect{default_dialect(options, configuration)};
const auto &custom_resolver{
resolver(options, options.contains("http"), dialect, configuration)};
try {
const auto configuration_path{find_configuration(entry.first)};
const auto &configuration{
read_configuration(options, configuration_path)};
const auto dialect{default_dialect(options, configuration)};
const auto &custom_resolver{
resolver(options, options.contains("http"), dialect, configuration)};

std::ostringstream expected;
if (options.contains("keep-ordering")) {
sourcemeta::core::prettify(entry.second, expected, indentation);
} else {
auto copy = entry.second;
sourcemeta::core::format(copy, sourcemeta::core::schema_official_walker,
custom_resolver, dialect);
sourcemeta::core::prettify(copy, expected, indentation);
}
expected << "\n";
std::ostringstream expected;
if (options.contains("keep-ordering")) {
sourcemeta::core::prettify(entry.second, expected, indentation);
} else {
auto copy = entry.second;
sourcemeta::core::format(copy, sourcemeta::core::schema_official_walker,
custom_resolver, dialect);
sourcemeta::core::prettify(copy, expected, indentation);
}
expected << "\n";

std::ifstream current_stream{entry.first};
std::ostringstream current;
current << current_stream.rdbuf();
std::ifstream current_stream{entry.first};
std::ostringstream current;
current << current_stream.rdbuf();

if (options.contains("check")) {
if (current.str() == expected.str()) {
LOG_VERBOSE(options) << "ok: " << entry.first.string() << "\n";
} else if (output_json) {
failed_files.push_back(entry.first.string());
result = false;
if (options.contains("check")) {
if (current.str() == expected.str()) {
LOG_VERBOSE(options) << "ok: " << entry.first.string() << "\n";
} else if (output_json) {
failed_files.push_back(entry.first.string());
result = false;
} else {
std::cerr << "fail: " << entry.first.string() << "\n";
result = false;
}
} else {
std::cerr << "fail: " << entry.first.string() << "\n";
result = false;
}
} else {
if (current.str() != expected.str()) {
std::ofstream output{entry.first};
output << expected.str();
if (current.str() != expected.str()) {
std::ofstream output{entry.first};
output << expected.str();
}
}
} catch (const sourcemeta::core::SchemaRelativeMetaschemaResolutionError
&error) {
throw FileError<
sourcemeta::core::SchemaRelativeMetaschemaResolutionError>(
entry.first, error);
} catch (const sourcemeta::core::SchemaResolutionError &error) {
throw FileError<sourcemeta::core::SchemaResolutionError>(entry.first,
error);
} catch (const sourcemeta::core::SchemaUnknownBaseDialectError &) {
throw FileError<sourcemeta::core::SchemaUnknownBaseDialectError>(
entry.first);
} catch (const sourcemeta::core::SchemaError &error) {
throw FileError<sourcemeta::core::SchemaError>(entry.first, error.what());
}
}

Expand Down
48 changes: 31 additions & 17 deletions src/command_inspect.cc
Original file line number Diff line number Diff line change
Expand Up @@ -159,27 +159,41 @@ auto sourcemeta::jsonschema::inspect(const sourcemeta::core::Options &options)
const auto configuration_path{find_configuration(schema_path)};
const auto &configuration{read_configuration(options, configuration_path)};
const auto dialect{default_dialect(options, configuration)};
const auto &custom_resolver{
resolver(options, options.contains("http"), dialect, configuration)};

const auto identifier{
sourcemeta::core::identify(schema, custom_resolver, dialect)};

sourcemeta::core::SchemaFrame frame{
sourcemeta::core::SchemaFrame::Mode::Instances};

frame.analyse(
schema, sourcemeta::core::schema_official_walker, custom_resolver,
dialect,

// Only use the file-based URI if the schema has no identifier,
// as otherwise we make the output unnecessarily hard when it
// comes to debugging schemas
identifier.has_value()
? std::optional<sourcemeta::core::JSON::String>(std::nullopt)
: sourcemeta::core::URI::from_path(
sourcemeta::core::weakly_canonical(schema_path))
.recompose());
try {
const auto &custom_resolver{
resolver(options, options.contains("http"), dialect, configuration)};
const auto identifier{
sourcemeta::core::identify(schema, custom_resolver, dialect)};

frame.analyse(
schema, sourcemeta::core::schema_official_walker, custom_resolver,
dialect,

// Only use the file-based URI if the schema has no identifier,
// as otherwise we make the output unnecessarily hard when it
// comes to debugging schemas
identifier.has_value()
? std::optional<sourcemeta::core::JSON::String>(std::nullopt)
: sourcemeta::core::URI::from_path(
sourcemeta::core::weakly_canonical(schema_path))
.recompose());
} catch (
const sourcemeta::core::SchemaRelativeMetaschemaResolutionError &error) {
throw FileError<sourcemeta::core::SchemaRelativeMetaschemaResolutionError>(
schema_path, error);
} catch (const sourcemeta::core::SchemaResolutionError &error) {
throw FileError<sourcemeta::core::SchemaResolutionError>(schema_path,
error);
} catch (const sourcemeta::core::SchemaUnknownBaseDialectError &) {
throw FileError<sourcemeta::core::SchemaUnknownBaseDialectError>(
schema_path);
} catch (const sourcemeta::core::SchemaError &error) {
throw FileError<sourcemeta::core::SchemaError>(schema_path, error.what());
}

if (options.contains("json")) {
sourcemeta::core::prettify(frame.to_json(positions), std::cout);
Expand Down
Loading
Loading