Skip to content

Commit

Permalink
Fix enum misbehaving in propertyNames during validation
Browse files Browse the repository at this point in the history
Fixes: #225
Signed-off-by: Juan Cruz Viotti <jv@jviotti.com>
  • Loading branch information
jviotti committed Feb 10, 2025
1 parent a83509a commit d919e3b
Show file tree
Hide file tree
Showing 81 changed files with 1,153 additions and 1,046 deletions.
6 changes: 3 additions & 3 deletions DEPENDENCIES
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
vendorpull https://github.com/sourcemeta/vendorpull dea311b5bfb53b6926a4140267959ae334d3ecf4
core https://github.com/sourcemeta/core 32f08ad1e4d3e39097eda3fdd44e58ad0b5d59ec
core https://github.com/sourcemeta/core 47ba2307b9bfab9fb378386207b3172c97ed1363
hydra https://github.com/sourcemeta/hydra a67b879df800e834ed8a2d056f98398f7211d870
jsonbinpack https://github.com/sourcemeta/jsonbinpack d0f111b04fc4d252e278bafd66c382a9db3d3057
blaze https://github.com/sourcemeta/blaze ee117240f8399831001cb1c764d8b08503fc9112
jsonbinpack https://github.com/sourcemeta/jsonbinpack 5fb659a3ebf8b4985e89d4c0c6761a65bb5cb169
blaze https://github.com/sourcemeta/blaze d0aafed3d2c0d16edaccddcc41917940c6f6f2b5
4 changes: 2 additions & 2 deletions src/command_bundle.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ auto sourcemeta::jsonschema::cli::bundle(
auto schema{sourcemeta::jsonschema::cli::read_file(options.at("").front())};

sourcemeta::core::bundle(
schema, sourcemeta::core::default_schema_walker,
schema, sourcemeta::core::schema_official_walker,
resolver(options, options.contains("h") || options.contains("http")));

if (options.contains("w") || options.contains("without-id")) {
log_verbose(options) << "Removing schema identifiers\n";
sourcemeta::core::unidentify(
schema, sourcemeta::core::default_schema_walker,
schema, sourcemeta::core::schema_official_walker,
resolver(options, options.contains("h") || options.contains("http")));
}

Expand Down
4 changes: 2 additions & 2 deletions src/command_decode.cc
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ auto sourcemeta::jsonschema::cli::decode(
}

// TODO: Take a real schema as argument
auto schema{sourcemeta::core::parse(R"JSON({
auto schema{sourcemeta::core::parse_json(R"JSON({
"$schema": "https://json-schema.org/draft/2020-12/schema"
})JSON")};

sourcemeta::jsonbinpack::compile(
schema, sourcemeta::core::default_schema_walker,
schema, sourcemeta::core::schema_official_walker,
resolver(options, options.contains("h") || options.contains("http")));
const auto encoding{sourcemeta::jsonbinpack::load(schema)};

Expand Down
4 changes: 2 additions & 2 deletions src/command_encode.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ auto sourcemeta::jsonschema::cli::encode(
}

// TODO: Take a real schema as argument
auto schema{sourcemeta::core::parse(R"JSON({
auto schema{sourcemeta::core::parse_json(R"JSON({
"$schema": "https://json-schema.org/draft/2020-12/schema"
})JSON")};

sourcemeta::jsonbinpack::compile(
schema, sourcemeta::core::default_schema_walker,
schema, sourcemeta::core::schema_official_walker,
resolver(options, options.contains("h") || options.contains("http")));
const auto encoding{sourcemeta::jsonbinpack::load(schema)};

Expand Down
37 changes: 20 additions & 17 deletions src/command_frame.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,17 @@
#include "command.h"
#include "utils.h"

static auto enum_to_string(const sourcemeta::core::Frame::LocationType type)
static auto
enum_to_string(const sourcemeta::core::SchemaFrame::LocationType type)
-> std::string {
switch (type) {
case sourcemeta::core::Frame::LocationType::Resource:
case sourcemeta::core::SchemaFrame::LocationType::Resource:
return "resource";
case sourcemeta::core::Frame::LocationType::Anchor:
case sourcemeta::core::SchemaFrame::LocationType::Anchor:
return "anchor";
case sourcemeta::core::Frame::LocationType::Pointer:
case sourcemeta::core::SchemaFrame::LocationType::Pointer:
return "pointer";
case sourcemeta::core::Frame::LocationType::Subschema:
case sourcemeta::core::SchemaFrame::LocationType::Subschema:
return "subschema";
default:
return "unknown";
Expand All @@ -37,8 +38,8 @@ auto sourcemeta::jsonschema::cli::frame(
const sourcemeta::core::JSON schema{
sourcemeta::jsonschema::cli::read_file(options.at("").front())};

sourcemeta::core::Frame frame;
frame.analyse(schema, sourcemeta::core::default_schema_walker,
sourcemeta::core::SchemaFrame frame;
frame.analyse(schema, sourcemeta::core::schema_official_walker,
resolver(options));

const auto output_json = options.contains("json") || options.contains("j");
Expand Down Expand Up @@ -75,10 +76,11 @@ auto sourcemeta::jsonschema::cli::frame(
for (const auto &[pointer, entry] : frame.references()) {
auto ref_entry = sourcemeta::core::JSON::make_object();
ref_entry.assign(
"type", sourcemeta::core::JSON{
pointer.first == sourcemeta::core::ReferenceType::Dynamic
? "dynamic"
: "static"});
"type",
sourcemeta::core::JSON{
pointer.first == sourcemeta::core::SchemaReferenceType::Dynamic
? "dynamic"
: "static"});
ref_entry.assign("destination",
sourcemeta::core::JSON{entry.destination});
if (entry.base.has_value()) {
Expand Down Expand Up @@ -106,16 +108,16 @@ auto sourcemeta::jsonschema::cli::frame(
} else {
for (const auto &[key, entry] : frame.locations()) {
switch (entry.type) {
case sourcemeta::core::Frame::LocationType::Resource:
case sourcemeta::core::SchemaFrame::LocationType::Resource:
std::cout << "(LOCATION)";
break;
case sourcemeta::core::Frame::LocationType::Anchor:
case sourcemeta::core::SchemaFrame::LocationType::Anchor:
std::cout << "(ANCHOR)";
break;
case sourcemeta::core::Frame::LocationType::Pointer:
case sourcemeta::core::SchemaFrame::LocationType::Pointer:
std::cout << "(POINTER)";
break;
case sourcemeta::core::Frame::LocationType::Subschema:
case sourcemeta::core::SchemaFrame::LocationType::Subschema:
std::cout << "(SUBSCHEMA)";
break;
default:
Expand All @@ -129,7 +131,7 @@ auto sourcemeta::jsonschema::cli::frame(
std::cout << key.second << "\n";

std::cout << " Type : ";
if (key.first == sourcemeta::core::ReferenceType::Dynamic) {
if (key.first == sourcemeta::core::SchemaReferenceType::Dynamic) {
std::cout << "Dynamic";
} else {
std::cout << "Static";
Expand Down Expand Up @@ -160,7 +162,8 @@ auto sourcemeta::jsonschema::cli::frame(
sourcemeta::core::stringify(pointer.second, std::cout);
std::cout << "\n";
std::cout << " Type : "
<< (pointer.first == sourcemeta::core::ReferenceType::Dynamic
<< (pointer.first ==
sourcemeta::core::SchemaReferenceType::Dynamic
? "Dynamic"
: "Static")
<< "\n";
Expand Down
4 changes: 2 additions & 2 deletions src/command_lint.cc
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ auto sourcemeta::jsonschema::cli::lint(
}

auto copy = entry.second;
bundle.apply(copy, sourcemeta::core::default_schema_walker,
bundle.apply(copy, sourcemeta::core::schema_official_walker,
resolver(options));
std::ofstream output{entry.first};
sourcemeta::core::prettify(copy, output,
Expand All @@ -53,7 +53,7 @@ auto sourcemeta::jsonschema::cli::lint(
parse_extensions(options))) {
log_verbose(options) << "Linting: " << entry.first.string() << "\n";
const bool subresult = bundle.check(
entry.second, sourcemeta::core::default_schema_walker,
entry.second, sourcemeta::core::schema_official_walker,
resolver(options),
[&entry](const auto &pointer, const auto &name, const auto &message) {
std::cout << entry.first.string() << ":\n";
Expand Down
2 changes: 1 addition & 1 deletion src/command_metaschema.cc
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ auto sourcemeta::jsonschema::cli::metaschema(
sourcemeta::core::metaschema(entry.second, custom_resolver)};
if (!cache.contains(dialect.value())) {
const auto metaschema_template{sourcemeta::blaze::compile(
metaschema, sourcemeta::core::default_schema_walker, custom_resolver,
metaschema, sourcemeta::core::schema_official_walker, custom_resolver,
sourcemeta::blaze::default_schema_compiler)};
cache.insert({dialect.value(), metaschema_template});
}
Expand Down
2 changes: 1 addition & 1 deletion src/command_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ auto sourcemeta::jsonschema::cli::test(

try {
schema_template = sourcemeta::blaze::compile(
schema.value(), sourcemeta::core::default_schema_walker,
schema.value(), sourcemeta::core::schema_official_walker,
test_resolver, sourcemeta::blaze::default_schema_compiler);
} catch (const sourcemeta::core::SchemaReferenceError &error) {
if (error.location() == sourcemeta::core::Pointer{"$ref"} &&
Expand Down
6 changes: 3 additions & 3 deletions src/command_validate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ auto sourcemeta::jsonschema::cli::validate(
const auto benchmark{options.contains("b") || options.contains("benchmark")};
const auto trace{options.contains("t") || options.contains("trace")};
const auto schema_template{sourcemeta::blaze::compile(
schema, sourcemeta::core::default_schema_walker, custom_resolver,
schema, sourcemeta::core::schema_official_walker, custom_resolver,
sourcemeta::blaze::default_schema_compiler)};
sourcemeta::blaze::Evaluator evaluator;

Expand Down Expand Up @@ -122,9 +122,9 @@ auto sourcemeta::jsonschema::cli::validate(
break;
}
}
} catch (const sourcemeta::core::ParseError &error) {
} catch (const sourcemeta::core::JSONParseError &error) {
// For producing better error messages
throw sourcemeta::core::FileParseError(instance_path, error);
throw sourcemeta::core::JSONFileParseError(instance_path, error);
}

if (index == 0) {
Expand Down
4 changes: 2 additions & 2 deletions src/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -131,13 +131,13 @@ auto main(int argc, char *argv[]) noexcept -> int {
std::cerr << "error: " << error.what() << " at column " << error.column()
<< "\n";
return EXIT_FAILURE;
} catch (const sourcemeta::core::FileParseError &error) {
} catch (const sourcemeta::core::JSONFileParseError &error) {
std::cerr << "error: " << error.what() << " at line " << error.line()
<< " and column " << error.column() << "\n "
<< std::filesystem::weakly_canonical(error.path()).string()
<< "\n";
return EXIT_FAILURE;
} catch (const sourcemeta::core::ParseError &error) {
} catch (const sourcemeta::core::JSONParseError &error) {
std::cerr << "error: " << error.what() << " at line " << error.line()
<< " and column " << error.column() << "\n";
return EXIT_FAILURE;
Expand Down
12 changes: 6 additions & 6 deletions src/utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,10 @@ namespace sourcemeta::jsonschema::cli {

auto read_file(const std::filesystem::path &path) -> sourcemeta::core::JSON {
if (path.extension() == ".yaml" || path.extension() == ".yml") {
return sourcemeta::core::from_yaml(path);
return sourcemeta::core::read_yaml(path);
}

return sourcemeta::core::from_file(path);
return sourcemeta::core::read_json(path);
}

auto for_each_json(const std::vector<std::string> &arguments,
Expand Down Expand Up @@ -239,7 +239,7 @@ auto print(const sourcemeta::blaze::TraceOutput &output, std::ostream &stream)
static auto fallback_resolver(
const std::map<std::string, std::vector<std::string>> &options,
std::string_view identifier) -> std::optional<sourcemeta::core::JSON> {
auto official_result{sourcemeta::core::official_resolver(identifier)};
auto official_result{sourcemeta::core::schema_official_resolver(identifier)};
if (official_result.has_value()) {
return official_result;
}
Expand All @@ -262,17 +262,17 @@ static auto fallback_resolver(
throw std::runtime_error(error.str());
}

return sourcemeta::core::parse(response.body());
return sourcemeta::core::parse_json(response.body());
}

auto resolver(const std::map<std::string, std::vector<std::string>> &options,
const bool remote) -> sourcemeta::core::SchemaResolver {
sourcemeta::core::MapSchemaResolver dynamic_resolver{
sourcemeta::core::SchemaMapResolver dynamic_resolver{
[remote, &options](std::string_view identifier) {
if (remote) {
return fallback_resolver(options, identifier);
} else {
return sourcemeta::core::official_resolver(identifier);
return sourcemeta::core::schema_official_resolver(identifier);
}
}};

Expand Down
52 changes: 30 additions & 22 deletions vendor/blaze/src/compiler/compile.cc

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit d919e3b

Please sign in to comment.