我正在验证一个json方案,我需要检查json是否有'活动'数组,如果没有,是否有'live'属性必须为true。
我的架构非常简单note the enum is not working
const viewSchema = {
"type": "object",
"anyOf": [
{"required": ["live"]},
{"required": ["activities"]}
],
"properties":{
"title": {"type": "string"},
"live": {"type": "boolean", "enum": [ true ]},
"activities": {"type": "array"}
}
所以我试图验证以下
isValid({title: 'a title'}) // false: activities or live required
isValid({title: 'a title', activities: []}) // true
isValid({title: 'a title', live: true}) // true
isValid({title: 'a title', live: false) // true - this should be false