我尝试使用swagger来描述JSON。到目前为止,它看起来不错,但我不知道如何使用anyOf结构来定义JSON答案中不同对象类型的数组。
以下JSON是有效的,它应该描述一个由文章和视频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中,对象类型总是显示为未定义的,而不是“文章或视频”。
能不能大摇大摆地把这件事做好?
发布于 2015-12-21 19:11:24
澄清一下:swaggerv2.0不支持anyOf。请看里德更多信息:https://github.com/swagger-api/swagger-spec/issues/57
https://stackoverflow.com/questions/23762282
复制相似问题