Skip to content

Commit

Permalink
Prepare a fallback resolver for HTTP resolution (#15)
Browse files Browse the repository at this point in the history
Signed-off-by: Juan Cruz Viotti <[email protected]>
  • Loading branch information
jviotti authored May 30, 2024
1 parent e6b1bd5 commit bb5758a
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,25 @@ auto pretty_evaluate_callback(
std::cerr << "\"\n";
}

static auto fallback_resolver(std::string_view identifier)
-> std::future<std::optional<sourcemeta::jsontoolkit::JSON>> {
auto official_result{
sourcemeta::jsontoolkit::official_resolver(identifier).get()};
if (official_result.has_value()) {
std::promise<std::optional<sourcemeta::jsontoolkit::JSON>> promise;
promise.set_value(std::move(official_result));
return promise.get_future();
}

std::promise<std::optional<sourcemeta::jsontoolkit::JSON>> promise;
promise.set_value(std::nullopt);
return promise.get_future();
}

auto resolver(const std::map<std::string, std::vector<std::string>> &options)
-> sourcemeta::jsontoolkit::SchemaResolver {
sourcemeta::jsontoolkit::MapSchemaResolver dynamic_resolver{
sourcemeta::jsontoolkit::official_resolver};
fallback_resolver};

if (options.contains("resolve")) {
for (const auto &schema_path : options.at("resolve")) {
Expand Down

0 comments on commit bb5758a

Please sign in to comment.