我尝试使用swagger来描述 JSON API。到目前为止它看起来不错,但我不知道如何使用 anyOf 结构在 JSON 答案中定义不同对象类型的数组。
以下 JSON Schema 是有效的,它应该描述一个 Article 和 Video JSOn 对象的数组:
{
"Article":{
"id":"Article",
"required": ["title"],
"properties":{
"title":{
"type":"string",
"description": "Title of the article"
}
}
},
"Video":{
"id":"Video",
"required": ["title"],
"properties":{
"title":{
"type":"string",
"description": "Title of the video"
}
}
},
"News":{
"id":"News",
"required": ["instance_data"],
"properties":{
"instance_data":{
"anyOf":[
{ "$ref": "Article" },
{ "$ref": "Video" } ],
"description": "News instance data"
}
}
}
}
但在 swagger 中,对象类型始终显示为未定义,而不是“文章或视频”。
是否有可能大摇大摆地完成这项工作?