json模式中的关键字之间的逻辑关系是什么? [英] What is the logical relationship between keyword in a json schema?
问题描述
根据规范( http://json-schema.org/schema)模式关键字之间没有相互排斥. 例如,我可以创建以下架构:
According to the specification (http://json-schema.org/schema) there is no mutual exclusion among schema keywords. For example I could create the following schema:
{
"properties" : {
"foo" : {"type" : "string"}
}
"items" : [
{"type" : "integer" },
{"type" : "number" }
]
}
此架构是否可以针对对象和数组进行验证? 如果是这样,则意味着关键字之间存在或"关系.
Would this schema validate against both objects and arrays? If so it would imply an "OR" relationship between keyword.
但是,如果我们考虑以下架构:
But if we consider the following schema:
{
"anyOf" : [
{ "type" : "string",},
{ "type" : "integer"}
]
"not" : {
{ "type" : "string",
"maxLength" : 5
}
}
}
解释它的最实用方法是anyOf而不是关键字之间的"AND"关系.
The most practical way to interpret it would be an "AND" relationship between anyOf and not keywords.
我在v4草案中找不到任何有关关键字如何进行逻辑交互的指示.谁能指出我要回答这个问题的文档/标准吗?
I could not find any indication in the draft v4 on how keywords logically interact. Can anyone point me to a documentation/standard that would answer this question?
推荐答案
关键字始终是与"关系.数据必须满足架构中的 all 关键字.
Keywords are always an "AND" relationship. Data must satisfy all keywords from a schema.
properties
和items
关键字未指定对象的类型(必须使用type
).相反,它们仅对特定类型有意义,否则将被忽略.所以properties
实际上是指:
The properties
and items
keywords don't specify the type of the object (you have to use type
for that). Instead, they only have meaning for particular types, and are ignored otherwise. So properties
actually means:
如果数据是对象,则以下属性定义适用...
If the data is an object, then the following property definitions apply...
这意味着{"properties":{...}}
将匹配任何字符串,因为对于不是对象的值,properties
被忽略.而items
的实际含义是:
This means that {"properties":{...}}
will match any string, because properties
is ignored for values that aren't objects. And items
actually means:
如果数据是数组,则以下项目定义适用...
If the data is an array, then the following item definitions apply...
所以AND组合看起来像:
So the AND combination looks like:
(如果数据是对象,则
properties
适用)AND(如果数据是数组,则items
适用)
(If the data is an object, then
properties
applies) AND (if the data is an array, thenitems
applies)
这篇关于json模式中的关键字之间的逻辑关系是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!