招摇:不允许requestBody

时间:2017-10-06 17:20:11

标签: node.js swagger

我正在尝试使用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

我的规格出了什么问题?

1 个答案:

答案 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'

更多信息:Describing Request Body