Swagger编辑器上的文件上传OpenAPI 3在尝试时未显示文件浏览器

时间:2018-02-04 10:27:24

标签: swagger swagger-ui swagger-editor openapi

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

File Upload "Try it out" screenshot

这是路线的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

我在这里缺少什么?

1 个答案:

答案 0 :(得分:1)

你的定义是正确的。

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