【问题标题】:Swagger 2.0 duplicated mapping key parser errorSwagger 2.0 重复映射键解析器错误
【发布时间】:2018-01-14 22:43:57
【问题描述】:

我有一个用于 API 的 swagger 文件,该文件将驻留在 IBM API Connect 中。我是从 IBM 教程中打出来的,我试图复制讲师正在做的事情(他没有提供任何源文件,所以我不得不打出来)。

教程可在此处获得:https://www.youtube.com/watch?v=hCvUYd67rbI 这家伙在 21:40 左右将 swagger 文件复制粘贴到 APIConnect 本地设计器中。

我把 swagger 文件放到http://editor.swagger.io/ 中,我得到了一堆解析器错误:

Errors
Hide
Parser error duplicated mapping key
Jump to line 31

Semantic error at definitions.shipping.properties.xyz.type
Sibling values are not allowed alongside $refs
Jump to line 86

Semantic error at definitions.shipping.properties.cek.type
Sibling values are not allowed alongside $refs
Jump to line 89

我进行了一些挖掘,但没有找到很多资源来解决我的问题。我仔细检查了我是否从教程中正确输入了它。也许这与本教程中使用的旧版本的 API Connect 有关。

提前感谢任何可以提供帮助的人。

编辑:

不好意思,来晚了,累了,我在yaml文件中添加源代码:

info:
    x-ibm-name: logistics
    title: logistics
    version: 1.0.0
schemes:
    - https
basePath: /logistics
consumes:
    - application/json
produces:
    - application/json
securityDefinitions:
  clientIdHeader:
    type: apiKey
    in: header
    name: X-IBM-Client-Id
security:
    - clientdHeader: []
x-ibm-configuration:
    testable: true
    enforced: true
    cors:
        enabled: true
    gateway: datapower-gateway
    catalogs:
        apic-dev:
            properties:
                runtime-url: $(TARGET_URL)
    properties:
        shipping_svc_url:
            value: 'http://shipping.think.ibm:5000/calculate'
            description: Location of the shipping calculator service
            encoded: false
paths:
    /shipping:
        get:
            responses:
                '200':
                    description: 200 OK
                    schema:
                        $ref: '#/definitions/shipping'
            summary: Calculate shipping costs to a destination zip code
            operationId: shipping.calc
            parameters:
                - name: zip
                  type: string
                  required: true
                  in: query
                  description: Destination zip code.
    /stores:
        get:
            responses:
                '200':
                    description: 200 OK
                    schema:
                        $ref: '#/definitions/store_location'
            tags:
                - stores
            summary: Locate store near zip code
            operationId: get.stores
            parameters:
                - name: zip
                  type: string
                  required: true
                  in: query
definitions:
    rates:
        properties:
            next_day:
                type: string
                example: '20.00'
            two_day:
                type: string
                example: '17.00'
            ground:
                type: string
                example: '8.00'
        required:
            - two_day
            - next_day
            - ground
    shipping:
        properties:
            xyz:
                type: string
                $ref: '#/definitions/rates'
            cek:
                type: string
                $ref: '#/definitions/rates'
        required:
            - xyz
            - cek
    store_location:
        properties:
            google_maps_link:
                type: string
                example: 'https://www.google.com/maps?q=34.1030032,-118.4104684'
        required:
            - google_maps_link

【问题讨论】:

    标签: parsing yaml swagger apiconnect


    【解决方案1】:
    1. 有错别字:securityDefinitions 定义了clientIdHeader,但security 指的是clientdHeader..ntd.. 而不是..enId..)。

    2. “$refs 旁边不允许有兄弟值”不是语法错误,而是警告。这是由这一行引起的:

       definitions:
           rates:
               properties:
                   ...
           shipping:
               properties:
                   xyz:
                       type: string   # <---------------
                       $ref: '#/definitions/rates'
      

    $ref 是一个JSON Reference,它通过用$ref 指向的内容替换自身和所有同级属性来工作。因此,type 属性和$ref 旁边的任何其他属性都将被忽略。如果$ref 旁边有重要属性,则警告会通知您——这些属性需要移动到$ref'erenced 架构中才能生效。

    也就是说,xyztype: string 没有意义,因为 rates 是一个对象而不是字符串。

    您还应该考虑将type: object 添加到ratesshippingstore_location 定义中,以表明它们是对象。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-06-14
      • 2020-06-16
      • 2017-01-10
      • 2018-12-31
      • 2021-01-27
      相关资源
      最近更新 更多