我正在尝试使用swagger定义后端点,但它不允许使用requestBody
参数:
/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
时,我明白了:
API Errors:
#/paths/~1names~1{roster}/post: Additional properties not allowed: requestBody
1 error and 0 warnings
我的规格出了什么问题?
答案 0 :(得分:4)
您可能正在混合使用OpenAPI / Swagger 2.0和OpenAPI 3.0语法。您的规范似乎是2.0,但requestBody
关键字是3.0功能。在2.0中,请求主体被定义为主体参数:
paths:
/names/{roster}:
post:
produces:
- application/json
...
parameters:
- ...
- in: body
name: body
required: true
schema:
$ref: '#/definitions/ManageNamesRequest'