本文介绍了招摇: requestBody 不允许的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用 swagger 定义发布端点,但它不允许使用 requestBody
参数:
I'm trying to define a post endpoint using swagger, but it isn't allowing the requestBody
parameter:
/names/{roster}:
get:
#...
post:
x-swagger-router-controller: names
description: Adds or removes name(s)
operationId: manageNames
parameters:
- name: roster
in: path
description: the roster to use
type: string
required: true
requestBody:
content:
'application/json':
schema:
$ref: '#/definitions/ManageNamesRequest'
当我运行 npm start
时,我得到:
when I run npm start
, I get this:
API Errors:
#/paths/~1names~1{roster}/post: Additional properties not allowed: requestBody
1 error and 0 warnings
我的规格有什么问题?
推荐答案
您可能正在混合使用 OpenAPI/Swagger 2.0 和 OpenAPI 3.0 语法.您的规范似乎是 2.0,但 requestBody
关键字是 3.0 功能.在 2.0 中,请求体被定义为一个体参数:
You are probably mixing OpenAPI/Swagger 2.0 and OpenAPI 3.0 syntax. Your spec seems to be 2.0, but the requestBody
keyword is a 3.0 feature. In 2.0, the request body is defined as a body parameter:
paths:
/names/{roster}:
post:
produces:
- application/json
...
parameters:
- ...
- in: body
name: body
required: true
schema:
$ref: '#/definitions/ManageNamesRequest'
更多信息:描述请求正文
这篇关于招摇: requestBody 不允许的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!