Can I define
schema/job.js
import Joi from 'joi';
export default Joi.object().keys(...)
And then on another module
import jobSchema from '../schema/job';
// ...
route1({
validation: jobSchema
});
route2({
validation: jobSchema
});
This way, both handlers will use the same object instance.
Since I wont change the Joi object, is it safe to use the object with Joi.assert(value, schema) on both handlers?
Thanks!
Joi objects manipulated in the context of Joi standard operations are immutable so yes.
Most helpful comment
Joi objects manipulated in the context of Joi standard operations are immutable so yes.