【问题标题】:File upload on Swagger Editor OpenAPI 3 not showing the file browser when trying it outSwagger Editor OpenAPI 3 上的文件上传在尝试时未显示文件浏览器
【发布时间】:2018-07-14 09:30:18
【问题描述】:

我正在使用带有 OpenAPI 3.0 的 Swagger 编辑器。我需要记录一条包含上传图片的路线。尝试“试用”时,我没有让文件浏览器在请求正文中选择要上传的图像,我得到的只是一个带有参数名称和类型的 JSON 字符串。

这是路由的 YAML 描述:

openapi: 3.0.0
...
paths:
  /media/upload/thumbnail:
    post:
      tags:
        - media
        - publications
      security:
        - bearerAuth: []
      summary: upload a kid's publication
      operationId: uploadPublication
      requestBody:
        content:
          multipart/form-data:
            schema:
              type: object
              properties:
                upload:
                  type: string
                  format: binary
      responses:
        '200':
          description: Successful operation
          content:
            application/json:
              schema:
                type: object
                properties:
                  id:
                    type: string
                    description: ObjectId of the uploaded file in db (original size)
                    example: 5a6048b3fad06019afe44f24
                  filename:
                    type: string
                    example: myPainting.png
                  thumbnail:
                    type: string
                    description: ObjectId of the uploaded file in db (thumbnai size)
                    example: 5a6048b3fad06019afe44f26
        '400':
          description: Authentication failed

我在这里缺少什么?

【问题讨论】:

    标签: swagger swagger-ui swagger-editor openapi


    【解决方案1】:

    你的定义是正确的。

    在 Swagger Editor 3.5.7 和 Swagger UI 3.16.0 中添加了对 OpenAPI 3.0 定义中的 multipart/form-data 请求的文件上传支持。确保您使用的是支持文件上传的版本。

    【讨论】:

      【解决方案2】:

      试试

      content:
                image/png:
                  schema:
                    properties:
                      file:
                        type: string
                        format: binary
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2019-09-08
        • 1970-01-01
        • 1970-01-01
        • 2021-08-06
        • 2018-09-14
        • 1970-01-01
        • 2020-12-08
        相关资源
        最近更新 更多