@@ -55,7 +55,8 @@ export class YupSchemaVisitor extends BaseSchemaVisitor {
55
55
indent ( 'test: (value) => schemas.some((schema) => schema.isValidSync(value))' , 2 ) ,
56
56
indent ( '}).defined()' ) ,
57
57
] . join ( '\n' ) ,
58
- ) . string } `
58
+ )
59
+ . string } `
59
60
) ;
60
61
}
61
62
@@ -82,12 +83,10 @@ export class YupSchemaVisitor extends BaseSchemaVisitor {
82
83
const appendArguments = argumentBlocks ? `\n${ argumentBlocks } ` : '' ;
83
84
84
85
// Building schema for fields.
85
- const shape = node . fields
86
- ?. map ( ( field ) => {
87
- const fieldSchema = generateFieldYupSchema ( this . config , visitor , field , 2 ) ;
88
- return isNonNullType ( field . type ) ? fieldSchema : `${ fieldSchema } .optional()` ;
89
- } )
90
- . join ( ',\n' ) ;
86
+ const shape = node . fields ?. map ( ( field ) => {
87
+ const fieldSchema = generateFieldYupSchema ( this . config , visitor , field , 2 ) ;
88
+ return isNonNullType ( field . type ) ? fieldSchema : `${ fieldSchema } .optional()` ;
89
+ } ) . join ( ',\n' ) ;
91
90
92
91
switch ( this . config . validationSchemaExportType ) {
93
92
case 'const' :
@@ -96,7 +95,8 @@ export class YupSchemaVisitor extends BaseSchemaVisitor {
96
95
. export ( )
97
96
. asKind ( 'const' )
98
97
. withName ( `${ name } Schema: yup.ObjectSchema<${ name } >` )
99
- . withContent ( [ `yup.object({` , shape , '})' ] . join ( '\n' ) ) . string + appendArguments
98
+ . withContent ( [ `yup.object({` , shape , '})' ] . join ( '\n' ) )
99
+ . string + appendArguments
100
100
) ;
101
101
102
102
case 'function' :
@@ -106,7 +106,8 @@ export class YupSchemaVisitor extends BaseSchemaVisitor {
106
106
. export ( )
107
107
. asKind ( 'function' )
108
108
. withName ( `${ name } Schema(): yup.ObjectSchema<${ name } >` )
109
- . withBlock ( [ indent ( `return yup.object({` ) , shape , indent ( '})' ) ] . join ( '\n' ) ) . string + appendArguments
109
+ . withBlock ( [ indent ( `return yup.object({` ) , shape , indent ( '})' ) ] . join ( '\n' ) )
110
+ . string + appendArguments
110
111
) ;
111
112
}
112
113
} ) ,
@@ -141,7 +142,8 @@ export class YupSchemaVisitor extends BaseSchemaVisitor {
141
142
shape ,
142
143
'})' ,
143
144
] . join ( '\n' ) ,
144
- ) . string + appendArguments
145
+ )
146
+ . string + appendArguments
145
147
) ;
146
148
147
149
case 'function' :
@@ -158,7 +160,8 @@ export class YupSchemaVisitor extends BaseSchemaVisitor {
158
160
shape ,
159
161
indent ( '})' ) ,
160
162
] . join ( '\n' ) ,
161
- ) . string + appendArguments
163
+ )
164
+ . string + appendArguments
162
165
) ;
163
166
}
164
167
} ) ,
@@ -207,37 +210,37 @@ export class YupSchemaVisitor extends BaseSchemaVisitor {
207
210
const unionName = visitor . convertName ( node . name . value ) ;
208
211
this . importTypes . push ( unionName ) ;
209
212
210
- const unionElements = node . types
211
- ?. map ( ( t ) => {
212
- const element = visitor . convertName ( t . name . value ) ;
213
- const typ = visitor . getType ( t . name . value ) ;
214
- if ( typ ?. astNode ?. kind === 'EnumTypeDefinition' )
215
- return `${ element } Schema` ;
213
+ const unionElements = node . types ?. map ( ( t ) => {
214
+ const element = visitor . convertName ( t . name . value ) ;
215
+ const typ = visitor . getType ( t . name . value ) ;
216
+ if ( typ ?. astNode ?. kind === 'EnumTypeDefinition' )
217
+ return `${ element } Schema` ;
216
218
217
- switch ( this . config . validationSchemaExportType ) {
218
- case 'const' :
219
- return `${ element } Schema` ;
220
- case 'function' :
221
- default :
222
- return `${ element } Schema()` ;
223
- }
224
- } )
225
- . join ( ', ' ) ;
219
+ switch ( this . config . validationSchemaExportType ) {
220
+ case 'const' :
221
+ return `${ element } Schema` ;
222
+ case 'function' :
223
+ default :
224
+ return `${ element } Schema()` ;
225
+ }
226
+ } ) . join ( ', ' ) ;
226
227
227
228
switch ( this . config . validationSchemaExportType ) {
228
229
case 'const' :
229
230
return new DeclarationBlock ( { } )
230
231
. export ( )
231
232
. asKind ( 'const' )
232
233
. withName ( `${ unionName } Schema: yup.MixedSchema<${ unionName } >` )
233
- . withContent ( `union<${ unionName } >(${ unionElements } )` ) . string ;
234
+ . withContent ( `union<${ unionName } >(${ unionElements } )` )
235
+ . string ;
234
236
case 'function' :
235
237
default :
236
238
return new DeclarationBlock ( { } )
237
239
. export ( )
238
240
. asKind ( 'function' )
239
241
. withName ( `${ unionName } Schema(): yup.MixedSchema<${ unionName } >` )
240
- . withBlock ( indent ( `return union<${ unionName } >(${ unionElements } )` ) ) . string ;
242
+ . withBlock ( indent ( `return union<${ unionName } >(${ unionElements } )` ) )
243
+ . string ;
241
244
}
242
245
} ,
243
246
} ;
@@ -256,15 +259,17 @@ export class YupSchemaVisitor extends BaseSchemaVisitor {
256
259
. export ( )
257
260
. asKind ( 'const' )
258
261
. withName ( `${ name } Schema: yup.ObjectSchema<${ name } >` )
259
- . withContent ( [ 'yup.object({' , shape , '})' ] . join ( '\n' ) ) . string ;
262
+ . withContent ( [ 'yup.object({' , shape , '})' ] . join ( '\n' ) )
263
+ . string ;
260
264
261
265
case 'function' :
262
266
default :
263
267
return new DeclarationBlock ( { } )
264
268
. export ( )
265
269
. asKind ( 'function' )
266
270
. withName ( `${ name } Schema(): yup.ObjectSchema<${ name } >` )
267
- . withBlock ( [ indent ( `return yup.object({` ) , shape , indent ( '})' ) ] . join ( '\n' ) ) . string ;
271
+ . withBlock ( [ indent ( `return yup.object({` ) , shape , indent ( '})' ) ] . join ( '\n' ) )
272
+ . string ;
268
273
}
269
274
}
270
275
}
0 commit comments