MQTTSuite
Loading...
Searching...
No Matches
issue-243-root-default-values.cpp File Reference
#include <iostream>
#include <nlohmann/json-schema.hpp>
Include dependency graph for issue-243-root-default-values.cpp:

Go to the source code of this file.

Functions

int main (void)

Variables

static const json root_default

Function Documentation

◆ main()

int main ( void )

Definition at line 21 of file issue-243-root-default-values.cpp.

22{
24
25 validator.set_root_schema(root_default);
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}
nlohmann::json_schema::json_validator validator
nlohmann::json json
static const json root_default

References nlohmann::json_schema::json_validator::json_validator(), root_default, nlohmann::json_schema::json_validator::set_root_schema(), and nlohmann::json_schema::json_validator::validate().

Here is the call graph for this function:

Variable Documentation

◆ root_default

const json root_default
static
Initial value:
= R"(
{
"$schema": "http://json-schema.org/draft-07/schema#",
"properties": {
"width": {
"type": "integer"
}
},
"default": {
"width": 42
}
})"_json

Definition at line 8 of file issue-243-root-default-values.cpp.

Referenced by main().