Skip to content

The sample code is wrong when using in query parameters with a list of values #909

@JaimeOVasconcelos

Description

@JaimeOVasconcelos

Describe the bug

The generated code in curl, Python, etc. is not well generated when we have query parameters with a list of values.
The query parameters in the sample code have the list of values separated by commas (",") and should be exploded instead, i.e., repeat the query parameter for each value separated by an "&".
This behavior is defined by the explode OpenAPI property (that defaults to true), which seems to be being ignored.
Even when we force explode to true, it is ignored.
See this example in the OpenAPI spec (you can download it with the Export button at https://developers.probely.com/api/reference/probely-developer-documentation):

image

See more about the explodeproperty at https://swagger.io/docs/specification/serialization/#query

Expected behavior

In the endpoint https://developers.probely.com/api/reference/api-users-list, when adding values for query parameters exclude and exclude_target like this:

Screenshot 2024-08-06 at 17 38 12

Screenshot 2024-08-06 at 17 38 36

The generated curl should be:

curl -L -X GET 'https://api.probely.com/api-users/?exclude=field1&exclude=field2&exclude_target=t1&exclude_target=t2' \
-H 'Accept: application/json' \
-H 'Authorization: JWT <YOUR_API_TOKEN>'

Current behavior

Currently, the generated curl is wrong with the values of the query params exclude and exclude_targetseparated by commas (","):

curl -L -X GET 'https://api.probely.com/api-users/?exclude=field1,field2&exclude_target=t1,t2' \
-H 'Accept: application/json' \
-H 'Authorization: JWT <YOUR_API_TOKEN>'

Possible solution

Consider the explode property of the OpenAPI to generate the sample code.

If explode is not defined or is true the query parameters in the sample code should be repeated for each value that is inserted and separated by "&".
If explode is false the values of the query parameter in the sample code should be separated by a comma (",")

Steps to reproduce

  1. Go to https://developers.probely.com/api/reference/api-users-list
  2. At the right hand side, in the REQUEST section, click on Show optional parameters
  3. Add "field 1" and "field2" to the exclude query parameter
  4. Add "t1" and "t2" to the exclude_targetquery parameter
  5. Check the generated sample code in curl that is generated with query parameters separated by commas

Screenshots

image

Context

This provides a bad user experience for people trying to get the sample code to use the API endpoint since it will not work, and it's difficult to understand why.

Your Environment

  • Version used: docusaurus: 2.4.3, docusaurus-plugin-openapi-docs: 2.1.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingroadmapFeatures or bug fixes planned for future release

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions