File tree Expand file tree Collapse file tree 2 files changed +39
-5
lines changed Expand file tree Collapse file tree 2 files changed +39
-5
lines changed Original file line number Diff line number Diff line change @@ -55,11 +55,18 @@ export class ValibotSchemaVisitor extends BaseSchemaVisitor {
55
55
56
56
// hoist enum declarations
57
57
this . enumDeclarations . push (
58
- new DeclarationBlock ( { } )
59
- . export ( )
60
- . asKind ( 'const' )
61
- . withName ( `${ enumname } Schema` )
62
- . withContent ( `v.enum_(${ enumname } )` ) . string ,
58
+ this . config . enumsAsTypes
59
+ ? new DeclarationBlock ( { } )
60
+ . export ( )
61
+ . asKind ( 'const' )
62
+ . withName ( `${ enumname } Schema` )
63
+ . withContent ( `v.picklist([${ node . values ?. map ( enumOption => `'${ enumOption . name . value } '` ) . join ( ', ' ) } ])` )
64
+ . string
65
+ : new DeclarationBlock ( { } )
66
+ . export ( )
67
+ . asKind ( 'const' )
68
+ . withName ( `${ enumname } Schema` )
69
+ . withContent ( `v.enum_(${ enumname } )` ) . string ,
63
70
) ;
64
71
} ,
65
72
} ;
Original file line number Diff line number Diff line change @@ -182,4 +182,31 @@ describe('valibot', () => {
182
182
"
183
183
` ) ;
184
184
} ) ;
185
+
186
+ it . todo ( 'with importFrom' ) ;
187
+ it . todo ( 'with importFrom & useTypeImports' )
188
+
189
+ it ( 'with enumsAsTypes' , async ( ) => {
190
+ const schema = buildSchema ( /* GraphQL */ `
191
+ enum PageType {
192
+ PUBLIC
193
+ BASIC_AUTH
194
+ }
195
+ ` ) ;
196
+ const result = await plugin (
197
+ schema ,
198
+ [ ] ,
199
+ {
200
+ schema : 'valibot' ,
201
+ enumsAsTypes : true ,
202
+ } ,
203
+ { } ,
204
+ ) ;
205
+ expect ( result . content ) . toMatchInlineSnapshot ( `
206
+ "
207
+ export const PageTypeSchema = v.picklist([\'PUBLIC\', \'BASIC_AUTH\']);
208
+ "
209
+ ` ) ;
210
+ } ) ;
211
+
185
212
} )
You can’t perform that action at this time.
0 commit comments