【发布时间】:2018-01-21 14:14:41
【问题描述】:
我在 json 架构中创建了一个 Avatar,在我的应用程序中,如果我们想隐藏头像,我们将其作为 false 传递,否则,头像有图像和名称。
在json模式中,我指定头像为
const avatarSchema = {
"type": ["object", "boolean"],
"required": [],
"additionalProperties": false,
"properties":{
"name": {
"type": "string"
},
"image": {
"type": "string",
"format": "url"
}
}
};
这不起作用,因为如果 Avatar = true, 'image' does not exist on type 'Avatar'.
Property 'image' does not exist on type 'true'.
我不希望Avatar 都是true,要么是false 要么是{image, name},我如何告诉json schema 以这种方式操作?
【问题讨论】:
标签: jsonschema