Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 1 addition & 30 deletions examples/openapi-ts-ky/src/client/client/client.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import type {
Config,
RequestOptions,
ResolvedRequestOptions,
RetryOptions,
} from './types.gen';
import type { Middleware } from './utils.gen';
import {
Expand Down Expand Up @@ -131,41 +130,13 @@ export const createClient = (config: Config = {}): Client => {
const validBody = getValidRequestBody(opts);

const kyOptions: KyOptions = {
...opts,
body: validBody as BodyInit,
cache: opts.cache,
credentials: opts.credentials,
headers: opts.headers,
integrity: opts.integrity,
keepalive: opts.keepalive,
method: opts.method as KyOptions['method'],
mode: opts.mode,
redirect: 'follow',
referrer: opts.referrer,
referrerPolicy: opts.referrerPolicy,
signal: opts.signal,
throwHttpErrors: opts.throwOnError ?? false,
timeout: opts.timeout,
...opts.kyOptions,
};

if (opts.retry && typeof opts.retry === 'object') {
const retryOpts = opts.retry as RetryOptions;
kyOptions.retry = {
limit: retryOpts.limit ?? 2,
methods: retryOpts.methods as Array<
| 'get'
| 'post'
| 'put'
| 'patch'
| 'head'
| 'delete'
| 'options'
| 'trace'
>,
statusCodes: retryOpts.statusCodes,
};
}

let request = new Request(url, {
body: kyOptions.body as BodyInit,
headers: kyOptions.headers as HeadersInit,
Expand Down
1 change: 0 additions & 1 deletion examples/openapi-ts-ky/src/client/client/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ export type {
RequestResult,
ResolvedRequestOptions,
ResponseStyle,
RetryOptions,
TDataShape,
} from './types.gen';
export { createConfig, mergeHeaders } from './utils.gen';
71 changes: 5 additions & 66 deletions examples/openapi-ts-ky/src/client/client/types.gen.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// This file is auto-generated by @hey-api/openapi-ts

import type { KyInstance, Options as KyOptions } from 'ky';

import type { Auth } from '../core/auth.gen';
import type {
ServerSentEventsOptions,
Expand All @@ -13,57 +15,14 @@ import type { Middleware } from './utils.gen';

export type ResponseStyle = 'data' | 'fields';

export interface RetryOptions {
/**
* Maximum number of retry attempts
*
* @default 2
*/
limit?: number;
/**
* HTTP methods to retry
*
* @default ['get', 'put', 'head', 'delete', 'options', 'trace']
*/
methods?: Array<
'get' | 'post' | 'put' | 'delete' | 'patch' | 'head' | 'options' | 'trace'
>;
/**
* HTTP status codes to retry
*
* @default [408, 413, 429, 500, 502, 503, 504]
*/
statusCodes?: number[];
}

export interface Config<T extends ClientOptions = ClientOptions>
extends Omit<
import('ky').Options,
'body' | 'headers' | 'method' | 'prefixUrl' | 'retry' | 'throwHttpErrors'
KyOptions,
'body' | 'headers' | 'method' | 'prefixUrl' | 'throwHttpErrors'
>,
CoreConfig {
/**
* Base URL for all requests made by this client.
*/
baseUrl?: T['baseUrl'];
/**
* Ky instance to use. You can use this option to provide a custom
* ky instance.
*/
ky?: typeof import('ky').default;
/**
* 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'>;
/**
* Return the response data parsed in a specified format. By default, `auto`
* will infer the appropriate method from the `Content-Type` response header.
* You can override this behavior with any of the {@link Body} methods.
* Select `stream` if you don't want to parse response data at all.
*
* @default 'auto'
*/
ky?: KyInstance;
parseAs?:
| 'arrayBuffer'
| 'auto'
Expand All @@ -72,28 +31,8 @@ export interface Config<T extends ClientOptions = ClientOptions>
| 'json'
| 'stream'
| 'text';
/**
* Should we return only data or multiple fields (data, error, response, etc.)?
*
* @default 'fields'
*/
responseStyle?: ResponseStyle;
/**
* Retry configuration
*/
retry?: RetryOptions;
/**
* Throw an error instead of returning it in the response?
*
* @default false
*/
throwOnError?: T['throwOnError'];
/**
* Request timeout in milliseconds
*
* @default 10000
*/
timeout?: number;
}

export interface RequestOptions<
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import type {
Config,
RequestOptions,
ResolvedRequestOptions,
RetryOptions,
} from './types.gen';
import type { Middleware } from './utils.gen';
import {
Expand Down Expand Up @@ -131,41 +130,13 @@ export const createClient = (config: Config = {}): Client => {
const validBody = getValidRequestBody(opts);

const kyOptions: KyOptions = {
...opts,
body: validBody as BodyInit,
cache: opts.cache,
credentials: opts.credentials,
headers: opts.headers,
integrity: opts.integrity,
keepalive: opts.keepalive,
method: opts.method as KyOptions['method'],
mode: opts.mode,
redirect: 'follow',
referrer: opts.referrer,
referrerPolicy: opts.referrerPolicy,
signal: opts.signal,
throwHttpErrors: opts.throwOnError ?? false,
timeout: opts.timeout,
...opts.kyOptions,
};

if (opts.retry && typeof opts.retry === 'object') {
const retryOpts = opts.retry as RetryOptions;
kyOptions.retry = {
limit: retryOpts.limit ?? 2,
methods: retryOpts.methods as Array<
| 'get'
| 'post'
| 'put'
| 'patch'
| 'head'
| 'delete'
| 'options'
| 'trace'
>,
statusCodes: retryOpts.statusCodes,
};
}

let request = new Request(url, {
body: kyOptions.body as BodyInit,
headers: kyOptions.headers as HeadersInit,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ export type {
RequestResult,
ResolvedRequestOptions,
ResponseStyle,
RetryOptions,
TDataShape,
} from './types.gen';
export { createConfig, mergeHeaders } from './utils.gen';
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// This file is auto-generated by @hey-api/openapi-ts

import type { KyInstance, Options as KyOptions } from 'ky';

import type { Auth } from '../core/auth.gen';
import type {
ServerSentEventsOptions,
Expand All @@ -13,57 +15,14 @@ import type { Middleware } from './utils.gen';

export type ResponseStyle = 'data' | 'fields';

export interface RetryOptions {
/**
* Maximum number of retry attempts
*
* @default 2
*/
limit?: number;
/**
* HTTP methods to retry
*
* @default ['get', 'put', 'head', 'delete', 'options', 'trace']
*/
methods?: Array<
'get' | 'post' | 'put' | 'delete' | 'patch' | 'head' | 'options' | 'trace'
>;
/**
* HTTP status codes to retry
*
* @default [408, 413, 429, 500, 502, 503, 504]
*/
statusCodes?: number[];
}

export interface Config<T extends ClientOptions = ClientOptions>
extends Omit<
import('ky').Options,
'body' | 'headers' | 'method' | 'prefixUrl' | 'retry' | 'throwHttpErrors'
KyOptions,
'body' | 'headers' | 'method' | 'prefixUrl' | 'throwHttpErrors'
>,
CoreConfig {
/**
* Base URL for all requests made by this client.
*/
baseUrl?: T['baseUrl'];
/**
* Ky instance to use. You can use this option to provide a custom
* ky instance.
*/
ky?: typeof import('ky').default;
/**
* 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'>;
/**
* Return the response data parsed in a specified format. By default, `auto`
* will infer the appropriate method from the `Content-Type` response header.
* You can override this behavior with any of the {@link Body} methods.
* Select `stream` if you don't want to parse response data at all.
*
* @default 'auto'
*/
ky?: KyInstance;
parseAs?:
| 'arrayBuffer'
| 'auto'
Expand All @@ -72,28 +31,8 @@ export interface Config<T extends ClientOptions = ClientOptions>
| 'json'
| 'stream'
| 'text';
/**
* Should we return only data or multiple fields (data, error, response, etc.)?
*
* @default 'fields'
*/
responseStyle?: ResponseStyle;
/**
* Retry configuration
*/
retry?: RetryOptions;
/**
* Throw an error instead of returning it in the response?
*
* @default false
*/
throwOnError?: T['throwOnError'];
/**
* Request timeout in milliseconds
*
* @default 10000
*/
timeout?: number;
}

export interface RequestOptions<
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import type {
Config,
RequestOptions,
ResolvedRequestOptions,
RetryOptions,
} from './types.gen';
import type { Middleware } from './utils.gen';
import {
Expand Down Expand Up @@ -131,41 +130,13 @@ export const createClient = (config: Config = {}): Client => {
const validBody = getValidRequestBody(opts);

const kyOptions: KyOptions = {
...opts,
body: validBody as BodyInit,
cache: opts.cache,
credentials: opts.credentials,
headers: opts.headers,
integrity: opts.integrity,
keepalive: opts.keepalive,
method: opts.method as KyOptions['method'],
mode: opts.mode,
redirect: 'follow',
referrer: opts.referrer,
referrerPolicy: opts.referrerPolicy,
signal: opts.signal,
throwHttpErrors: opts.throwOnError ?? false,
timeout: opts.timeout,
...opts.kyOptions,
};

if (opts.retry && typeof opts.retry === 'object') {
const retryOpts = opts.retry as RetryOptions;
kyOptions.retry = {
limit: retryOpts.limit ?? 2,
methods: retryOpts.methods as Array<
| 'get'
| 'post'
| 'put'
| 'patch'
| 'head'
| 'delete'
| 'options'
| 'trace'
>,
statusCodes: retryOpts.statusCodes,
};
}

let request = new Request(url, {
body: kyOptions.body as BodyInit,
headers: kyOptions.headers as HeadersInit,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ export type {
RequestResult,
ResolvedRequestOptions,
ResponseStyle,
RetryOptions,
TDataShape,
} from './types.gen';
export { createConfig, mergeHeaders } from './utils.gen';
Loading
Loading