61{
64
65 {
66
67 json person_emtpy_address = R
"({
68 "name": "Hans",
69 "age": 69,
70 "address": {}
71 })"_json;
72
73 const auto default_patch =
validator.validate(person_emtpy_address);
74
75 if (!default_patch.is_array()) {
76 std::cerr << "Patch with defaults is expected to be an array" << std::endl;
77 return 1;
78 }
79
80 if (default_patch.size() != 1) {
81 std::cerr << "Patch with defaults is expected to contain one opperation" << std::endl;
82 return 1;
83 }
84
85 const auto &single_op = default_patch[0];
86
87 if (!single_op.contains("op")) {
88 std::cerr << "Patch with defaults is expected to contain opperation entry" << std::endl;
89 return 1;
90 }
91
92 if (single_op["op"].get<std::string>() != "add") {
93 std::cerr << "Patch with defaults is expected to contain add opperation" << std::endl;
94 return 1;
95 }
96
97 if (!single_op.contains("path")) {
98 std::cerr << "Patch with defaults is expected to contain a path" << std::endl;
99 return 1;
100 }
101
102 const auto &readPath = single_op["path"].get<std::string>();
103 if (readPath != "/address/street") {
104 std::cerr << "Patch with defaults contains wrong path. It is " << readPath << " and should be "
105 << "/address/street" << std::endl;
106 return 1;
107 }
108
109 if (!single_op.contains("value")) {
110 std::cerr << "Patch with defaults is expected to contain a value" << std::endl;
111 return 1;
112 }
113
114 if (single_op["value"].get<std::string>() != "Abbey Road") {
115 std::cerr << "Patch with defaults contains wrong value" << std::endl;
116 return 1;
117 }
118 }
119 {
120
121
122 json person_missing_address = R
"({
123 "name": "Hans",
124 "age": 69
125 })"_json;
126
127 const auto default_patch =
validator.validate(person_missing_address);
128
129 if (!default_patch.is_array()) {
130 std::cerr << "Patch with defaults is expected to be an array" << std::endl;
131 return 1;
132 }
133
134 if (default_patch.size() != 1) {
135 std::cerr << "Patch with defaults is expected to contain one opperation" << std::endl;
136 return 1;
137 }
138
139 const auto &single_op = default_patch[0];
140
141 if (!single_op.contains("op")) {
142 std::cerr << "Patch with defaults is expected to contain opperation entry" << std::endl;
143 return 1;
144 }
145
146 if (single_op["op"].get<std::string>() != "add") {
147 std::cerr << "Patch with defaults is expected to contain add opperation" << std::endl;
148 return 1;
149 }
150
151 if (!single_op.contains("path")) {
152 std::cerr << "Patch with defaults is expected to contain a path" << std::endl;
153 return 1;
154 }
155
156 const auto &readPath = single_op["path"].get<std::string>();
157 if (readPath != "/address") {
158 std::cerr << "Patch with defaults contains wrong path. It is " << readPath << " and should be "
159 << "/address" << std::endl;
160 return 1;
161 }
162
163 if (!single_op.contains("value")) {
164 std::cerr << "Patch with defaults is expected to contain a value" << std::endl;
165 return 1;
166 }
167
nlohmann::json_schema::json_validator validator
static json person_schema