json-schema edge cases

76 views
Skip to first unread message

Nicolas FROIDURE

unread,
Apr 14, 2015, 8:36:26 AM4/14/15
to json-...@googlegroups.com
    Hi everyone!

  At work we'd like to embrace json-schema but there are some edge case we can get rid of with it. I'll try to describe them clearly:

- minimum/maximum only apply to numbers (and strings through minLengh/maxLength), but we'd like to have the ability to check if a date is between 2 other dates. Something like a formatMaximum/formatMinimum formatMaxinumExclusive/formatMininumExclusive would be nice.

- we'd like to have the ability to "compute" some values in order to declare natural relations between values. By example,. The above mininum date could be computed depending on another property of the validated object. Such a schema could look like this:
{
  type: "object"
  properties: {
    startDate: {
      type: "string",
      format: "date-time"
    }
    endDate: {
      type: "string",
      format: "date-time",
      formatMininum: {
        $computed: {
           engine: "objectquery",
           formula: 'parent.startDate'
      }
    }
  }
}
json-schema validators would just add the ability to register engines that would simply be functions accepting the currently validated object and the formula to return the computed value.
Another use case was with the skip/limit query parameters of our REST API, we'd like the skip parameter to be multipleOf the limit one, sadly it seems impossible with the current spec.

- i'd also like to be able to add cross-properties constraints. By example, i'd like to have a namespaced uniqueItem instruction to validate schemas like this:
{
  type: "object"
  properties: {
    _id: {
      type: "string",
      format: "uuid",
      uniqueInSet: 'mongodb/objectid'
    }
    organisation_id: {
      type: "string",
      format: "uuid",
      uniqueInSet: 'mongodb/objectid'
    }
  }
}
The json-schema validators would simply maintain a set of values used in the given namespace and fail validation when dupes are found.

Hope you'll consider to add such features.

Cheers.
Reply all
Reply to author
Forward
0 new messages