【问题标题】:Swagger - calling a service which returns file does not work properlySwagger - 调用返回文件的服务无法正常工作
【发布时间】:2016-04-26 13:26:16
【问题描述】:

我遇到了与herehere 描述的问题类似的问题。我有一项服务,它返回一个带有Content-Disposition 标头的pdf 文件作为附件。这在我从浏览器调用端点时有效 - 文件已下载。在 Swagger UI 上,调用响应内容类型为 application/pdf 的服务后,我得到了一个下载链接,但是该链接下载的是一个空的 pdf 文件:

请注意,我的swagger.json 是由 Enunciate(2.3.0 版)生成的,相关部分如下所示:

"responses": {
  "200": {
    "schema": {
    "description": "",
    "$ref": "#/definitions/json_File"
  }, ...

我尝试在其中添加"type": "file",但并没有解决问题。这里可能出了什么问题?

【问题讨论】:

    标签: rest swagger swagger-ui enunciate


    【解决方案1】:

    您可以将响应的返回类型 (200) 记录为二进制(格式):

      responses:
        '200':
          description: successful operation
          schema:
            type: string
            format: binary
    

    根据规范,“二进制”(格式)是指“任何八位字节序列 "

    参考:https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md#data-types

    【讨论】:

    • 我试过了,但我仍然遇到同样的问题。根据最后一条评论here 类型应该是file
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-07-02
    • 1970-01-01
    • 1970-01-01
    • 2015-03-06
    • 1970-01-01
    • 2023-02-08
    • 1970-01-01
    相关资源
    最近更新 更多