我有一个看起来像/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行
我在做什么错?
在您的路径参数中,更改
schema:
type: integer
format: int32
to
type: integer
format: int32
在OpenAPI / Swagger 2.0中,路径,标头,查询和formData参数直接使用type
,而没有schema
。 schema
关键字仅用于身体参数。