我从http://json-schema.org/examples.html得到了下面的模式,我想知道所需的关键字是否只能来自顶层。或者如果存在object类型的属性,它也可以进入属性内。在规范http://tools.ietf.org/html/draft-fge-json-schema-validation-00#section-5.4.3中找不到与此相关的任何事物。JSON模式中的“required”关键字
{
"title": "Example Schema",
"type": "object",
"properties": {
"firstName": {
"type": "string"
},
"lastName": {
"type": "string"
},
"age": {
"description": "Age in years",
"type": "integer",
"minimum": 0
}
},
"required": ["firstName", "lastName"]
}
所以下面的例子是一个有效的架构
{
"title":"Example Schema",
"type":"object",
"properties":{
"firstName":{
"type":"string"
},
"lastName":{
"type":"string"
},
"age":{
"type":"object",
"properties":{
"minAge":{
"type":"number"
},
"maxAge":{
"type":"number"
},
"required":[
"minAge",
"maxAge"
]
}
}
},
"required":[
"firstName",
"lastName"
]
}
你的嵌套'required'在错误的地方。它需要成为“物业”的同伴,而不是孩子。你在最高级别做对了,所以我确信这只是打字错误。 – Jason 2015-04-07 18:41:50