xogroup / felicity

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

Problem with Joi.alternatives().try() #108

Closed WesTyler closed 7 years ago

WesTyler commented 7 years ago

Context

What are you trying to achieve or the steps to reproduce ?

const schema = Joi.object({
    alternative: Joi.alternatives().try(Joi.number().integer().min(1), Joi.string().guid().lowercase()).required()
});
const Document = Felicity.entityFor(schema);
const doc = new Document();
/* Error: Cannot read property 'type' of undefined 
      at childrenKeys.forEach (/[redacted]/felicity/lib/joiGenerator.js:72:33)
      at Array.forEach (native)
      at schemaMapper (/[redacted]/felicity/lib/joiGenerator.js:52:26)
      at Constructor.generate (/[redacted]/felicity/lib/joiGenerator.js:93:5)
      at new Constructor /[redacted]/felicity/lib/index.js:88:22)
*/

What result did you expect ?

The document should be instantiated with the alternative key set to null.

What result did you observe ?

Error: Cannot read property 'type' of undefined