Skip to content

Send OpenAPI and ctx.fetch queries exactly as built - #2590

Open
yashgix wants to merge 1 commit into
UsefulSoftwareCo:v2from
yashgix:query-as-built
Open

yashgix wants to merge 1 commit into
UsefulSoftwareCo:v2from
yashgix:query-as-built

Conversation

@yashgix

@yashgix yashgix commented Nov 24, 2026 •

Copy link
Copy Markdown

Send OpenAPI and ctx.fetch queries exactly as built

Problem

invocationFetch passes each request through HttpClientRequest.fromWeb, which reads the query into parameters and appends them again with form encoding. A query that was built correctly changes on the way out:

Built Sent today
tags=red,blue tags=red%2Cblue
q=a%20b q=a+b
path=a/b:c path=a%2Fb%3Ac

This affects OpenAPI tools and the ctx.fetch a tool receives. App code's global fetch is not affected. A closed earlier PR (#354) noticed the same re-encoding in setUrlParam; this one is still in the invocation path.

Change

  • asSent (packages/telemetry/src/context.ts) keeps fromWeb(request) for the method, headers, body and signal, clears the parsed parameters, and sets the original URL again without its fragment. A bare trailing ? survives.
  • The OpenAPI request builder (openapi-request.ts) escapes only what a URI query cannot hold, and refuses a reserved value that contains #, which would cut the query short.
  • Two scenarios: openapi-query-styles.spec.ts for each style and explode setting, and app-fetch-query.spec.ts for ctx.fetch, including a bare ?, a keepalive POST and a streamed POST.

Behaviour change: query bytes change for affected specs, which is the fix. Reserved values containing # are now refused.

Not changed

With allowReserved, an existing escape such as %2F is still sent as %252F. OpenAPI 3.0.4, 3.1.1 and 3.2.0 and RFC 6570 section 3.2.3 say percent-encoded triples pass through unchanged. The cause is in swagger-client, it predates this change, and it deserves its own PR.

Verification

Both scenarios run on the self-host stack:

  • bun run e2e:self-host --test-name "Imported OpenAPI query parameters reach the upstream as OpenAPI serializes each style" passes.
  • bun run e2e:self-host --test-name "An app's fetch sends its query to the upstream exactly as written" passes.
  • With the product code left as it is on v2 and only these scenarios added, both fail. The first fails on tags=red%2Cblue where tags=red,blue is expected.
  • With only the earlier fetch code restored (it dropped a bare ?), the ctx.fetch scenario fails on the bare ? case.
  • After the rebase onto v2 7cabe226e, bun run check passes all 18 checks on this commit, and the scenarios above were run again on it. The release-note check accepted the original commit (d5733f56b) and was not rerun.

Supplemental evidence, from both import-diagnostics and this change applied together (this change alone was not measured), measured on the original commits before the rebase: offline, against 68,090 generated inputs from public specs, nothing that stays exposed got worse compared with v2. Six queries changed bytes but stay equivalent (* became %2A).

Limits:

  • The server cannot see the keepalive flag, so that case shows the request and body arrive, not that the flag is forwarded.
  • No live provider was called. The bytes are verified, provider acceptance is not.
  • v2 shares no history with main, so pr:check could not run as a whole. I ran its parts: bun run check on the rebased commit, and the release-note check and e2e:check-description on the original commit, with v2 standing in for main and main's workflows copied in. The last two were not rerun after the rebase. apps-version was not run.
openapi-query-styles.spec.ts
app-fetch-query.spec.ts

I directed the scope and review of this contribution, using Claude Code during implementation and additional AI tools for independent review. The tests, measurements, and known limitations are documented above.

The invocation fetch read each query into parameters and sent it again form-encoded, which escaped list commas, slashes and colons and turned percent-encoded spaces into plus signs. The request now keeps its query as written, without its fragment. The OpenAPI builder escapes only what a URI query cannot hold and refuses a reserved value containing a number sign.

Release-note: Fix: OpenAPI tools and app requests now send query strings exactly as built, so comma separated lists and encoded spaces reach the API unchanged.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant