如何在swagger定义中获取嵌套数组 [英] How to get nested array in swagger definition
本文介绍了如何在swagger定义中获取嵌套数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
试图用昂首阔步的定义使这个Json脱颖而出:
Trying to get this Json outpun with swagger definitions:
{
"attachments":[{
"attachment":
{
"filename": "string",
"filedata": "string",
"filetype": "string"
}
},
{
"attachment":
{
"filename": "string",
"filedata": "string",
"filetype": "string"
}
}]
}
我的swagger.json看起来像这样:
My swagger.json looks like this:
"attachments": {
"type":"array",
"items": {
"$ref": "#/definitions/attachment"
}
},
"attachment": {
"type": "object",
"properties": {
"filename": {
"type": "string"
},
"filedata": {
"type": "string"
},
"filetype": {
"type": "string"
}
}
},
我在请求中得到了这个Json:
And I get this Json on the request:
"attachments": [
{
"filename": "string",
"filedata": "string",
"filetype": "string"
}
],
如何获得首个Json语法Swagger引用?
How do I get the first Json syntax trough Swagger references?
推荐答案
您需要具有attachment
属性的包装对象的附加定义:
You need an extra definition for the wrapper object that has the attachment
property:
"attachmentWrapper": {
"type": "object",
"properties": {
"attachment": {
"$ref": "#/definitions/attachment"
}
}
}
然后更改您的数组定义以将此包装器用作项目类型:
Then change your array definition to use this wrapper as the item type:
"attachments": {
"type":"array",
"items": {
"$ref": "#/definitions/attachmentWrapper"
}
}
这篇关于如何在swagger定义中获取嵌套数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文