如何在 OpenAPI 2.0 中为同一操作定义路径和 formData 参数?
How to define path and formData parameters for the same operation in OpenAPI 2.0?
我有一个看起来像 /test/{id}/relationships/image
的图像上传端点。我想使用 OpenAPI 2.0 (Swagger 2.0) 来描述这个端点。
端点同时具有路径和 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 Editor 显示错误:
Schema error at
paths['/test/{id}/relationships/image'].post.parameters[0].in should
be equal to one of the allowed values allowedValues: body, header,
formData, query Jump to line 17
Schema error at
paths['/test/{id}/relationships/image'].post.parameters[0] should NOT
have additional properties additionalProperty: schema, in, name,
required Jump to line 17
我做错了什么?
在您的路径参数中,更改
schema:
type: integer
format: int32
到
type: integer
format: int32
在OpenAPI/Swagger 2.0 中,path、header、query 和formData 参数直接使用type
,没有schema
。 schema
关键字仅用于正文参数。
我有一个看起来像 /test/{id}/relationships/image
的图像上传端点。我想使用 OpenAPI 2.0 (Swagger 2.0) 来描述这个端点。
端点同时具有路径和 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 Editor 显示错误:
Schema error at paths['/test/{id}/relationships/image'].post.parameters[0].in should be equal to one of the allowed values allowedValues: body, header, formData, query Jump to line 17
Schema error at paths['/test/{id}/relationships/image'].post.parameters[0] should NOT have additional properties additionalProperty: schema, in, name, required Jump to line 17
我做错了什么?
在您的路径参数中,更改
schema:
type: integer
format: int32
到
type: integer
format: int32
在OpenAPI/Swagger 2.0 中,path、header、query 和formData 参数直接使用type
,没有schema
。 schema
关键字仅用于正文参数。