@@ -54,7 +54,7 @@ lives in his namespace.
54
54
Instance validation is thread-safe and the same validator-object can be used by
55
55
different threads:
56
56
57
- The validate method is ` const ` which indicated the object is not modified when
57
+ The validate method is ` const ` which indicates the object is not modified when
58
58
being called:
59
59
60
60
``` C++
@@ -308,15 +308,33 @@ All required tests are **OK**.
308
308
309
309
# Format
310
310
311
- Optionally JSON-schema-validator can validation predefined or user-defined formats.
311
+ Optionally JSON-schema-validator can validate predefined or user-defined formats.
312
312
Therefore a format-checker-function can be provided by the user which is called by
313
- the validator when a format-check is required.
313
+ the validator when a format-check is required (ie. the schema contains a format-field).
314
+
315
+ This is how the prototype looks like and how it can be passed to the validation-instance:
316
+
317
+ ```C++
318
+ static void my_format_checker(const std::string &format, const std::string &value)
319
+ {
320
+ if (format == "something") {
321
+ if (!check_value_for_something(value))
322
+ throw std::invalid_argument("value is not a good something");
323
+ } else
324
+ throw std::logic_error("Don't know how to validate " + format);
325
+ }
326
+
327
+ // when creating the validator
328
+
329
+ json_validator validator(nullptr, // or loader-callback
330
+ my_format_checker); // create validator
331
+ ```
314
332
315
333
The library contains a default-checker, which does some checks. It needs to be
316
334
provided manually to the constructor of the validator:
317
335
318
336
``` C++
319
- json_validator validator(loader,
337
+ json_validator validator (loader, // or nullptr for no loader
320
338
nlohmann::json_schema::default_string_format_check);
321
339
```
322
340
0 commit comments