Skip to content

Incorrect example generation for array query parameters #1024

@hjhrwerv2423

Description

@hjhrwerv2423

Current behavior

Plugin generates incorrect curl examples for array query parameters defined with style: form and explode: true. The plugin concatenates the array values into a single parameter with comma-separated values, which does not match the expected API format.

For the simplified OpenAPI file:

openapi: 3.0.0
info:
  title: Simple API
  version: 1.0.0
paths:
  /customers:
    get:
      summary: "Retrieve Customers"
      parameters:
        - name: customerIds[]
          in: query
          required: true
          style: form
          explode: true
          schema:
            type: array
            items:
              type: string
            example:
              - "cust789"
              - "cust123"
      responses:
        '200':
          description: OK

The plugin generates the following incorrect curl example:

curl -X GET 'https://api.example.com/customers?customerIds[]=cust789,cust123'

This example combines the array values into a single parameter customerIds[]=cust789,cust123, which does not work with the API.

Possible solution

Modify the plugin to correctly handle array query parameters with style: form and explode: true by generating separate parameters for each array item. The correct curl example should look like:

curl -X GET 'https://api.example.com/customers?customerIds%5B%5D=cust789&customerIds%5B%5D=cust123'

Steps to reproduce

  1. Install docusaurus-plugin-openapi-docs version ^4.2.0.
  2. Create an OpenAPI file with an array parameter as shown in the example above.
  3. Generate the documentation using the plugin.
  4. Notice that the generated curl example concatenates array values into a single parameter with commas.

How editor.swagger.io generates the curl command

When loading this OpenAPI file into editor.swagger.io, it generates the correct curl example:

curl -X GET "https://api.example.com/customers?customerIds%5B%5D=cust789&customerIds%5B%5D=cust123" -H "accept: application/json"

Editor.swagger.io correctly encodes each array item as a separate query parameter, using customerIds%5B%5D=cust789 and customerIds%5B%5D=cust123, which aligns with the OpenAPI specification and the expected API behavior.

Your Environment

  • Version used: docusaurus-plugin-openapi-docs ^4.2.0
  • Environment name and version: Node.js v14.x
  • Operating System and version: Windows 10
  • Link to your project: Private project; the issue can be reproduced using the provided OpenAPI file.

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions