Skip to content

Commit 82f962d

Browse files
committed
update README concerning format-checker-usage
1 parent cb5b83e commit 82f962d

File tree

1 file changed

+22
-4
lines changed

1 file changed

+22
-4
lines changed

README.md

+22-4
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ lives in his namespace.
5454
Instance validation is thread-safe and the same validator-object can be used by
5555
different threads:
5656

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
5858
being called:
5959

6060
```C++
@@ -308,15 +308,33 @@ All required tests are **OK**.
308308
309309
# Format
310310
311-
Optionally JSON-schema-validator can validation predefined or user-defined formats.
311+
Optionally JSON-schema-validator can validate predefined or user-defined formats.
312312
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+
```
314332

315333
The library contains a default-checker, which does some checks. It needs to be
316334
provided manually to the constructor of the validator:
317335

318336
```C++
319-
json_validator validator(loader,
337+
json_validator validator(loader, // or nullptr for no loader
320338
nlohmann::json_schema::default_string_format_check);
321339
```
322340

0 commit comments

Comments
 (0)