Json 架构未验证必需的属性

Json schema not validating required attribute

我正在编写以下 Json 架构:

{
  "$schema": "http://json-schema.org/schema#",
  "title": "Layout",
  "description": "The layout created by the user",
  "type": "object",
  "definitions": {
    "stdAttribute": {
      "type": "object",
      "properties": {
        "attributeValue": {
          "type": "object"
        },
        "attributeName": {
          "type": "string"
        }
      }
    },
    "stdItem": {
      "type": "object",
      "required" : ["stdAttributes"],
      "properties": {
        "stdType": {
          "enum": [
            "CONTAINER",
            "TEXT",
            "TEXTAREA",
            "BUTTON",
            "LABEL",
            "IMAGE",
            "MARCIMAGE",
            "DATA",
            "SELECT",
            "TABLE"
          ]
        },
        "stdAttributes": {
          "type": "array",
          "items": {
            "$ref": "#/definitions/stdAttribute"
          },
          "minItems": 1
        },
        "children": {
          "type": "array",
          "items": {
            "$ref": "#/definitions/stdItem"
          }
        }
      }
    }
  }
}

当我设置以下数据时:

{
    "stdItem": {
      "stdType": "CONTAINER",
      "stdAttributes": [],
      "children": []
  }
}

验证器说没有错误,但在模式中我使用了 minItems 和对 "StdAttribute" 模式的引用 "StdAttributtes".

我试图在基本模式中定义这个 属性,但验证器说了同样的话。

我应该如何验证 "StdAttributes" 中项目的类型和数量?

我正在使用 Java 验证器。

您缺少顶级的 properties 属性。现在你的模式唯一验证的是你的数据是一个对象。 definitions 本身不验证任何内容。它只是一个存放可以在您的模式中引用的模式的地方。以下是您必须添加到架构根目录才能获得预期结果的最少内容。

"properties": {
  "stdItem": { "$ref": "#/definitions/stdItem" }
}