`schema` 的`true` 值的定义行为在哪里?
Where is defined behavior of `true` value for `schema`?
enum
属性 for draft-07 定义为:
"enum": {
"type": "array",
"items": true,
"minItems": 1,
"uniqueItems": true
},
但在 SPEC 中没有 true
值的定义:
The value of "items" MUST be either a valid JSON Schema or an array of valid JSON Schemas.
Link 请让我知道 SPEC 定义了当 true
代替 schema
时验证器的行为
布尔 true
值本身是一个有效的 JSON 架构,因此枚举规范符合其自身的规范。
作为参考,规范定义如下,明确允许在根部使用布尔值:
{
"$schema": "http://json-schema.org/draft-07/schema#",
...
"type": [
"object",
"boolean"
],
...
}
如果要验证是否允许"items": true
,我们需要先查找items
属性的规范。正式定义如下:
"items": {
"anyOf": [
{ "$ref": "#" },
{ "$ref": "#/definitions/schemaArray" }
],
"default": true
},
这意味着 items
属性 的允许值是 JSON 架构(因为它引用规范架构的根对象)或者它是一个数组JSON 模式)。在这种情况下,我们因此需要验证 true
是否符合根架构 #
或 #/definitions/schemaArray
定义。因此,让我们首先看一下将类型指定为 ["object", "boolean"]
的根模式。由于 true
是布尔值,我们已经成功验证 属性 items
的值 true
确实有效。
http://json-schema.org/latest/json-schema-core.html#rfc.section.4.3.1
The boolean schema values "true" and "false" are trivial assertions that always return themselves regardless of the instance value. As an example, in terms of the validation vocabulary, boolean schemas are equivalent to the following behaviors:
true
- Always passes validation, as if the empty schema {}
false
- Always fails validation, as if the schema { "not":{} }
enum
属性 for draft-07 定义为:
"enum": {
"type": "array",
"items": true,
"minItems": 1,
"uniqueItems": true
},
但在 SPEC 中没有 true
值的定义:
The value of "items" MUST be either a valid JSON Schema or an array of valid JSON Schemas.
Link 请让我知道 SPEC 定义了当 true
代替 schema
布尔 true
值本身是一个有效的 JSON 架构,因此枚举规范符合其自身的规范。
作为参考,规范定义如下,明确允许在根部使用布尔值:
{
"$schema": "http://json-schema.org/draft-07/schema#",
...
"type": [
"object",
"boolean"
],
...
}
如果要验证是否允许"items": true
,我们需要先查找items
属性的规范。正式定义如下:
"items": {
"anyOf": [
{ "$ref": "#" },
{ "$ref": "#/definitions/schemaArray" }
],
"default": true
},
这意味着 items
属性 的允许值是 JSON 架构(因为它引用规范架构的根对象)或者它是一个数组JSON 模式)。在这种情况下,我们因此需要验证 true
是否符合根架构 #
或 #/definitions/schemaArray
定义。因此,让我们首先看一下将类型指定为 ["object", "boolean"]
的根模式。由于 true
是布尔值,我们已经成功验证 属性 items
的值 true
确实有效。
http://json-schema.org/latest/json-schema-core.html#rfc.section.4.3.1
The boolean schema values "true" and "false" are trivial assertions that always return themselves regardless of the instance value. As an example, in terms of the validation vocabulary, boolean schemas are equivalent to the following behaviors:
true
- Always passes validation, as if the empty schema {}
false
- Always fails validation, as if the schema { "not":{} }