pboettch / json-schema-validator

JSON schema validator for JSON for Modern C++
Other
496 stars 142 forks source link

Add format checkers to an existing validator. #329

Open zaun opened 5 days ago

zaun commented 5 days ago

Something like:

validator.set_format_check("url", [](const std::string &value) {
    const std::regex uri_regex(R"(^https?:\/\/[^\s]+$)");
    if (!std::regex_match(value, uri_regex)) {
        throw std::invalid_argument("Invalid URI format: " + value);
    }
});

Would allow easy adding of format checkers to an existing validator. It also, at least in my opinion, is easier to read than a monolithic format checker. A setup like this would allow the default checkers to be added automatically, but still let the user overwrite them with their own if they want.

pboettch commented 5 days ago

Nice idea. Are you able to develop this feature?

zaun commented 4 days ago

I can look into it.

Would you still want the ability to have the monolithic format checker? I would recommend removing it for simplicity, but that would be a breaking change to the API.