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 29, 2024
1 parent 03f5e38 commit be95b9b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
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": "^7.0.0",
"@hapi/inert": "^7.0.1",
"@hapi/joi-legacy-test": "npm:@hapi/joi@^15.0.0",
"@hapi/lab": "^26.0.0",
"@hapi/vision": "^7.0.1",
"@hapi/wreck": "^18.0.1",
Expand Down
30 changes: 23 additions & 7 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,20 +17,37 @@ const expect = Code.expect;

describe('validation', () => {

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

const Validator = class {
static compile(schema) {

if (schema.a === 'is-number') {
return {
validate(value, options) {

if (parseInt(value?.a, 10).toString() === value?.a.toString()) {
return { value };
}

throw new Error('Validation failed');
}
};
}
}
};

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

0 comments on commit be95b9b

Please sign in to comment.