MQTTSuite
Loading...
Searching...
No Matches
issue-93.cpp
Go to the documentation of this file.
1#include <nlohmann/json-schema.hpp>
2
3#include <fstream>
4#include <iostream>
5
6using nlohmann::json;
7using nlohmann::json_uri;
8using nlohmann::json_schema::json_validator;
9
10static const auto expected_patch = R"(
11[{"op":"add","path":"/0/renderable/bg","value":"Black"}]
12)"_json;
13
14static const auto instance = R"(
15[
16 {
17 "name":"player",
18 "renderable": {
19 "fg":"White"
20 }
21 }
22]
23)"_json;
24
25static void loader(const json_uri &uri, json &schema)
26{
27 std::string filename = "./" + uri.path();
28 std::ifstream lf(filename);
29 if (!lf.good())
30 throw std::invalid_argument("could not open " + uri.url() + " tried with " + filename);
31 try {
32 lf >> schema;
33 } catch (const std::exception &e) {
34 throw e;
35 }
36}
37
38int main(void)
39{
40 json_validator validator(loader);
41
42 std::fstream f("blueprints.schema.json");
43
44 json schema;
45 f >> schema;
46
47 validator.set_root_schema(schema);
48
49 auto missing_default_patch = validator.validate(instance);
50
51 std::cerr << missing_default_patch << "\n";
52 std::cerr << expected_patch << "\n";
53
54 return missing_default_patch != expected_patch;
55}
json_validator(schema_loader=nullptr, format_checker=nullptr, content_checker=nullptr)
std::string url() const
const std::string & path() const
int main()
Definition format.cpp:34
static const auto instance
Definition issue-93.cpp:14
static void loader(const json_uri &uri, json &schema)
Definition issue-93.cpp:25
static const auto expected_patch
Definition issue-93.cpp:10