我有如下的jsonSchema
[{
"path": [
"General",
"label"
],
"type": "label",
"label": "Calculate Losses From Sub-Peril(s)",
"required": true
},
{
"path": [
"General",
"fire"
],
"type": "boolean",
"default": true,
"label": "Fire"
},
{
"path": [
"General",
"fireSmoke"
],
"type": "boolean",
"default": false,
"label": "Fire and Smoke"
}
],
我有jsonSchema规则,如下所示。因此,如果用户同时取消选中“火灾”和“火灾与烟雾”,则我想发出通知。我如何定义JsonSchema规则。有人可以解决这个问题吗?我有以下规则,但它给了我解析器错误。必须选中至少一个复选框。
{
"path": [
"General",
"fire"
],
"effect": "fireNotification",
"notification": {
"type": "warning",
"message": "At least one Sub-Peril must be selected",
"notificationID": "fire",
"dismissible": "false"
},
"condition": {
"operator": "oneOf": {
"properties": {
"fire": {
"enum": [
true
]
},
"fireSmoke": {
"enum": [
true
]
}
}
}
}
}
您的JSON在两种方式上都是无效的,都在同一行上:
"operator": "oneOf": {
"operator":
)(以及稍后需要一个匹配的闭括号。{
的值应该是一个数组,因此您需要在此处添加一个右括号("oneOf":
)(以及稍后匹配的右括号)。此外,您说“必须至少选择一个复选框”,但是您使用的是“ oneOf”规则,而不是“ anyOf”规则。使用“ oneOf”,如果两个属性都为true,则验证将失败。