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

fix: expose plugin in transformers

authored by

Lubos and committed by
GitHub
0d33fbc7 b2de0235

+20 -14
+5
.changeset/two-cameras-check.md
··· 1 + --- 2 + "@hey-api/openapi-ts": patch 3 + --- 4 + 5 + **plugin(@hey-api/transformers)**: expose plugin in context
+5 -7
packages/openapi-ts/src/plugins/@hey-api/transformers/expressions.ts
··· 2 2 import type ts from 'typescript'; 3 3 4 4 import { $ } from '../../../ts-dsl'; 5 - import type { UserConfig } from './types'; 5 + import type { HeyApiTransformersPlugin, UserConfig } from './types'; 6 6 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` */ 12 9 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']; 14 12 schema: IR.SchemaObject; 15 13 }) => Array<ReturnType<typeof $.fromValue>> | undefined; 16 14
+10 -7
packages/openapi-ts/src/plugins/@hey-api/transformers/plugin.ts
··· 14 14 15 15 type Expr = ReturnType<typeof $.fromValue | typeof $.return | typeof $.if>; 16 16 17 - const isNodeReturnStatement = (node: Expr) => node['~dsl'] === 'ReturnTsDsl'; 17 + function isNodeReturnStatement(node: Expr) { 18 + return node['~dsl'] === 'ReturnTsDsl'; 19 + } 18 20 19 - const schemaResponseTransformerNodes = ({ 21 + function schemaResponseTransformerNodes({ 20 22 plugin, 21 23 schema, 22 24 }: { 23 25 plugin: HeyApiTransformersPlugin['Instance']; 24 26 schema: IR.SchemaObject; 25 - }): Array<ts.Expression | ts.Statement | Expr> => { 27 + }): Array<ts.Expression | ts.Statement | Expr> { 26 28 const nodes = processSchemaType({ 27 29 dataExpression: $(dataVariableName), 28 30 plugin, ··· 36 38 } 37 39 } 38 40 return nodes; 39 - }; 41 + } 40 42 41 - const processSchemaType = ({ 43 + function processSchemaType({ 42 44 dataExpression, 43 45 plugin, 44 46 schema, ··· 46 48 dataExpression?: ts.Expression | string | ReturnType<typeof $.attr | typeof $.expr>; 47 49 plugin: HeyApiTransformersPlugin['Instance']; 48 50 schema: IR.SchemaObject; 49 - }): Array<Expr> => { 51 + }): Array<Expr> { 50 52 if (schema.$ref) { 51 53 const query: SymbolMeta = { 52 54 category: 'transform', ··· 265 267 const t = transformer({ 266 268 config: plugin.config, 267 269 dataExpression, 270 + plugin, 268 271 schema, 269 272 }); 270 273 if (t) { ··· 273 276 } 274 277 275 278 return []; 276 - }; 279 + } 277 280 278 281 // handles only response transformers for now 279 282 export const handler: HeyApiTransformersPlugin['Handler'] = ({ plugin }) => {