Swagger Editor shows the "Schema error: should NOT have additional properties" error for a path parameter

Swagger Editor shows the "Schema error: should NOT have additional properties" error for a path parameter

我正在使用 http://editor.swagger.io 设计一个 API,我收到一个错误,我不知道如何解决:

Schema error at paths['/employees/{employeeId}/roles'].get.parameters[0]
should NOT have additional properties
additionalProperty: type, format, name, in, description
Jump to line 24

我以类似的方式定义了其他端点,但没有出现此错误。我想知道缩进或未闭合引号是否有问题,但情况似乎并非如此。 Google 似乎也没有提供任何有用的结果。

swagger: "2.0"
info:
  description: Initial draft of the API specification
  version: '1.0'
  title: App 4.0 API
host: api.com
basePath: /v1
tags:
  - name: employees
    description: Employee management
schemes:
  - https
paths:
  /employees/{employeeId}/roles:
    get:
      tags:
        - employees
      summary: "Get a specific employee's roles"
      description: ''
      operationId: findEmployeeRoles
      produces:
        - application/json
      parameters:
        - name: employeeId   <====== Line 24
          in: path
          description: Id of employee whose roles we are fetching
          type: integer
          format: int64
      responses:
        '200':
          description: successful operation
          schema:
            type: array
            items:
              $ref: '#/definitions/Role'
        '403':
          description: No permission to see employee roles
        '404':
          description: EmployeeId not found

有什么提示吗?

错误消息具有误导性。实际错误是您的路径参数丢失 required: true。路径参数始终是必需的,因此请记住向它们添加 required: true

语法要求可能需要两个参数,正如 Helen required: true 所提到的那样 type:DataType 也是如此。该错误具有误导性。

有同样的问题。我不小心混淆了 Swagger 2.0Openapi 3.0.x 的语法。在 Openapi 3.0.x 中, 定义被重新定义为组件 。在 online editor 中,您可以单击按钮 Edit > Convert to OpenAPI 3 以使用 Openapi 3.0.x.

详细了解 组件 here

备注:

OAS 3 is the latest version of the OpenAPI Specification.

在我的例子中,我在 api 定义

中缺少参数定义
- name: parameterName
  in: query
  description: parameter's description here.
  required: false
  schema:
    type: string

对我来说,错误的原因是路径中缺少前导斜杠(internal/resource 而不是 /internal/resource)。

是的,错误消息非常无用。