Context
- node version: v9.4.0
- joi version: 13.1.2
- environment (node, browser): node
- used with (hapi, standalone, ...): with express-validation
- any other relevant information: N/A
What are you trying to achieve or the steps to reproduce ?
I'm trying to define my Joi schema in one module and include it in different modules (the base definition are meant to be shared in more modules to avoid code duplication). But seems like some definition works, other doesn't.
Module 1
import Joi from 'joi';
const working1 = Joi.string().alphanum().min(3).max(20).required();
const working2 = Joi.string().required().min(5);
const notWorking1 = Joi.number().default(0).min(0);
export default {
working1,
working2,
notWorking1,
};
Module 2
import m from './module1';
export default {
rule1: {
body: {
field1: r.working1,
field2: r.working2,
},
},
};
Module 3
import m from './module1';
export default {
rule2: {
query: {
field1: r.notWorking1,
},
},
};
Which result you had ?
Some validation schema are working well, while in other case I get a weird error (ex in module3). Something like this:
AssertionError [ERR_ASSERTION]: Invalid schema content: (rule2)
{"generatedMessage":false,"name":"AssertionError [ERR_ASSERTION]","code":"ERR_ASSERTION","actual":false,"expected":true,"operator":"==","path":"rule2"}
If I include the validation schema in the module3 file without importing it from the module1 it work as expected.
The schemas are included inside the ruotes using express-validation module.
import { Router } from 'express';
import validation from 'express-validation';
import v3 from './module3';
import v2 from './module2';
router.get('/x', validation(v2.rule1), (req, res, next) => ... ); // working
router.get('/y', validation(v3.rule2), (req, res, next) => ... ); // not working
What did you expect ?
I expect that it works in any case. Am I missing something?