fix: query apiKey auth lost when request has no query parameters#3853
fix: query apiKey auth lost when request has no query parameters#3853
Conversation
|
|
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
|
TL;DR — WIP PR opened by Copilot to address a bug where query Key changes
Summary | 0 files | 1 commits | base: Context
The linked issue traces the bug to The reporter suggests either making |
There was a problem hiding this comment.
Note
No file changes yet — the only commit is a placeholder "Initial plan" by Copilot and the diff is empty. Re-request review once the implementation is pushed.
A few notes for when the fix lands, based on the issue's root-cause analysis:
- The bug is in the shared bundle helper
setAuthParams(underpackages/openapi-ts/src/plugins/@hey-api/client-core/bundle/), which is consumed by all three plugin clients —client-fetch,client-ky, andclient-next. Verify the fix lands in the shared file and that all three client bundles pick it up; otherwise the regression coverage is incomplete. packages/custom-clienthas its ownsetAuthParamsand should be checked separately — it is not part of the client-core bundle.- Prefer mutating
optionsdirectly (drop the{ security, ...options }rest destructure) over returning a new object — it keeps the call site inbeforeRequestunchanged and matches the existing header-mutation pattern. Returning a new value forces every caller (includingmakeSseFn) to reassign, which is a wider blast radius. - Add a regression test for the no-query-params case at
packages/openapi-ts/src/plugins/@hey-api/client-{fetch,ky}/__tests__/client.test.ts(the existing query-auth tests likely all setqueryalready, which is why this slipped through).client-nexthas no equivalent interceptor test file today — worth adding one. - Generated snapshots under
packages/openapi-ts-tests/**/__snapshots__/**/client.gen.tsandexamples/**/client.gen.tswill need regenerating if the bundle template changes.
Remove destructuring in setAuthParams so mutations to options.query
propagate back to the original opts object used by buildUrl.
Before this fix, setAuthParams destructured its argument as
{ security, ...options }, which created a new local object. Setting
options.query = {} inside the function only updated that local copy,
so when the caller had no query params (opts.query === undefined), the
token was never visible to buildUrl(opts).
After this fix, setAuthParams receives the options object directly.
When options.query is undefined and a query apiKey is used, the
function initialises options.query = {} on the same reference that
buildUrl later reads, so the token appears in the URL.
Affected clients: client-fetch, client-next, client-axios, client-ky,
client-ofetch, client-nuxt, client-angular, custom-client.
Agent-Logs-Url: https://github.com/hey-api/openapi-ts/sessions/a6408979-09df-4657-a3de-44e893a7c8ce

When using a query
apiKeysecurity scheme, the token was silently dropped from the URL if the request had no other query parameters. Requests with existing query params worked fine because they shared an object reference; requests without query params did not becausesetAuthParamswas mutating a detached local copy.Root cause
setAuthParamsdestructured its argument, creating a new localoptionsobject:Changes
setAuthParams(all clients) — removed destructuring; function now takesoptionsdirectly and iteratesoptions.security ?? []. Signature changed fromPick<Required<RequestOptions>, 'security'> & Pick<RequestOptions, 'auth' | 'query'>toPick<RequestOptions, 'auth' | 'query' | 'security'>.beforeRequestcallers (all clients) — replacedawait setAuthParams({ ...opts, security: opts.security })withawait setAuthParams(opts)so mutations tooptions.queryare visible to the subsequentbuildUrl(opts)call.Nuxt
onRequestinterceptor — kept a thinauthOptswrapper (the$fetchinterceptor options have noauth/security), but propagated the initialized query back:if (authOpts.query !== options.query) options.query = authOpts.query.Regression tests — added
'sets access token in query when query is initially undefined'to each client'sutils.test.ts.Snapshots — updated ~300 generated snapshots to reflect the simplified
await setAuthParams(opts)call site.Affected:
client-fetch,client-next,client-axios,client-ky,client-ofetch,client-nuxt,client-angular,@hey-api/custom-client.Warning
Firewall rules blocked me from connecting to one or more addresses (expand for details)
I tried to connect to the following addresses, but was blocked by firewall rules:
dl.google.com/usr/lib/apt/methods/https /usr/lib/apt/methods/https(dns block)fonts.googleapis.com/usr/bin/node /usr/bin/node /home/REDACTED/work/openapi-ts/openapi-ts/node_modules/.pnpm/next@15.2.4_react-dom@19.0.0_react@19.0.0__react@19.0.0_sass@1.97.3/node_modules/next/dist/compiled/jest-worker/processChild.js rgo/bin/git bash preview/bin/tsgo.js --noprofile(dns block)If you need me to access, download, or install something from one of these locations, you can either: