Skip to content

Commit be95b9b

Browse files
committed
Remove support for pre v16 joi compiled schemas
1 parent 03f5e38 commit be95b9b

File tree

2 files changed

+23
-8
lines changed

2 files changed

+23
-8
lines changed

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@
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",

test/validation.js

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ const Code = require('@hapi/code');
55
const Hapi = require('..');
66
const Inert = require('@hapi/inert');
77
const Joi = require('joi');
8-
const JoiLegacy = require('@hapi/joi-legacy-test');
98
const Lab = require('@hapi/lab');
109

1110

@@ -18,20 +17,37 @@ const expect = Code.expect;
1817

1918
describe('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
});

0 commit comments

Comments
 (0)