Skip to content

Commit c123f05

Browse files
committed
feat(sdk): update validator config types
1 parent aea5dbd commit c123f05

File tree

127 files changed

+1180
-847
lines changed

Some content is hidden

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

127 files changed

+1180
-847
lines changed

docs/openapi-ts/plugins/custom.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export type { Config } from './types';
3131
::: code-group
3232

3333
```ts [types.d.ts]
34-
export interface Config {
34+
export type Config = {
3535
/**
3636
* Plugin name. Must be unique.
3737
*/
@@ -48,7 +48,7 @@ export interface Config {
4848
* @default false
4949
*/
5050
myOption?: boolean;
51-
}
51+
};
5252
```
5353

5454
:::
@@ -75,7 +75,6 @@ export const defaultConfig: Plugin.Config<Config> = {
7575
},
7676
dependencies: ['@hey-api/typescript'],
7777
handler,
78-
handlerLegacy: () => {},
7978
name: 'my-plugin',
8079
output: 'my-plugin',
8180
};

packages/custom-client/src/plugin.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ import {
77
type Plugin,
88
} from '@hey-api/openapi-ts';
99

10-
export interface Config extends Client.Config {
10+
export type Config = Client.Config & {
1111
/**
1212
* Plugin name. Must be unique.
1313
*/
1414
name: '@hey-api/custom-client';
15-
}
15+
};
1616

1717
export const defaultConfig: Plugin.Config<Config> = {
1818
...clientDefaultMeta,
@@ -21,7 +21,6 @@ export const defaultConfig: Plugin.Config<Config> = {
2121
bundle: false,
2222
},
2323
handler: clientPluginHandler,
24-
handlerLegacy: () => {},
2524
name: '@hey-api/custom-client',
2625
};
2726

packages/openapi-ts-tests/test/__snapshots__/3.1.x/clients/my-client/base-url-false/client/plugin.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,19 @@ import {
77
type Plugin,
88
} from '@hey-api/openapi-ts';
99

