MQTTSuite
Loading...
Searching...
No Matches
issue-243-root-default-values.cpp
Go to the documentation of this file.
1#include <iostream>
2#include <nlohmann/json-schema.hpp>
3
4using nlohmann::json;
5using nlohmann::json_uri;
6using nlohmann::json_schema::json_validator;
7
8static const json root_default = R"(
9{
10 "$schema": "http://json-schema.org/draft-07/schema#",
11 "properties": {
12 "width": {
13 "type": "integer"
14 }
15 },
16 "default": {
17 "width": 42
18 }
19})"_json;
20
21int main(void)
22{
23 json_validator validator{};
24
26
27 {
28 json nul_json;
29 if (!nul_json.is_null()) {
30 return 1;
31 }
32
33 const auto default_patch = validator.validate(nul_json);
34
35 if (default_patch.is_null()) {
36 std::cerr << "Patch is null but should contain operation to add defaults to root" << std::endl;
37 return 1;
38 }
39
40 const auto actual = nul_json.patch(default_patch);
41 const auto expected = R"({"width": 42})"_json;
42 if (actual != expected) {
43 std::cerr << "Patch of defaults is wrong for root schema: '" << actual.dump() << "' instead of expected '" << expected.dump() << "'" << std::endl;
44 }
45 }
46
47 return 0;
48}
json_validator(schema_loader=nullptr, format_checker=nullptr, content_checker=nullptr)
int main()
Definition format.cpp:34
static const json root_default