@@ -76,6 +76,7 @@ export class YupSchemaVisitor extends BaseSchemaVisitor {
76
76
leave : InterfaceTypeDefinitionBuilder ( this . config . withObjectType , ( node : InterfaceTypeDefinitionNode ) => {
77
77
const visitor = this . createVisitor ( 'output' ) ;
78
78
const name = visitor . convertName ( node . name . value ) ;
79
+ const typeName = visitor . prefixTypeNamespace ( name ) ;
79
80
this . importTypes . push ( name ) ;
80
81
81
82
// Building schema for field arguments.
@@ -94,7 +95,7 @@ export class YupSchemaVisitor extends BaseSchemaVisitor {
94
95
new DeclarationBlock ( { } )
95
96
. export ( )
96
97
. asKind ( 'const' )
97
- . withName ( `${ name } Schema: yup.ObjectSchema<${ name } >` )
98
+ . withName ( `${ name } Schema: yup.ObjectSchema<${ typeName } >` )
98
99
. withContent ( [ `yup.object({` , shape , '})' ] . join ( '\n' ) )
99
100
. string + appendArguments
100
101
) ;
@@ -105,7 +106,7 @@ export class YupSchemaVisitor extends BaseSchemaVisitor {
105
106
new DeclarationBlock ( { } )
106
107
. export ( )
107
108
. asKind ( 'function' )
108
- . withName ( `${ name } Schema(): yup.ObjectSchema<${ name } >` )
109
+ . withName ( `${ name } Schema(): yup.ObjectSchema<${ typeName } >` )
109
110
. withBlock ( [ indent ( `return yup.object({` ) , shape , indent ( '})' ) ] . join ( '\n' ) )
110
111
. string + appendArguments
111
112
) ;
@@ -119,6 +120,7 @@ export class YupSchemaVisitor extends BaseSchemaVisitor {
119
120
leave : ObjectTypeDefinitionBuilder ( this . config . withObjectType , ( node : ObjectTypeDefinitionNode ) => {
120
121
const visitor = this . createVisitor ( 'output' ) ;
121
122
const name = visitor . convertName ( node . name . value ) ;
123
+ const typeName = visitor . prefixTypeNamespace ( name ) ;
122
124
this . importTypes . push ( name ) ;
123
125
124
126
// Building schema for field arguments.
@@ -134,7 +136,7 @@ export class YupSchemaVisitor extends BaseSchemaVisitor {
134
136
new DeclarationBlock ( { } )
135
137
. export ( )
136
138
. asKind ( 'const' )
137
- . withName ( `${ name } Schema: yup.ObjectSchema<${ name } >` )
139
+ . withName ( `${ name } Schema: yup.ObjectSchema<${ typeName } >` )
138
140
. withContent (
139
141
[
140
142
`yup.object({` ,
@@ -152,7 +154,7 @@ export class YupSchemaVisitor extends BaseSchemaVisitor {
152
154
new DeclarationBlock ( { } )
153
155
. export ( )
154
156
. asKind ( 'function' )
155
- . withName ( `${ name } Schema(): yup.ObjectSchema<${ name } >` )
157
+ . withName ( `${ name } Schema(): yup.ObjectSchema<${ typeName } >` )
156
158
. withBlock (
157
159
[
158
160
indent ( `return yup.object({` ) ,
@@ -173,6 +175,7 @@ export class YupSchemaVisitor extends BaseSchemaVisitor {
173
175
leave : ( node : EnumTypeDefinitionNode ) => {
174
176
const visitor = this . createVisitor ( 'both' ) ;
175
177
const enumname = visitor . convertName ( node . name . value ) ;
178
+ const enumTypeName = visitor . prefixTypeNamespace ( enumname ) ;
176
179
this . importTypes . push ( enumname ) ;
177
180
178
181
// hoise enum declarations
@@ -193,7 +196,7 @@ export class YupSchemaVisitor extends BaseSchemaVisitor {
193
196
. export ( )
194
197
. asKind ( 'const' )
195
198
. withName ( `${ enumname } Schema` )
196
- . withContent ( `yup.string<${ enumname } >().oneOf(Object.values(${ enumname } )).defined()` ) . string ,
199
+ . withContent ( `yup.string<${ enumTypeName } >().oneOf(Object.values(${ enumTypeName } )).defined()` ) . string ,
197
200
) ;
198
201
}
199
202
} ,
@@ -208,6 +211,7 @@ export class YupSchemaVisitor extends BaseSchemaVisitor {
208
211
const visitor = this . createVisitor ( 'output' ) ;
209
212
210
213
const unionName = visitor . convertName ( node . name . value ) ;
214
+ const unionTypeName = visitor . prefixTypeNamespace ( unionName ) ;
211
215
this . importTypes . push ( unionName ) ;
212
216
213
217
const unionElements = node . types ?. map ( ( t ) => {
@@ -230,16 +234,16 @@ export class YupSchemaVisitor extends BaseSchemaVisitor {
230
234
return new DeclarationBlock ( { } )
231
235
. export ( )
232
236
. asKind ( 'const' )
233
- . withName ( `${ unionName } Schema: yup.MixedSchema<${ unionName } >` )
234
- . withContent ( `union<${ unionName } >(${ unionElements } )` )
237
+ . withName ( `${ unionName } Schema: yup.MixedSchema<${ unionTypeName } >` )
238
+ . withContent ( `union<${ unionTypeName } >(${ unionElements } )` )
235
239
. string ;
236
240
case 'function' :
237
241
default :
238
242
return new DeclarationBlock ( { } )
239
243
. export ( )
240
244
. asKind ( 'function' )
241
- . withName ( `${ unionName } Schema(): yup.MixedSchema<${ unionName } >` )
242
- . withBlock ( indent ( `return union<${ unionName } >(${ unionElements } )` ) )
245
+ . withName ( `${ unionName } Schema(): yup.MixedSchema<${ unionTypeName } >` )
246
+ . withBlock ( indent ( `return union<${ unionTypeName } >(${ unionElements } )` ) )
243
247
. string ;
244
248
}
245
249
} ,
@@ -251,14 +255,15 @@ export class YupSchemaVisitor extends BaseSchemaVisitor {
251
255
visitor : Visitor ,
252
256
name : string ,
253
257
) {
258
+ const typeName = visitor . prefixTypeNamespace ( name ) ;
254
259
const shape = shapeFields ( fields , this . config , visitor ) ;
255
260
256
261
switch ( this . config . validationSchemaExportType ) {
257
262
case 'const' :
258
263
return new DeclarationBlock ( { } )
259
264
. export ( )
260
265
. asKind ( 'const' )
261
- . withName ( `${ name } Schema: yup.ObjectSchema<${ name } >` )
266
+ . withName ( `${ name } Schema: yup.ObjectSchema<${ typeName } >` )
262
267
. withContent ( [ 'yup.object({' , shape , '})' ] . join ( '\n' ) )
263
268
. string ;
264
269
@@ -267,7 +272,7 @@ export class YupSchemaVisitor extends BaseSchemaVisitor {
267
272
return new DeclarationBlock ( { } )
268
273
. export ( )
269
274
. asKind ( 'function' )
270
- . withName ( `${ name } Schema(): yup.ObjectSchema<${ name } >` )
275
+ . withName ( `${ name } Schema(): yup.ObjectSchema<${ typeName } >` )
271
276
. withBlock ( [ indent ( `return yup.object({` ) , shape , indent ( '})' ) ] . join ( '\n' ) )
272
277
. string ;
273
278
}
0 commit comments