Closed acehko closed 7 years ago
Hi @acehko yes, you can seperate your data from the pattern with an extra property and validate it. We also could implement custom functions easily.
seneca.add({
topic: 'math',
cmd: 'add',
data: Joi.object().keys({ b: Joi.required() })
})
@StarpTech I don't want to separate the data like that. I just want the validation for the whole pattern to be in one "key" in the pattern. Like the joi$
property in seneca-joi
. What I want is something like this:
hemera.add({
topic : 'math',
cmd : 'add',
joi$ : function(schema) {
return schema.keys({
a : Joi.number().required(),
b : Joi.number().required()
});
}
}
The main reason is to be able to separate the validation functions to another module. eg.:
hemera.add({ topic : 'math', cmd : 'add', joi$: require('./validation/add') });
With hemera-joi 0.1.71 you can pass full schema for the action by the joi$
property
Changes: https://github.com/hemerajs/hemera/blob/master/packages/hemera-joi/index.js#L23
let Joi = hemera.exposition['hemera-joi'].joi
hemera.add({
topic : 'math',
cmd : 'add',
joi$ : require('./validation/add')
})
That was fast, thanks :)
Is it possible to validate the whole pattern using a custom function like in
seneca-joi
? Example: