File tree Expand file tree Collapse file tree 4 files changed +34
-1
lines changed Expand file tree Collapse file tree 4 files changed +34
-1
lines changed Original file line number Diff line number Diff line change @@ -137,6 +137,7 @@ export {
137
137
export { clientPluginHandler } from './plugins/@hey-api/client-core/plugin' ;
138
138
export type { Client } from './plugins/@hey-api/client-core/types' ;
139
139
export type { ExpressionTransformer } from './plugins/@hey-api/transformers/expressions' ;
140
+ export type { TypeTransformer } from './plugins/@hey-api/transformers/types' ;
140
141
export { definePluginConfig } from './plugins/shared/utils/config' ;
141
142
export type { DefinePlugin , Plugin } from './plugins/types' ;
142
143
export { compiler , tsc } from './tsc' ;
Original file line number Diff line number Diff line change 1
1
export { defaultConfig , defineConfig } from './config' ;
2
- export type { HeyApiTransformersPlugin } from './types' ;
2
+ export type { HeyApiTransformersPlugin , TypeTransformer } from './types' ;
Original file line number Diff line number Diff line change
1
+ import type ts from 'typescript' ;
2
+
3
+ import type { GeneratedFile } from '../../../generate/file' ;
4
+ import type { IR } from '../../../ir/types' ;
1
5
import type { DefinePlugin , Plugin } from '../../types' ;
2
6
import type { ExpressionTransformer } from './expressions' ;
3
7
8
+ /**
9
+ * Returns the TypeScript type node for a schema with a specific format.
10
+ * If undefined is returned, the default type will be used.
11
+ */
12
+ export type TypeTransformer = ( {
13
+ file,
14
+ schema,
15
+ } : {
16
+ file : GeneratedFile ;
17
+ schema : IR . SchemaObject ;
18
+ } ) => ts . TypeNode | undefined ;
19
+
4
20
export type UserConfig = Plugin . Name < '@hey-api/transformers' > & {
5
21
/**
6
22
* Convert long integers into BigInt values?
@@ -31,6 +47,11 @@ export type UserConfig = Plugin.Name<'@hey-api/transformers'> & {
31
47
* Custom transforms to apply to the generated code.
32
48
*/
33
49
transformers ?: ReadonlyArray < ExpressionTransformer > ;
50
+
51
+ /**
52
+ * Custom type transformers that modify the TypeScript types generated.
53
+ */
54
+ typeTransformers ?: ReadonlyArray < TypeTransformer > ;
34
55
} ;
35
56
36
57
export type HeyApiTransformersPlugin = DefinePlugin < UserConfig > ;
Original file line number Diff line number Diff line change @@ -401,6 +401,17 @@ const schemaTypeToIdentifier = ({
401
401
schema : IR . SchemaObject ;
402
402
state : PluginState ;
403
403
} ) : ts . TypeNode => {
404
+ const transformersPlugin = plugin . getPlugin ( '@hey-api/transformers' ) ;
405
+ if ( transformersPlugin ?. config . typeTransformers ) {
406
+ for ( const typeTransformer of transformersPlugin . config . typeTransformers ) {
407
+ const file = plugin . context . file ( { id : typesId } ) ! ;
408
+ const typeNode = typeTransformer ( { file, schema } ) ;
409
+ if ( typeNode ) {
410
+ return typeNode ;
411
+ }
412
+ }
413
+ }
414
+
404
415
switch ( schema . type as Required < IR . SchemaObject > [ 'type' ] ) {
405
416
case 'array' :
406
417
return arrayTypeToIdentifier ( {
You can’t perform that action at this time.
0 commit comments