fork of hey-api/openapi-ts because I need some additional things
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge pull request #2383 from j-ibarra/main

authored by

Lubos and committed by
GitHub
27c8be7b ed7500ca

+39 -1
+5
.changeset/lucky-seals-boil.md
··· 1 + --- 2 + "@hey-api/openapi-ts": patch 3 + --- 4 + 5 + fix(transformers): add `typeTransformers` option allowing passing custom transform functions
+1
packages/openapi-ts/src/index.ts
··· 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';
+1 -1
packages/openapi-ts/src/plugins/@hey-api/transformers/index.ts
··· 1 1 export { defaultConfig, defineConfig } from './config'; 2 - export type { HeyApiTransformersPlugin } from './types'; 2 + export type { HeyApiTransformersPlugin, TypeTransformer } from './types';
+21
packages/openapi-ts/src/plugins/@hey-api/transformers/types.d.ts
··· 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'; 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; 3 19 4 20 export type UserConfig = Plugin.Name<'@hey-api/transformers'> & { 5 21 /** ··· 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>;
+11
packages/openapi-ts/src/plugins/@hey-api/typescript/plugin.ts
··· 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({