File tree Expand file tree Collapse file tree 2 files changed +29
-1
lines changed Expand file tree Collapse file tree 2 files changed +29
-1
lines changed Original file line number Diff line number Diff line change @@ -409,7 +409,7 @@ export const ElysiaType = {
409
409
. Decode ( ( value ) => {
410
410
if ( typeof value === 'string' ) return value === 'true'
411
411
412
- if ( property && ! Value . Check ( schema , value ) )
412
+ if ( value !== undefined && ! Value . Check ( schema , value ) )
413
413
throw new ValidationError ( 'property' , schema , value )
414
414
415
415
return value
Original file line number Diff line number Diff line change @@ -200,6 +200,34 @@ describe('Query Validator', () => {
200
200
expect ( await res . json ( ) ) . toEqual ( { param1 : true } )
201
201
} )
202
202
203
+ it ( 'parse optional boolean string with second parameter' , async ( ) => {
204
+ const schema = t . Object ( {
205
+ registered : t . Optional ( t . Boolean ( ) ) ,
206
+ other : t . String ( ) ,
207
+ } )
208
+ const app = new Elysia ( ) . get ( '/' , ( { query } ) => query , {
209
+ query : schema
210
+ } )
211
+ const res = await app . handle ( req ( '/?other=sucrose' ) )
212
+
213
+ expect ( res . status ) . toBe ( 200 )
214
+ expect ( await res . json ( ) ) . toEqual ( { other : 'sucrose' } )
215
+ } )
216
+
217
+ it ( 'parse optional boolean string with default value' , async ( ) => {
218
+ const schema = t . Object ( {
219
+ registered : t . Optional ( t . Boolean ( { default : true } ) ) ,
220
+ other : t . String ( ) ,
221
+ } )
222
+ const app = new Elysia ( ) . get ( '/' , ( { query } ) => query , {
223
+ query : schema
224
+ } )
225
+ const res = await app . handle ( req ( '/?other=sucrose' ) )
226
+
227
+ expect ( res . status ) . toBe ( 200 )
228
+ expect ( await res . json ( ) ) . toEqual ( { other : 'sucrose' , registered : true } )
229
+ } )
230
+
203
231
it ( 'validate optional object' , async ( ) => {
204
232
const app = new Elysia ( ) . get (
205
233
'/' ,
You can’t perform that action at this time.
0 commit comments