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

Query parameters incorrectly appended with '?' instead of '&' for URLs containing existing params #2095

Open
MPratley opened this issue Jan 8, 2025 · 0 comments
Labels
bug Something isn't working openapi-fetch Relevant to the openapi-fetch library

Comments

@MPratley
Copy link

MPratley commented Jan 8, 2025

openapi-fetch version

0.13.4

Description

When using openapi-fetch to make requests to endpoints that already contain query parameters, additional query parameters are incorrectly appended using a question mark (?) instead of an ampersand (&). This results in malformed URLs that may not be properly processed by the server.

Reproduction

Example:

import { createClient } from 'openapi-fetch'

const client = createClient({
  baseUrl: 'https://api.example.com'
})

const response = await client.GET('/index.php?task=users.getUsers', {
  params: {
    query: {
      page: '1',
      limit: '10'
    }
  }
})

Expected result

Given the example above, When adding additional params like { page: 1, limit: 10 } should result in:

"/index.php?task=users.getUsers&page=1&limit=10"

But currently results in

"/index.php?task=users.getUsers?page=1&limit=10"  // Invalid URL format, has two '?'s

We're interfacing with a legacy php application, where a lot of our "endpoints" are just calls to an old MVC framework. As a result, a load of our endpoints are structured as query params that define the requested resource + query params that change pagination / what entities to return. See the reproduction for an example.

(I'm happy to open a pull request for this - but may need pointing in the direction of the code the currently handles query param appends)

@MPratley MPratley added bug Something isn't working openapi-fetch Relevant to the openapi-fetch library labels Jan 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working openapi-fetch Relevant to the openapi-fetch library
Projects
None yet
Development

No branches or pull requests

1 participant