@@ -57,6 +57,18 @@ export const intrinsicNameToTSType = new Map<string, string>([
57
57
export class ZodEmitter extends CodeTypeEmitter < EmitterOptions > {
58
58
protected nsByName : Map < string , Scope < string > > = new Map ( ) ;
59
59
60
+ getPrefix ( ) {
61
+ const options = this . emitter . getOptions ( ) ;
62
+ return options [ "schema-prefix" ] ?? "" ;
63
+ }
64
+ getSuffix ( ) {
65
+ const options = this . emitter . getOptions ( ) ;
66
+ return options [ "schema-suffix" ] ?? "Schema" ;
67
+ }
68
+ wrapIdentifier ( name : string ) {
69
+ return `${ this . getPrefix ( ) } ${ name } ${ this . getSuffix ( ) } ` ;
70
+ }
71
+
60
72
emitNamespaces ( scope : Scope < string > ) {
61
73
let res = "" ;
62
74
for ( const childScope of scope . childScopes ) {
@@ -197,7 +209,7 @@ export class ZodEmitter extends CodeTypeEmitter<EmitterOptions> {
197
209
198
210
return this . emitter . result . declaration (
199
211
name ,
200
- code `${ commentCode } \nexport const ${ name } Schema = z.object({
212
+ code `${ commentCode } \nexport const ${ this . wrapIdentifier ( name ) } = z.object({
201
213
${ this . emitter . emitModelProperties ( model ) }
202
214
})`
203
215
) ;
@@ -238,7 +250,7 @@ export class ZodEmitter extends CodeTypeEmitter<EmitterOptions> {
238
250
) : EmitterOutput < string > {
239
251
return this . emitter . result . declaration (
240
252
name ,
241
- code `export const ${ name } Schema = z.array(${ this . emitter . emitTypeReference ( elementType ) } );`
253
+ code `export const ${ this . wrapIdentifier ( name ) } = z.array(${ this . emitter . emitTypeReference ( elementType ) } );`
242
254
) ;
243
255
}
244
256
@@ -257,7 +269,7 @@ export class ZodEmitter extends CodeTypeEmitter<EmitterOptions> {
257
269
const returnsOutput = code `.returns(${ this . emitter . emitOperationReturnType ( operation ) } )` ;
258
270
return this . emitter . result . declaration (
259
271
name ,
260
- code `export const ${ name } Schema = z.function()${ argsOutput } ${ returnsOutput } `
272
+ code `export const ${ this . wrapIdentifier ( name ) } = z.function()${ argsOutput } ${ returnsOutput } `
261
273
) ;
262
274
}
263
275
@@ -289,7 +301,7 @@ export class ZodEmitter extends CodeTypeEmitter<EmitterOptions> {
289
301
return this . emitter . result . declaration (
290
302
name ,
291
303
code `
292
- export const ${ name } Schema = z.object({
304
+ export const ${ this . wrapIdentifier ( name ) } = z.object({
293
305
${ this . emitter . emitInterfaceOperations ( iface ) }
294
306
})
295
307
`
@@ -330,7 +342,7 @@ export class ZodEmitter extends CodeTypeEmitter<EmitterOptions> {
330
342
unionDeclaration ( union : Union , name : string ) : EmitterOutput < string > {
331
343
return this . emitter . result . declaration (
332
344
name ,
333
- code `export const ${ name } Schema = ${ this . emitter . emitUnionVariants ( union ) } `
345
+ code `export const ${ this . wrapIdentifier ( name ) } = ${ this . emitter . emitUnionVariants ( union ) } `
334
346
) ;
335
347
}
336
348
@@ -391,9 +403,9 @@ export class ZodEmitter extends CodeTypeEmitter<EmitterOptions> {
391
403
const basePath = pathDown . map ( ( s ) => s . name ) . join ( "." ) ;
392
404
return basePath
393
405
? this . emitter . result . rawCode (
394
- `${ basePath } .${ targetDeclaration . name } Schema `
406
+ `${ basePath } .${ this . wrapIdentifier ( targetDeclaration . name ) } `
395
407
)
396
- : this . emitter . result . rawCode ( ` ${ targetDeclaration . name } Schema` ) ;
408
+ : this . emitter . result . rawCode ( this . wrapIdentifier ( targetDeclaration . name ) ) ;
397
409
}
398
410
399
411
async sourceFile ( sourceFile : SourceFile < string > ) : Promise < EmittedSourceFile > {
0 commit comments