I try to use swagger for describing a JSON API. So far it looks good, but I can't figure out how to use the anyOf structure for defining an array of different object types in a JSON answer.
The following JSON Schema is valid, and it should describe an array of Article and Video JSOn objects:
{
"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"
}
}
}
}
But in swagger the object type is always displayed as undefined instead of "Article or Video".
Is it possible at all in swagger to make this work?
Just to be clear: Swagger v2.0 does not support anyOf. Reed more here: https://github.com/swagger-api/swagger-spec/issues/57