Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove support for pre v16 joi #4474

Open
wants to merge 1 commit into
base: next
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading