|
@@ -1,7 +1,6 @@
|
|
|
#include <cstdio>
|
|
#include <cstdio>
|
|
|
#include <cstdlib>
|
|
#include <cstdlib>
|
|
|
#include <filesystem>
|
|
#include <filesystem>
|
|
|
-#include <fstream>
|
|
|
|
|
#include <iostream>
|
|
#include <iostream>
|
|
|
#include <sstream>
|
|
#include <sstream>
|
|
|
#include <stdexcept>
|
|
#include <stdexcept>
|
|
@@ -11,57 +10,19 @@
|
|
|
|
|
|
|
|
#include <jvalidate/adapter.h>
|
|
#include <jvalidate/adapter.h>
|
|
|
#include <jvalidate/adapters/jsoncpp.h>
|
|
#include <jvalidate/adapters/jsoncpp.h>
|
|
|
|
|
+#include <jvalidate/compat/curl.h>
|
|
|
#include <jvalidate/enum.h>
|
|
#include <jvalidate/enum.h>
|
|
|
|
|
+#include <jvalidate/forward.h>
|
|
|
#include <jvalidate/schema.h>
|
|
#include <jvalidate/schema.h>
|
|
|
#include <jvalidate/status.h>
|
|
#include <jvalidate/status.h>
|
|
|
#include <jvalidate/uri.h>
|
|
#include <jvalidate/uri.h>
|
|
|
#include <jvalidate/validator.h>
|
|
#include <jvalidate/validator.h>
|
|
|
|
|
|
|
|
-#include <json/reader.h>
|
|
|
|
|
#include <json/value.h>
|
|
#include <json/value.h>
|
|
|
#include <json/writer.h>
|
|
#include <json/writer.h>
|
|
|
|
|
|
|
|
-bool load_stream(std::istream & in, Json::Value & out) {
|
|
|
|
|
- Json::CharReaderBuilder builder;
|
|
|
|
|
- std::string error;
|
|
|
|
|
- return Json::parseFromStream(builder, in, &out, &error);
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-bool load_file(std::filesystem::path const & path, Json::Value & out) {
|
|
|
|
|
- std::ifstream in(path);
|
|
|
|
|
- return load_stream(in, out);
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-size_t transfer_to_buffer(char * data, size_t size, size_t nmemb, void * userdata) {
|
|
|
|
|
- std::stringstream & ss = *reinterpret_cast<std::stringstream *>(userdata);
|
|
|
|
|
- size_t actual_size = size * nmemb;
|
|
|
|
|
- ss << std::string_view(data, actual_size);
|
|
|
|
|
- return actual_size;
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-bool curl_get(jvalidate::URI const & uri, Json::Value & out) {
|
|
|
|
|
- if (uri.scheme().starts_with("http")) {
|
|
|
|
|
- std::stringstream ss;
|
|
|
|
|
- if (CURL * curl = curl_easy_init(); curl) {
|
|
|
|
|
- curl_easy_setopt(curl, CURLOPT_URL, uri.c_str());
|
|
|
|
|
- curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
|
|
|
|
|
- curl_easy_setopt(curl, CURLOPT_WRITEDATA, &ss);
|
|
|
|
|
- curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, &transfer_to_buffer);
|
|
|
|
|
-
|
|
|
|
|
- CURLcode res = curl_easy_perform(curl);
|
|
|
|
|
- curl_easy_cleanup(curl);
|
|
|
|
|
-
|
|
|
|
|
- if (res == CURLE_OK) {
|
|
|
|
|
- return load_stream(ss, out);
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- return false;
|
|
|
|
|
- } else if (uri.scheme() == "file") {
|
|
|
|
|
- return load_file(uri.resource(), out);
|
|
|
|
|
- } else {
|
|
|
|
|
- return false;
|
|
|
|
|
- }
|
|
|
|
|
-}
|
|
|
|
|
|
|
+using jvalidate::adapter::load_file;
|
|
|
|
|
+using jvalidate::adapter::load_stream;
|
|
|
|
|
|
|
|
struct ProgramArgs {
|
|
struct ProgramArgs {
|
|
|
ProgramArgs(std::string_view program, std::vector<std::string_view> args) {
|
|
ProgramArgs(std::string_view program, std::vector<std::string_view> args) {
|
|
@@ -105,7 +66,7 @@ int main(int argc, char const * const * argv) {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
using enum jvalidate::schema::Version;
|
|
using enum jvalidate::schema::Version;
|
|
|
- jvalidate::Schema schema(jschema, Draft2020_12, &curl_get);
|
|
|
|
|
|
|
+ jvalidate::Schema schema(jschema, Draft2020_12, &jvalidate::curl_get<Json::Value>);
|
|
|
|
|
|
|
|
jvalidate::ValidationResult result;
|
|
jvalidate::ValidationResult result;
|
|
|
bool compact_error = !args.verbose && !args.format_as_explaination;
|
|
bool compact_error = !args.verbose && !args.format_as_explaination;
|
|
@@ -135,14 +96,14 @@ int main(int argc, char const * const * argv) {
|
|
|
|
|
|
|
|
Json::Value out;
|
|
Json::Value out;
|
|
|
for (Json::Value & elem : json["details"]) {
|
|
for (Json::Value & elem : json["details"]) {
|
|
|
- if (!elem.isMember("errors") || elem["valid"].asBool()) {
|
|
|
|
|
|
|
+ if (!elem.isMember("errors")) {
|
|
|
continue;
|
|
continue;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
for (std::string const & path = elem["evaluationPath"].asString();
|
|
for (std::string const & path = elem["evaluationPath"].asString();
|
|
|
auto const & [key, reason] : because) {
|
|
auto const & [key, reason] : because) {
|
|
|
- if (path.starts_with(key)) {
|
|
|
|
|
- elem["because"] = reason;
|
|
|
|
|
|
|
+ if (path.starts_with(key) && path != reason["evaluationPath"].asString()) {
|
|
|
|
|
+ elem["because"].append(reason);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|