You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When using Hapi.types.Object() at the root of a validation specification, a request fails with the following trace:
TypeError: Object function (value, obj, key, errors, keyPath) {
if (typeof value !== 'object') {
errors.add('the value of ' + key + ' must be an object', keyPath);
return false;
}
return self._traverse(value, self._config, errors, keyPath);
} has no method 'validate'
at validateKeyConfig (/Users/pedroteixeira/projects/test/node_modules/hapi/node_modules/joi/lib/index.js:77:47)
at processConfig (/Users/pedroteixeira/projects/test/node_modules/hapi/node_modules/joi/lib/index.js:56:13)
at Object.exports.validate (/Users/pedroteixeira/projects/test/node_modules/hapi/node_modules/joi/lib/index.js:111:5)
at exports.payload (/Users/pedroteixeira/projects/test/node_modules/hapi/lib/validation.js:25:21)
at /Users/pedroteixeira/projects/test/node_modules/hapi/lib/request.js:300:13
at iterate (/Users/pedroteixeira/projects/test/node_modules/hapi/node_modules/async/lib/async.js:131:13)
at /Users/pedroteixeira/projects/test/node_modules/hapi/node_modules/async/lib/async.js:142:25
at /Users/pedroteixeira/projects/test/node_modules/hapi/node_modules/hoek/lib/index.js:582:22
at process._tickDomainCallback (node.js:459:13)
Can someone explain the second argument (true) to types.Object and also query.__test = true?
I was able to get this working by just unwrapping query from types.Object:
var Hapi = require('hapi');
var server = Hapi.createServer('0.0.0.0', 8080);
var types = Hapi.types;
var query = {
param: types.String().required()
};
var validate = {
query: query
};
server.route({
method: 'GET',
path: '/test',
config: {
validate: validate,
handler: handler
}
});
server.start();
function handler(req) {
req.reply('HAY');
}
As an aside, I ran into very similar, if not the same issue, when trying to set validate.payload to a Joi schema defined in a separate node module. I ended up unwrapping schemas from types.Object(), similar to above, and also having to run npm dedup in order to enforce the same Joi instance being returned when required().
When using Hapi.types.Object() at the root of a validation specification, a request fails with the following trace:
Simple test case:
Start the server and then query it:
$ curl http://localhost:8080/test?param=true
I have pinned it down to the fact that hapi clones the route config, loosing the joi.types.Object type at the root.
The text was updated successfully, but these errors were encountered: