Add ky HTTP client support
Problem
PR #1601 added initial ky support but has been stale for a while and is now in a conflicting state. Its template implementation was also incomplete — it returned a KyResponse type instead of the project's HttpResponse<D,E> wrapper, and dropped support for format, unwrapResponseData, cancelToken, customFetch, and disableThrowOnError.
Separately, the generate command had a latent bug where any truthy --http-client value was silently coerced to axios rather than being used as the literal string.
Solution
Redone from scratch with full feature parity against the Fetch client:
templates/base/http-clients/ky-http-client.ejs— new template backed byky.create({ fetch: customFetch ?? fetch, throwHttpErrors: false }). Preserves theHttpResponse<D,E>response wrapper,ResponseFormat, manual query serialization (not ky'ssearchParams),secure/securityWorker,cancelToken/AbortController,formatparsing,disableThrowOnError,unwrapResponseData, andbaseApiParams/mergeRequestParams. Drop-in compatible withprocedure-call.ejs.src/constants.ts— addedKY: "ky"toHTTP_CLIENT.types/index.ts— widened the hard-codedhttpClientTypeunion to include"ky".index.ts— fixed the--http-clientCLI resolution bug; the value is now validated againstObject.values(HTTP_CLIENT)and honored directly, with the legacy--axiosboolean as a fallback.templates/default/procedure-call.ejsandtemplates/modular/procedure-call.ejs— changed theFORM_DATAresponse-format predicate fromisFetchTemplate ?to!== HTTP_CLIENT.AXIOS ?so ky (like fetch) uses"formData"rather than"document".package.json— addedkyas a devDependency so generated output typechecks in CI.README.md— documented ky alongside Fetch and Axios..changeset/add-ky-http-client.md— minor version bump.
Verification
bun install
bun run build
bun run test # 93 files, 277 tests — all passing, no type errors
bun run format:check # clean
# CLI smoke test
sta generate -p tests/spec/ky/schema.json -o /tmp/out -n schema.ts --http-client ky
Three new spec test dirs cover the ky client: tests/spec/ky/ (base), tests/spec/kySingleHttpClient/ (--single-http-client), and tests/spec/jsKy/ (--js / JS translation), mirroring the existing axios test coverage.
Closes #1601
Summary by cubic
Adds ky as a first-class HTTP client with full Fetch parity and fixes --http-client handling so the chosen client is respected. Disables ky’s default retry/timeout for parity and restores the sta CLI alias.
-
New Features
- Support
--http-client kyandhttpClientType: "ky"; generated client usesky.create({ fetch: customFetch ?? fetch, throwHttpErrors: false, timeout: false, retry: 0 })with the sameHttpResponse<D,E>/unwrapResponseDatabehavior as Fetch. - Parity with Fetch:
secure/securityWorker,cancelToken(AbortController), manual query serialization,format,disableThrowOnError,customFetch, andbaseApiParamsmerge. - Non-
axiosclients now use"formData"for form-data responses. - Docs updated to include
ky; addedkyas a devDependency; added TS/JS and single-http-client tests forky.
- Support
-
Bug Fixes
- CLI now validates and honors
--http-client("fetch" | "axios" | "ky"); invalid values throw with a clear message; legacy--axiosstill works. - Restored
stabin alias so bothstaandswagger-typescript-apiCLIs work. - Ensured
AbortControllercleanup runs on errors via.finally().
- CLI now validates and honors