Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
drwpow opened this issue Oct 1, 2024 Discussed in #1934 · 1 comment · May be fixed by #1936
Open

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

drwpow opened this issue Oct 1, 2024 Discussed in #1934 · 1 comment · May be fixed by #1936
Labels
bug Something isn't working good first issue Straightforward problem, solvable for first-time contributors without deep knowledge of the project openapi-fetch Relevant to the openapi-fetch library PRs welcome PRs are welcome to solve this issue!

Comments

@drwpow
Copy link
Contributor

drwpow commented Oct 1, 2024

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.

@drwpow drwpow added bug Something isn't working PRs welcome PRs are welcome to solve this issue! good first issue Straightforward problem, solvable for first-time contributors without deep knowledge of the project openapi-fetch Relevant to the openapi-fetch library labels Oct 1, 2024
@BlakeSzabo
Copy link

Hi @drwpow I'm happy to do the work for this one if that's all good

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Straightforward problem, solvable for first-time contributors without deep knowledge of the project openapi-fetch Relevant to the openapi-fetch library PRs welcome PRs are welcome to solve this issue!
Projects
None yet
2 participants