Skip to content

Commit 60c5a10

Browse files
committed
Remove support for pre v16 joi compiled schemas
1 parent 23d6550 commit 60c5a10

File tree

3 files changed

+2
-39
lines changed

3 files changed

+2
-39
lines changed

lib/validation.js

+2-12
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ internals.input = async function (source, request) {
126126
const schema = request.route.settings.validate[source];
127127
const bind = request.route.settings.bind;
128128

129-
var value = await (typeof schema !== 'function' ? internals.validate(request[source], schema, localOptions) : schema.call(bind, request[source], localOptions));
129+
var value = await (typeof schema !== 'function' ? schema.validateAsync(request[source], localOptions) : schema.call(bind, request[source], localOptions));
130130
return;
131131
}
132132
catch (err) {
@@ -217,7 +217,7 @@ exports.response = async function (request) {
217217
let value;
218218

219219
if (typeof schema !== 'function') {
220-
value = await internals.validate(source, schema, localOptions);
220+
value = await schema.validateAsync(source, localOptions);
221221
}
222222
else {
223223
value = await schema(source, localOptions);
@@ -238,13 +238,3 @@ exports.response = async function (request) {
238238
return request._core.toolkit.failAction(request, request.route.settings.response.failAction, err, { tags: ['validation', 'response', 'error'] });
239239
}
240240
};
241-
242-
243-
internals.validate = function (value, schema, options) {
244-
245-
if (typeof schema.validateAsync === 'function') {
246-
return schema.validateAsync(value, options);
247-
}
248-
249-
return schema.validate(value, options);
250-
};

package.json

-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@
4747
"@hapi/code": "^9.0.3",
4848
"@hapi/eslint-plugin": "*",
4949
"@hapi/inert": "^7.0.1",
50-
"@hapi/joi-legacy-test": "npm:@hapi/joi@^15.0.0",
5150
"@hapi/lab": "^25.1.2",
5251
"@hapi/vision": "^7.0.1",
5352
"@hapi/wreck": "^18.0.1",

test/validation.js

-26
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,31 +17,6 @@ const expect = Code.expect;
1817

1918
describe('validation', () => {
2019

21-
it('validates using joi v15', async () => {
22-
23-
const server = Hapi.server();
24-
server.validator(JoiLegacy);
25-
server.route({
26-
method: 'POST',
27-
path: '/',
28-
handler: () => 'ok',
29-
options: {
30-
validate: {
31-
payload: JoiLegacy.object({
32-
a: JoiLegacy.number(),
33-
b: JoiLegacy.array()
34-
})
35-
}
36-
}
37-
});
38-
39-
const res1 = await server.inject({ url: '/', method: 'POST', payload: { a: '1', b: [1] } });
40-
expect(res1.statusCode).to.equal(200);
41-
42-
const res2 = await server.inject({ url: '/', method: 'POST', payload: { a: 'x', b: [1] } });
43-
expect(res2.statusCode).to.equal(400);
44-
});
45-
4620
describe('inputs', () => {
4721

4822
it('validates valid input', async () => {

0 commit comments

Comments
 (0)