Skip to content

Conversation

@SebastiaanWouters
Copy link
Contributor

@SebastiaanWouters SebastiaanWouters commented Nov 11, 2025

Closes #2794

Implements @hey-api/client-ky plugin with support for ky HTTP client.

Features:

  • Ky integration with native retry, timeout, and hooks
  • Standard interceptors pattern (request/response/error)
  • Configurable retry options (limit, methods, statusCodes)
  • Raw ky options via kyOptions escape hatch
  • Full HTTP method support and SSE
  • Follows established client plugin architecture

The implementation maintains consistency with other client plugins while leveraging ky's powerful built-in features.

Implements @hey-api/client-ky plugin with support for ky HTTP client.

Features:
- Ky integration with native retry, timeout, and hooks
- Standard interceptors pattern (request/response/error)
- Configurable retry options (limit, methods, statusCodes)
- Raw ky options via kyOptions escape hatch
- Full HTTP method support and SSE
- Follows established client plugin architecture

The implementation maintains consistency with other client plugins
while leveraging ky's powerful built-in features.
@bolt-new-by-stackblitz
Copy link

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

@changeset-bot
Copy link

changeset-bot bot commented Nov 11, 2025

🦋 Changeset detected

Latest commit: 212fcaf

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

This PR includes changesets to release 1 package
Name Type
@hey-api/openapi-ts Patch

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

@dosubot dosubot bot added the size:XL This PR changes 500-999 lines, ignoring generated files. label Nov 11, 2025
@vercel
Copy link

vercel bot commented Nov 11, 2025

@SebastiaanWouters is attempting to deploy a commit to the Hey API Team on Vercel.

A member of the Team first needs to authorize it.

@dosubot dosubot bot added the feature 🚀 New feature or request label Nov 11, 2025
@codecov
Copy link

codecov bot commented Nov 11, 2025

Codecov Report

❌ Patch coverage is 83.67730% with 87 lines in your changes missing coverage. Please review.
✅ Project coverage is 29.41%. Comparing base (680ae2a) to head (212fcaf).
⚠️ Report is 9 commits behind head on main.

Files with missing lines Patch % Lines
...ts/src/plugins/@hey-api/client-ky/bundle/client.ts 82.17% 46 Missing ⚠️
...-ts/src/plugins/@hey-api/client-ky/bundle/utils.ts 85.71% 36 Missing ⚠️
...-ts/src/plugins/@hey-api/client-ky/bundle/index.ts 16.66% 5 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2958      +/-   ##
==========================================
+ Coverage   28.58%   29.41%   +0.83%     
==========================================
  Files         394      403       +9     
  Lines       35186    35766     +580     
  Branches     1938     2066     +128     
==========================================
+ Hits        10057    10522     +465     
- Misses      25102    25217     +115     
  Partials       27       27              
Flag Coverage Δ
unittests 29.41% <83.67%> (+0.83%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Add test suite for ky client plugin with comprehensive coverage:
- buildUrl functionality with various path/query scenarios
- zero-length body handling for all content types
- unserialized and serialized request body handling
- request, response, and error interceptors
- error handling with throwOnError option
- retry configuration
- responseStyle configuration

Tests follow patterns from client-fetch and cover all core functionality.
@dosubot dosubot bot added size:XXL This PR changes 1000+ lines, ignoring generated files. and removed size:XL This PR changes 500-999 lines, ignoring generated files. labels Nov 11, 2025
Fix TypeScript compilation errors without using `as any`:

- Use inline array type instead of accessing `KyOptions['retry']['methods']`
  to avoid type error when retry can be number | object
- Add type assertion for headers as HeadersInit to satisfy Request constructor
- Change body type from `BodyInit | null` to `unknown` for consistency with
  client-fetch and to allow testing with edge case values
- Use `Partial<KyInstance> as KyInstance` pattern in tests (same as client-axios)
  to properly type mock ky instances without `as any`
Add example project demonstrating ky client usage:
- Created @example/openapi-ts-ky package with React/Vite setup
- Configured to use @hey-api/client-ky plugin
- Includes generated client code from Swagger Petstore OpenAPI spec

Updated build configuration:
- Added 'client-ky' to tsdown.config.ts plugin list
- Ensures ky bundle files are copied to dist/clients/ky during build
- Enables runtime access to ky client implementation

This example allows typecheck validation in CI and serves as
documentation for ky client integration.
@SebastiaanWouters SebastiaanWouters mentioned this pull request Nov 11, 2025
@pkg-pr-new
Copy link

pkg-pr-new bot commented Nov 11, 2025

Open in StackBlitz

npm i https://pkg.pr.new/hey-api/openapi-ts/@hey-api/codegen-core@2958
npm i https://pkg.pr.new/hey-api/openapi-ts/@hey-api/nuxt@2958
npm i https://pkg.pr.new/hey-api/openapi-ts/@hey-api/openapi-ts@2958
npm i https://pkg.pr.new/hey-api/openapi-ts/@hey-api/vite-plugin@2958

commit: b249eed

@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Nov 11, 2025
@mrlubos mrlubos merged commit 4c72db6 into hey-api:main Nov 11, 2025
11 of 12 checks passed
@hey-api hey-api bot mentioned this pull request Nov 11, 2025
* Additional ky-specific options that will be passed directly to ky.
* This allows you to use any ky option not explicitly exposed in the config.
*/
kyOptions?: Omit<import('ky').Options, 'method' | 'prefixUrl'>;
Copy link
Member

Choose a reason for hiding this comment

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

@SebastiaanWouters why did you decide to namespace these instead of extending Config?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Vibe coded v0 sometimes contain weird choices, better to expose ky's API directly here indeed.


export interface Config<T extends ClientOptions = ClientOptions>
extends Omit<
import('ky').Options,
Copy link
Member

Choose a reason for hiding this comment

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

@SebastiaanWouters why use dynamic import instead of importing on top?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes import on top is the better choice here 👍

@SebastiaanWouters
Copy link
Contributor Author

#2961

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

Labels

feature 🚀 New feature or request lgtm This PR has been approved by a maintainer size:XXL This PR changes 1000+ lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Ky client

2 participants