| 178 | } |
| 179 | |
| 180 | void defaults_example() |
| 181 | { |
| 182 | json schema = json::parse(R"( |
| 183 | { |
| 184 | "$schema": "https://json-schema.org/draft/2020-12/schema", |
| 185 | "properties": { |
| 186 | "bar": { |
| 187 | "type": "string", |
| 188 | "minLength": 4, |
| 189 | "default": "bad" |
| 190 | } |
| 191 | } |
| 192 | } |
| 193 | )"); |
| 194 | |
| 195 | try |
| 196 | { |
| 197 | // Data |
| 198 | json data = json::parse("{}"); |
| 199 | |
| 200 | // will throw schema_error if JSON Schema compilation fails |
| 201 | jsonschema::json_schema<json> compiled = jsonschema::make_json_schema(schema); |
| 202 | |
| 203 | // will throw a validation_error when a schema violation happens |
| 204 | json patch; |
| 205 | compiled.validate(data, patch); |
| 206 | |
| 207 | std::cout << "Patch: " << patch << "\n"; |
| 208 | |
| 209 | std::cout << "Original data: " << data << "\n"; |
| 210 | |
| 211 | jsonpatch::apply_patch(data, patch); |
| 212 | |
| 213 | std::cout << "Patched data: " << data << "\n\n"; |
| 214 | } |
| 215 | catch (const std::exception& e) |
| 216 | { |
| 217 | std::cout << e.what() << "\n"; |
| 218 | } |
| 219 | } |
| 220 | |
| 221 | #if defined(JSONCONS_HAS_STD_VARIANT) |
| 222 |
no test coverage detected