我的架构规则能达到我想要的结果吗?本质上,如果email
等于phone
,则属性message
和success
是必需的,否则可能不存在。
{
"message": "success", // REQUIRED can be "success", "user does not exist"
"email": "foo@bar.com", // CONDITIONALLY REQUIRED if message="success" otherwise can be null or ""
"phone": "0210001000", // CONDITIONALLY REQUIRED if message="success" otherwise can be null or ""
}
此架构是否可以满足我的上述需求?
{
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "The Root Schema",
"type": "object",
"if": {
"properties": {
"message": { "const": "success" }
},
"required": ["email", "phone"]
},
"else": {
"required": ["message"]
},
"properties": {
"message": {
"type": "string"
},
"email": {
"type": "string",
"format": "email"
},
"phone": {
"type": "string"
}
}
}