@hey-api/openapi-ts 0.94.4 → 0.95.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -93,26 +93,6 @@ Hey API is sponsor-funded. If you rely on Hey API in production, consider becomi
93
93
  <p></p>
94
94
  </td>
95
95
  </tr>
96
- <tr>
97
- <td align="center" width="336px">
98
- <p></p>
99
- <p>
100
- <a href="https://kutt.to/6vrYy9" target="_blank">
101
- <picture height="50px">
102
- <source media="(prefers-color-scheme: dark)" srcset="https://heyapi.dev/assets/mintlify/logo-light.svg">
103
- <img alt="Mintlify logo" height="50px" src="https://heyapi.dev/assets/mintlify/logo-dark.svg">
104
- </picture>
105
- </a>
106
- <br/>
107
- The intelligent knowledge platform.
108
- <br/>
109
- <a href="https://kutt.to/6vrYy9" style="text-decoration:none;" target="_blank">
110
- mintlify.com
111
- </a>
112
- </p>
113
- <p></p>
114
- </td>
115
- </tr>
116
96
  </tbody>
117
97
  </table>
118
98
 
@@ -306,9 +286,9 @@ Plugins are responsible for generating artifacts from your input. By default, He
306
286
 
307
287
  ### Client
308
288
 
309
- Clients are responsible for sending the actual HTTP requests. Using clients is not required, but you must add a client to `plugins` if you're generating SDKs (we default to Fetch).
289
+ Clients are responsible for sending the actual HTTP requests. We default to Fetch client if you're generating SDKs, but you can choose a different option from the available clients.
310
290
 
311
- ### Native Clients
291
+ ### Available Clients
312
292
 
