Feat: Add uuid support
This commit is contained in:
parent
89ed13d76b
commit
1c2c3e39d6
@ -332,6 +332,8 @@ json_validator validator(nullptr, // or loader-callback
|
||||
my_format_checker); // create validator
|
||||
```
|
||||
|
||||
## Default Checker
|
||||
|
||||
The library contains a default-checker, which does some checks. It needs to be
|
||||
provided manually to the constructor of the validator:
|
||||
|
||||
@ -340,6 +342,10 @@ json_validator validator(loader, // or nullptr for no loader
|
||||
nlohmann::json_schema::default_string_format_check);
|
||||
```
|
||||
|
||||
Supported formats: `date-time, date, time, email, hostname, ipv4, ipv6, uuid, regex`
|
||||
|
||||
More formats can be added in `src/string-format-check.cpp`. Please contribute implementions for missing json scheme draft format.
|
||||
|
||||
# Contributing
|
||||
|
||||
Before opening a pull request, please apply the coding style given in the
|
||||
|
||||
@ -166,6 +166,8 @@ const std::string host{
|
||||
"|" + regName +
|
||||
")"};
|
||||
|
||||
const std::string uuid{R"([0-9a-fA-F]{8}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{12})"};
|
||||
|
||||
// from http://stackoverflow.com/questions/106179/regular-expression-to-match-dns-hostname-or-ip-address
|
||||
const std::string hostname{R"(^([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]{0,61}[a-zA-Z0-9])(\.([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]{0,61}[a-zA-Z0-9]))*$)"};
|
||||
|
||||
@ -295,6 +297,11 @@ void default_string_format_check(const std::string &format, const std::string &v
|
||||
if (!std::regex_match(value, ipv6Regex)) {
|
||||
throw std::invalid_argument(value + " is not an IPv6 string according to RFC 5954.");
|
||||
}
|
||||
} else if (format == "uuid") {
|
||||
static const std::regex uuidRegex{uuid};
|
||||
if (!std::regex_match(value, uuidRegex)) {
|
||||
throw std::invalid_argument(value + " is not an uuid string according to RFC 4122.");
|
||||
}
|
||||
} else if (format == "regex") {
|
||||
try {
|
||||
std::regex re(value, std::regex::ECMAScript);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user