From 18ccc81ae75718157949c9724d86d6225f0c0eb0 Mon Sep 17 00:00:00 2001 From: Lubos Date: Tue, 17 Mar 2026 16:56:51 +0100 Subject: [PATCH] fix: expose plugin in transformers --- .changeset/two-cameras-check.md | 5 +++++ .../@hey-api/transformers/expressions.ts | 12 +++++------- .../src/plugins/@hey-api/transformers/plugin.ts | 17 ++++++++++------- 3 files changed, 20 insertions(+), 14 deletions(-) create mode 100644 .changeset/two-cameras-check.md diff --git a/.changeset/two-cameras-check.md b/.changeset/two-cameras-check.md new file mode 100644 index 000000000..7b90037d8 --- /dev/null +++ b/.changeset/two-cameras-check.md @@ -0,0 +1,5 @@ +--- +"@hey-api/openapi-ts": patch +--- + +**plugin(@hey-api/transformers)**: expose plugin in context diff --git a/packages/openapi-ts/src/plugins/@hey-api/transformers/expressions.ts b/packages/openapi-ts/src/plugins/@hey-api/transformers/expressions.ts index aac929244..f4066503d 100644 --- a/packages/openapi-ts/src/plugins/@hey-api/transformers/expressions.ts +++ b/packages/openapi-ts/src/plugins/@hey-api/transformers/expressions.ts @@ -2,15 +2,13 @@ import type { IR } from '@hey-api/shared'; import type ts from 'typescript'; import { $ } from '../../../ts-dsl'; -import type { UserConfig } from './types'; +import type { HeyApiTransformersPlugin, UserConfig } from './types'; -export type ExpressionTransformer = ({ - config, - dataExpression, - schema, -}: { +export type ExpressionTransformer = (ctx: { + /** @deprecated Use `plugin` instead and access the config via `plugin.config` */ config: Omit; - dataExpression?: ts.Expression | ReturnType | string; + dataExpression?: ts.Expression | ReturnType | string; + plugin: HeyApiTransformersPlugin['Instance']; schema: IR.SchemaObject; }) => Array> | undefined; diff --git a/packages/openapi-ts/src/plugins/@hey-api/transformers/plugin.ts b/packages/openapi-ts/src/plugins/@hey-api/transformers/plugin.ts index 90e8b8def..8d2f1a5b6 100644 --- a/packages/openapi-ts/src/plugins/@hey-api/transformers/plugin.ts +++ b/packages/openapi-ts/src/plugins/@hey-api/transformers/plugin.ts @@ -14,15 +14,17 @@ const buildingSymbols = new Set(); type Expr = ReturnType; -const isNodeReturnStatement = (node: Expr) => node['~dsl'] === 'ReturnTsDsl'; +function isNodeReturnStatement(node: Expr) { + return node['~dsl'] === 'ReturnTsDsl'; +} -const schemaResponseTransformerNodes = ({ +function schemaResponseTransformerNodes({ plugin, schema, }: { plugin: HeyApiTransformersPlugin['Instance']; schema: IR.SchemaObject; -}): Array => { +}): Array { const nodes = processSchemaType({ dataExpression: $(dataVariableName), plugin, @@ -36,9 +38,9 @@ const schemaResponseTransformerNodes = ({ } } return nodes; -}; +} -const processSchemaType = ({ +function processSchemaType({ dataExpression, plugin, schema, @@ -46,7 +48,7 @@ const processSchemaType = ({ dataExpression?: ts.Expression | string | ReturnType; plugin: HeyApiTransformersPlugin['Instance']; schema: IR.SchemaObject; -}): Array => { +}): Array { if (schema.$ref) { const query: SymbolMeta = { category: 'transform', @@ -265,6 +267,7 @@ const processSchemaType = ({ const t = transformer({ config: plugin.config, dataExpression, + plugin, schema, }); if (t) { @@ -273,7 +276,7 @@ const processSchemaType = ({ } return []; -}; +} // handles only response transformers for now export const handler: HeyApiTransformersPlugin['Handler'] = ({ plugin }) => { -- 2.51.2