-
Notifications
You must be signed in to change notification settings - Fork 289
Description
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: OKThe 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
- Install
docusaurus-plugin-openapi-docsversion^4.2.0. - Create an OpenAPI file with an array parameter as shown in the example above.
- Generate the documentation using the plugin.
- 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.