313
293
  - [`@hey-api/client-fetch`](https://heyapi.dev/openapi-ts/clients/fetch)
314
294
  - [`@hey-api/client-angular`](https://heyapi.dev/openapi-ts/clients/angular)
@@ -318,15 +298,15 @@ Clients are responsible for sending the actual HTTP requests. Using clients is n
318
298
  - [`@hey-api/client-nuxt`](https://heyapi.dev/openapi-ts/clients/nuxt)
319
299
  - [`@hey-api/client-ofetch`](https://heyapi.dev/openapi-ts/clients/ofetch)
320
300
 
321
- ### Planned Clients
301
+ ### Proposed Clients (Vote to Prioritize)
322
302
 
323
- The following clients are planned but not in development yet. You can help us prioritize them by voting on [GitHub](https://github.com/hey-api/openapi-ts/labels/RSVP%20%F0%9F%91%8D%F0%9F%91%8E).
303
+ The following clients are roadmap proposals and are not started yet. You can help us prioritize them by voting on [GitHub](https://github.com/hey-api/openapi-ts/issues?q=state%3Aopen%20label%3A%22vote%20%F0%9F%93%A9%22).
324
304
 
325
305
  - [`@hey-api/client-effect`](https://heyapi.dev/openapi-ts/clients/effect)
326
306
 
327
307
  Don't see your client? [Build your own](https://heyapi.dev/openapi-ts/clients/custom) or let us know your interest by [opening an issue](https://github.com/hey-api/openapi-ts/issues).
328
308
 
329
- ### Native Plugins
309
+ ### Available Plugins
330
310
 
331
311
  These plugins help reduce boilerplate associated with third-party dependencies. Hey API natively supports the most popular packages. Please open an issue on [GitHub](https://github.com/hey-api/openapi-ts/issues) if you'd like us to support your favorite package.
332
312
 
@@ -343,13 +323,14 @@ These plugins help reduce boilerplate associated with third-party dependencies.
343
323
  - [`@tanstack/svelte-query`](https://heyapi.dev/openapi-ts/plugins/tanstack-query)
344
324
  - [`@tanstack/vue-query`](https://heyapi.dev/openapi-ts/plugins/tanstack-query)
345
325
  - [`fastify`](https://heyapi.dev/openapi-ts/plugins/fastify)
326
+ - [`orpc`](https://heyapi.dev/openapi-ts/plugins/orpc)
346
327
  - [`nestjs`](https://heyapi.dev/openapi-ts/plugins/nest)
347
328
  - [`valibot`](https://heyapi.dev/openapi-ts/plugins/valibot)
348
329
  - [`zod`](https://heyapi.dev/openapi-ts/plugins/zod)
349
330
 
350
- ### Planned Plugins
331
+ ### Proposed Plugins (Vote to Prioritize)
351
332
 
352
- The following plugins are planned but not in development yet. You can help us prioritize them by voting on [GitHub](https://github.com/hey-api/openapi-ts/labels/RSVP%20%F0%9F%91%8D%F0%9F%91%8E).
333
+ The following plugins are roadmap proposals and are not started yet. You can help us prioritize them by voting on [GitHub](https://github.com/hey-api/openapi-ts/issues?q=state%3Aopen%20label%3A%22vote%20%F0%9F%93%A9%22).
353
334
 
354
335
  - [Adonis](https://heyapi.dev/openapi-ts/plugins/adonis)
355
336
  - [Ajv](https://heyapi.dev/openapi-ts/plugins/ajv)
@@ -95,7 +95,14 @@ export const createClient = (config: Config = {}): Client => {
95
95
  return { opts, req, url };
96
96
  };
97
97
 
98
- const beforeRequest = async (options: RequestOptions) => {
98
+ const beforeRequest = async <
99
+ TData = unknown,
100
+ TResponseStyle extends ResponseStyle = 'fields',
101
+ ThrowOnError extends boolean = boolean,
102
+ Url extends string = string,
103
+ >(
104
+ options: RequestOptions<TData, TResponseStyle, ThrowOnError, Url>,
105
+ ) => {
99
106
  const { opts, req, url } = requestOptions(options);
100
107
 
101
108
  if (opts.security) {
@@ -113,7 +120,6 @@ export const createClient = (config: Config = {}): Client => {
113
120
  };
114
121
 
115
122
  const request: Client['request'] = async (options) => {
116
- // @ts-expect-error
117
123
  const { opts, req: initialReq } = await beforeRequest(options);
118
124
 
119
125
  let req = initialReq;
@@ -157,7 +157,7 @@ type SseFn = <
157
157
  ThrowOnError extends boolean = false,
158
158
  TResponseStyle extends ResponseStyle = 'fields',
159
159
  >(
160
- options: Omit<RequestOptions<TData, TResponseStyle, ThrowOnError>, 'method'>,
160
+ options: Omit<RequestOptions<never, TResponseStyle, ThrowOnError>, 'method'>,
161
161
  ) => Promise<ServerSentEventsResult<TData, TError>>;
162
162
 
163
163
  type RequestFn = <
@@ -296,7 +296,7 @@ export const mergeHeaders = (
296
296
  mergedHeaders = mergedHeaders.append(key, v as string);
297
297
  }
298
298
  } else if (value !== undefined) {
299
- // assume object headers are meant to be JSON stringified, i.e. their
299
+ // assume object headers are meant to be JSON stringified, i.e., their
300
300
  // content value in OpenAPI specification is 'application/json'
301
301
  mergedHeaders = mergedHeaders.set(
302
302
  key,
@@ -33,7 +33,13 @@ export const createClient = (config: Config = {}): Client => {
33
33
  return getConfig();
34
34
  };
35
35
 
36
- const beforeRequest = async (options: RequestOptions) => {
36
+ const beforeRequest = async <
37
+ TData = unknown,
38
+ ThrowOnError extends boolean = boolean,
39
+ Url extends string = string,
40
+ >(
41
+ options: RequestOptions<TData, ThrowOnError, Url>,
42
+ ) => {
37
43
  const opts = {
38
44
  ..._config,
39
45
  ...options,
@@ -63,7 +69,6 @@ export const createClient = (config: Config = {}): Client => {
63
69
 
64
70
  // @ts-expect-error
65
71
  const request: Client['request'] = async (options) => {
66
- // @ts-expect-error
67
72
  const { opts, url } = await beforeRequest(options);
68
73
  try {
69
74
  // assign Axios here for consistency with fetch
@@ -106,7 +106,7 @@ type MethodFn = <TData = unknown, TError = unknown, ThrowOnError extends boolean
106
106
  ) => RequestResult<TData, TError, ThrowOnError>;
107
107
 
108
108
  type SseFn = <TData = unknown, TError = unknown, ThrowOnError extends boolean = false>(
109
- options: Omit<RequestOptions<TData, ThrowOnError>, 'method'>,
109
+ options: Omit<RequestOptions<never, ThrowOnError>, 'method'>,
110
110
  ) => Promise<ServerSentEventsResult<TData, TError>>;
111
111
 
112
112
  type RequestFn = <TData = unknown, TError = unknown, ThrowOnError extends boolean = false>(
@@ -116,13 +116,16 @@ type RequestFn = <TData = unknown, TError = unknown, ThrowOnError extends boolea
116
116
 
117
117
  type BuildUrlFn = <
118
118
  TData extends {
119
- body?: unknown;
120
119
  path?: Record<string, unknown>;
121
120
  query?: Record<string, unknown>;
122
121
  url: string;
123
122
  },
124
123
  >(
125
- options: TData & Options<TData>,
124
+ options: TData &
125
+ Pick<
126
+ RequestOptions<unknown, boolean>,
127
+ 'axios' | 'baseURL' | 'paramsSerializer' | 'querySerializer'
128
+ >,
126
129
  ) => string;
127
130
 
128
131
  export type Client = CoreClient<RequestFn, Config, MethodFn, BuildUrlFn, SseFn> & {
@@ -128,7 +128,7 @@ export const buildUrl: Client['buildUrl'] = (options) => {
128
128
  const instanceBaseUrl = options.axios?.defaults?.baseURL;
129
129
 
130
130
  const baseUrl =
131
- !!options.baseURL && typeof options.baseURL === 'string' ? options.baseURL : instanceBaseUrl;
131
+ options.baseURL && typeof options.baseURL === 'string' ? options.baseURL : instanceBaseUrl;
132
132
 
133
133
  return getUrl({
134
134
  baseUrl: baseUrl as string,
@@ -190,7 +190,7 @@ export const mergeHeaders = (
190
190
  mergedHeaders[key] = [...(mergedHeaders[key] ?? []), v as string];
191
191
  }
192
192
  } else if (value !== undefined) {
193
- // assume object headers are meant to be JSON stringified, i.e. their
193
+ // assume object headers are meant to be JSON stringified, i.e., their
194
194
  // content value in OpenAPI specification is 'application/json'
195
195
  mergedHeaders[key] = typeof value === 'object' ? JSON.stringify(value) : (value as string);
196
196
  }
@@ -78,7 +78,7 @@ export interface Config {
78
78
  requestValidator?: (data: unknown) => Promise<unknown>;
79
79
  /**
80
80
  * A function transforming response data before it's returned. This is useful
81
- * for post-processing data, e.g. converting ISO strings into Date objects.
81
+ * for post-processing data, e.g., converting ISO strings into Date objects.
82
82
  */
83
83
  responseTransformer?: (data: unknown) => Promise<unknown>;
84
84
  /**
@@ -124,7 +124,7 @@ export function getValidRequestBody(options: {
124
124
  return hasSerializedBody ? options.serializedBody : null;
125
125
  }
126
126
 
127
- // not all clients implement a serializedBody property (i.e. client-axios)
127
+ // not all clients implement a serializedBody property (i.e., client-axios)
128
128
  return options.body !== '' ? options.body : null;
129
129
  }
130
130
 
@@ -29,7 +29,14 @@ export const createClient = (config: Config = {}): Client => {
29
29
 
30
30
  const interceptors = createInterceptors<Request, Response, unknown, ResolvedRequestOptions>();
31
31
 
32
- const beforeRequest = async (options: RequestOptions) => {
32
+ const beforeRequest = async <
33
+ TData = unknown,
34
+ TResponseStyle extends 'data' | 'fields' = 'fields',
35
+ ThrowOnError extends boolean = boolean,
36
+ Url extends string = string,
37
+ >(
38
+ options: RequestOptions<TData, TResponseStyle, ThrowOnError, Url>,
39
+ ) => {
33
40
  const opts = {
34
41
  ..._config,
35
42
  ...options,
@@ -58,13 +65,14 @@ export const createClient = (config: Config = {}): Client => {
58
65
  opts.headers.delete('Content-Type');
59
66
  }
60
67
 
61
- const url = buildUrl(opts);
68
+ const resolvedOpts = opts as typeof opts &
69
+ ResolvedRequestOptions<TResponseStyle, ThrowOnError, Url>;
70
+ const url = buildUrl(resolvedOpts);
62
71
 
63
- return { opts, url };
72
+ return { opts: resolvedOpts, url };
64
73
  };
65
74
 
66
75
  const request: Client['request'] = async (options) => {
67
- // @ts-expect-error
68
76
  const { opts, url } = await beforeRequest(options);
69
77
  const requestInit: ReqInit = {
70
78
  redirect: 'follow',
@@ -150,7 +150,7 @@ type SseFn = <
150
150
  ThrowOnError extends boolean = false,
151
151
  TResponseStyle extends ResponseStyle = 'fields',
152
152
  >(
153
- options: Omit<RequestOptions<TData, TResponseStyle, ThrowOnError>, 'method'>,
153
+ options: Omit<RequestOptions<never, TResponseStyle, ThrowOnError>, 'method'>,
154
154
  ) => Promise<ServerSentEventsResult<TData, TError>>;
155
155
 
156
156
  type RequestFn = <
@@ -202,7 +202,7 @@ export const mergeHeaders = (
202
202
  mergedHeaders.append(key, v as string);
203
203
  }
204
204
  } else if (value !== undefined) {
205
- // assume object headers are meant to be JSON stringified, i.e. their
205
+ // assume object headers are meant to be JSON stringified, i.e., their
206
206
  // content value in OpenAPI specification is 'application/json'
207
207
  mergedHeaders.set(
208
208
  key,
@@ -28,7 +28,14 @@ export const createClient = (config: Config = {}): Client => {
28
28
 
29
29
  const interceptors = createInterceptors<Request, Response, unknown, ResolvedRequestOptions>();
30
30
 
31
- const beforeRequest = async (options: RequestOptions) => {
31
+ const beforeRequest = async <
32
+ TData = unknown,
33
+ TResponseStyle extends 'data' | 'fields' = 'fields',
34
+ ThrowOnError extends boolean = boolean,
35
+ Url extends string = string,
36
+ >(
37
+ options: RequestOptions<TData, TResponseStyle, ThrowOnError, Url>,
38
+ ) => {
32
39
  const opts = {
33
40
  ..._config,
34
41
  ...options,
@@ -56,9 +63,11 @@ export const createClient = (config: Config = {}): Client => {
56
63
  opts.headers.delete('Content-Type');
57
64
  }
58
65
 
59
- const url = buildUrl(opts);
66
+ const resolvedOpts = opts as typeof opts &
67
+ ResolvedRequestOptions<TResponseStyle, ThrowOnError, Url>;
68
+ const url = buildUrl(resolvedOpts);
60
69
 
61
- return { opts, url };
70
+ return { opts: resolvedOpts, url };
62
71
  };
63
72
 
64
73
  const parseErrorResponse = async (
@@ -105,7 +114,6 @@ export const createClient = (config: Config = {}): Client => {
105
114
  };
106
115
 
107
116
  const request: Client['request'] = async (options) => {
108
- // @ts-expect-error
109
117
  const { opts, url } = await beforeRequest(options);
110
118
 
111
119
  const kyInstance = opts.ky!;
@@ -182,7 +182,7 @@ type SseFn = <
182
182
  ThrowOnError extends boolean = false,
183
183
  TResponseStyle extends ResponseStyle = 'fields',
184
184
  >(
185
- options: Omit<RequestOptions<TData, TResponseStyle, ThrowOnError>, 'method'>,
185
+ options: Omit<RequestOptions<never, TResponseStyle, ThrowOnError>, 'method'>,
186
186
  ) => Promise<ServerSentEventsResult<TData, TError>>;
187
187
 
188
188
  type RequestFn = <
@@ -29,7 +29,13 @@ export const createClient = (config: Config = {}): Client => {
29
29
 
30
30
  const interceptors = createInterceptors<Response, unknown, ResolvedRequestOptions>();
31
31
 
32
- const beforeRequest = async (options: RequestOptions) => {
32
+ const beforeRequest = async <
33
+ TData = unknown,
34
+ ThrowOnError extends boolean = boolean,
35
+ Url extends string = string,
36
+ >(
37
+ options: RequestOptions<TData, ThrowOnError, Url>,
38
+ ) => {
33
39
  const opts = {
34
40
  ..._config,
35
41
  ...options,
@@ -58,14 +64,14 @@ export const createClient = (config: Config = {}): Client => {
58
64
  opts.headers.delete('Content-Type');
59
65
  }
60
66
 
61
- const url = buildUrl(opts);
67
+ const resolvedOpts = opts as typeof opts & ResolvedRequestOptions<ThrowOnError, Url>;
68
+ const url = buildUrl(resolvedOpts);
62
69
 
63
- return { opts, url };
70
+ return { opts: resolvedOpts, url };
64
71
  };
65
72
 
66
73
  // @ts-expect-error
67
74
  const request: Client['request'] = async (options) => {
68
- // @ts-expect-error
69
75
  const { opts, url } = await beforeRequest(options);
70
76
 
71
77
  for (const fn of interceptors.request.fns) {
@@ -110,7 +110,7 @@ type MethodFn = <TData = unknown, TError = unknown, ThrowOnError extends boolean
110
110
  ) => RequestResult<TData, TError, ThrowOnError>;
111
111
 
112
112
  type SseFn = <TData = unknown, TError = unknown, ThrowOnError extends boolean = false>(
113
- options: Omit<RequestOptions<TData, ThrowOnError>, 'method'>,
113
+ options: Omit<RequestOptions<never, ThrowOnError>, 'method'>,
114
114
  ) => Promise<ServerSentEventsResult<TData, TError>>;
115
115
 
116
116
  type RequestFn = <TData = unknown, TError = unknown, ThrowOnError extends boolean = false>(
@@ -311,7 +311,7 @@ export const mergeHeaders = (
311
311
  mergedHeaders.append(key, v as string);
312
312
  }
313
313
  } else if (value !== undefined) {
314
- // assume object headers are meant to be JSON stringified, i.e. their
314
+ // assume object headers are meant to be JSON stringified, i.e., their
315
315
  // content value in OpenAPI specification is 'application/json'
316
316
  mergedHeaders.set(
317
317
  key,
@@ -286,7 +286,7 @@ export const mergeHeaders = (
286
286
  }
287
287
  } else if (value !== undefined) {
288
288
  const v = unwrapRefs(value);
289
- // assume object headers are meant to be JSON stringified, i.e. their
289
+ // assume object headers are meant to be JSON stringified, i.e., their
290
290
  // content value in OpenAPI specification is 'application/json'
291
291
  mergedHeaders.set(key, typeof v === 'object' ? JSON.stringify(v) : (v as string));
292
292
  }
@@ -213,7 +213,7 @@ type SseFn = <
213
213
  ThrowOnError extends boolean = false,
214
214
  TResponseStyle extends ResponseStyle = 'fields',
215
215
  >(
216
- options: Omit<RequestOptions<TData, TResponseStyle, ThrowOnError>, 'method'>,
216
+ options: Omit<RequestOptions<never, TResponseStyle, ThrowOnError>, 'method'>,
217
217
  ) => Promise<ServerSentEventsResult<TData, TError>>;
218
218
 
219
219
  type RequestFn = <
@@ -233,7 +233,7 @@ export const mergeHeaders = (
233
233
  mergedHeaders.append(key, v as string);
234
234
  }
235
235
  } else if (value !== undefined) {
236
- // assume object headers are meant to be JSON stringified, i.e. their
236
+ // assume object headers are meant to be JSON stringified, i.e., their
237
237
  // content value in OpenAPI specification is 'application/json'
238
238
  mergedHeaders.set(
239
239
  key,