10-
export interface Config extends Client.Config {
10+
type Config = Client.Config & {
1111
/**
1212
* Plugin name. Must be unique.
1313
*/
1414
name: string;
1515
}
1616

17-
export const defaultConfig: Plugin.Config<Config> = {
17+
export type MyClientPlugin = Plugin.Types<Config>;
18+
19+
export const defaultConfig: Plugin.Config<MyClientPlugin> = {
1820
...clientDefaultMeta,
1921
config: clientDefaultConfig,
20-
handler: clientPluginHandler,
22+
handler: clientPluginHandler as Plugin.Handler<MyClientPlugin>,
2123
name: __filename,
2224
};
2325

packages/openapi-ts-tests/test/__snapshots__/3.1.x/clients/my-client/base-url-number/client/plugin.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,19 @@ import {
77
type Plugin,
88
} from '@hey-api/openapi-ts';
99

10-
export interface Config extends Client.Config {
10+
type Config = Client.Config & {
1111
/**
1212
* Plugin name. Must be unique.
1313
*/
1414
name: string;
1515
}
1616

17-
export const defaultConfig: Plugin.Config<Config> = {
17+
export type MyClientPlugin = Plugin.Types<Config>;
18+
19+
export const defaultConfig: Plugin.Config<MyClientPlugin> = {
1820
...clientDefaultMeta,
1921
config: clientDefaultConfig,
20-
handler: clientPluginHandler,
22+
handler: clientPluginHandler as Plugin.Handler<MyClientPlugin>,
2123
name: __filename,
2224
};
2325

packages/openapi-ts-tests/test/__snapshots__/3.1.x/clients/my-client/base-url-strict/client/plugin.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,19 @@ import {
77
type Plugin,
88
} from '@hey-api/openapi-ts';
99

10-
export interface Config extends Client.Config {
10+
type Config = Client.Config & {
1111
/**
1212
* Plugin name. Must be unique.
1313
*/
1414
name: string;
1515
}
1616

17-
export const defaultConfig: Plugin.Config<Config> = {
17+
export type MyClientPlugin = Plugin.Types<Config>;
18+
19+
export const defaultConfig: Plugin.Config<MyClientPlugin> = {
1820
...clientDefaultMeta,
1921
config: clientDefaultConfig,
20-
handler: clientPluginHandler,
22+
handler: clientPluginHandler as Plugin.Handler<MyClientPlugin>,
2123
name: __filename,
2224
};
2325

packages/openapi-ts-tests/test/__snapshots__/3.1.x/clients/my-client/base-url-string/client/plugin.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,19 @@ import {
77
type Plugin,
88
} from '@hey-api/openapi-ts';
99

10-
export interface Config extends Client.Config {
10+
type Config = Client.Config & {
1111
/**
1212
* Plugin name. Must be unique.
1313
*/
1414
name: string;
1515
}
1616

17-
export const defaultConfig: Plugin.Config<Config> = {
17+
export type MyClientPlugin = Plugin.Types<Config>;
18+
19+
export const defaultConfig: Plugin.Config<MyClientPlugin> = {
1820
...clientDefaultMeta,
1921
config: clientDefaultConfig,
20-
handler: clientPluginHandler,
22+
handler: clientPluginHandler as Plugin.Handler<MyClientPlugin>,
2123
name: __filename,
2224
};
2325

packages/openapi-ts-tests/test/__snapshots__/3.1.x/clients/my-client/bundle/client/plugin.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,19 @@ import {
77
type Plugin,
88
} from '@hey-api/openapi-ts';
99

10-
export interface Config extends Client.Config {
10+
type Config = Client.Config & {
1111
/**
1212
* Plugin name. Must be unique.
1313
*/
1414
name: string;
1515
}
1616

17-
export const defaultConfig: Plugin.Config<Config> = {
17+
export type MyClientPlugin = Plugin.Types<Config>;
18+
19+
export const defaultConfig: Plugin.Config<MyClientPlugin> = {
1820
...clientDefaultMeta,
1921
config: clientDefaultConfig,
20-
handler: clientPluginHandler,
22+
handler: clientPluginHandler as Plugin.Handler<MyClientPlugin>,
2123
name: __filename,
2224
};
2325

packages/openapi-ts-tests/test/__snapshots__/3.1.x/clients/my-client/default/client/plugin.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,19 @@ import {
77
type Plugin,
88
} from '@hey-api/openapi-ts';
99

10-
export interface Config extends Client.Config {
10+
type Config = Client.Config & {
1111
/**
1212
* Plugin name. Must be unique.
1313
*/
1414
name: string;
1515
}
1616

17-
export const defaultConfig: Plugin.Config<Config> = {
17+
export type MyClientPlugin = Plugin.Types<Config>;
18+
19+
export const defaultConfig: Plugin.Config<MyClientPlugin> = {
1820
...clientDefaultMeta,
1921
config: clientDefaultConfig,
20-
handler: clientPluginHandler,
22+
handler: clientPluginHandler as Plugin.Handler<MyClientPlugin>,
2123
name: __filename,
2224
};
2325

packages/openapi-ts-tests/test/__snapshots__/3.1.x/clients/my-client/sdk-client-optional/client/plugin.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,19 @@ import {
77
type Plugin,
88
} from '@hey-api/openapi-ts';
99

10-
export interface Config extends Client.Config {
10+
type Config = Client.Config & {
1111
/**
1212
* Plugin name. Must be unique.
1313
*/
1414
name: string;
1515
}
1616

17-
export const defaultConfig: Plugin.Config<Config> = {
17+
export type MyClientPlugin = Plugin.Types<Config>;
18+
19+
export const defaultConfig: Plugin.Config<MyClientPlugin> = {
1820
...clientDefaultMeta,
1921
config: clientDefaultConfig,
20-
handler: clientPluginHandler,
22+
handler: clientPluginHandler as Plugin.Handler<MyClientPlugin>,
2123
name: __filename,
2224
};
2325

packages/openapi-ts-tests/test/__snapshots__/3.1.x/clients/my-client/sdk-client-required/client/plugin.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,19 @@ import {
77
type Plugin,
88
} from '@hey-api/openapi-ts';
99

10-
export interface Config extends Client.Config {
10+
type Config = Client.Config & {
1111
/**
1212
* Plugin name. Must be unique.
1313
*/
1414
name: string;
1515
}
1616

17-
export const defaultConfig: Plugin.Config<Config> = {
17+
export type MyClientPlugin = Plugin.Types<Config>;
18+
19+
export const defaultConfig: Plugin.Config<MyClientPlugin> = {
1820
...clientDefaultMeta,
1921
config: clientDefaultConfig,
20-
handler: clientPluginHandler,
22+
handler: clientPluginHandler as Plugin.Handler<MyClientPlugin>,
2123
name: __filename,
2224
};
2325

packages/openapi-ts-tests/test/custom/client/plugin.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,19 @@ import {
77
type Plugin,
88
} from '@hey-api/openapi-ts';
99

10-
export interface Config extends Client.Config {
10+
type Config = Client.Config & {
1111
/**
1212
* Plugin name. Must be unique.
1313
*/
1414
name: string;
15-
}
15+
};
16+
17+
export type MyClientPlugin = Plugin.Types<Config>;
1618

17-
export const defaultConfig: Plugin.Config<Config> = {
19+
export const defaultConfig: Plugin.Config<MyClientPlugin> = {
1820
...clientDefaultMeta,
1921
config: clientDefaultConfig,
20-
handler: clientPluginHandler,
22+
handler: clientPluginHandler as Plugin.Handler<MyClientPlugin>,
2123
name: __filename,
2224
};
2325

packages/openapi-ts-tests/test/openapi-ts.config.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,10 @@ export default defineConfig(() => {
127127
// throwOnError: true,
128128
// transformer: '@hey-api/transformers',
129129
transformer: true,
130-
validator: 'valibot',
130+
validator: {
131+
request: 'valibot',
132+
response: 'zod',
133+
},
131134
},
132135
{
133136
// bigInt: true,

packages/openapi-ts-tests/test/plugins.test.ts

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -519,10 +519,19 @@ for (const version of versions) {
519519
describe('custom plugin', () => {
520520
it('handles a custom plugin', async () => {
521521
const myPlugin: Plugin.Config<{
522-
customOption: boolean;
523-
name: any;
524-
output: string;
522+
api: undefined;
523+
config: {
524+
customOption: boolean;
525+
name: any;
526+
output: string;
527+
};
528+
resolvedConfig: {
529+
customOption: boolean;
530+
name: any;
531+
output: string;
532+
};
525533
}> = {
534+
api: undefined,
526535
config: {
527536
customOption: true,
528537
},
@@ -548,9 +557,17 @@ for (const version of versions) {
548557

549558
it('throws on invalid dependency', async () => {
550559
const myPlugin: Plugin.Config<{
551-
name: any;
552-
output: string;
560+
api: undefined;
561+
config: {
562+
name: any;
563+
output: string;
564+
};
565+
resolvedConfig: {
566+
name: any;
567+
output: string;
568+
};
553569
}> = {
570+
api: undefined,
554571
config: {},
555572
dependencies: ['@hey-api/oops'],
556573
handler: vi.fn(),

packages/openapi-ts/src/generate/__tests__/class.test.ts

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,30 +42,37 @@ describe('generateLegacyClientClass', () => {
4242
],
4343
plugins: {
4444
'@hey-api/schemas': {
45-
config: {},
45+
config: {
46+
name: '@hey-api/schemas',
47+
},
4648
handler: () => {},
47-
handlerLegacy: () => {},
4849
name: '@hey-api/schemas',
50+
output: '',
4951
},
5052
'@hey-api/sdk': {
51-
config: {},
53+
config: {
54+
name: '@hey-api/sdk',
55+
},
5256
handler: () => {},
53-
handlerLegacy: () => {},
5457
name: '@hey-api/sdk',
58+
output: '',
5559
},
5660
'@hey-api/typescript': {
5761
config: {
5862
enums: 'javascript',
63+
name: '@hey-api/typescript',
5964
},
6065
handler: () => {},
61-
handlerLegacy: () => {},
6266
name: '@hey-api/typescript',
67+
output: '',
6368
},
6469
'legacy/fetch': {
65-
config: {},
70+
config: {
71+
name: 'legacy/fetch',
72+
},
6673
handler: () => {},
67-
handlerLegacy: () => {},
6874
name: 'legacy/fetch',
75+
output: '',
6976
tags: ['client'],
7077
},
7178
},

0 commit comments

Comments
 (0)