JSON-Schema recursive self-regulation

Is this a valid json schema:

  object:
    $ref: '#/definitions/object'

Do you recommend using this format?

+4
source share
1 answer

Permissions and useful links. However, your example looks like it will just be a reference infinite loop. Here is an example JSON schema that uses recursive links to define a tree structure of unlimited depth.

{
  "type": "object",
  "properties": {
    "name": { "type": "string" },
    "tree": { "$ref": "#/definitions/tree" }
  },
  "definitions": {
    "tree": {
      "type": "object",
      "properties": {
        "value": { "type": "string" },
        "branches": {
          "type": "array",
          "items": { "$ref": "#/definitions/tree" },
          "minItems": 1
        }
      },
      "required": ["value"]
    }
  }
}
+6
source

Source: https://habr.com/ru/post/1627634/


All Articles