From bb5758a9f5884a4d6a0cd9224e5743b444ae822f Mon Sep 17 00:00:00 2001 From: Juan Cruz Viotti Date: Thu, 30 May 2024 13:31:50 +0100 Subject: [PATCH] Prepare a fallback resolver for HTTP resolution (#15) Signed-off-by: Juan Cruz Viotti --- src/utils.cc | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/utils.cc b/src/utils.cc index d192592..ae60857 100644 --- a/src/utils.cc +++ b/src/utils.cc @@ -120,10 +120,25 @@ auto pretty_evaluate_callback( std::cerr << "\"\n"; } +static auto fallback_resolver(std::string_view identifier) + -> std::future> { + auto official_result{ + sourcemeta::jsontoolkit::official_resolver(identifier).get()}; + if (official_result.has_value()) { + std::promise> promise; + promise.set_value(std::move(official_result)); + return promise.get_future(); + } + + std::promise> promise; + promise.set_value(std::nullopt); + return promise.get_future(); +} + auto resolver(const std::map> &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")) {