我正在尝试使用swagger定义post端点,但是不允许使用该requestBody参数:
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,我得到这个:
npm start
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中,请求正文被定义为正文参数:
paths: /names/{roster}: post: produces: - application/json ... parameters: - ... - in: body name: body required: true schema: $ref: '#/definitions/ManageNamesRequest'
更多信息:描述请求正文