ex_json_schema icon indicating copy to clipboard operation
ex_json_schema copied to clipboard

Custom keyword validation

Open JPOverclock opened this issue 1 year ago • 2 comments

Adding support for optionally validating custom keywords, which are currently ignored and should continue to be so by default.

Should users provide an extended schema (or vocabulary in the future) containing custom keywords, it should be possible to extend the library's validation capabilities to include these keywords. This is done with an extension mechanism similar to the one present for custom_format_validator.

In practice, this opens up the possibility of introducing validations for constructs such as date range validation via an extended vocabulary. e.g.:

{
  "properties": {
    "startDate": {
      "format": "date",
      "type": "string",
      "x-min-date": "2020-01-01"
    }
  }

JPOverclock avatar Aug 22 '24 18:08 JPOverclock

Thank you for the contribution. I like the idea, I will have some time later this week to have a look at your implementation in detail.

jonasschmidt avatar Aug 27 '24 12:08 jonasschmidt

Thank you for the quick turn-around on the review! :pray:

I like your proposal and it should be simple to implement in a backwards-compatible manner :+1: I'll open a follow-up MR and we can see how it looks.

As for this approach, it's very much off-spec, inspired by jsonschema which offers what I believe to be this exact functionality. Maybe it would serve as a stopgap for the draft vocabulary support, but this would indeed be hard to deprecate (or even coexist) if proper vocabulary support is introduced here.

JPOverclock avatar Aug 30 '24 19:08 JPOverclock