Skip to content

Commit 347584c

Browse files
committed
Merge branch 'main' of https://github.com/hey-api/openapi-ts into feat/pinia-colada-plugin
2 parents bff275e + aa0bfaa commit 347584c

File tree

1,136 files changed

+110941
-25855
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,136 files changed

+110941
-25855
lines changed

.changeset/smooth-ties-brush.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@hey-api/openapi-ts': patch
3+
---
4+
5+
feat(plugin): add `@pinia/colada` plugin

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ test/generated
2424
test/e2e/generated
2525

2626
# debug files
27-
debug
2827
openapi-ts-debug-*
2928
# error files
3029
logs

docs/openapi-ts/migrating.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,28 @@ description: Migrating to @hey-api/openapi-ts.
77

88
While we try to avoid breaking changes, sometimes it's unavoidable in order to offer you the latest features. This page lists changes that require updates to your code. If you run into a problem with migration, please [open an issue](https://github.com/hey-api/openapi-ts/issues).
99

10+
## v0.81.0
11+
12+
### Server-Sent Events (SSE)
13+
14+
This release adds support for server-sent events (SSE). Instead of treating `text/event-stream` content types as regular HTTP methods, we now generate SSE streams. In practice, you will want to update your affected endpoints to process streamed events.
15+
16+
::: code-group
17+
18+
```js [before]
19+
const { data } = await foo();
20+
console.log(data.type);
21+
```
22+
23+
```js [after]
24+
const { stream } = await foo();
25+
for await (const event of stream) {
26+
console.log(event.type);
27+
}
28+
```
29+
30+
:::
31+
1032
## v0.80.0
1133

1234
### Added Zod 4 and Zod Mini

