···35353636## Installation
37373838-Start by adding `@hey-api/client-axios` to your dependencies.
3939-4040-::: code-group
4141-4242-```sh [npm]
4343-npm install @hey-api/client-axios
4444-```
4545-4646-```sh [pnpm]
4747-pnpm add @hey-api/client-axios
4848-```
4949-5050-```sh [yarn]
5151-yarn add @hey-api/client-axios
5252-```
5353-5454-```sh [bun]
5555-bun add @hey-api/client-axios
5656-```
5757-5858-:::
5959-6038In your [configuration](/openapi-ts/get-started), add `@hey-api/client-axios` to your plugins and you'll be ready to generate client artifacts. :tada:
61396240::: code-group
···137115You can also create your own client instance. You can use it to manually send requests or point it to a different domain.
138116139117```js
140140-import { createClient } from '@hey-api/client-axios';
118118+import { createClient } from './client/client';
141119142120const myClient = createClient({
143121 baseURL: 'https://example.com',
···226204 url: '/foo/{fooId}',
227205});
228206console.log(url); // prints '/foo/1?bar=baz'
229229-```
230230-231231-## Bundling
232232-233233-Sometimes, you may not want to declare client packages as a dependency. This scenario is common if you're using Hey API to generate output that is repackaged and published for other consumers under your own brand. For such cases, our clients support bundling through the `client.bundle` configuration option.
234234-235235-```js
236236-export default {
237237- input: 'https://get.heyapi.dev/hey-api/backend',
238238- output: 'src/client',
239239- plugins: [
240240- {
241241- bundle: true, // [!code ++]
242242- name: '@hey-api/client-axios',
243243- },
244244- ],
245245-};
246207```
247208248209<!--@include: ../../examples.md-->
+7-40
docs/openapi-ts/clients/fetch.md
···35353636## Installation
37373838-Start by adding `@hey-api/client-fetch` to your dependencies.
3939-4040-::: code-group
4141-4242-```sh [npm]
4343-npm install @hey-api/client-fetch
4444-```
4545-4646-```sh [pnpm]
4747-pnpm add @hey-api/client-fetch
4848-```
4949-5050-```sh [yarn]
5151-yarn add @hey-api/client-fetch
5252-```
5353-5454-```sh [bun]
5555-bun add @hey-api/client-fetch
5656-```
5757-5858-:::
5959-6038In your [configuration](/openapi-ts/get-started), add `@hey-api/client-fetch` to your plugins and you'll be ready to generate client artifacts. :tada:
61396240::: code-group
···7553 -o src/client \
7654 -c @hey-api/client-fetch # [!code ++]
7755```
5656+5757+:::
5858+5959+::: tip
6060+6161+This step is optional because Fetch is the default client.
78627963:::
8064···137121You can also create your own client instance. You can use it to manually send requests or point it to a different domain.
138122139123```js
140140-import { createClient } from '@hey-api/client-fetch';
124124+import { createClient } from './client/client';
141125142126const myClient = createClient({
143127 baseUrl: 'https://example.com',
···297281 url: '/foo/{fooId}',
298282});
299283console.log(url); // prints '/foo/1?bar=baz'
300300-```
301301-302302-## Bundling
303303-304304-Sometimes, you may not want to declare client packages as a dependency. This scenario is common if you're using Hey API to generate output that is repackaged and published for other consumers under your own brand. For such cases, our clients support bundling through the `client.bundle` configuration option.
305305-306306-```js
307307-export default {
308308- input: 'https://get.heyapi.dev/hey-api/backend',
309309- output: 'src/client',
310310- plugins: [
311311- {
312312- bundle: true, // [!code ++]
313313- name: '@hey-api/client-fetch',
314314- },
315315- ],
316316-};
317284```
318285319286<!--@include: ../../examples.md-->
+1-40
docs/openapi-ts/clients/next-js.md
···29293030## Installation
31313232-Start by adding `@hey-api/client-next` to your dependencies.
3333-3434-::: code-group
3535-3636-```sh [npm]
3737-npm install @hey-api/client-next
3838-```
3939-4040-```sh [pnpm]
4141-pnpm add @hey-api/client-next
4242-```
4343-4444-```sh [yarn]
4545-yarn add @hey-api/client-next
4646-```
4747-4848-```sh [bun]
4949-bun add @hey-api/client-next
5050-```
5151-5252-:::
5353-5432In your [configuration](/openapi-ts/get-started), add `@hey-api/client-next` to your plugins and you'll be ready to generate client artifacts. :tada:
55335634::: code-group
···131109You can also create your own client instance. You can use it to manually send requests or point it to a different domain.
132110133111```js
134134-import { createClient } from '@hey-api/client-next';
112112+import { createClient } from './client/client';
135113136114const myClient = createClient({
137115 baseUrl: 'https://example.com',
···290268 url: '/foo/{fooId}',
291269});
292270console.log(url); // prints '/foo/1?bar=baz'
293293-```
294294-295295-## Bundling
296296-297297-Sometimes, you may not want to declare client packages as a dependency. This scenario is common if you're using Hey API to generate output that is repackaged and published for other consumers under your own brand. For such cases, our clients support bundling through the `client.bundle` configuration option.
298298-299299-```js
300300-export default {
301301- input: 'https://get.heyapi.dev/hey-api/backend',
302302- output: 'src/client',
303303- plugins: [
304304- {
305305- bundle: true, // [!code ++]
306306- name: '@hey-api/client-next',
307307- },
308308- ],
309309-};
310271```
311272312273<!--@include: ../../examples.md-->
···2020├── node_modules/
2121├── src/
2222│ ├── client/
2323+│ │ ├── client/
2424+│ │ ├── core/
2325│ │ ├── client.gen.ts
2426│ │ ├── index.ts
2527│ │ ├── sdk.gen.ts
···6668 indexFile: false, // [!code ++]
6769 path: 'src/client',
6870 },
6969- plugins: ['@hey-api/client-fetch'],
7071};
7172```
7273···8283 output: 'src/client',
8384 plugins: [
8485 ...defaultPlugins,
8585- '@hey-api/client-fetch',
8686 {
8787 exportFromIndex: true, // [!code ++]
8888 name: 'zod',
···9494::: warning
9595Re-exporting additional files from index file may result in broken output due to naming conflicts.
9696:::
9797-9898-## Client
9999-100100-`client.gen.ts` is generated by [client plugins](/openapi-ts/clients). If you choose to generate SDKs (enabled by default), you must specify a client which will create this file.
101101-102102-::: code-group
103103-104104-```ts [client.gen.ts]
105105-import { createClient, createConfig } from '@hey-api/client-fetch';
106106-107107-export const client = createClient(createConfig());
108108-```
109109-110110-:::
111111-112112-The contents of this file are consumed by SDKs, but you can also import `client` in your application to perform additional configuration or send manual requests.
1139711498<!--@include: ../examples.md-->
11599<!--@include: ../sponsors.md-->
+27
docs/openapi-ts/output/client.md
···11+---
22+title: Client
33+description: Learn about files generated with @hey-api/openapi-ts.
44+---
55+66+# Client
77+88+`client.gen.ts` is generated by [client plugins](/openapi-ts/clients). If you choose to generate SDKs (enabled by default), we use the Fetch client unless specified otherwise.
99+1010+::: code-group
1111+1212+```ts [client.gen.ts]
1313+import { createClient, createConfig } from './client';
1414+1515+export const client = createClient(createConfig());
1616+```
1717+1818+:::
1919+2020+The contents of this file are consumed by SDKs, but you can also import `client` in your application to perform additional configuration or send manual requests.
2121+2222+## Bundle
2323+2424+Client plugins provide their bundles inside `client` and `core` folders. The contents of these folders don't depend on the provided input. Everything inside these folders serves as a scaffolding so the generated code can make HTTP requests.
2525+2626+<!--@include: ../../examples.md-->
2727+<!--@include: ../../sponsors.md-->
···11import './App.css';
2233-import { createClient } from '@hey-api/client-axios';
43import * as Form from '@radix-ui/react-form';
54import { DownloadIcon, PlusIcon, ReloadIcon } from '@radix-ui/react-icons';
65import {
···1716} from '@radix-ui/themes';
1817import { useState } from 'react';
19181919+import { createClient } from './client/client';
2020import { PetSchema } from './client/schemas.gen';
2121import { addPet, getPetById, updatePet } from './client/sdk.gen';
2222import type { Pet } from './client/types.gen';
···55 type Config,
66 createClient,
77 createConfig,
88-} from '@hey-api/client-axios';
99-88+} from './client';
109import type { ClientOptions } from './types.gen';
11101211/**
···11+import type { Auth, AuthToken } from './auth';
22+import type {
33+ BodySerializer,
44+ QuerySerializer,
55+ QuerySerializerOptions,
66+} from './bodySerializer';
77+88+export interface Client<
99+ RequestFn = never,
1010+ Config = unknown,
1111+ MethodFn = never,
1212+ BuildUrlFn = never,
1313+> {
1414+ /**
1515+ * Returns the final request URL.
1616+ */
1717+ buildUrl: BuildUrlFn;
1818+ connect: MethodFn;
1919+ delete: MethodFn;
2020+ get: MethodFn;
2121+ getConfig: () => Config;
2222+ head: MethodFn;
2323+ options: MethodFn;
2424+ patch: MethodFn;
2525+ post: MethodFn;
2626+ put: MethodFn;
2727+ request: RequestFn;
2828+ setConfig: (config: Config) => Config;
2929+ trace: MethodFn;
3030+}
3131+3232+export interface Config {
3333+ /**
3434+ * Auth token or a function returning auth token. The resolved value will be
3535+ * added to the request payload as defined by its `security` array.
3636+ */
3737+ auth?: ((auth: Auth) => Promise<AuthToken> | AuthToken) | AuthToken;
3838+ /**
3939+ * A function for serializing request body parameter. By default,
4040+ * {@link JSON.stringify()} will be used.
4141+ */
4242+ bodySerializer?: BodySerializer | null;
4343+ /**
4444+ * An object containing any HTTP headers that you want to pre-populate your
4545+ * `Headers` object with.
4646+ *
4747+ * {@link https://developer.mozilla.org/docs/Web/API/Headers/Headers#init See more}
4848+ */
4949+ headers?:
5050+ | RequestInit['headers']
5151+ | Record<
5252+ string,
5353+ | string
5454+ | number
5555+ | boolean
5656+ | (string | number | boolean)[]
5757+ | null
5858+ | undefined
5959+ | unknown
6060+ >;
6161+ /**
6262+ * The request method.
6363+ *
6464+ * {@link https://developer.mozilla.org/docs/Web/API/fetch#method See more}
6565+ */
6666+ method?:
6767+ | 'CONNECT'
6868+ | 'DELETE'
6969+ | 'GET'
7070+ | 'HEAD'
7171+ | 'OPTIONS'
7272+ | 'PATCH'
7373+ | 'POST'
7474+ | 'PUT'
7575+ | 'TRACE';
7676+ /**
7777+ * A function for serializing request query parameters. By default, arrays
7878+ * will be exploded in form style, objects will be exploded in deepObject
7979+ * style, and reserved characters are percent-encoded.
8080+ *
8181+ * This method will have no effect if the native `paramsSerializer()` Axios
8282+ * API function is used.
8383+ *
8484+ * {@link https://swagger.io/docs/specification/serialization/#query View examples}
8585+ */
8686+ querySerializer?: QuerySerializer | QuerySerializerOptions;
8787+ /**
8888+ * A function transforming response data before it's returned. This is useful
8989+ * for post-processing data, e.g. converting ISO strings into Date objects.
9090+ */
9191+ responseTransformer?: (data: unknown) => Promise<unknown>;
9292+ /**
9393+ * A function validating response data. This is useful if you want to ensure
9494+ * the response conforms to the desired shape, so it can be safely passed to
9595+ * the transformers and returned to the user.
9696+ */
9797+ responseValidator?: (data: unknown) => Promise<unknown>;
9898+}
+5-10
examples/openapi-ts-axios/src/client/sdk.gen.ts
···11// This file is auto-generated by @hey-api/openapi-ts
2233-import type {
44- Client,
55- Options as ClientOptions,
66- TDataShape,
77-} from '@hey-api/client-axios';
88-33+import type { Client, Options as ClientOptions, TDataShape } from './client';
94import { client as _heyApiClient } from './client.gen';
105import type {
116 AddPetData,
···107102 ...options,
108103 headers: {
109104 'Content-Type': 'application/json',
110110- ...options?.headers,
105105+ ...options.headers,
111106 },
112107 });
113108···134129 ...options,
135130 headers: {
136131 'Content-Type': 'application/json',
137137- ...options?.headers,
132132+ ...options.headers,
138133 },
139134 });
140135···280275 ...options,
281276 headers: {
282277 'Content-Type': 'application/octet-stream',
283283- ...options?.headers,
278278+ ...options.headers,
284279 },
285280 });
286281···485480 ...options,
486481 headers: {
487482 'Content-Type': 'application/json',
488488- ...options?.headers,
483483+ ...options.headers,
489484 },
490485 });
···55 type Config,
66 createClient,
77 createConfig,
88-} from '@hey-api/client-fetch';
99-88+} from './client';
109import type { ClientOptions } from './types.gen';
11101211/**
···11+import type { Auth, AuthToken } from './auth';
22+import type {
33+ BodySerializer,
44+ QuerySerializer,
55+ QuerySerializerOptions,
66+} from './bodySerializer';
77+88+export interface Client<
99+ RequestFn = never,
1010+ Config = unknown,
1111+ MethodFn = never,
1212+ BuildUrlFn = never,
1313+> {
1414+ /**
1515+ * Returns the final request URL.
1616+ */
1717+ buildUrl: BuildUrlFn;
1818+ connect: MethodFn;
1919+ delete: MethodFn;
2020+ get: MethodFn;
2121+ getConfig: () => Config;
2222+ head: MethodFn;
2323+ options: MethodFn;
2424+ patch: MethodFn;
2525+ post: MethodFn;
2626+ put: MethodFn;
2727+ request: RequestFn;
2828+ setConfig: (config: Config) => Config;
2929+ trace: MethodFn;
3030+}
3131+3232+export interface Config {
3333+ /**
3434+ * Auth token or a function returning auth token. The resolved value will be
3535+ * added to the request payload as defined by its `security` array.
3636+ */
3737+ auth?: ((auth: Auth) => Promise<AuthToken> | AuthToken) | AuthToken;
3838+ /**
3939+ * A function for serializing request body parameter. By default,
4040+ * {@link JSON.stringify()} will be used.
4141+ */
4242+ bodySerializer?: BodySerializer | null;
4343+ /**
4444+ * An object containing any HTTP headers that you want to pre-populate your
4545+ * `Headers` object with.
4646+ *
4747+ * {@link https://developer.mozilla.org/docs/Web/API/Headers/Headers#init See more}
4848+ */
4949+ headers?:
5050+ | RequestInit['headers']
5151+ | Record<
5252+ string,
5353+ | string
5454+ | number
5555+ | boolean
5656+ | (string | number | boolean)[]
5757+ | null
5858+ | undefined
5959+ | unknown
6060+ >;
6161+ /**
6262+ * The request method.
6363+ *
6464+ * {@link https://developer.mozilla.org/docs/Web/API/fetch#method See more}
6565+ */
6666+ method?:
6767+ | 'CONNECT'
6868+ | 'DELETE'
6969+ | 'GET'
7070+ | 'HEAD'
7171+ | 'OPTIONS'
7272+ | 'PATCH'
7373+ | 'POST'
7474+ | 'PUT'
7575+ | 'TRACE';
7676+ /**
7777+ * A function for serializing request query parameters. By default, arrays
7878+ * will be exploded in form style, objects will be exploded in deepObject
7979+ * style, and reserved characters are percent-encoded.
8080+ *
8181+ * This method will have no effect if the native `paramsSerializer()` Axios
8282+ * API function is used.
8383+ *
8484+ * {@link https://swagger.io/docs/specification/serialization/#query View examples}
8585+ */
8686+ querySerializer?: QuerySerializer | QuerySerializerOptions;
8787+ /**
8888+ * A function transforming response data before it's returned. This is useful
8989+ * for post-processing data, e.g. converting ISO strings into Date objects.
9090+ */
9191+ responseTransformer?: (data: unknown) => Promise<unknown>;
9292+ /**
9393+ * A function validating response data. This is useful if you want to ensure
9494+ * the response conforms to the desired shape, so it can be safely passed to
9595+ * the transformers and returned to the user.
9696+ */
9797+ responseValidator?: (data: unknown) => Promise<unknown>;
9898+}
+1-6
examples/openapi-ts-fastify/src/client/sdk.gen.ts
···11// This file is auto-generated by @hey-api/openapi-ts
2233-import type {
44- Client,
55- Options as ClientOptions,
66- TDataShape,
77-} from '@hey-api/client-fetch';
88-33+import type { Client, Options as ClientOptions, TDataShape } from './client';
94import { client as _heyApiClient } from './client.gen';
105import type {
116 CreatePetsData,
···11import './App.css';
2233-import { createClient } from '@hey-api/client-fetch';
43import * as Form from '@radix-ui/react-form';
54import { DownloadIcon, PlusIcon, ReloadIcon } from '@radix-ui/react-icons';
65import {
···1716} from '@radix-ui/themes';
1817import { useState } from 'react';
19181919+import { createClient } from './client/client';
2020import { PetSchema } from './client/schemas.gen';
2121import { addPet, getPetById, updatePet } from './client/sdk.gen';
2222import type { Pet } from './client/types.gen';
···55 type Config,
66 createClient,
77 createConfig,
88-} from '@hey-api/client-fetch';
99-88+} from './client';
109import type { ClientOptions } from './types.gen';
11101211/**
···11+import type { Auth, AuthToken } from './auth';
22+import type {
33+ BodySerializer,
44+ QuerySerializer,
55+ QuerySerializerOptions,
66+} from './bodySerializer';
77+88+export interface Client<
99+ RequestFn = never,
1010+ Config = unknown,
1111+ MethodFn = never,
1212+ BuildUrlFn = never,
1313+> {
1414+ /**
1515+ * Returns the final request URL.
1616+ */
1717+ buildUrl: BuildUrlFn;
1818+ connect: MethodFn;
1919+ delete: MethodFn;
2020+ get: MethodFn;
2121+ getConfig: () => Config;
2222+ head: MethodFn;
2323+ options: MethodFn;
2424+ patch: MethodFn;
2525+ post: MethodFn;
2626+ put: MethodFn;
2727+ request: RequestFn;
2828+ setConfig: (config: Config) => Config;
2929+ trace: MethodFn;
3030+}
3131+3232+export interface Config {
3333+ /**
3434+ * Auth token or a function returning auth token. The resolved value will be
3535+ * added to the request payload as defined by its `security` array.
3636+ */
3737+ auth?: ((auth: Auth) => Promise<AuthToken> | AuthToken) | AuthToken;
3838+ /**
3939+ * A function for serializing request body parameter. By default,
4040+ * {@link JSON.stringify()} will be used.
4141+ */
4242+ bodySerializer?: BodySerializer | null;
4343+ /**
4444+ * An object containing any HTTP headers that you want to pre-populate your
4545+ * `Headers` object with.
4646+ *
4747+ * {@link https://developer.mozilla.org/docs/Web/API/Headers/Headers#init See more}
4848+ */
4949+ headers?:
5050+ | RequestInit['headers']
5151+ | Record<
5252+ string,
5353+ | string
5454+ | number
5555+ | boolean
5656+ | (string | number | boolean)[]
5757+ | null
5858+ | undefined
5959+ | unknown
6060+ >;
6161+ /**
6262+ * The request method.
6363+ *
6464+ * {@link https://developer.mozilla.org/docs/Web/API/fetch#method See more}
6565+ */
6666+ method?:
6767+ | 'CONNECT'
6868+ | 'DELETE'
6969+ | 'GET'
7070+ | 'HEAD'
7171+ | 'OPTIONS'
7272+ | 'PATCH'
7373+ | 'POST'
7474+ | 'PUT'
7575+ | 'TRACE';
7676+ /**
7777+ * A function for serializing request query parameters. By default, arrays
7878+ * will be exploded in form style, objects will be exploded in deepObject
7979+ * style, and reserved characters are percent-encoded.
8080+ *
8181+ * This method will have no effect if the native `paramsSerializer()` Axios
8282+ * API function is used.
8383+ *
8484+ * {@link https://swagger.io/docs/specification/serialization/#query View examples}
8585+ */
8686+ querySerializer?: QuerySerializer | QuerySerializerOptions;
8787+ /**
8888+ * A function transforming response data before it's returned. This is useful
8989+ * for post-processing data, e.g. converting ISO strings into Date objects.
9090+ */
9191+ responseTransformer?: (data: unknown) => Promise<unknown>;
9292+ /**
9393+ * A function validating response data. This is useful if you want to ensure
9494+ * the response conforms to the desired shape, so it can be safely passed to
9595+ * the transformers and returned to the user.
9696+ */
9797+ responseValidator?: (data: unknown) => Promise<unknown>;
9898+}
+5-10
examples/openapi-ts-fetch/src/client/sdk.gen.ts
···11// This file is auto-generated by @hey-api/openapi-ts
2233-import type {
44- Client,
55- Options as ClientOptions,
66- TDataShape,
77-} from '@hey-api/client-fetch';
88-33+import type { Client, Options as ClientOptions, TDataShape } from './client';
94import { client as _heyApiClient } from './client.gen';
105import type {
116 AddPetData,
···106101 ...options,
107102 headers: {
108103 'Content-Type': 'application/json',
109109- ...options?.headers,
104104+ ...options.headers,
110105 },
111106 });
112107···132127 ...options,
133128 headers: {
134129 'Content-Type': 'application/json',
135135- ...options?.headers,
130130+ ...options.headers,
136131 },
137132 });
138133···273268 ...options,
274269 headers: {
275270 'Content-Type': 'application/octet-stream',
276276- ...options?.headers,
271271+ ...options.headers,
277272 },
278273 });
279274···471466 ...options,
472467 headers: {
473468 'Content-Type': 'application/json',
474474- ...options?.headers,
469469+ ...options.headers,
475470 },
476471 });
···11// This file is auto-generated by @hey-api/openapi-ts
2233+import { createClientConfig } from '../hey-api';
34import {
45 type ClientOptions as DefaultClientOptions,
56 type Config,
67 createClient,
78 createConfig,
88-} from '@hey-api/client-next';
99-1010-import { createClientConfig } from '../hey-api';
99+} from './client';
1110import type { ClientOptions } from './types.gen';
12111312/**
···11+import type { Auth, AuthToken } from './auth';
22+import type {
33+ BodySerializer,
44+ QuerySerializer,
55+ QuerySerializerOptions,
66+} from './bodySerializer';
77+88+export interface Client<
99+ RequestFn = never,
1010+ Config = unknown,
1111+ MethodFn = never,
1212+ BuildUrlFn = never,
1313+> {
1414+ /**
1515+ * Returns the final request URL.
1616+ */
1717+ buildUrl: BuildUrlFn;
1818+ connect: MethodFn;
1919+ delete: MethodFn;
2020+ get: MethodFn;
2121+ getConfig: () => Config;
2222+ head: MethodFn;
2323+ options: MethodFn;
2424+ patch: MethodFn;
2525+ post: MethodFn;
2626+ put: MethodFn;
2727+ request: RequestFn;
2828+ setConfig: (config: Config) => Config;
2929+ trace: MethodFn;
3030+}
3131+3232+export interface Config {
3333+ /**
3434+ * Auth token or a function returning auth token. The resolved value will be
3535+ * added to the request payload as defined by its `security` array.
3636+ */
3737+ auth?: ((auth: Auth) => Promise<AuthToken> | AuthToken) | AuthToken;
3838+ /**
3939+ * A function for serializing request body parameter. By default,
4040+ * {@link JSON.stringify()} will be used.
4141+ */
4242+ bodySerializer?: BodySerializer | null;
4343+ /**
4444+ * An object containing any HTTP headers that you want to pre-populate your
4545+ * `Headers` object with.
4646+ *
4747+ * {@link https://developer.mozilla.org/docs/Web/API/Headers/Headers#init See more}
4848+ */
4949+ headers?:
5050+ | RequestInit['headers']
5151+ | Record<
5252+ string,
5353+ | string
5454+ | number
5555+ | boolean
5656+ | (string | number | boolean)[]
5757+ | null
5858+ | undefined
5959+ | unknown
6060+ >;
6161+ /**
6262+ * The request method.
6363+ *
6464+ * {@link https://developer.mozilla.org/docs/Web/API/fetch#method See more}
6565+ */
6666+ method?:
6767+ | 'CONNECT'
6868+ | 'DELETE'
6969+ | 'GET'
7070+ | 'HEAD'
7171+ | 'OPTIONS'
7272+ | 'PATCH'
7373+ | 'POST'
7474+ | 'PUT'
7575+ | 'TRACE';
7676+ /**
7777+ * A function for serializing request query parameters. By default, arrays
7878+ * will be exploded in form style, objects will be exploded in deepObject
7979+ * style, and reserved characters are percent-encoded.
8080+ *
8181+ * This method will have no effect if the native `paramsSerializer()` Axios
8282+ * API function is used.
8383+ *
8484+ * {@link https://swagger.io/docs/specification/serialization/#query View examples}
8585+ */
8686+ querySerializer?: QuerySerializer | QuerySerializerOptions;
8787+ /**
8888+ * A function transforming response data before it's returned. This is useful
8989+ * for post-processing data, e.g. converting ISO strings into Date objects.
9090+ */
9191+ responseTransformer?: (data: unknown) => Promise<unknown>;
9292+ /**
9393+ * A function validating response data. This is useful if you want to ensure
9494+ * the response conforms to the desired shape, so it can be safely passed to
9595+ * the transformers and returned to the user.
9696+ */
9797+ responseValidator?: (data: unknown) => Promise<unknown>;
9898+}
+5-10
examples/openapi-ts-next/src/client/sdk.gen.ts
···11// This file is auto-generated by @hey-api/openapi-ts
2233-import type {
44- Client,
55- Options as ClientOptions,
66- TDataShape,
77-} from '@hey-api/client-next';
88-33+import type { Client, Options as ClientOptions, TDataShape } from './client';
94import { client as _heyApiClient } from './client.gen';
105import type {
116 AddPetData,
···106101 ...options,
107102 headers: {
108103 'Content-Type': 'application/json',
109109- ...options?.headers,
104104+ ...options.headers,
110105 },
111106 });
112107···132127 ...options,
133128 headers: {
134129 'Content-Type': 'application/json',
135135- ...options?.headers,
130130+ ...options.headers,
136131 },
137132 });
138133···273268 ...options,
274269 headers: {
275270 'Content-Type': 'application/octet-stream',
276276- ...options?.headers,
271271+ ...options.headers,
277272 },
278273 });
279274···471466 ...options,
472467 headers: {
473468 'Content-Type': 'application/json',
474474- ...options?.headers,
469469+ ...options.headers,
475470 },
476471 });
···11// This file is auto-generated by @hey-api/openapi-ts
2233+import { createClientConfig } from '../hey-api';
34import {
45 type ClientOptions as DefaultClientOptions,
56 type Config,
67 createClient,
78 createConfig,
88-} from '@hey-api/client-fetch';
99-1010-import { createClientConfig } from '../hey-api';
99+} from './client';
1110import type { ClientOptions } from './types.gen';
12111312/**
···11+import type { Auth, AuthToken } from './auth';
22+import type {
33+ BodySerializer,
44+ QuerySerializer,
55+ QuerySerializerOptions,
66+} from './bodySerializer';
77+88+export interface Client<
99+ RequestFn = never,
1010+ Config = unknown,
1111+ MethodFn = never,
1212+ BuildUrlFn = never,
1313+> {
1414+ /**
1515+ * Returns the final request URL.
1616+ */
1717+ buildUrl: BuildUrlFn;
1818+ connect: MethodFn;
1919+ delete: MethodFn;
2020+ get: MethodFn;
2121+ getConfig: () => Config;
2222+ head: MethodFn;
2323+ options: MethodFn;
2424+ patch: MethodFn;
2525+ post: MethodFn;
2626+ put: MethodFn;
2727+ request: RequestFn;
2828+ setConfig: (config: Config) => Config;
2929+ trace: MethodFn;
3030+}
3131+3232+export interface Config {
3333+ /**
3434+ * Auth token or a function returning auth token. The resolved value will be
3535+ * added to the request payload as defined by its `security` array.
3636+ */
3737+ auth?: ((auth: Auth) => Promise<AuthToken> | AuthToken) | AuthToken;
3838+ /**
3939+ * A function for serializing request body parameter. By default,
4040+ * {@link JSON.stringify()} will be used.
4141+ */
4242+ bodySerializer?: BodySerializer | null;
4343+ /**
4444+ * An object containing any HTTP headers that you want to pre-populate your
4545+ * `Headers` object with.
4646+ *
4747+ * {@link https://developer.mozilla.org/docs/Web/API/Headers/Headers#init See more}
4848+ */
4949+ headers?:
5050+ | RequestInit['headers']
5151+ | Record<
5252+ string,
5353+ | string
5454+ | number
5555+ | boolean
5656+ | (string | number | boolean)[]
5757+ | null
5858+ | undefined
5959+ | unknown
6060+ >;
6161+ /**
6262+ * The request method.
6363+ *
6464+ * {@link https://developer.mozilla.org/docs/Web/API/fetch#method See more}
6565+ */
6666+ method?:
6767+ | 'CONNECT'
6868+ | 'DELETE'
6969+ | 'GET'
7070+ | 'HEAD'
7171+ | 'OPTIONS'
7272+ | 'PATCH'
7373+ | 'POST'
7474+ | 'PUT'
7575+ | 'TRACE';
7676+ /**
7777+ * A function for serializing request query parameters. By default, arrays
7878+ * will be exploded in form style, objects will be exploded in deepObject
7979+ * style, and reserved characters are percent-encoded.
8080+ *
8181+ * This method will have no effect if the native `paramsSerializer()` Axios
8282+ * API function is used.
8383+ *
8484+ * {@link https://swagger.io/docs/specification/serialization/#query View examples}
8585+ */
8686+ querySerializer?: QuerySerializer | QuerySerializerOptions;
8787+ /**
8888+ * A function transforming response data before it's returned. This is useful
8989+ * for post-processing data, e.g. converting ISO strings into Date objects.
9090+ */
9191+ responseTransformer?: (data: unknown) => Promise<unknown>;
9292+ /**
9393+ * A function validating response data. This is useful if you want to ensure
9494+ * the response conforms to the desired shape, so it can be safely passed to
9595+ * the transformers and returned to the user.
9696+ */
9797+ responseValidator?: (data: unknown) => Promise<unknown>;
9898+}
+5-10
examples/openapi-ts-sample/src/client/sdk.gen.ts
···11// This file is auto-generated by @hey-api/openapi-ts
2233-import type {
44- Client,
55- Options as ClientOptions,
66- TDataShape,
77-} from '@hey-api/client-fetch';
88-33+import type { Client, Options as ClientOptions, TDataShape } from './client';
94import { client as _heyApiClient } from './client.gen';
105import type {
116 AddPetData,
···106101 ...options,
107102 headers: {
108103 'Content-Type': 'application/json',
109109- ...options?.headers,
104104+ ...options.headers,
110105 },
111106 });
112107···132127 ...options,
133128 headers: {
134129 'Content-Type': 'application/json',
135135- ...options?.headers,
130130+ ...options.headers,
136131 },
137132 });
138133···273268 ...options,
274269 headers: {
275270 'Content-Type': 'application/octet-stream',
276276- ...options?.headers,
271271+ ...options.headers,
277272 },
278273 });
279274···471466 ...options,
472467 headers: {
473468 'Content-Type': 'application/json',
474474- ...options?.headers,
469469+ ...options.headers,
475470 },
476471 });
+1-1
examples/openapi-ts-sample/src/hey-api.ts
···11-import type { CreateClientConfig } from '@hey-api/client-fetch';
11+import type { CreateClientConfig } from './client/client';
2233export const createClientConfig: CreateClientConfig = (config) => ({
44 ...config,
···55 type Config,
66 createClient,
77 createConfig,
88-} from '@hey-api/client-fetch';
99-88+} from './client';
109import type { ClientOptions } from './types.gen';
11101211/**
···11+import type { Auth, AuthToken } from './auth';
22+import type {
33+ BodySerializer,
44+ QuerySerializer,
55+ QuerySerializerOptions,
66+} from './bodySerializer';
77+88+export interface Client<
99+ RequestFn = never,
1010+ Config = unknown,
1111+ MethodFn = never,
1212+ BuildUrlFn = never,
1313+> {
1414+ /**
1515+ * Returns the final request URL.
1616+ */
1717+ buildUrl: BuildUrlFn;
1818+ connect: MethodFn;
1919+ delete: MethodFn;
2020+ get: MethodFn;
2121+ getConfig: () => Config;
2222+ head: MethodFn;
2323+ options: MethodFn;
2424+ patch: MethodFn;
2525+ post: MethodFn;
2626+ put: MethodFn;
2727+ request: RequestFn;
2828+ setConfig: (config: Config) => Config;
2929+ trace: MethodFn;
3030+}
3131+3232+export interface Config {
3333+ /**
3434+ * Auth token or a function returning auth token. The resolved value will be
3535+ * added to the request payload as defined by its `security` array.
3636+ */
3737+ auth?: ((auth: Auth) => Promise<AuthToken> | AuthToken) | AuthToken;
3838+ /**
3939+ * A function for serializing request body parameter. By default,
4040+ * {@link JSON.stringify()} will be used.
4141+ */
4242+ bodySerializer?: BodySerializer | null;
4343+ /**
4444+ * An object containing any HTTP headers that you want to pre-populate your
4545+ * `Headers` object with.
4646+ *
4747+ * {@link https://developer.mozilla.org/docs/Web/API/Headers/Headers#init See more}
4848+ */
4949+ headers?:
5050+ | RequestInit['headers']
5151+ | Record<
5252+ string,
5353+ | string
5454+ | number
5555+ | boolean
5656+ | (string | number | boolean)[]
5757+ | null
5858+ | undefined
5959+ | unknown
6060+ >;
6161+ /**
6262+ * The request method.
6363+ *
6464+ * {@link https://developer.mozilla.org/docs/Web/API/fetch#method See more}
6565+ */
6666+ method?:
6767+ | 'CONNECT'
6868+ | 'DELETE'
6969+ | 'GET'
7070+ | 'HEAD'
7171+ | 'OPTIONS'
7272+ | 'PATCH'
7373+ | 'POST'
7474+ | 'PUT'
7575+ | 'TRACE';
7676+ /**
7777+ * A function for serializing request query parameters. By default, arrays
7878+ * will be exploded in form style, objects will be exploded in deepObject
7979+ * style, and reserved characters are percent-encoded.
8080+ *
8181+ * This method will have no effect if the native `paramsSerializer()` Axios
8282+ * API function is used.
8383+ *
8484+ * {@link https://swagger.io/docs/specification/serialization/#query View examples}
8585+ */
8686+ querySerializer?: QuerySerializer | QuerySerializerOptions;
8787+ /**
8888+ * A function transforming response data before it's returned. This is useful
8989+ * for post-processing data, e.g. converting ISO strings into Date objects.
9090+ */
9191+ responseTransformer?: (data: unknown) => Promise<unknown>;
9292+ /**
9393+ * A function validating response data. This is useful if you want to ensure
9494+ * the response conforms to the desired shape, so it can be safely passed to
9595+ * the transformers and returned to the user.
9696+ */
9797+ responseValidator?: (data: unknown) => Promise<unknown>;
9898+}
···11import './App.css';
2233-import { createClient } from '@hey-api/client-fetch';
43import * as Form from '@radix-ui/react-form';
54import { DownloadIcon, PlusIcon, ReloadIcon } from '@radix-ui/react-icons';
65import {
···2322 getPetByIdOptions,
2423 updatePetMutation,
2524} from './client/@tanstack/react-query.gen';
2525+import { createClient } from './client/client';
2626import { PetSchema } from './client/schemas.gen';
2727import type { Pet } from './client/types.gen';
2828
···55 type Config,
66 createClient,
77 createConfig,
88-} from '@hey-api/client-fetch';
99-88+} from './client';
109import type { ClientOptions } from './types.gen';
11101211/**
···11+import type { Auth, AuthToken } from './auth';
22+import type {
33+ BodySerializer,
44+ QuerySerializer,
55+ QuerySerializerOptions,
66+} from './bodySerializer';
77+88+export interface Client<
99+ RequestFn = never,
1010+ Config = unknown,
1111+ MethodFn = never,
1212+ BuildUrlFn = never,
1313+> {
1414+ /**
1515+ * Returns the final request URL.
1616+ */
1717+ buildUrl: BuildUrlFn;
1818+ connect: MethodFn;
1919+ delete: MethodFn;
2020+ get: MethodFn;
2121+ getConfig: () => Config;
2222+ head: MethodFn;
2323+ options: MethodFn;
2424+ patch: MethodFn;
2525+ post: MethodFn;
2626+ put: MethodFn;
2727+ request: RequestFn;
2828+ setConfig: (config: Config) => Config;
2929+ trace: MethodFn;
3030+}
3131+3232+export interface Config {
3333+ /**
3434+ * Auth token or a function returning auth token. The resolved value will be
3535+ * added to the request payload as defined by its `security` array.
3636+ */
3737+ auth?: ((auth: Auth) => Promise<AuthToken> | AuthToken) | AuthToken;
3838+ /**
3939+ * A function for serializing request body parameter. By default,
4040+ * {@link JSON.stringify()} will be used.
4141+ */
4242+ bodySerializer?: BodySerializer | null;
4343+ /**
4444+ * An object containing any HTTP headers that you want to pre-populate your
4545+ * `Headers` object with.
4646+ *
4747+ * {@link https://developer.mozilla.org/docs/Web/API/Headers/Headers#init See more}
4848+ */
4949+ headers?:
5050+ | RequestInit['headers']
5151+ | Record<
5252+ string,
5353+ | string
5454+ | number
5555+ | boolean
5656+ | (string | number | boolean)[]
5757+ | null
5858+ | undefined
5959+ | unknown
6060+ >;
6161+ /**
6262+ * The request method.
6363+ *
6464+ * {@link https://developer.mozilla.org/docs/Web/API/fetch#method See more}
6565+ */
6666+ method?:
6767+ | 'CONNECT'
6868+ | 'DELETE'
6969+ | 'GET'
7070+ | 'HEAD'
7171+ | 'OPTIONS'
7272+ | 'PATCH'
7373+ | 'POST'
7474+ | 'PUT'
7575+ | 'TRACE';
7676+ /**
7777+ * A function for serializing request query parameters. By default, arrays
7878+ * will be exploded in form style, objects will be exploded in deepObject
7979+ * style, and reserved characters are percent-encoded.
8080+ *
8181+ * This method will have no effect if the native `paramsSerializer()` Axios
8282+ * API function is used.
8383+ *
8484+ * {@link https://swagger.io/docs/specification/serialization/#query View examples}
8585+ */
8686+ querySerializer?: QuerySerializer | QuerySerializerOptions;
8787+ /**
8888+ * A function transforming response data before it's returned. This is useful
8989+ * for post-processing data, e.g. converting ISO strings into Date objects.
9090+ */
9191+ responseTransformer?: (data: unknown) => Promise<unknown>;
9292+ /**
9393+ * A function validating response data. This is useful if you want to ensure
9494+ * the response conforms to the desired shape, so it can be safely passed to
9595+ * the transformers and returned to the user.
9696+ */
9797+ responseValidator?: (data: unknown) => Promise<unknown>;
9898+}
···55 type Config,
66 createClient,
77 createConfig,
88-} from '@hey-api/client-fetch';
99-88+} from './client';
109import type { ClientOptions } from './types.gen';
11101211/**
···11+import type { Auth, AuthToken } from './auth';
22+import type {
33+ BodySerializer,
44+ QuerySerializer,
55+ QuerySerializerOptions,
66+} from './bodySerializer';
77+88+export interface Client<
99+ RequestFn = never,
1010+ Config = unknown,
1111+ MethodFn = never,
1212+ BuildUrlFn = never,
1313+> {
1414+ /**
1515+ * Returns the final request URL.
1616+ */
1717+ buildUrl: BuildUrlFn;
1818+ connect: MethodFn;
1919+ delete: MethodFn;
2020+ get: MethodFn;
2121+ getConfig: () => Config;
2222+ head: MethodFn;
2323+ options: MethodFn;
2424+ patch: MethodFn;
2525+ post: MethodFn;
2626+ put: MethodFn;
2727+ request: RequestFn;
2828+ setConfig: (config: Config) => Config;
2929+ trace: MethodFn;
3030+}
3131+3232+export interface Config {
3333+ /**
3434+ * Auth token or a function returning auth token. The resolved value will be
3535+ * added to the request payload as defined by its `security` array.
3636+ */
3737+ auth?: ((auth: Auth) => Promise<AuthToken> | AuthToken) | AuthToken;
3838+ /**
3939+ * A function for serializing request body parameter. By default,
4040+ * {@link JSON.stringify()} will be used.
4141+ */
4242+ bodySerializer?: BodySerializer | null;
4343+ /**
4444+ * An object containing any HTTP headers that you want to pre-populate your
4545+ * `Headers` object with.
4646+ *
4747+ * {@link https://developer.mozilla.org/docs/Web/API/Headers/Headers#init See more}
4848+ */
4949+ headers?:
5050+ | RequestInit['headers']
5151+ | Record<
5252+ string,
5353+ | string
5454+ | number
5555+ | boolean
5656+ | (string | number | boolean)[]
5757+ | null
5858+ | undefined
5959+ | unknown
6060+ >;
6161+ /**
6262+ * The request method.
6363+ *
6464+ * {@link https://developer.mozilla.org/docs/Web/API/fetch#method See more}
6565+ */
6666+ method?:
6767+ | 'CONNECT'
6868+ | 'DELETE'
6969+ | 'GET'
7070+ | 'HEAD'
7171+ | 'OPTIONS'
7272+ | 'PATCH'
7373+ | 'POST'
7474+ | 'PUT'
7575+ | 'TRACE';
7676+ /**
7777+ * A function for serializing request query parameters. By default, arrays
7878+ * will be exploded in form style, objects will be exploded in deepObject
7979+ * style, and reserved characters are percent-encoded.
8080+ *
8181+ * This method will have no effect if the native `paramsSerializer()` Axios
8282+ * API function is used.
8383+ *
8484+ * {@link https://swagger.io/docs/specification/serialization/#query View examples}
8585+ */
8686+ querySerializer?: QuerySerializer | QuerySerializerOptions;
8787+ /**
8888+ * A function transforming response data before it's returned. This is useful
8989+ * for post-processing data, e.g. converting ISO strings into Date objects.
9090+ */
9191+ responseTransformer?: (data: unknown) => Promise<unknown>;
9292+ /**
9393+ * A function validating response data. This is useful if you want to ensure
9494+ * the response conforms to the desired shape, so it can be safely passed to
9595+ * the transformers and returned to the user.
9696+ */
9797+ responseValidator?: (data: unknown) => Promise<unknown>;
9898+}
···55 type Config,
66 createClient,
77 createConfig
88-} from '@hey-api/client-fetch'
99-88+} from './client'
109import type { ClientOptions } from './types.gen'
11101211/**
···11+import type { Auth, AuthToken } from './auth'
22+import type { BodySerializer, QuerySerializer, QuerySerializerOptions } from './bodySerializer'
33+44+export interface Client<RequestFn = never, Config = unknown, MethodFn = never, BuildUrlFn = never> {
55+ /**
66+ * Returns the final request URL.
77+ */
88+ buildUrl: BuildUrlFn
99+ connect: MethodFn
1010+ delete: MethodFn
1111+ get: MethodFn
1212+ getConfig: () => Config
1313+ head: MethodFn
1414+ options: MethodFn
1515+ patch: MethodFn
1616+ post: MethodFn
1717+ put: MethodFn
1818+ request: RequestFn
1919+ setConfig: (config: Config) => Config
2020+ trace: MethodFn
2121+}
2222+2323+export interface Config {
2424+ /**
2525+ * Auth token or a function returning auth token. The resolved value will be
2626+ * added to the request payload as defined by its `security` array.
2727+ */
2828+ auth?: ((auth: Auth) => Promise<AuthToken> | AuthToken) | AuthToken
2929+ /**
3030+ * A function for serializing request body parameter. By default,
3131+ * {@link JSON.stringify()} will be used.
3232+ */
3333+ bodySerializer?: BodySerializer | null
3434+ /**
3535+ * An object containing any HTTP headers that you want to pre-populate your
3636+ * `Headers` object with.
3737+ *
3838+ * {@link https://developer.mozilla.org/docs/Web/API/Headers/Headers#init See more}
3939+ */
4040+ headers?:
4141+ | RequestInit['headers']
4242+ | Record<
4343+ string,
4444+ string | number | boolean | (string | number | boolean)[] | null | undefined | unknown
4545+ >
4646+ /**
4747+ * The request method.
4848+ *
4949+ * {@link https://developer.mozilla.org/docs/Web/API/fetch#method See more}
5050+ */
5151+ method?: 'CONNECT' | 'DELETE' | 'GET' | 'HEAD' | 'OPTIONS' | 'PATCH' | 'POST' | 'PUT' | 'TRACE'
5252+ /**
5353+ * A function for serializing request query parameters. By default, arrays
5454+ * will be exploded in form style, objects will be exploded in deepObject
5555+ * style, and reserved characters are percent-encoded.
5656+ *
5757+ * This method will have no effect if the native `paramsSerializer()` Axios
5858+ * API function is used.
5959+ *
6060+ * {@link https://swagger.io/docs/specification/serialization/#query View examples}
6161+ */
6262+ querySerializer?: QuerySerializer | QuerySerializerOptions
6363+ /**
6464+ * A function transforming response data before it's returned. This is useful
6565+ * for post-processing data, e.g. converting ISO strings into Date objects.
6666+ */
6767+ responseTransformer?: (data: unknown) => Promise<unknown>
6868+ /**
6969+ * A function validating response data. This is useful if you want to ensure
7070+ * the response conforms to the desired shape, so it can be safely passed to
7171+ * the transformers and returned to the user.
7272+ */
7373+ responseValidator?: (data: unknown) => Promise<unknown>
7474+}