0

我正在尝试使用openapiversion定义我的 API 3.0.0。我生成了以下 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参数部分Content-Type

我研究过openapi 文档,但我的 YAML 文件没有发现任何问题。

4

1 回答 1

4

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

您的文件中没有任何重复的键,但它是无效的(即无效的 YAML),因为键的缩进content(第二次出现,在paths/v1/service/uripostresponses→下的那个200),应该与之对齐 description键不能有既是标量 ( OK) 又是映射节点的值节点content: ....

于 2018-12-22T10:35:02.440 回答