试图使这个Json带有昂首阔步的定义:
{ "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" } ],
如何获得第一个Json语法槽Swagger参考?
您需要具有attachment属性的包装对象的附加定义:
attachment
"attachmentWrapper": { "type": "object", "properties": { "attachment": { "$ref": "#/definitions/attachment" } } }
然后更改您的数组定义以将此包装器用作项目类型:
"attachments": { "type":"array", "items": { "$ref": "#/definitions/attachmentWrapper" } }