orval-labs / orval

orval is able to generate client with appropriate type-signatures (TypeScript) from any valid OpenAPI v3 or Swagger v2 specification, either in yaml or json formats. 🍺
https://orval.dev
MIT License
3.18k stars 336 forks source link

Documentation mistake #1666

Closed dob9601 closed 1 month ago

dob9601 commented 1 month ago

Ran into an issue whereby my requests were missing a ? for any requests containing query parameters. I traced the issue back to this chunk of code I copied from the documentation, which is missing a question mark when constructing the URL. This issue is potentially responsible for: https://github.com/orval-labs/orval/issues/482

https://github.com/orval-labs/orval/blob/87e1db632b0b6678691b3796d162bed13879b065/docs/src/pages/guides/custom-client.md?plain=1#L40

What versions are you using?

Checked on master Please execute npx envinfo --system --npmPackages orval,zod,axios,msw,swr,@tanstack/react-query,@tanstack/vue-query,react,vue and paste the results here.

melloware commented 1 month ago

Can you post your exact fix? missing question mark where?

dob9601 commented 1 month ago

Replacing:

${baseURL}${url}

With:

${baseURL}${url}?

Solved the issue since URLSearchParams doesn't generate a leading question mark when stringified.

Note that this isn't necessarily the ideal solution since requests without query parameters will end up with a trailing question mark - ideally there should be a check beforehand to ensure there are query parameters.

Happy to create a PR if that would be easiest :)

melloware commented 1 month ago

please do! I will merge it

melloware commented 1 month ago

Assigned it to you.

dob9601 commented 1 month ago

See https://github.com/orval-labs/orval/pull/1667