Skip to content

Commit f10429b

Browse files
authored
Merge pull request #3617 from hey-api/fix/transformers-plugin-arg-2
fix: pass plugin to type transformer
2 parents 8bf6316 + 3ef32c3 commit f10429b

6 files changed

Lines changed: 20 additions & 19 deletions

File tree

.changeset/dark-areas-give.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33
"@hey-api/shared": patch
44
---
55

6-
**output**: pass context as second argument in `resolveModuleName()` function
6+
**output**: pass context as second argument in `module.resolve()` function

.changeset/two-cameras-check.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
"@hey-api/openapi-ts": patch
33
---
44

5-
**plugin(@hey-api/transformers)**: expose plugin in context
5+
**plugin(@hey-api/transformers)**: expose plugin in transformer function context

packages/openapi-ts/src/index.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,8 +169,7 @@ export type { UserConfig } from './config/types';
169169
export { clientDefaultConfig, clientDefaultMeta } from './plugins/@hey-api/client-core/config';
170170
export { clientPluginHandler } from './plugins/@hey-api/client-core/plugin';
171171
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';
174173
export * from './ts-dsl';
175174
export { Logger } from '@hey-api/codegen-core';
176175
export type {

packages/openapi-ts/src/plugins/@hey-api/transformers/expressions.ts

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,5 @@
1-
import type { IR } from '@hey-api/shared';
2-
import type ts from 'typescript';
3-
41
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';
143

154
export const bigIntExpressions: ExpressionTransformer = ({ dataExpression, schema }) => {
165
if (schema.type !== 'integer' || schema.format !== 'int64') {

packages/openapi-ts/src/plugins/@hey-api/transformers/types.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,26 @@ import type { IR } from '@hey-api/shared';
22
import type { DefinePlugin, Plugin } from '@hey-api/shared';
33
import type ts from 'typescript';
44

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;
619

720
/**
821
* Returns the TypeScript type node for a schema with a specific format.
922
* If undefined is returned, the default type will be used.
1023
*/
11-
export type TypeTransformer = ({ schema }: { schema: IR.SchemaObject }) => ts.TypeNode | undefined;
24+
export type TypeTransformer = (ctx: BaseTransformer) => MaybeTsDsl<ts.TypeNode> | undefined;
1225

1326
export type UserConfig = Plugin.Name<'@hey-api/transformers'> &
1427
Plugin.Hooks &

packages/openapi-ts/src/plugins/@hey-api/typescript/v1/walker.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ export function createVisitor(
9494
const transformersPlugin = ctx.plugin.getPlugin('@hey-api/transformers');
9595
if (transformersPlugin?.config.typeTransformers) {
9696
for (const typeTransformer of transformersPlugin.config.typeTransformers) {
97-
const typeNode = typeTransformer({ schema });
97+
const typeNode = typeTransformer({ plugin: transformersPlugin, schema });
9898
if (typeNode) {
9999
return { meta: defaultMeta(schema), type: typeNode };
100100
}

0 commit comments

Comments
 (0)