0

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

Helen
  • 87,344
  • 17
  • 243
  • 314
Muhammad Arif
  • 1,014
  • 3
  • 22
  • 56

1 Answers1

1

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.

Helen
  • 87,344
  • 17
  • 243
  • 314
  • Helen please tell me how I write path API for this format: /api/v1/products/8000 – Muhammad Arif Dec 07 '22 at 10:25
  • 1
    Use `/api/v1/products/{productId}` as the path and define `productId` as a [path parameter](https://swagger.io/docs/specification/describing-parameters/). – Helen Dec 07 '22 at 11:28
  • Helen When trying to do authorization through bearer token, then unauthenticated error shown. Please tell me about this ![Valid XHTML](https://ibb.co/8PH35F2). – Muhammad Arif Dec 10 '22 at 06:22
  • Make sure your API definition includes the `securitySchemes` AND `security` sections. See the [Bearer authentication](https://swagger.io/docs/specification/authentication/bearer-authentication/) example. – Helen Dec 10 '22 at 09:07
  • Helen I want results like "[ {"name": 5}, {"asim": 8} ]" and tried this requestBody: required: true content: application/json: schema: type: object properties: is_seller: type: array items: type: object properties: name: type: integer asim: type: integer and when run this code required results not shown – Muhammad Arif Dec 16 '22 at 04:43
  • Here is the output of the above code: { "is_seller": [ { "name": 0, "asim": 0 } ] } Helen please tell me how i get the results like : "[ {"name": 5}, {"asim": 8} ]" – Muhammad Arif Dec 16 '22 at 04:44