6
我试图实现这个条件:字段是必需的基于另一个字段的值,即如果请求与“索引”:“真”存在然后“ID”所需元素:true。JSON模式条件:字段是需要基于另一个字段的值
下面是一个简单的模式:
{
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "test title",
"type": "object",
"properties": {
"data": {
"type": "array",
"items": {
"$ref": "#/definitions/Item"
},
"minItems": 0
}
},
"required": [
"data"
],
"definitions": {
"Item": {
"type": "object",
"properties": {
"id": {
"type": [
"integer",
"string"
]
},
"type": {
"type": "string"
}
}
}
}
}
如何可以实现?
任何指针都会有帮助。
[如何在JSON模式中使用依赖关系(draft-04)](http://stackoverflow.com/questions/18375506/how-to-use-dependencies-in-json-schema-draft-04 ) – jruizaranguren 2014-11-24 09:10:33
[JSON模式 - 根据另一个字段的值需要指定字段]的可能重复(http://stackoverflow.com/questions/9029524/json-schema-specify-field-is-required-based-on-value -of-另一场) – buff 2016-01-22 13:05:23