docs/partials/contributors-list.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
- [Lubos](https://github.com/mrlubos)
4444
- [Maarten Knijnenberg](https://github.com/mknijnenberg)
4545
- [Mads Hougesen](https://github.com/hougesen)
46+
- [Malcolm Kee](https://github.com/malcolm-kee)
4647
- [Marcel Richter](https://github.com/mrclrchtr)
4748
- [Marek Lukáš](https://github.com/tajnymag)
4849
- [Matsu](https://github.com/Matsuuu)

package.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,6 @@
2626
"format": "prettier --write .",
2727
"lint:fix": "prettier --check --write . && eslint . --fix",
2828
"lint": "prettier --check . && eslint .",
29-
"openapi-ts": "turbo run $1 --filter=\"@hey-api/openapi-ts\"",
30-
"openapi-ts-tests": "turbo run $1 --filter=\"./packages/openapi-ts-tests/**/*\"",
31-
"openapi-ts-tests-sample": "turbo run $1 --filter=\"./packages/openapi-ts-tests/zod/v4\"",
3229
"prepare": "husky",
3330
"test:coverage": "turbo run test:coverage",
3431
"test:e2e": "turbo run test:e2e",

packages/openapi-ts-tests/main/test/3.1.x.test.ts

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -464,6 +464,14 @@ describe(`OpenAPI ${version}`, () => {
464464
description:
465465
'handles various enum names and values (TypeScript, preserve)',
466466
},
467+
{
468+
config: createConfig({
469+
input: 'union-types.json',
470+
output: 'union-types',
471+
plugins: ['@hey-api/typescript'],
472+
}),
473+
description: 'handles union of primitive types',
474+
},
467475
{
468476
config: createConfig({
469477
input: 'enum-null.json',
@@ -982,6 +990,89 @@ describe(`OpenAPI ${version}`, () => {
982990
description:
983991
'generates Pinia Colada plugin code with complex configuration combining all features',
984992
},
993+
{
994+
config: createConfig({
995+
input: 'opencode.yaml',
996+
output: 'sse-angular',
997+
parser: {
998+
filters: {
999+
operations: {
1000+
include: ['GET /event'],
1001+
},
1002+
},
1003+
},
1004+
plugins: ['@hey-api/client-angular', '@hey-api/sdk'],
1005+
}),
1006+
description: 'client with SSE (Angular)',
1007+
},
1008+
{
1009+
config: createConfig({
1010+
input: 'opencode.yaml',
1011+
output: 'sse-axios',
1012+
parser: {
1013+
filters: {
1014+
operations: {
1015+
include: ['GET /event'],
1016+
},
1017+
},
1018+
},
1019+
plugins: ['@hey-api/client-axios', '@hey-api/sdk'],
1020+
}),
1021+
description: 'client with SSE (Axios)',
1022+
},
1023+
{
1024+
config: createConfig({
1025+
input: 'opencode.yaml',
1026+
output: 'sse-fetch',
1027+
parser: {
1028+
filters: {
1029+
operations: {
1030+
include: ['GET /event'],
1031+
},
1032+
},
1033+
},
1034+
plugins: ['@hey-api/client-fetch', '@hey-api/sdk'],
1035+
}),
1036+
description: 'client with SSE (Fetch)',
1037+
},
1038+
{
1039+
config: createConfig({
1040+
input: 'opencode.yaml',
1041+
output: 'sse-next',
1042+
parser: {
1043+
filters: {
1044+
operations: {
1045+
include: ['GET /event'],
1046+
},
1047+
},
1048+
},
1049+
plugins: ['@hey-api/client-next', '@hey-api/sdk'],
1050+
}),
1051+
description: 'client with SSE (Next.js)',
1052+
},
1053+
{
1054+
config: createConfig({
1055+
input: 'opencode.yaml',
1056+
output: 'sse-nuxt',
1057+
parser: {
1058+
filters: {
1059+
operations: {
1060+
include: ['GET /event'],
1061+
},
1062+
},
1063+
},
1064+
plugins: ['@hey-api/client-nuxt', '@hey-api/sdk'],
1065+
}),
1066+
description: 'client with SSE (Nuxt)',
1067+
},
1068+
{
1069+
config: createConfig({
1070+
input: 'zoom-video-sdk.json',
1071+
output: 'webhooks',
1072+
plugins: ['@hey-api/typescript', 'valibot', 'zod'],
1073+
}),
1074+
description: 'webhook types and validator schemas',
1075+
},
9851076
];
9861077

9871078
it.each(scenarios)('$description', async ({ config }) => {

packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/body-response-text-plain/client/client.gen.ts

Lines changed: 53 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
// This file is auto-generated by @hey-api/openapi-ts
22

3-
import type { Client, Config, ResolvedRequestOptions } from './types.gen';
3+
import { createSseClient } from '../core/serverSentEvents.gen';
4+
import type { HttpMethod } from '../core/types.gen';
5+
import type {
6+
Client,
7+
Config,
8+
RequestOptions,
9+
ResolvedRequestOptions,
10+
} from './types.gen';
411
import {
512
buildUrl,
613
createConfig,
@@ -33,7 +40,7 @@ export const createClient = (config: Config = {}): Client => {
3340
ResolvedRequestOptions
3441
>();
3542

36-
const request: Client['request'] = async (options) => {
43+
const beforeRequest = async (options: RequestOptions) => {
3744
const opts = {
3845
..._config,
3946
...options,
@@ -63,6 +70,13 @@ export const createClient = (config: Config = {}): Client => {
6370
}
6471

6572
const url = buildUrl(opts);
73+
74+
return { opts, url };
75+
};
76+
77+
const request: Client['request'] = async (options) => {
78+
// @ts-expect-error
79+
const { opts, url } = await beforeRequest(options);
6680
const requestInit: ReqInit = {
6781
redirect: 'follow',
6882
...opts,
@@ -180,20 +194,47 @@ export const createClient = (config: Config = {}): Client => {
180194
};
181195
};
182196

197+
const makeMethodFn =
198+
(method: Uppercase<HttpMethod>) => (options: RequestOptions) =>
199+
request({ ...options, method });
200+
201+
const makeSseFn =
202+
(method: Uppercase<HttpMethod>) => async (options: RequestOptions) => {
203+
const { opts, url } = await beforeRequest(options);
204+
return createSseClient({
205+
...opts,
206+
body: opts.body as BodyInit | null | undefined,
207+
headers: opts.headers as unknown as Record<string, string>,
208+
method,
209+
url,
210+
});
211+
};
212+
183213
return {
184214
buildUrl,
185-
connect: (options) => request({ ...options, method: 'CONNECT' }),
186-
delete: (options) => request({ ...options, method: 'DELETE' }),
187-
get: (options) => request({ ...options, method: 'GET' }),
215+
connect: makeMethodFn('CONNECT'),
216+
delete: makeMethodFn('DELETE'),
217+
get: makeMethodFn('GET'),
188218
getConfig,
189-
head: (options) => request({ ...options, method: 'HEAD' }),
219+
head: makeMethodFn('HEAD'),
190220
interceptors,
191-
options: (options) => request({ ...options, method: 'OPTIONS' }),
192-
patch: (options) => request({ ...options, method: 'PATCH' }),
193-
post: (options) => request({ ...options, method: 'POST' }),
194-
put: (options) => request({ ...options, method: 'PUT' }),
221+
options: makeMethodFn('OPTIONS'),
222+
patch: makeMethodFn('PATCH'),
223+
post: makeMethodFn('POST'),
224+
put: makeMethodFn('PUT'),
195225
request,
196226
setConfig,
197-
trace: (options) => request({ ...options, method: 'TRACE' }),
198-
};
227+
sse: {
228+
connect: makeSseFn('CONNECT'),
229+
delete: makeSseFn('DELETE'),
230+
get: makeSseFn('GET'),
231+
head: makeSseFn('HEAD'),
232+
options: makeSseFn('OPTIONS'),
233+
patch: makeSseFn('PATCH'),
234+
post: makeSseFn('POST'),
235+
put: makeSseFn('PUT'),
236+
trace: makeSseFn('TRACE'),
237+
},
238+
trace: makeMethodFn('TRACE'),
239+
} as Client;
199240
};

packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/body-response-text-plain/client/types.gen.ts

Lines changed: 51 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
// This file is auto-generated by @hey-api/openapi-ts
22

33
import type { Auth } from '../core/auth.gen';
4+
import type {
5+
ServerSentEventsOptions,
6+
ServerSentEventsResult,
7+
} from '../core/serverSentEvents.gen';
48
import type {
59
Client as CoreClient,
610
Config as CoreConfig,
@@ -61,13 +65,22 @@ export interface Config<T extends ClientOptions = ClientOptions>
6165
}
6266

6367
export interface RequestOptions<
68+
TData = unknown,
6469
TResponseStyle extends ResponseStyle = 'fields',
6570
ThrowOnError extends boolean = boolean,
6671
Url extends string = string,
6772
> extends Config<{
68-
responseStyle: TResponseStyle;
69-
throwOnError: ThrowOnError;
70-
}> {
73+
responseStyle: TResponseStyle;
74+
throwOnError: ThrowOnError;
75+
}>,
76+
Pick<
77+
ServerSentEventsOptions<TData>,
78+
| 'onSseError'
79+
| 'onSseEvent'
80+
| 'sseDefaultRetryDelay'
81+
| 'sseMaxRetryAttempts'
82+
| 'sseMaxRetryDelay'
83+
> {
7184
/**
7285
* Any body that you want to add to your request.
7386
*
@@ -87,7 +100,7 @@ export interface ResolvedRequestOptions<
87100
TResponseStyle extends ResponseStyle = 'fields',
88101
ThrowOnError extends boolean = boolean,
89102
Url extends string = string,
90-
> extends RequestOptions<TResponseStyle, ThrowOnError, Url> {
103+
> extends RequestOptions<unknown, TResponseStyle, ThrowOnError, Url> {
91104
serializedBody?: string;
92105
}
93106

@@ -148,17 +161,29 @@ type MethodFn = <
148161
ThrowOnError extends boolean = false,
149162
TResponseStyle extends ResponseStyle = 'fields',
150163
>(
151-
options: Omit<RequestOptions<TResponseStyle, ThrowOnError>, 'method'>,
164+
options: Omit<RequestOptions<TData, TResponseStyle, ThrowOnError>, 'method'>,
152165
) => RequestResult<TData, TError, ThrowOnError, TResponseStyle>;
153166

167+
type SseFn = <
168+
TData = unknown,
169+
TError = unknown,
170+
ThrowOnError extends boolean = false,
171+
TResponseStyle extends ResponseStyle = 'fields',
172+
>(
173+
options: Omit<RequestOptions<TData, TResponseStyle, ThrowOnError>, 'method'>,
174+
) => Promise<ServerSentEventsResult<TData, TError>>;
175+
154176
type RequestFn = <
155177
TData = unknown,
156178
TError = unknown,
157179
ThrowOnError extends boolean = false,
158180
TResponseStyle extends ResponseStyle = 'fields',
159181
>(
160-
options: Omit<RequestOptions<TResponseStyle, ThrowOnError>, 'method'> &
161-
Pick<Required<RequestOptions<TResponseStyle, ThrowOnError>>, 'method'>,
182+
options: Omit<RequestOptions<TData, TResponseStyle, ThrowOnError>, 'method'> &
183+
Pick<
184+
Required<RequestOptions<TData, TResponseStyle, ThrowOnError>>,
185+
'method'
186+
>,
162187
) => RequestResult<TData, TError, ThrowOnError, TResponseStyle>;
163188

164189
type BuildUrlFn = <
@@ -172,7 +197,13 @@ type BuildUrlFn = <
172197
options: Pick<TData, 'url'> & Options<TData>,
173198
) => string;
174199

175-
export type Client = CoreClient<RequestFn, Config, MethodFn, BuildUrlFn> & {
200+
export type Client = CoreClient<
201+
RequestFn,
202+
Config,
203+
MethodFn,
204+
BuildUrlFn,
205+
SseFn
206+
> & {
176207
interceptors: Middleware<Request, Response, unknown, ResolvedRequestOptions>;
177208
};
178209

@@ -201,9 +232,10 @@ type OmitKeys<T, K> = Pick<T, Exclude<keyof T, K>>;
201232
export type Options<
202233
TData extends TDataShape = TDataShape,
203234
ThrowOnError extends boolean = boolean,
235+
TResponse = unknown,
204236
TResponseStyle extends ResponseStyle = 'fields',
205237
> = OmitKeys<
206-
RequestOptions<TResponseStyle, ThrowOnError>,
238+
RequestOptions<TResponse, TResponseStyle, ThrowOnError>,
207239
'body' | 'path' | 'query' | 'url'
208240
> &
209241
Omit<TData, 'url'>;
@@ -215,18 +247,22 @@ export type OptionsLegacyParser<
215247
> = TData extends { body?: any }
216248
? TData extends { headers?: any }
217249
? OmitKeys<
218-
RequestOptions<TResponseStyle, ThrowOnError>,
250+
RequestOptions<unknown, TResponseStyle, ThrowOnError>,
219251
'body' | 'headers' | 'url'
220252
> &
221253
TData
222-
: OmitKeys<RequestOptions<TResponseStyle, ThrowOnError>, 'body' | 'url'> &
254+
: OmitKeys<
255+
RequestOptions<unknown, TResponseStyle, ThrowOnError>,
256+
'body' | 'url'
257+
> &
223258
TData &
224-
Pick<RequestOptions<TResponseStyle, ThrowOnError>, 'headers'>
259+
Pick<RequestOptions<unknown, TResponseStyle, ThrowOnError>, 'headers'>
225260
: TData extends { headers?: any }
226261
? OmitKeys<
227-
RequestOptions<TResponseStyle, ThrowOnError>,
262+
RequestOptions<unknown, TResponseStyle, ThrowOnError>,
228263
'headers' | 'url'
229264
> &
230265
TData &
231-
Pick<RequestOptions<TResponseStyle, ThrowOnError>, 'body'>
232-
: OmitKeys<RequestOptions<TResponseStyle, ThrowOnError>, 'url'> & TData;
266+
Pick<RequestOptions<unknown, TResponseStyle, ThrowOnError>, 'body'>
267+
: OmitKeys<RequestOptions<unknown, TResponseStyle, ThrowOnError>, 'url'> &
268+
TData;

0 commit comments

Comments
 (0)