Skip to content

Replace Array<T> with Iterable<T> in request parameters #1832

Open
@htunnicliff

Description

@htunnicliff

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

Metadata

Metadata

Assignees

Labels

PRs welcomePRs are welcome to solve this issue!enhancementNew feature or requestgood first issueStraightforward problem, solvable for first-time contributors without deep knowledge of the projectopenapi-fetchRelevant to the openapi-fetch library

Type

No type

Projects

Status

No status

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions