Skip to content

Commit

Permalink
Remove support for pre v16 joi compiled schemas
Browse files Browse the repository at this point in the history
  • Loading branch information
kanongil committed Nov 17, 2023
1 parent 23d6550 commit 60c5a10
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 39 deletions.
14 changes: 2 additions & 12 deletions lib/validation.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ internals.input = async function (source, request) {
const schema = request.route.settings.validate[source];
const bind = request.route.settings.bind;

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

if (typeof schema !== 'function') {
value = await internals.validate(source, schema, localOptions);
value = await schema.validateAsync(source, localOptions);
}
else {
value = await schema(source, localOptions);
Expand All @@ -238,13 +238,3 @@ exports.response = async function (request) {
return request._core.toolkit.failAction(request, request.route.settings.response.failAction, err, { tags: ['validation', 'response', 'error'] });
}
};


internals.validate = function (value, schema, options) {

if (typeof schema.validateAsync === 'function') {
return schema.validateAsync(value, options);
}

return schema.validate(value, options);
};
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@
"@hapi/code": "^9.0.3",
"@hapi/eslint-plugin": "*",
"@hapi/inert": "^7.0.1",
"@hapi/joi-legacy-test": "npm:@hapi/joi@^15.0.0",
"@hapi/lab": "^25.1.2",
"@hapi/vision": "^7.0.1",
"@hapi/wreck": "^18.0.1",
Expand Down
26 changes: 0 additions & 26 deletions test/validation.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ const Code = require('@hapi/code');
const Hapi = require('..');
const Inert = require('@hapi/inert');
const Joi = require('joi');
const JoiLegacy = require('@hapi/joi-legacy-test');
const Lab = require('@hapi/lab');


Expand All @@ -18,31 +17,6 @@ const expect = Code.expect;

describe('validation', () => {

it('validates using joi v15', async () => {

const server = Hapi.server();
server.validator(JoiLegacy);
server.route({
method: 'POST',
path: '/',
handler: () => 'ok',
options: {
validate: {
payload: JoiLegacy.object({
a: JoiLegacy.number(),
b: JoiLegacy.array()
})
}
}
});

const res1 = await server.inject({ url: '/', method: 'POST', payload: { a: '1', b: [1] } });
expect(res1.statusCode).to.equal(200);

const res2 = await server.inject({ url: '/', method: 'POST', payload: { a: 'x', b: [1] } });
expect(res2.statusCode).to.equal(400);
});

describe('inputs', () => {

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

0 comments on commit 60c5a10

Please sign in to comment.