Skip to content

feat: write nameless query string entries to the URL as raw segments - #370

Open
erunion wants to merge 3 commits into
mainfrom
feat/nameless-query-string
Open

erunion wants to merge 3 commits into
mainfrom
feat/nameless-query-string

Conversation

@erunion

@erunion erunion commented Dec 5, 2026 •

Copy link
Copy Markdown
Member

🧰 Changes

Adds support for query strings that have no parameter name.

OpenAPI 3.2 lets an in: querystring parameter be the entire query string. With a media type like application/json, {"numbers":[1,2],"flag":null} serializes to ?%7B%22numbers%22%3A%5B1%2C2%5D%2C%22flag%22%3Anull%7D, with no name=. @readme/oas-to-har represents that as a HAR queryString entry with an empty name. httpsnippet used to turn it into ?=%7B..., so @readme/oas-to-snippet strips those entries before it gets here.

httpsnippet now writes these as raw query segments, exactly as given:

{
  method: 'GET',
  url: 'https://httpbin.org/anything',
  queryString: [{ name: '', value: '%7B%22numbers%22%3A%5B1%2C2%5D%2C%22flag%22%3Anull%7D' }],
}
// fullUrl: https://httpbin.org/anything?%7B%22numbers%22%3A%5B1%2C2%5D%2C%22flag%22%3Anull%7D
  • A queryString entry with an empty name, or a URL query segment with no =, is a raw segment. Empty values are ignored.
  • Raw segments are on a new rawQuery array. Named parameters stay in queryObj, repeated names included.
  • A raw segment is copied as-is when harIsAlreadyEncoded is set, and percent-encoded otherwise.
  • The same segment on both url and queryString is written once.
  • The logic lives in the new src/helpers/query.ts.

A params map can't hold a raw segment, so clients that build the query from one now send the full URL instead. This covers javascript:axios, php:http1, php:http2, clojure:clj_http, rust:reqwest, r:httr, shell:httpie and swift:urlsession. Clients that already print fullUrl needed no change.

ruby:faraday is the exception. It writes each raw segment as req.params['…'] = nil, which Faraday sends as the key with no =. Putting it in the URL would not work because Faraday parses [] there as nested params.

r:httr also changes. It decided whether to print a query list by looking at the HAR queryString, so it ignored params that only exist on the URL and dropped any param named key. It now uses the params it prints, so both show up (see the query.r, full.r and nested.r fixtures).

Known gap: shell:curl with globOff: true runs unescape() on the URL, which decodes any percent-encoded query value, raw segments included. This PR doesn't change that.

🧬 QA & Testing

  • New query-nameless and query-repeated-nameless request fixtures, with expected output for every client. The second mixes repeated id params with a raw segment.
  • Unit tests in src/index.test.ts for encoded and unencoded values, mixing a raw segment with named params (JSON, JSONPath and plaintext like helloworld), empty values, duplicates across url and queryString, valueless URL segments, and percent-encoding that differs only by hex case.
  • New r:httr case for a param that only exists on the URL.

OpenAPI 3.2 `in: querystring` parameters with a media type other than
`application/x-www-form-urlencoded` serialize to the whole query string with
no `name=` part, e.g. `?%7B%22numbers%22%3A%5B1%2C2%5D%7D`. `@readme/oas-to-har`
writes those as a HAR `queryString` entry with an empty name.

`prepare` now keeps empty-name entries out of `queryObj` and appends their
values to the query string as-is (percent-encoded unless
`harIsAlreadyEncoded`), joined with `&` to any named parameters. Because a
raw segment can't be expressed as a params map, a request that has one keeps
its whole query string in `url` and gets an empty `queryObj`, so targets that
pass `queryObj` to a client's params option send the URL as-is instead.

R `httr` now decides whether to emit a query list from `queryObj` rather than
the raw HAR `queryString`, and Ruby `faraday` passes the query through
`req.params` (with `nil` for a nameless segment) since Faraday rebuilds the
query string from its params.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@erunion erunion added the enhancement New feature or request label Dec 5, 2026
erunion and others added 2 commits December 4, 2026 17:34
The shell integration suite runs these scripts directly, and CI rejected them with permission denied.

Co-authored-by: Cursor <cursoragent@cursor.com>
@erunion
erunion marked this pull request as ready for review December 5, 2026 01:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant