根据Swagger send body and formData parameter和OpenAPI 2.0 Specification,在OpenAPI 2.0中,in: body
和in: formData
参数不能同时用于同一操作。那是有道理的。
但是我正在使用OpenAPI 3.0,我想知道是否有一种方法可以根据路径参数切换requestBody
?当store
为path1
时,requestBody
应该将内容与application/json
一起使用;当store
为path2
时,requestBody
应该使用带有multipart/form-data
的内容。
/customs/{store}:
post:
description: Customs server calls Nomad to receive the filing result of one
order
operationId: post_customs_callback
parameters:
- description: ID of the store.
explode: true
in: path
name: store
required: true
schema:
type: string
style: simple
requestBody:
required: true
content:
multipart/form-data:
schema:
type: object
properties: # Request parts
openReq:
type: string
# application/json:
# schema:
# type: string
description: Order details
答案 0 :(得分:1)
OpenAPI规范没有基于特定参数值更改请求/响应正文的方法。但是,在您的方案中,您可以改用两个非参数化路径– /customs/path1
用于JSON请求,/customs/path2
用于多部分请求。
openapi: 3.0.0
...
paths:
/customs/path1:
post:
...
requestBody:
required: true
content:
application/json:
schema:
...
/customs/path2:
post:
...
requestBody:
required: true
content:
multipart/form-data:
schema:
...