它是有效的json模式吗?

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

您会建议使用这种格式吗?

最佳答案

自我引用是允许的并且有用的。但是,您的示例看起来就像是引用无限循环。这是一个JSON模式的示例,该示例使用递归引用来定义无限深度的树结构。

{
  "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"]
    }
  }
}

关于jsonschema - 递归自引用JSON模式,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/35250621/

10-12 00:22
查看更多