File tree Expand file tree Collapse file tree 2 files changed +23
-8
lines changed
Expand file tree Collapse file tree 2 files changed +23
-8
lines changed Original file line number Diff line number Diff line change 4747 "@hapi/code" : " ^9.0.3" ,
4848 "@hapi/eslint-plugin" : " ^7.0.0" ,
4949 "@hapi/inert" : " ^7.0.1" ,
50- "@hapi/joi-legacy-test" : " npm:@hapi/joi@^15.0.0" ,
5150 "@hapi/lab" : " ^26.0.0" ,
5251 "@hapi/vision" : " ^7.0.1" ,
5352 "@hapi/wreck" : " ^18.0.1" ,
Original file line number Diff line number Diff line change @@ -5,7 +5,6 @@ const Code = require('@hapi/code');
55const Hapi = require ( '..' ) ;
66const Inert = require ( '@hapi/inert' ) ;
77const Joi = require ( 'joi' ) ;
8- const JoiLegacy = require ( '@hapi/joi-legacy-test' ) ;
98const Lab = require ( '@hapi/lab' ) ;
109
1110
@@ -18,20 +17,37 @@ const expect = Code.expect;
1817
1918describe ( 'validation' , ( ) => {
2019
21- it ( 'validates using joi v15' , async ( ) => {
20+ it ( 'validates using custom validator' , async ( ) => {
21+
22+ const Validator = class {
23+ static compile ( schema ) {
24+
25+ if ( schema . a === 'is-number' ) {
26+ return {
27+ validate ( value , options ) {
28+
29+ if ( parseInt ( value ?. a , 10 ) . toString ( ) === value ?. a . toString ( ) ) {
30+ return { value } ;
31+ }
32+
33+ throw new Error ( 'Validation failed' ) ;
34+ }
35+ } ;
36+ }
37+ }
38+ } ;
2239
2340 const server = Hapi . server ( ) ;
24- server . validator ( JoiLegacy ) ;
41+ server . validator ( Validator ) ;
2542 server . route ( {
2643 method : 'POST' ,
2744 path : '/' ,
2845 handler : ( ) => 'ok' ,
2946 options : {
3047 validate : {
31- payload : JoiLegacy . object ( {
32- a : JoiLegacy . number ( ) ,
33- b : JoiLegacy . array ( )
34- } )
48+ payload : {
49+ a : 'is-number'
50+ }
3551 }
3652 }
3753 } ) ;
You can’t perform that action at this time.
0 commit comments