openapi-typescript icon indicating copy to clipboard operation
openapi-typescript copied to clipboard

Replace `Array<T>` with `Iterable<T>` in request parameters

Open htunnicliff opened this issue 1 year ago • 2 comments

Description

When working with APIs that accept array query parameters, sometimes data structures that differ from arrays are used to keep track of these parameters before requests.

For example, when passing an array of IDs as a query parameter, the code responsible for keeping the IDs might use a Set to ensure all IDs are unique.

When passing this Set into an openapi-fetch request, it must be converted to an array like so:

const client = createClient(...);

const itemsIds = new Set(["id-1", "id-1", "id-1"]); // Set {"id-1"}

await client.GET("/some/path", {
  params: {
    query: {
      ids: Array.from(itemIds) // or [...itemIds]
    }
  }
});

Proposal

I propose that both the types and internals for openapi-fetch be modified to support Iterable data structures so that users don't need to convert structures into an array before using in openapi-fetch requests.

Checklist

htunnicliff avatar Aug 09 '24 18:08 htunnicliff