OpenAPITools / OpenAPITools/openapi-generator
[REQ] Expose option to provide default value for useQuerystring in the typescript-node generator
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Overview
Currently the typescript-node generator creates API clients with the value of useQuerystring set to false. The problem is around how array query params are handled which is documented here: https://github.com/request/request#requestoptions-callback.
Depending on how the server is handing array query params may result in different usages of the generated API client.
For example, as the code is today if your server can deserialize the following request into an array then all is good.
/foo?arrayParam[0]=test1&arrayParam[1]=test2
However, not all servers handle array query parameters the same way.
If the server expects arrays to be sent as the following:
/foo?arrayParam=test1&arrayParam=test2
You won't receive the values as you would expect unless the consumer sets useQuerystring to true on the client.
This usage means that the consumers must always update the option to true by calling useQuerystring(true) if the API in question requires a different format for an array in the query string.
Since the sever determines which format it accepts for arrays within a query string it seems like it's best to allow this property to be configured. By exposing this option we will have more control over creating clients that work out of the box leading to less confusion for consumers of the generated client.
Proposed solution
I would like to see a configuration option useQuerystring exposed on the typescript-node generator.
The default value provided for this would be false to keep the change backwards compatible with existing clients.
I'm open to other names here if we feel that this isn't representative but it feels like its the right option as it maps directly to the underlying request libraries useQuerystring option.
Alternative solution
I've considered the alternative of providing custom templates to create clients with useQuerystring set to true. This approach would work but it incurs a lot of overhead on consumers of the generator to tweak the underlying http client option.
Additional context
If you agree this is a change that we want incorporated I am happy to open a PR with the changes to add this functionality.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at the typescript-node generator and inspect how the generated client sets the request library's useQuerystring option, using the proposed custom-template approach as context. Done means the generator exposes a useQuerystring configuration option, defaults it to false, and generated clients honor the configured value.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- node.js, typescript
- Domain
- api, tooling
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100