Skip to content

Multiple query parameter empty arrays append orphaned ampersands to query string #1935

Closed
@drwpow

Description

@drwpow

Discussed in #1934

Originally posted by BlakeSzabo October 1, 2024
Hi,

I've been using openapi-fetch and have been enjoying it so far but I have noticed a strange behaviour with arrays being passed in query params

here's a basic implementation of a client that will call the /posts endpoint and pass in four separate query params, each an empty array just to be a bit dramatic:

import createClient from 'openapi-fetch';
import type { paths } from '../types/api';

const client = createClient<paths>({ baseUrl: 'http://localhost:3001' });

export const getPosts = () => {
    client.GET('/posts', {
        params: {
            query: {
                first_array: [],
                second_array: [],
                third_array: [],
                fourth_array: [],
            },
        },
    });
};

Given all these arrays are empty, I wouldn't expect them to impact the query params; similar to how undefined or null would behave. However, the resulting request URL is http://localhost:3001/posts?&&&
image

I assume this behaviour isn't intended but wanted to check before raising an issue. I'm also willing to contribute to help solve this if I can. Thanks.

Metadata

Metadata

Assignees

No one assigned

    Labels

    PRs welcomePRs are welcome to solve this issue!bugSomething isn't workinggood first issueStraightforward problem, solvable for first-time contributors without deep knowledge of the projectopenapi-fetchRelevant to the openapi-fetch library

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions