Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Json 如何在swagger定义中获取嵌套数组_Json_Swagger_Swagger 2.0 - Fatal编程技术网

Json 如何在swagger定义中获取嵌套数组

Json 如何在swagger定义中获取嵌套数组,json,swagger,swagger-2.0,Json,Swagger,Swagger 2.0,正在尝试使用swagger定义获取此Json输出: { "attachments":[{ "attachment": { "filename": "string", "filedata": "string", "filetype": "string" } }, { "attachment": { "filename": "string", "filedata": "string", "filetype": "string" }

正在尝试使用swagger定义获取此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"
  }
],

如何通过Swagger引用获得第一个Json语法?

您需要为具有
附件属性的包装器对象提供一个额外的定义:

"attachmentWrapper": {
  "type": "object",
  "properties": {
    "attachment": {
      "$ref": "#/definitions/attachment"
    }
  }
}
然后更改数组定义,将此包装器用作项类型:

"attachments": {
  "type":"array",
  "items": {
    "$ref": "#/definitions/attachmentWrapper"
  }
}

您说的是“嵌套数组”,但第一个示例是对象/哈希映射。哪一个是正确的?对不起,目标是得到一个数组,我用正确的语法编辑了这个问题。谢谢你。