我对用户的新消息有一个JSON模式:
message_creation = {
"title": "Message",
"type": "object",
"properties": {
"post": {
"oneOf": [
{
"type": "object",
"properties": {
"content": {
"type": "string"
}
},
"additionalProperties": False,
"required": ["content"]
},
{
"type": "object",
"properties": {
"image": {
"type": "string"
}
},
"additionalProperties": False,
"required": ["image"]
},
{
"type": "object",
"properties": {
"video_path": {
"type": "string"
}
},
"additionalProperties": False,
"required": ["video"]
}
]
},
"doc_type": {
"type": "string",
"enum": ["text", "image", "video"]
}
},
"required": ["post", "doc_type"],
"additionalProperties": False
}就是这么简单!有两个字段,一个是type,另一个是post。因此,如下所示的有效负载成功了:
{
"post": {
"image": "Hey there!"
},
"type": "image"
}现在的问题是,如果用户将type的值设置为text,我就无法验证是否已经给出了文本的模式。我应该如何验证这个?如果type设置为image,我应该如何检查,然后确保post中存在image?
https://stackoverflow.com/questions/50700456
复制相似问题