问题
Trying to get this Json outpun with swagger definitions:
{
"attachments":[{
"attachment":
{
"filename": "string",
"filedata": "string",
"filetype": "string"
}
},
{
"attachment":
{
"filename": "string",
"filedata": "string",
"filetype": "string"
}
}]
}
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"
}
}
},
And I get this Json on the request:
"attachments": [
{
"filename": "string",
"filedata": "string",
"filetype": "string"
}
],
How do I get the first Json syntax trough Swagger references?
回答1:
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"
}
}
来源:https://stackoverflow.com/questions/43876840/how-to-get-nested-array-in-swagger-definition