Gets duplicated mapping key error using openapi 3.0

Zeinab Abbasimazar picture Zeinab Abbasimazar · Dec 22, 2018 · Viewed 7.7k times · Source

I am trying to define my APIs using openapi version 3.0.0. I've generated following YAML file:

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

When I copy/paste these lines into Swagger Editor, it gives me duplicated mapping key error on line 19; it is for section description of parameter Content-Type.

I have studied openapi documentation, but I didn't see anything wrong with my YAML file.

Answer

Anthon picture Anthon · Dec 22, 2018

I am not sure why you get that error, I tried to find out in which language Swagger is written, as there are several YAML parsers out there that are known to have problems, but couldn't easily determine that using google or wikipedia.

You don't have any duplicate keys in your file, but it is invalid (i.e. not valid YAML) because of the indentation of the key content (the second occurrence, the one under paths/v1/service/uripostresponses200), that should be aligned with description as that key cannot have a value node that is both a scalar (OK) as well as a mapping node content: ....