如何在OpenAPI 2.0中为同一操作定义path和formData参数?

问题描述 投票:9回答:1

我有一个看起来像/test/{id}/relationships/image的图像上传端点。我想使用OpenAPI 2.0(Swagger 2.0)描述此端点。

端点同时具有path和formData参数。我尝试了以下方法:

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编辑器显示错误:

架构错误位于path ['/ test / {id} / relationships / image']。post.parameters [0] .in应该等于允许的值之一allowedValues:主体,标头,formData,查询跳转到第17行

架构错误位于path ['/ test / {id} / relationships / image']。post.parameters [0]不应具有其他属性extraProperty:架构,名称,必需跳到第17行

我在做什么错?

swagger swagger-2.0 openapi swagger-editor
1个回答
17
投票

在您的路径参数中,更改

          schema:
            type: integer
            format: int32

to

          type: integer
          format: int32

在OpenAPI / Swagger 2.0中,路径,标头,查询和formData参数直接使用type,而没有schemaschema关键字仅用于身体参数。

© www.soinside.com 2019 - 2024. All rights reserved.