如何在 OpenAPI 2.0 中为同一操作定义 path 和 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) 来描述这个端点.
I have an image upload endpoint that looks like /test/{id}/relationships/image
. I want to describe this endpoint using OpenAPI 2.0 (Swagger 2.0).
端点同时具有 path 和 formData 参数.我尝试了以下方法:
The endpoint has both path and formData parameters. I tried the following:
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 显示错误:
But Swagger Editor shows errors:
架构错误路径['/test/{id}/relationships/image'].post.parameters[0].in 应该等于允许的值之一 allowedValues:body、header、formData, query 跳转到第17行
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
架构错误路径['/test/{id}/relationships/image'].post.parameters[0] 不应该有附加属性 additionalProperty: schema, in, name,需要跳转到第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
我做错了什么?
推荐答案
在你的路径参数中,改变
In your path parameter, change
schema:
type: integer
format: int32
到
type: integer
format: int32
在 OpenAPI/Swagger 2.0 中,path、header、query 和 formData 参数直接使用 type
,没有 schema
.schema
关键字仅用于正文参数.
In OpenAPI/Swagger 2.0, path, header, query and formData parameters use type
directly, without a schema
. The schema
keyword is used for body parameters only.
这篇关于如何在 OpenAPI 2.0 中为同一操作定义 path 和 formData 参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!