微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Swagger 编辑器 - 附加属性错误

如何解决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

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。