Skip to content

Commit 0d33fbc

Browse files
authored
Merge pull request #3610 from hey-api/fix/transformers-plugin-arg
fix: expose plugin in transformers
2 parents b2de023 + 18ccc81 commit 0d33fbc

3 files changed

Lines changed: 20 additions & 14 deletions

File tree

.changeset/two-cameras-check.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@hey-api/openapi-ts": patch
3+
---
4+
5+
**plugin(@hey-api/transformers)**: expose plugin in context

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

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

44
import { $ } from '../../../ts-dsl';
5-
import type { UserConfig } from './types';
5+
import type { HeyApiTransformersPlugin, UserConfig } from './types';
66

7-
export type ExpressionTransformer = ({
8-
config,
9-
dataExpression,
10-
schema,
11-
}: {
7+
export type ExpressionTransformer = (ctx: {
8+
/** @deprecated Use `plugin` instead and access the config via `plugin.config` */
129
config: Omit<UserConfig, 'name'>;
13-
dataExpression?: ts.Expression | ReturnType<typeof $.expr | typeof $.attr> | string;
10+
dataExpression?: ts.Expression | ReturnType<typeof $.attr | typeof $.expr> | string;
11+
plugin: HeyApiTransformersPlugin['Instance'];
1412
schema: IR.SchemaObject;
1513
}) => Array<ReturnType<typeof $.fromValue>> | undefined;
1614

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

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,17 @@ const buildingSymbols = new Set<number>();
1414

1515
type Expr = ReturnType<typeof $.fromValue | typeof $.return | typeof $.if>;
1616

17-
const isNodeReturnStatement = (node: Expr) => node['~dsl'] === 'ReturnTsDsl';
17+
function isNodeReturnStatement(node: Expr) {
18+
return node['~dsl'] === 'ReturnTsDsl';
19+
}
1820

19-
const schemaResponseTransformerNodes = ({
21+
function schemaResponseTransformerNodes({
2022
plugin,
2123
schema,
2224
}: {
2325
plugin: HeyApiTransformersPlugin['Instance'];
2426
schema: IR.SchemaObject;
25-
}): Array<ts.Expression | ts.Statement | Expr> => {
27+
}): Array<ts.Expression | ts.Statement | Expr> {
2628
const nodes = processSchemaType({
2729
dataExpression: $(dataVariableName),
2830
plugin,
@@ -36,17 +38,17 @@ const schemaResponseTransformerNodes = ({
3638
}
3739
}
3840
return nodes;
39-
};
41+
}
4042

41-
const processSchemaType = ({
43+
function processSchemaType({
4244
dataExpression,
4345
plugin,
4446
schema,
4547
}: {
4648
dataExpression?: ts.Expression | string | ReturnType<typeof $.attr | typeof $.expr>;
4749
plugin: HeyApiTransformersPlugin['Instance'];
4850
schema: IR.SchemaObject;
49-
}): Array<Expr> => {
51+
}): Array<Expr> {
5052
if (schema.$ref) {
5153
const query: SymbolMeta = {
5254
category: 'transform',
@@ -265,6 +267,7 @@ const processSchemaType = ({
265267
const t = transformer({
266268
config: plugin.config,
267269
dataExpression,
270+
plugin,
268271
schema,
269272
});
270273
if (t) {
@@ -273,7 +276,7 @@ const processSchemaType = ({
273276
}
274277

275278
return [];
276-
};
279+
}
277280

278281
// handles only response transformers for now
279282
export const handler: HeyApiTransformersPlugin['Handler'] = ({ plugin }) => {

0 commit comments

Comments
 (0)