@@ -76,6 +76,7 @@ export class YupSchemaVisitor extends BaseSchemaVisitor {
7676 leave : InterfaceTypeDefinitionBuilder ( this . config . withObjectType , ( node : InterfaceTypeDefinitionNode ) => {
7777 const visitor = this . createVisitor ( 'output' ) ;
7878 const name = visitor . convertName ( node . name . value ) ;
79+ const typeName = visitor . prefixTypeNamespace ( name ) ;
7980 this . importTypes . push ( name ) ;
8081
8182 // Building schema for field arguments.
@@ -94,7 +95,7 @@ export class YupSchemaVisitor extends BaseSchemaVisitor {
9495 new DeclarationBlock ( { } )
9596 . export ( )
9697 . asKind ( 'const' )
97- . withName ( `${ name } Schema: yup.ObjectSchema<${ name } >` )
98+ . withName ( `${ name } Schema: yup.ObjectSchema<${ typeName } >` )
9899 . withContent ( [ `yup.object({` , shape , '})' ] . join ( '\n' ) )
99100 . string + appendArguments
100101 ) ;
@@ -105,7 +106,7 @@ export class YupSchemaVisitor extends BaseSchemaVisitor {
105106 new DeclarationBlock ( { } )
106107 . export ( )
107108 . asKind ( 'function' )
108- . withName ( `${ name } Schema(): yup.ObjectSchema<${ name } >` )
109+ . withName ( `${ name } Schema(): yup.ObjectSchema<${ typeName } >` )
109110 . withBlock ( [ indent ( `return yup.object({` ) , shape , indent ( '})' ) ] . join ( '\n' ) )
110111 . string + appendArguments
111112 ) ;
@@ -119,6 +120,7 @@ export class YupSchemaVisitor extends BaseSchemaVisitor {
119120 leave : ObjectTypeDefinitionBuilder ( this . config . withObjectType , ( node : ObjectTypeDefinitionNode ) => {
120121 const visitor = this . createVisitor ( 'output' ) ;
121122 const name = visitor . convertName ( node . name . value ) ;
123+ const typeName = visitor . prefixTypeNamespace ( name ) ;
122124 this . importTypes . push ( name ) ;
123125
124126 // Building schema for field arguments.
@@ -134,7 +136,7 @@ export class YupSchemaVisitor extends BaseSchemaVisitor {
134136 new DeclarationBlock ( { } )
135137 . export ( )
136138 . asKind ( 'const' )
137- . withName ( `${ name } Schema: yup.ObjectSchema<${ name } >` )
139+ . withName ( `${ name } Schema: yup.ObjectSchema<${ typeName } >` )
138140 . withContent (
139141 [
140142 `yup.object({` ,
@@ -152,7 +154,7 @@ export class YupSchemaVisitor extends BaseSchemaVisitor {
152154 new DeclarationBlock ( { } )
153155 . export ( )
154156 . asKind ( 'function' )
155- . withName ( `${ name } Schema(): yup.ObjectSchema<${ name } >` )
157+ . withName ( `${ name } Schema(): yup.ObjectSchema<${ typeName } >` )
156158 . withBlock (
157159 [
158160 indent ( `return yup.object({` ) ,
@@ -173,6 +175,7 @@ export class YupSchemaVisitor extends BaseSchemaVisitor {
173175 leave : ( node : EnumTypeDefinitionNode ) => {
174176 const visitor = this . createVisitor ( 'both' ) ;
175177 const enumname = visitor . convertName ( node . name . value ) ;
178+ const enumTypeName = visitor . prefixTypeNamespace ( enumname ) ;
176179 this . importTypes . push ( enumname ) ;
177180
178181 // hoise enum declarations
@@ -193,7 +196,7 @@ export class YupSchemaVisitor extends BaseSchemaVisitor {
193196 . export ( )
194197 . asKind ( 'const' )
195198 . 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 ,
197200 ) ;
198201 }
199202 } ,
@@ -208,6 +211,7 @@ export class YupSchemaVisitor extends BaseSchemaVisitor {
208211 const visitor = this . createVisitor ( 'output' ) ;
209212
210213 const unionName = visitor . convertName ( node . name . value ) ;
214+ const unionTypeName = visitor . prefixTypeNamespace ( unionName ) ;
211215 this . importTypes . push ( unionName ) ;
212216
213217 const unionElements = node . types ?. map ( ( t ) => {
@@ -230,16 +234,16 @@ export class YupSchemaVisitor extends BaseSchemaVisitor {
230234 return new DeclarationBlock ( { } )
231235 . export ( )
232236 . 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 } )` )
235239 . string ;
236240 case 'function' :
237241 default :
238242 return new DeclarationBlock ( { } )
239243 . export ( )
240244 . 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 } )` ) )
243247 . string ;
244248 }
245249 } ,
@@ -251,14 +255,15 @@ export class YupSchemaVisitor extends BaseSchemaVisitor {
251255 visitor : Visitor ,
252256 name : string ,
253257 ) {
258+ const typeName = visitor . prefixTypeNamespace ( name ) ;
254259 const shape = shapeFields ( fields , this . config , visitor ) ;
255260
256261 switch ( this . config . validationSchemaExportType ) {
257262 case 'const' :
258263 return new DeclarationBlock ( { } )
259264 . export ( )
260265 . asKind ( 'const' )
261- . withName ( `${ name } Schema: yup.ObjectSchema<${ name } >` )
266+ . withName ( `${ name } Schema: yup.ObjectSchema<${ typeName } >` )
262267 . withContent ( [ 'yup.object({' , shape , '})' ] . join ( '\n' ) )
263268 . string ;
264269
@@ -267,7 +272,7 @@ export class YupSchemaVisitor extends BaseSchemaVisitor {
267272 return new DeclarationBlock ( { } )
268273 . export ( )
269274 . asKind ( 'function' )
270- . withName ( `${ name } Schema(): yup.ObjectSchema<${ name } >` )
275+ . withName ( `${ name } Schema(): yup.ObjectSchema<${ typeName } >` )
271276 . withBlock ( [ indent ( `return yup.object({` ) , shape , indent ( '})' ) ] . join ( '\n' ) )
272277 . string ;
273278 }
0 commit comments