openapiswagger-editorswaggerhub

How to fix the "duplicate mapping key" error in the SwaggerHub editor?


When I paste my OpenAPI definition into the SwaggerHub editor, it shows the "duplicate mapping key" error. If I add some spaces, then an indentation error is shown. How to fix these errors?

Here is my OpenAPI YAML code:

  paths:
   /widgets/home-page:
   get:
  tags:
    - home Page APIs sfssf
  description: asd
  operationId: getwidgets
  responses:
    '200':
      description: home page catregories widgets
      content:
        application/json:
          schema:
            type: array
            items:
              type: string
              format: https://api.inspireuplift.com/api/v1/widgets/home-page

"Duplicate mapping key" error in the SwaggerHub editor


Solution

  • There are indentation errors and structural errors in your OpenAPI YAML. Specifically, there should be just one paths section at the root level, with individual paths listed inside it, like so:

    paths:                  # <-----
      /widgets/home-page:   # <-----
        get:                # <-----
          tags:
            - home Page APIs sfssf
          description: asd
          operationId: getwidgets
          responses:
            '200':
              ...
    
      /trending-products:   # <-----
        get:                # <-----
          tags:             # <-----
            - ...
          description: ...
          ...
    

    Pay attention to the structure and indentation in this example and fix your definition accordingly.

    See the Paths and Operations guide on swagger.io for more details.