Swagger 编辑器 - 其他属性错误

Swagger Editor - Additional Properties Error

我刚开始使用 Swagger Editor/OpenAPI 3 规范,所以目前进展不顺利。我已经在本地机器上安装了 运行 Swagger Editor v. 3.15.2。

这是我目前拥有的 yaml:

openapi: "3.0.0"
info:
  version: 1.0.0
  title: Test
paths:
  /object:
    post:
      summary: Create an object
      operationId: createObject
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/Object"
    responses:
      '201':
        description: Created
components:
  schemas:
    Object:
      required:
        - name
        - description
      properties:
        name:
          type: string
        description:
          type: string

它显示此错误:

Errors


Resolver error
e is undefined
Structural error at paths./object
should NOT have additional properties
additionalProperty: responses
Jump to line 6
Structural error at paths./object.post
should have required property 'responses'
missingProperty: responses
Jump to line 7

我确保所有缩进都使用了两个空格。当我从编辑器中复制 yaml 并将其放入 Notepad++ 时,它看起来不错。我还将它粘贴到另一个编辑器中,注意到它只使用换行符而不使用回车 returns。我将其更新为同时使用两者,但仍然出现相同的错误。

我查看了具有相同问题的其他问题,但 none 的解决方案对我有用。所以,不确定我做错了什么。非常感谢任何指导。

你有一个小的缩进问题。

增加一级缩进

responses:
  '201':
    description: Created

这样你就有了:

openapi: "3.0.0"
info:
  version: 1.0.0
  title: Test
paths:
  /object:
    post:
      summary: Create an object
      operationId: createObject
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/Object"
      responses:
        '201':
          description: Created
components:
  schemas:
    Object:
      required:
        - name
        - description
      properties:
        name:
          type: string
        description:
          type: string