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 #3617 from hey-api/fix/transformers-plugin-arg-2

fix: pass plugin to type transformer

authored by

Lubos and committed by
GitHub
f10429be 8bf63165

+20 -19
+1 -1
.changeset/dark-areas-give.md
··· 3 3 "@hey-api/shared": patch 4 4 --- 5 5 6 - **output**: pass context as second argument in `resolveModuleName()` function 6 + **output**: pass context as second argument in `module.resolve()` function
+1 -1
.changeset/two-cameras-check.md
··· 2 2 "@hey-api/openapi-ts": patch 3 3 --- 4 4 5 - **plugin(@hey-api/transformers)**: expose plugin in context 5 + **plugin(@hey-api/transformers)**: expose plugin in transformer function context
+1 -2
packages/openapi-ts/src/index.ts
··· 169 169 export { clientDefaultConfig, clientDefaultMeta } from './plugins/@hey-api/client-core/config'; 170 170 export { clientPluginHandler } from './plugins/@hey-api/client-core/plugin'; 171 171 export type { Client } from './plugins/@hey-api/client-core/types'; 172 - export type { ExpressionTransformer } from './plugins/@hey-api/transformers/expressions'; 173 - export type { TypeTransformer } from './plugins/@hey-api/transformers/types'; 172 + export type { ExpressionTransformer, TypeTransformer } from './plugins/@hey-api/transformers/types'; 174 173 export * from './ts-dsl'; 175 174 export { Logger } from '@hey-api/codegen-core'; 176 175 export type {
+1 -12
packages/openapi-ts/src/plugins/@hey-api/transformers/expressions.ts
··· 1 - import type { IR } from '@hey-api/shared'; 2 - import type ts from 'typescript'; 3 - 4 1 import { $ } from '../../../ts-dsl'; 5 - import type { HeyApiTransformersPlugin, UserConfig } from './types'; 6 - 7 - export type ExpressionTransformer = (ctx: { 8 - /** @deprecated Use `plugin` instead and access the config via `plugin.config` */ 9 - config: Omit<UserConfig, 'name'>; 10 - dataExpression?: ts.Expression | ReturnType<typeof $.attr | typeof $.expr> | string; 11 - plugin: HeyApiTransformersPlugin['Instance']; 12 - schema: IR.SchemaObject; 13 - }) => Array<ReturnType<typeof $.fromValue>> | undefined; 2 + import type { ExpressionTransformer } from './types'; 14 3 15 4 export const bigIntExpressions: ExpressionTransformer = ({ dataExpression, schema }) => { 16 5 if (schema.type !== 'integer' || schema.format !== 'int64') {
+15 -2
packages/openapi-ts/src/plugins/@hey-api/transformers/types.ts
··· 2 2 import type { DefinePlugin, Plugin } from '@hey-api/shared'; 3 3 import type ts from 'typescript'; 4 4 5 - import type { ExpressionTransformer } from './expressions'; 5 + import type { $, MaybeTsDsl, TsDsl } from '../../../ts-dsl'; 6 + 7 + interface BaseTransformer { 8 + plugin: HeyApiTransformersPlugin['Instance']; 9 + schema: IR.SchemaObject; 10 + } 11 + 12 + export type ExpressionTransformer = ( 13 + ctx: BaseTransformer & { 14 + /** @deprecated Use `plugin` instead and access the config via `plugin.config` */ 15 + config: Omit<UserConfig, 'name'>; 16 + dataExpression?: ts.Expression | ReturnType<typeof $.attr | typeof $.expr> | string; 17 + }, 18 + ) => Array<TsDsl<ts.Expression>> | undefined; 6 19 7 20 /** 8 21 * Returns the TypeScript type node for a schema with a specific format. 9 22 * If undefined is returned, the default type will be used. 10 23 */ 11 - export type TypeTransformer = ({ schema }: { schema: IR.SchemaObject }) => ts.TypeNode | undefined; 24 + export type TypeTransformer = (ctx: BaseTransformer) => MaybeTsDsl<ts.TypeNode> | undefined; 12 25 13 26 export type UserConfig = Plugin.Name<'@hey-api/transformers'> & 14 27 Plugin.Hooks &
+1 -1
packages/openapi-ts/src/plugins/@hey-api/typescript/v1/walker.ts
··· 94 94 const transformersPlugin = ctx.plugin.getPlugin('@hey-api/transformers'); 95 95 if (transformersPlugin?.config.typeTransformers) { 96 96 for (const typeTransformer of transformersPlugin.config.typeTransformers) { 97 - const typeNode = typeTransformer({ schema }); 97 + const typeNode = typeTransformer({ plugin: transformersPlugin, schema }); 98 98 if (typeNode) { 99 99 return { meta: defaultMeta(schema), type: typeNode }; 100 100 }