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

REBELinBLUE picture REBELinBLUE  路  3Comments

JbIPS picture JbIPS  路  4Comments

mohamadresaaa picture mohamadresaaa  路  3Comments

sergibondarenko picture sergibondarenko  路  3Comments

neroaugustus1 picture neroaugustus1  路  4Comments