使用OpenAPI 3.0获取重复的映射键错误

时间:2018-12-22 08:17:28

标签: yaml openapi swagger-3.0

我正在尝试使用openapi版本3.0.0定义我的API。我生成了以下YAML文件:

openapi: 3.0.0

info:
    title: My YAML
    description: My YAML
    version: 1.0.0

servers:
- url: http://my.server.url

paths:
     /v1/service/uri:
        post:
          summary: Getting some information.
          parameters:

          - name: Content-Type
            in: header
            description: Content type of request body.
            required: true
            style: simple
            explode: false
            schema:
              type: string

          - name: Host 
            in: header
            description: Originate host which returns the response.
            required: false
            style: simple
            explode: false
            schema:
              type: string

          requestBody:
            content:
              application/json:
                schema:
                  $ref: '#/components/schemas/MyPostRequest'
                  example:
                      my_name: "zizi"
                      my_age: 29

            required: true

          responses:
            200:
              description: OK
                  content:
                    application/json:
                      schema:
                        $ref: '#/components/schemas/MyPostResponse'

components:
    schemas:

        MyPostRequest:
            type: object
            properties:
                my_name:
                    type: string
                my_age:
                    type: integer
                    format: int32

        MyPostResponse:
            type: object
            properties:
                status:
                    type: integer
                    format: int32

当我将这些行复制/粘贴到Swagger Editor时,在行duplicated mapping key上出现19错误;用于参数description的{​​{1}}部分。

我研究了openapi documentation,但是我的YAML文件没有出现任何问题。

1 个答案:

答案 0 :(得分:3)

我不确定您为什么会收到该错误,我试图找出Swagger是用哪种语言编写的,因为那里有多个已知存在问题的YAML解析器,但无法轻易确定使用google还是维基百科。

您的文件中没有重复的密钥,但由于密钥content的缩进(第二次出现,paths下的一个),它无效(即,无效的YAML) → /v1/service/uripostresponses200),应与 description,因为该键不能同时具有标量(OK)和映射节点content: ....

的值节点