簡體   English   中英

使用OpenAPI 3.0獲取重復的映射鍵錯誤

[英]Gets duplicated mapping key error using openapi 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編輯器中時 ,它使我在第19行出現了duplicated mapping key錯誤; 用於參數Content-Typedescription

我已經研究過openapi文檔 ,但是我的YAML文件沒有發現任何問題。

我不確定您為什么會收到該錯誤,我試圖找出Swagger是用哪種語言編寫的,因為那里有多個已知存在問題的YAML解析器,但是使用Google或Wikipedia無法輕松確定。

您的文件中沒有重復的密鑰,但是由於密鑰content的縮進(第二次出現, paths/v1/service/uripostresponses ),因此無效(即無效的YAML) → 200 ),應該與description保持一致,因為該鍵不能有一個既是標量( OK )也不是映射節點content: ....的值節點content: ....

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM