xogroup / felicity

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

Generate options are not getting passed down in recursive cases #135

Closed samueljoli closed 6 years ago

samueljoli commented 6 years ago

Context

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

'use strict';

const Felicity = require('felicity');
const xoDataHub = new(require('.'))();
const Joi = require('joi');

const schema = Joi.object().keys({
    name: Joi.string(),
    age: Joi.number().optional(),
    list: Joi.array().items(Joi.object().keys({
        prop1: Joi.string(),
        prop2: Joi.string().optional()
    }))
});

class Thing extends Felicity.entityFor(schema){};

const instance = new Thing();
const options = {
    config: {
        includeOptional: true,
        ignoreValids: true,
    }
}

console.log(instance.example(options));

/* 
{ 
  name: 'carf2l7rnw',
  age: 1.406448789972858,
  list: [ 
    { prop1: 'er1djjw67n4' } 
  ]
} 
prop2 with optional() set does not get generated
*/

What result did you expect ?

A full example to be generated

WesTyler commented 6 years ago

Patch on master (v3), backport to v2 branch

samueljoli commented 6 years ago

@WesTyler Hey found some time to take a look at this.

Findings:

Seems like options weren't being passed in here, and here

So when we got here includeOptional was undefined

It's late, couldn't muster up enuff juice to write some tests 😴. Can't say when I'll have the time to write them, but if you hadn't taken a look at it yet..here's a jumpstart!

WesTyler commented 6 years ago

Awesome, thanks! I'm trying to wrap up our hapi 17 stuff, but I'll post here when I get started on this. Feel free to make a PR if you beat me to it! Thanks for digging in :D

WesTyler commented 6 years ago

Backported to the v2 branch and released in Felicity@2.4.4

Thanks again @Samueljoli