Cristian Baciu
Cristian Baciu

Reputation: 163

Swagger 2.0 duplicated mapping key parser error

I have a swagger file for an API that is going to reside inside IBM API Connect. I typed it out from an IBM tutorial, and I was trying to replicate what the instructor was doing(he did not provide any source files, so I had to type it out).

The tutorial is available here: https://www.youtube.com/watch?v=hCvUYd67rbI The guy is copy-pasting the swagger file inside the APIConnect local designer around 21:40.

I took the swagger file and put it into http://editor.swagger.io/ and I got a bunch of parser errors:

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

I did some digging, and I did not find a lot of resources for my kind of problem. I double-checked if I typed it out correctly from the tutorial. Maybe it has something to do with an older version of API Connect being used in ths tutorial.

Thanks in advance for anyone who can help.

EDIT:

Sorry, it was a bit late so I was tired, I am adding the source code in the yaml file:

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

Upvotes: 1

Views: 21898

Answers (1)

Helen
Helen

Reputation: 97677

  1. There's typo: securityDefinitions defines clientIdHeader, but security refers to clientdHeader (..ntd.. instead of ..enId..).

  2. "Sibling values are not allowed alongside $refs" is not a syntax error, but rather a warning. It's caused by this line:

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

$ref is a JSON Reference, it works by replacing itself and all sibling attributes with the content the $ref is pointing at. So, the type attribute and any other attributes alongside $ref will be ignored. The warning informs you about this in case there are important attributes alongside $ref -- these attributes need to be moved into the $ref'erenced schema to have effect.

That said, xyz being type: string does not make sense, because rates is an object and not a string.

You should also consider adding type: object to the rates, shipping and store_location definitions to indicate that they are objects.

Upvotes: 1

Related Questions