Skip to content

deepProperties and deepRequired #18

Open
@epoberezkin

Description

@epoberezkin

Same as properties and required, but instead of property names JSON pointers are used (where the root means current part of the data instance).

{
  "deepProperties": {
    "/user/role": { "enum": ["admin"] }
  }
}

is equivalent to

{
  "properties": {
    "user": {
      "properties": {
        "role": { "enum": ["admin"] }
      }
    }
  }
}

and

{ "deepRequired": ["/user/role"] }

is equivalent to

{
   "required": ["user"],
   "properties": {
     "user": {
       "type": "object",
       "required": ["role"]
     }
   }
}

I had this situation a couple of times and it gets very annoying (and visually noisy) when you have to drill down into the hierarchy with "properties" keywords. It is particularly useful when you have conditionals :).

Given that JSON pointers can have indices in arrays, numeric segments should probably be treated as array items rather than as property names, so this schema:

{
  "deepProperties": {
    "/users/1/role": { "enum": ["admin"] }
  }
}

should be equivalent to

{
  "properties": {
    "users": {
      "items": [
        {},
        {
          "properties": {
            "role": { "enum": ["admin"] }
          }
        }
      ]
    }
  }
}

and

{ "deepRequired": [ "/users/1/role" ] }

should be equivalent to

{
   "required": ["users"],
   "properties": {
     "users": {
       "type": "array",
       "minItems": 2,
       "items": [
         {},
         {
           "type": "object",
           "required": ["role"]
         }
       ]
     }
   }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions