Repository navigation
feat(api): Make the query-string@7 serializer the default - #131247
Conversation
Consumers could already pass querySerializer to createSentryClient, but code whose URLs, cache keys or snapshots depend on query-string@7 had no matching serializer. queryStringSerializer gives stringify's default output: sorted keys, null as a bare key, undefined omitted, repeated arrays, strict percent-encoding. The client's default serializer is unchanged. Co-Authored-By: BYK <[email protected]>
…ng-serializer Co-Authored-By: BYK <[email protected]> # Conflicts: # static/packages/api/build.mjs
…ng-serializer # Conflicts: # static/packages/api/build.mjs
…ng-serializer Co-Authored-By: BYK <[email protected]>
The client and every generated operation now sort query keys, write null as a bare key, omit undefined and repeat arrays, as query-string@7's stringify does. Objects stay in deepObject style. The previous serializer, its options form and the opt-in queryStringSerializer export are gone; querySerializer now only takes a function. Co-Authored-By: BYK <[email protected]>
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 649f876. Configure here.
| ]; | ||
| }); | ||
|
|
||
| rewrite("core/types.gen.ts", file => { |
There was a problem hiding this comment.
No way to override this at build time??
There was a problem hiding this comment.
Only partly. The one generation-time hook in @hey-api/openapi-ts 0.98 is the client plugin's runtimeConfigPath: a module that exports createClientConfig(), which the generated client.gen.ts calls to set the initial config of the default client. There's no option to plug in a query serializer module; the client runtime (client/utils.gen.ts, core/*) is copied verbatim.
With runtimeConfigPath alone:
- the default
clientwould getserializeQuery; createSentryClient(config)callscreateClient(config), which merges withcreateConfig()and still defaults todefaultQuerySerializer. We'd fix that in our ownsentry-client.gen.tsgenerator by passingquerySerializer: serializeQuery;buildUrlwould still fall back to hey-api'screateQuerySerializerwheneverquerySerializerisn't a function;- the old serializer and the
QuerySerializerOptionstypes would stay in the output.
Since the goal was to drop the old serializer completely, a post-generation step would still be needed for the last two points. So this script does all of it in one place, with AST-located edits that fail the build if hey-api's output changes shape. If you'd rather choose the default through runtimeConfigPath plus the createSentryClient generator and keep only a smaller removal step, that's doable, but it splits the change across two mechanisms.

Part of #131203
@sentry/apinow writes query strings the wayquery-string@7'sstringifydoes with its default options, forcreateSentryClientand every generated operation. The Sentry frontend builds its URLs with query-string, so making this the default means the SDK and the frontend produce the same URLs and cache keys for the same query, without every consumer opting in. The previous serializer is removed.nullbecomes a bare key (?query);""staysquery=.undefinedis omitted, and so is an empty array.field=id&field=title), with the same rules per item.!'()*.deepObjectencoding (filter[status]=open, inner keys sorted), because query-string can't encode them. Dates are still written as ISO strings, and nested arrays or objects still throw.A build step (
scripts/replace-query-serializer.mjs) swaps hey-api's serializer forlib/query-serializer.tsin the generated client, using AST-located edits.API changes
queryStringSerializerexport from earlier in this PR is gone. It's the default now, so a separate name would only duplicate it; the function is internal (serializeQuery).querySerializernow only takes a function(query) => string. hey-api's options form ({ array, object, parameters, ... }) configured the old serializer and is removed along with it.Breaking change
nullnow becomes a bare key instead of being dropped. On a URL that already has a query,nullstill removes the existing values for that key, but then adds a bare key back. For example,prepareRequest({ url: "/items/?cursor=abc", query: { cursor: null } })used to produce/items/and now produces/items/?cursor. Sentry's paginator reads an emptycursoras the first page.undefinedis still dropped.querySerializerno longer typechecks. Pass a function instead.What changes for the toolkit CLI and MCP (getsentry/toolkit uses the default client)
prepareRequestsends sorted keys. That changes URLs, response-cache keys and pagination context keys, and toolkit tests that pin exact URLs may need new expectations.sentry apipagination (packages/cli/src/commands/api.ts) passescursor: nullto drop the cursor from the endpoint. It will now send a barecursor, which the server treats as the first page. Passingundefinedwon't remove an existing cursor, so it may be cleaner to stripcursorfrom the endpoint string before callingprepareRawApiRequest.querySerializeror options form is used there.via @BYK.
--
View Session [Sentry]