在下面的模型中,仅当“detail”数组为空时才需要“category_id”属性。
如果“detail”数组不为空,则不需要“category_id”属性。
如何使用 JSON Schema 做到这一点?
{
"description": "Expense model validation.",
"type": "object",
"properties": {
"description": {
"type": "string"
},
"category_id": {
"type": "string"
},
"detail": {
"type": "array",
"items": {
"description": "Expense detail",
"type": "object",
"properties": {
"description": {
"type": "string"
}
},
"required": [ "description" ]
}
}
},
"required": [ "description", "category_id" ]
}