File tree Expand file tree Collapse file tree 4 files changed +37
-23
lines changed
packages/openapi-ts/src/plugins/zod Expand file tree Collapse file tree 4 files changed +37
-23
lines changed Original file line number Diff line number Diff line change @@ -33,13 +33,13 @@ export function createProcessor(plugin: ZodPlugin['Instance']): ProcessorResult
3333 return ctx . schema ;
3434 }
3535
36- function process ( ctx : ProcessorContext ) : void {
36+ function process ( ctx : ProcessorContext ) : ZodFinal | void {
3737 if ( ! processor . markEmitted ( ctx . path ) ) return ;
3838
39+ const shouldExport = ctx . export !== false ;
40+
3941 return processor . withContext ( { anchor : ctx . namingAnchor , tags : ctx . tags } , ( ) => {
40- const visitor = createVisitor ( {
41- schemaExtractor : extractor ,
42- } ) ;
42+ const visitor = createVisitor ( { schemaExtractor : extractor } ) ;
4343 const walk = createSchemaWalker ( visitor ) ;
4444
4545 const result = walk ( ctx . schema , {
@@ -52,7 +52,12 @@ export function createProcessor(plugin: ZodPlugin['Instance']): ProcessorResult
5252 plugin,
5353 } ) as ZodFinal ;
5454
55- exportAst ( { ...ctx , final, plugin } ) ;
55+ if ( shouldExport ) {
56+ exportAst ( { ...ctx , final, plugin } ) ;
57+ return ;
58+ }
59+
60+ return final ;
5661 } ) ;
5762 }
5863
Original file line number Diff line number Diff line change 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' ;
72
83import type { ZodPlugin } from '../types' ;
9- import type { TypeOptions } from './types' ;
4+ import type { TypeOptions , ZodFinal } from './types' ;
105
116export type ProcessorContext = SchemaProcessorContext & {
7+ /** Whether to export the result (default: true) */
8+ export ?: boolean ;
129 naming : NamingConfig & TypeOptions ;
1310 /** The plugin instance. */
1411 plugin : ZodPlugin [ 'Instance' ] ;
1512 schema : IR . SchemaObject ;
1613} ;
1714
18- export type ProcessorResult = SchemaProcessorResult < ProcessorContext > ;
15+ export type ProcessorResult = {
16+ process : ( ctx : ProcessorContext ) => ZodFinal | void ;
17+ } ;
Original file line number Diff line number Diff line change @@ -33,13 +33,13 @@ export function createProcessor(plugin: ZodPlugin['Instance']): ProcessorResult
3333 return ctx . schema ;
3434 }
3535
36- function process ( ctx : ProcessorContext ) : void {
36+ function process ( ctx : ProcessorContext ) : ZodFinal | void {
3737 if ( ! processor . markEmitted ( ctx . path ) ) return ;
3838
39+ const shouldExport = ctx . export !== false ;
40+
3941 return processor . withContext ( { anchor : ctx . namingAnchor , tags : ctx . tags } , ( ) => {
40- const visitor = createVisitor ( {
41- schemaExtractor : extractor ,
42- } ) ;
42+ const visitor = createVisitor ( { schemaExtractor : extractor } ) ;
4343 const walk = createSchemaWalker ( visitor ) ;
4444
4545 const result = walk ( ctx . schema , {
@@ -52,7 +52,12 @@ export function createProcessor(plugin: ZodPlugin['Instance']): ProcessorResult
5252 plugin,
5353 } ) as ZodFinal ;
5454
55- exportAst ( { ...ctx , final, plugin } ) ;
55+ if ( shouldExport ) {
56+ exportAst ( { ...ctx , final, plugin } ) ;
57+ return ;
58+ }
59+
60+ return final ;
5661 } ) ;
5762 }
5863
Original file line number Diff line number Diff line change @@ -33,13 +33,13 @@ export function createProcessor(plugin: ZodPlugin['Instance']): ProcessorResult
3333 return ctx . schema ;
3434 }
3535
36- function process ( ctx : ProcessorContext ) : void {
36+ function process ( ctx : ProcessorContext ) : ZodFinal | void {
3737 if ( ! processor . markEmitted ( ctx . path ) ) return ;
3838
39+ const shouldExport = ctx . export !== false ;
40+
3941 return processor . withContext ( { anchor : ctx . namingAnchor , tags : ctx . tags } , ( ) => {
40- const visitor = createVisitor ( {
41- schemaExtractor : extractor ,
42- } ) ;
42+ const visitor = createVisitor ( { schemaExtractor : extractor } ) ;
4343 const walk = createSchemaWalker ( visitor ) ;
4444
4545 const result = walk ( ctx . schema , {
@@ -52,7 +52,12 @@ export function createProcessor(plugin: ZodPlugin['Instance']): ProcessorResult
5252 plugin,
5353 } ) as ZodFinal ;
5454
55- exportAst ( { ...ctx , final, plugin } ) ;
55+ if ( shouldExport ) {
56+ exportAst ( { ...ctx , final, plugin } ) ;
57+ return ;
58+ }
59+
60+ return final ;
5661 } ) ;
5762 }
5863
You can’t perform that action at this time.
0 commit comments