根据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使用content;当store为path2时,requestBody应对multipart/form-data使用content。
/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发布于 2019-12-10 19:37:45
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:
...https://stackoverflow.com/questions/59234495
复制相似问题