代码之家  ›  专栏  ›  技术社区  ›  JuKe

如何在OpenAPI 2.0中为相同的操作定义路径和formData参数?

  •  9
  • JuKe  · 技术社区  · 8 年前

    /test/{id}/relationships/image 。我想使用OpenAPI 2.0(Swagger 2.0)描述这个端点。

    swagger: '2.0'
    info:
      title: API
      version: 1.0.0
    host: api.server.de
    schemes:
      - https
    produces:
      - application/json
    paths:
      '/test/{id}/relationships/image':
        post:
          operationId: addImage
          consumes:
            - multipart/form-data
          parameters:
            - in: path
              name: id
              required: true
              schema:
                type: integer
                format: int32
            - in: formData
              name: file
              type: file
              required: true
              description: The file to upload.
            - in: formData
              name: metadata
              type: string
              required: false
              description: Description of file contents.
          responses:
            '202':
              description: Uploaded
    

    但Swagger Editor显示了错误:

    路径['/test/{id}/relationships/image']。post.parameters[0]。在should中 formData,查询跳转到第17行

    架构错误 路径['/test/{id}/relationships/image']。参数[0]不应 具有其他属性additionalProperty:schema、in、name、, 需要跳到17号线

    我做错了什么?

    1 回复  |  直到 6 年前
        1
  •  17
  •   Helen    8 年前

    在路径参数中,更改

              schema:
                type: integer
                format: int32
    

              type: integer
              format: int32
    

    type 直接,无需 schema 架构 关键字仅用于正文参数。