2017-08-08 16 views
0

core/validation meta-schemaitemstype属性定义如下:如果`items`和`type`被定义为阵列,而不anyOf属性

"items": { 
    "anyOf": [ 
     { "$ref": "#" }, 
     { 
      "type": "array", 
      "minItems": 1, 
      "items": { "$ref": "#" } 
     } 
    ], 
    "default": {} 
}, 

类型

"type": { 
    "anyOf": [ 
     { "$ref": "#/definitions/simpleTypes" }, 
     { 
      "type": "array", 
      "items": { "$ref": "#/definitions/simpleTypes" }, 
      "minItems": 1, 
      "uniqueItems": true 
     } 
    ] 
}, 

据我了解它:

  • items可以是一个模式或阵列的至少一个模式
  • type可以是simpleType或中的至少一个simpleType
从的实用性和舒适

除了阵列写作,我是否认为这些定义是等同的?

"items": { 
    "type": "array", 
    "items": { "$ref": "#" } 
    "default": [{}] 
}, 

类型

"type": { 
    "type": "array", 
    "items": { "$ref": "#/definitions/simpleTypes" }, 
    "uniqueItems": true 
}, 

换句话说,是有以下两种模式之间在解释的差:

模式#1

{ 
    "type": "array", 
    "items": { 
     "type": "string" 
    } 
} 

模式#2

{ 
    "type": ["array"], 
    "items": [ 
     { 
      "type": "string" 
     } 
    ] 
} 

回答

1

接听 “换句话说,” 部分:

  • "type": "array""type": ["array"]

  • 但之间没有语义差异“项目”是不同的:

    • "items": {"type": "string"}意味着与任何数目的串项目
    • "items": [{"type": "string"}]指任何数量的元素,其中的第0必须是字符串的数组的数组,其余的可以是任何

你可以在这里找到更多关于列表与元组验证的信息:https://spacetelescope.github.io/understanding-json-schema/reference/array.html

相关问题