Skip to content

Add ky HTTP client support#1802

Open
torrespro wants to merge 3 commits into
acacode:mainfrom
torrespro:add-ky-http-client
Open

Add ky HTTP client support#1802
torrespro wants to merge 3 commits into
acacode:mainfrom
torrespro:add-ky-http-client

Conversation

@torrespro

@torrespro torrespro commented Jun 26, 2026

Copy link
Copy Markdown

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 by ky.create({ fetch: customFetch ?? fetch, throwHttpErrors: false }). Preserves the HttpResponse<D,E> response wrapper, ResponseFormat, manual query serialization (not ky's searchParams), secure/securityWorker, cancelToken/AbortController, format parsing, disableThrowOnError, unwrapResponseData, and baseApiParams/mergeRequestParams. Drop-in compatible with procedure-call.ejs.
  • src/constants.ts — added KY: "ky" to HTTP_CLIENT.
  • types/index.ts — widened the hard-coded httpClientType union to include "ky".
  • index.ts — fixed the --http-client CLI resolution bug; the value is now validated against Object.values(HTTP_CLIENT) and honored directly, with the legacy --axios boolean as a fallback.
  • templates/default/procedure-call.ejs and templates/modular/procedure-call.ejs — changed the FORM_DATA response-format predicate from isFetchTemplate ? to !== HTTP_CLIENT.AXIOS ? so ky (like fetch) uses "formData" rather than "document".
  • package.json — added ky as 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 ky and httpClientType: "ky"; generated client uses ky.create({ fetch: customFetch ?? fetch, throwHttpErrors: false, timeout: false, retry: 0 }) with the same HttpResponse<D,E>/unwrapResponseData behavior as Fetch.
    • Parity with Fetch: secure/securityWorker, cancelToken (AbortController), manual query serialization, format, disableThrowOnError, customFetch, and baseApiParams merge.
    • Non-axios clients now use "formData" for form-data responses.
    • Docs updated to include ky; added ky as a devDependency; added TS/JS and single-http-client tests for ky.
  • Bug Fixes

    • CLI now validates and honors --http-client ("fetch" | "axios" | "ky"); invalid values throw with a clear message; legacy --axios still works.
    • Restored sta bin alias so both sta and swagger-typescript-api CLIs work.
    • Ensured AbortController cleanup runs on errors via .finally().

Written for commit 17be8d5. Summary will update on new commits.

Review in cubic

Introduces ky as a third supported HTTP client alongside Fetch and Axios.
The generated client is a drop-in for Fetch: same HttpResponse<D,E> wrapper,
query serialization, cancelToken, secure/securityWorker, format, unwrapResponseData,
and disableThrowOnError — backed by ky.create({ throwHttpErrors: false }).

Also fixes a CLI bug where any truthy --http-client value was coerced to
axios instead of being honored as the literal string.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@changeset-bot

changeset-bot Bot commented Jun 26, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 17be8d5

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
swagger-typescript-api Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

6 issues found across 19 files

Tip: cubic can generate docs of your entire codebase and keep them up to date. Try it here.

Re-trigger cubic

Comment thread templates/base/http-clients/ky-http-client.ejs
Comment thread templates/base/http-clients/ky-http-client.ejs
Comment thread package.json
Comment thread .changeset/add-ky-http-client.md Outdated
Comment thread types/index.ts Outdated
Comment thread index.ts Outdated
Andrés Torres and others added 2 commits June 27, 2026 13:10
- Add timeout: false and retry: 0 to ky.create() — fetch has no built-in
  timeout or retry; disabling ky's defaults preserves parity
- Move AbortController cleanup to .finally() so it runs on rejection too
- Restore sta bin alias and fix tsdown.config.ts to emit both bin entries
  explicitly (bun add had dropped sta from the auto-generated bin field)
- Use HttpClientType alias in types/index.ts instead of a hard-coded union
- Update changeset to drop "drop-in match" claim and note retry/timeout defaults

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Previously any invalid value silently fell back to fetch. Now the CLI
throws with a clear message listing the valid options.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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