PaloAltoNetworks / PaloAltoNetworks/docusaurus-openapi-docs

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

Open
#909 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug roadmap
Dominant language
TypeScript
Stars
1.1k
Forks
315
Avg merge
7d 5h
Merged PRs (30d)
7

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the generated request sample for the api-users-list endpoint with multiple values in exclude and exclude_target. Trace the sample-code generation entry point and how it reads OpenAPI query-parameter serialization; compare explode=true, omitted, and false. Done means repeated query parameters use '&' when exploded and comma-separated values remain for explode=false.

Written by the indexing model from the issue text.

Assessment

Tech stack
openapi, typescript
Domain
documentation, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.