一尘不染

昂首阔步:requestBody不允许

node.js

我正在尝试使用swagger定义post端点,但是不允许使用该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

我的规格有什么问题?


阅读 241

收藏
2020-07-07

共1个答案

一尘不染

您可能正在混合使用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'

更多信息:描述请求正文

2020-07-07