@@ -10,54 +10,61 @@ const test = tap.test
10
10
11
11
tap . plan ( 15 )
12
12
13
- test ( 'Should allow custom AJV instance for querystring' , async t => {
14
- t . plan ( 1 )
15
- const customAjv = new AJV ( { coerceTypes : false } )
16
- const server = Fastify ( )
13
+ test (
14
+ 'Should allow custom AJV instance for querystring' ,
15
+ { only : true } ,
16
+ async t => {
17
+ t . plan ( 1 )
18
+ const customAjv = new AJV ( { coerceTypes : false } )
19
+ const server = Fastify ( )
17
20
18
- server . register ( plugin , { } )
21
+ server . register ( plugin , { } )
19
22
20
- server . get (
21
- '/' ,
22
- {
23
- schema : {
24
- querystring : {
25
- msg : {
26
- type : 'array' ,
27
- items : {
28
- type : 'string'
23
+ server . get (
24
+ '/' ,
25
+ {
26
+ schema : {
27
+ querystring : {
28
+ type : 'object' ,
29
+ properties : {
30
+ msg : {
31
+ type : 'array' ,
32
+ items : {
33
+ type : 'string'
34
+ }
35
+ }
29
36
}
30
37
}
38
+ } ,
39
+ config : {
40
+ schemaValidators : {
41
+ // TODO: normalize to query
42
+ querystring : customAjv
43
+ }
31
44
}
32
45
} ,
33
- config : {
34
- schemaValidators : {
35
- // TODO: normalize to query
36
- querystring : customAjv
37
- }
38
- }
39
- } ,
40
- ( req , reply ) => { }
41
- )
46
+ ( req , reply ) => { }
47
+ )
42
48
43
- try {
44
- const res = await server . inject ( {
45
- method : 'GET' ,
46
- url : '/' ,
47
- query : {
48
- msg : [ 'hello world' ]
49
- }
50
- } )
49
+ try {
50
+ const res = await server . inject ( {
51
+ method : 'GET' ,
52
+ url : '/' ,
53
+ query : {
54
+ msg : [ 'hello world' ]
55
+ }
56
+ } )
51
57
52
- t . equal (
53
- res . statusCode ,
54
- 400 ,
55
- 'Should coerce the single element array into string'
56
- )
57
- } catch ( err ) {
58
- t . error ( err )
58
+ t . equal (
59
+ res . statusCode ,
60
+ 400 ,
61
+ 'Should coerce the single element array into string'
62
+ )
63
+ } catch ( err ) {
64
+ t . error ( err )
65
+ }
59
66
}
60
- } )
67
+ )
61
68
62
69
test ( 'Should allow custom AJV instance for body' , async t => {
63
70
t . plan ( 2 )
@@ -125,8 +132,11 @@ test('Should allow custom AJV instance for params', async t => {
125
132
{
126
133
schema : {
127
134
params : {
128
- msg : {
129
- type : 'integer'
135
+ type : 'object' ,
136
+ properties : {
137
+ msg : {
138
+ type : 'integer'
139
+ }
130
140
}
131
141
}
132
142
} ,
@@ -170,8 +180,11 @@ test('Should allow custom AJV instance for headers', async t => {
170
180
{
171
181
schema : {
172
182
headers : {
173
- 'x-type' : {
174
- type : 'integer'
183
+ type : 'object' ,
184
+ properties : {
185
+ 'x-type' : {
186
+ type : 'integer'
187
+ }
175
188
}
176
189
}
177
190
} ,
@@ -234,8 +247,11 @@ test('Should work with referenced schemas (querystring)', async t => {
234
247
{
235
248
schema : {
236
249
query : {
237
- msg : {
238
- $ref : 'some#'
250
+ type : 'object' ,
251
+ properties : {
252
+ msg : {
253
+ $ref : 'some#'
254
+ }
239
255
}
240
256
}
241
257
} ,
@@ -289,8 +305,11 @@ test('Should work with referenced schemas (params)', async t => {
289
305
{
290
306
schema : {
291
307
params : {
292
- id : {
293
- $ref : 'some#'
308
+ type : 'object' ,
309
+ properties : {
310
+ id : {
311
+ $ref : 'some#'
312
+ }
294
313
}
295
314
}
296
315
} ,
@@ -337,8 +356,11 @@ test('Should work with referenced schemas (headers)', async t => {
337
356
{
338
357
schema : {
339
358
headers : {
340
- 'x-id' : {
341
- $ref : 'some#'
359
+ type : 'object' ,
360
+ properties : {
361
+ 'x-id' : {
362
+ $ref : 'some#'
363
+ }
342
364
}
343
365
}
344
366
} ,
@@ -577,13 +599,19 @@ test('Should work with parent nested schemas', async t => {
577
599
{
578
600
schema : {
579
601
querystring : {
580
- msg : {
581
- $ref : 'some#'
602
+ type : 'object' ,
603
+ properties : {
604
+ msg : {
605
+ $ref : 'some#'
606
+ }
582
607
}
583
608
} ,
584
609
headers : {
585
- 'x-another' : {
586
- $ref : 'another#'
610
+ type : 'object' ,
611
+ properties : {
612
+ 'x-another' : {
613
+ $ref : 'another#'
614
+ }
587
615
}
588
616
}
589
617
} ,
@@ -659,13 +687,19 @@ test('Should handle parsing to querystring (query)', async t => {
659
687
{
660
688
schema : {
661
689
query : {
662
- msg : {
663
- $ref : 'some#'
690
+ type : 'object' ,
691
+ properties : {
692
+ msg : {
693
+ $ref : 'some#'
694
+ }
664
695
}
665
696
} ,
666
697
headers : {
667
- 'x-another' : {
668
- $ref : 'another#'
698
+ type : 'object' ,
699
+ properties : {
700
+ 'x-another' : {
701
+ $ref : 'another#'
702
+ }
669
703
}
670
704
}
671
705
} ,
@@ -756,13 +790,19 @@ test('Should use default plugin validator as fallback', async t => {
756
790
{
757
791
schema : {
758
792
query : {
759
- msg : {
760
- $ref : 'some#'
793
+ type : 'object' ,
794
+ properties : {
795
+ msg : {
796
+ $ref : 'some#'
797
+ }
761
798
}
762
799
} ,
763
800
headers : {
764
- 'x-another' : {
765
- $ref : 'another#'
801
+ type : 'object' ,
802
+ properties : {
803
+ 'x-another' : {
804
+ $ref : 'another#'
805
+ }
766
806
}
767
807
}
768
808
}
@@ -830,7 +870,7 @@ test('Should always cache schema to default plugin validator', async t => {
830
870
}
831
871
} )
832
872
833
- server . register ( async ( instance , opts , done ) => {
873
+ server . register ( async ( instance , opts ) => {
834
874
instance . addSchema ( {
835
875
$id : 'another' ,
836
876
type : 'integer'
@@ -843,13 +883,19 @@ test('Should always cache schema to default plugin validator', async t => {
843
883
{
844
884
schema : {
845
885
query : {
846
- msg : {
847
- $ref : 'some#'
886
+ type : 'object' ,
887
+ properties : {
888
+ msg : {
889
+ $ref : 'some#'
890
+ }
848
891
}
849
892
} ,
850
893
headers : {
851
- 'x-another' : {
852
- $ref : 'another#'
894
+ type : 'object' ,
895
+ properties : {
896
+ 'x-another' : {
897
+ $ref : 'another#'
898
+ }
853
899
}
854
900
}
855
901
} ,
@@ -922,13 +968,19 @@ test('Should use default provided validator as fallback', async t => {
922
968
{
923
969
schema : {
924
970
query : {
925
- msg : {
926
- $ref : 'some#'
971
+ type : 'object' ,
972
+ properties : {
973
+ msg : {
974
+ $ref : 'some#'
975
+ }
927
976
}
928
977
} ,
929
978
headers : {
930
- 'x-another' : {
931
- $ref : 'another#'
979
+ type : 'object' ,
980
+ properties : {
981
+ 'x-another' : {
982
+ $ref : 'another#'
983
+ }
932
984
}
933
985
}
934
986
}
0 commit comments