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

pluginClient: fetch ignores all query parameters #1480

Open
nimo23 opened this issue Dec 18, 2024 · 0 comments
Open

pluginClient: fetch ignores all query parameters #1480

nimo23 opened this issue Dec 18, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@nimo23
Copy link

nimo23 commented Dec 18, 2024

What version of kubb is running?

3.3.4

What kind of platform do you use?

None

How does your kubb.config.ts config look like

pluginClient({
..
client: 'fetch',
operations: true,
paramsType: "inline",
pathParamsType: "inline",
dataReturnType: 'full'
}),

Swagger/OpenAPI file?

No response

What version of external packages are you using(@tanstack-query, MSW, React, Vue, ...)

React 19

What steps can reproduce the bug?

  1. Use fetch client with RequestParam (e.g. /api/user/test?allFields=true (where test is the username)
  2. You will see that all query parameters (after ?) are ignored

How often does this bug happen?

Every time

What is the expected behavior?

Query params should not be ignored

Additional information

Looking at Kubb's fetch.js code, the query parameters are not processed:

// src/clients/fetch.ts
var fetchClient = async (config) => {
  const response = await fetch([config.baseURL, config.url].filter(Boolean).join(""), {
    method: config.method.toUpperCase(),
    body: JSON.stringify(config.data),
    signal: config.signal,
    headers: config.headers
  });
  const data = await response.json();
  return {
    data,
    status: response.status,
    statusText: response.statusText
  };
};

For example, if you look at the code generated by orval, the query parameters are appended to the URL (which is not the case with kubb):

export const getGetUserByUsernameUrl = (username: string,
    params?: GetUserByUsernameParams,) => {
  const normalizedParams = new URLSearchParams();

  Object.entries(params || {}).forEach(([key, value]) => {
    
    if (value !== undefined) {
      normalizedParams.append(key, value === null ? 'null' : value.toString())
    }
  });

  return normalizedParams.size ? `/api/user/${username}?${normalizedParams.toString()}` : `/api/user/${username}`
}
@nimo23 nimo23 added the bug Something isn't working label Dec 18, 2024
@nimo23 nimo23 changed the title pluginClient: fetch ignores any query params pluginClient: fetch ignores all query parameters Dec 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant