小编典典

如何在摇摇欲坠的定义中获取嵌套数组

json

试图使这个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参考?


阅读 220

收藏
2020-07-27

共1个答案

小编典典

您需要具有attachment属性的包装对象的附加定义:

"attachmentWrapper": {
  "type": "object",
  "properties": {
    "attachment": {
      "$ref": "#/definitions/attachment"
    }
  }
}

然后更改您的数组定义以将此包装器用作项目类型:

"attachments": {
  "type":"array",
  "items": {
    "$ref": "#/definitions/attachmentWrapper"
  }
}
2020-07-27