Swagger docs在Rails中上传二进制文件不正确的curl命令

时间:2017-05-22 17:14:20

标签: ruby-on-rails curl swagger swagger-2.0

为我的api端点创建一个Swagger文档。我有一个在终端

中工作的curl命令
curl -X POST -b "http://localhost:3000/v0/users/4/avatar" -H "accept: application/json" -H "content-type: multipart/form-data" -F avatar=@wolf.b64

这返回的是来自rails的ActionDispatch::Http::UploadedFile对象。

但是,我的swagger doc curl命令看起来像这样

curl -X POST "http://localhost:3000/v0/users/4/avatar" -H "accept: application/json" -H "content-type: multipart/form-data" -F avatar=wolf.b64

头像参数不以@开头,这使得它只是一个字符串而不是一个文件。

我需要帮助弄清楚如何设置swagger,以便在文件名前面添加@。

这就是我的Swagger的样子。

  "post": {
    "tags": [
      "user"
    ],
    "description": "Update user",
    "operationId": "updateUser",
    "produces": [
      "application/json"
    ],
    "consumes": [
      "multipart/form-data"
    ],
    "parameters": [
      {
        "name": "userId",
        "in": "path",
        "description": "ID of the user that needs to be updated",
        "required": true,
        "type": "integer",
        "format": "int64"
      },
      {
        "name": "avatar",
        "in": "formData",
        "description": "Base64 encoded image upload",
        "required": true,
        "type": "file"
      }
    ],
    "responses": {
      "200": {
        "description": "The user avatars was successfully updated"
      },
      "401": {
        "description": "Unauthorized"
      }
    }
  }
},

0 个答案:

没有答案