尝试以宽松的定义来获得这个Json outpun:
{
"attachments":[{
"attachment":
{
"filename": "string",
"filedata": "string",
"filetype": "string"
}
},
{
"attachment":
{
"filename": "string",
"filedata": "string",
"filetype": "string"
}
}]
}
我的swagger.json看起来像这样:
"attachments": {
"type":"array",
"items": {
"$ref": "#/definitions/attachment"
}
},
"attachment": {
"type": "object",
"properties": {
"filename": {
"type": "string"
},
"filedata": {
"type": "string"
},
"filetype": {
"type": "string"
}
}
},
我根据要求得到了这个Json:
"attachments": [
{
"filename": "string",
"filedata": "string",
"filetype": "string"
}
],
如何通过Swagger引用获得第一个Json语法?
答案 0 :(得分:1)
您需要为具有attachment
属性的包装器对象提供额外的定义:
"attachmentWrapper": {
"type": "object",
"properties": {
"attachment": {
"$ref": "#/definitions/attachment"
}
}
}
然后更改数组定义以将此包装器用作项类型:
"attachments": {
"type":"array",
"items": {
"$ref": "#/definitions/attachmentWrapper"
}
}