xogroup / felicity

Javascript object constructors and sample data based on Joi schema.
Other
110 stars 9 forks source link

Support Joi extensions #80

Open WesTyler opened 7 years ago

WesTyler commented 7 years ago

This is a forum to discuss support and implementation of Joi extensions.

In order to maintain a 1:1 api parity with Joi, we will eventually need some level of support for Joi extensions.

It's important to note in thinking about implementation that extensions do not modify the Joi module itself, but provide a new Joi instance to the consumer. Felicity will not be able to pick up extensions automagically through Joi because of this fact. So we will need some sort of dynamic behavior for example and entityFor around customized schema types/extensions.

lamchakchan commented 7 years ago

Maybe we can support Joi extensions like Joi does and make Felicity extensible. Author of a Joi extension can also author a Felicity extension. We can create a new repo for felicity/contrib where all of that work does into. What I'm not sure is if extensions modifies or overrides any.describe.

WesTyler commented 7 years ago

Yeah I'm not sure about that either. I'll do some digging.

WesTyler commented 7 years ago

Specifically take a look at supporting https://github.com/hapijs/joi-date-extensions first, since it is a Joi syntax that was deprecated in upgrading from Joi v9->v10.

WesTyler commented 7 years ago

Once the extension API/convention is figured out, I'd like to remove joi-date-extensions from the dependencies and go back to using "vanilla" Joi.

WesTyler commented 7 years ago

Per discussions with @danielo515 on #116, this could potentially be support through the use of a generate function provided by the extension via describe functionality. Perhaps something like

if (typeof Hoek.reach(schemaDescription, 'generate') === 'function') {
    return schemaDescription.generate();
}

return this._generate(rules);