Swagger 编辑器 - 附加属性错误

问题描述

我刚刚开始使用 Swagger 编辑器/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++ 时,它看起来不错。我还将它粘贴到另一个编辑器中,并注意到它只使用换行符而不使用回车符。我更新了它以同时使用两者,但仍然出现相同的错误

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

解决方法

你有一个小的缩进问题。

添加一个缩进级别

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

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...