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 #3555 from hey-api/feat/zod-processor-export

feat: add export flag to zod processor

authored by

Lubos and committed by
GitHub
ebc84f56 f9b5e001

+37 -23
+10 -5
packages/openapi-ts/src/plugins/zod/mini/processor.ts
··· 33 33 return ctx.schema; 34 34 } 35 35 36 - function process(ctx: ProcessorContext): void { 36 + function process(ctx: ProcessorContext): ZodFinal | void { 37 37 if (!processor.markEmitted(ctx.path)) return; 38 + 39 + const shouldExport = ctx.export !== false; 38 40 39 41 return processor.withContext({ anchor: ctx.namingAnchor, tags: ctx.tags }, () => { 40 - const visitor = createVisitor({ 41 - schemaExtractor: extractor, 42 - }); 42 + const visitor = createVisitor({ schemaExtractor: extractor }); 43 43 const walk = createSchemaWalker(visitor); 44 44 45 45 const result = walk(ctx.schema, { ··· 52 52 plugin, 53 53 }) as ZodFinal; 54 54 55 - exportAst({ ...ctx, final, plugin }); 55 + if (shouldExport) { 56 + exportAst({ ...ctx, final, plugin }); 57 + return; 58 + } 59 + 60 + return final; 56 61 }); 57 62 } 58 63
+7 -8
packages/openapi-ts/src/plugins/zod/shared/processor.ts
··· 1 - import type { 2 - IR, 3 - NamingConfig, 4 - SchemaProcessorContext, 5 - SchemaProcessorResult, 6 - } from '@hey-api/shared'; 1 + import type { IR, NamingConfig, SchemaProcessorContext } from '@hey-api/shared'; 7 2 8 3 import type { ZodPlugin } from '../types'; 9 - import type { TypeOptions } from './types'; 4 + import type { TypeOptions, ZodFinal } from './types'; 10 5 11 6 export type ProcessorContext = SchemaProcessorContext & { 7 + /** Whether to export the result (default: true) */ 8 + export?: boolean; 12 9 naming: NamingConfig & TypeOptions; 13 10 /** The plugin instance. */ 14 11 plugin: ZodPlugin['Instance']; 15 12 schema: IR.SchemaObject; 16 13 }; 17 14 18 - export type ProcessorResult = SchemaProcessorResult<ProcessorContext>; 15 + export type ProcessorResult = { 16 + process: (ctx: ProcessorContext) => ZodFinal | void; 17 + };
+10 -5
packages/openapi-ts/src/plugins/zod/v3/processor.ts
··· 33 33 return ctx.schema; 34 34 } 35 35 36 - function process(ctx: ProcessorContext): void { 36 + function process(ctx: ProcessorContext): ZodFinal | void { 37 37 if (!processor.markEmitted(ctx.path)) return; 38 + 39 + const shouldExport = ctx.export !== false; 38 40 39 41 return processor.withContext({ anchor: ctx.namingAnchor, tags: ctx.tags }, () => { 40 - const visitor = createVisitor({ 41 - schemaExtractor: extractor, 42 - }); 42 + const visitor = createVisitor({ schemaExtractor: extractor }); 43 43 const walk = createSchemaWalker(visitor); 44 44 45 45 const result = walk(ctx.schema, { ··· 52 52 plugin, 53 53 }) as ZodFinal; 54 54 55 - exportAst({ ...ctx, final, plugin }); 55 + if (shouldExport) { 56 + exportAst({ ...ctx, final, plugin }); 57 + return; 58 + } 59 + 60 + return final; 56 61 }); 57 62 } 58 63
+10 -5
packages/openapi-ts/src/plugins/zod/v4/processor.ts
··· 33 33 return ctx.schema; 34 34 } 35 35 36 - function process(ctx: ProcessorContext): void { 36 + function process(ctx: ProcessorContext): ZodFinal | void { 37 37 if (!processor.markEmitted(ctx.path)) return; 38 + 39 + const shouldExport = ctx.export !== false; 38 40 39 41 return processor.withContext({ anchor: ctx.namingAnchor, tags: ctx.tags }, () => { 40 - const visitor = createVisitor({ 41 - schemaExtractor: extractor, 42 - }); 42 + const visitor = createVisitor({ schemaExtractor: extractor }); 43 43 const walk = createSchemaWalker(visitor); 44 44 45 45 const result = walk(ctx.schema, { ··· 52 52 plugin, 53 53 }) as ZodFinal; 54 54 55 - exportAst({ ...ctx, final, plugin }); 55 + if (shouldExport) { 56 + exportAst({ ...ctx, final, plugin }); 57 + return; 58 + } 59 + 60 + return final; 56 61 }); 57 62 } 58 63