Joi: Are Joi objects safe to reuse?

Created on 18 Mar 2016  路  1Comment  路  Source: sideway/joi

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!

support

Most helpful comment

Joi objects manipulated in the context of Joi standard operations are immutable so yes.

>All comments

Joi objects manipulated in the context of Joi standard operations are immutable so yes.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

hueniverse picture hueniverse  路  19Comments

Marsup picture Marsup  路  135Comments

ivan-kleshnin picture ivan-kleshnin  路  48Comments

javierbyte picture javierbyte  路  24Comments

rooftopsparrow picture rooftopsparrow  路  21Comments