Skip to content

[REQ] Expose option to provide default value for useQuerystring in the typescript-node generator #7787

@paulrizzo

Description

@paulrizzo

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions