xogroup / felicity

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

felicity.example() throws an error for Joi.object().default(<OBJECT>) #137

Closed gxapplications closed 6 years ago

gxapplications commented 6 years ago

Context

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

When trying to generate an example with this, it's ok:

const schema = Joi.object().keys({
  a: Joi.object().default('hello string')
})
Felicity.example(schema)

-> OK

But when default() contains an object, it fails:

const schema = Joi.object().keys({
  a: Joi.object().default({ b: 'hello in an object' })
})
Felicity.example(schema)

-> KO (stack trace below)

What result did you expect ?

An example object with a clone of the object given in the default() function arg.

What result did you observe ?

TypeError: schemaDescription.flags.default.function is not a function
      at Object.getDefault (node_modules/felicity/lib/helpers.js:8:56)
      at ObjectExample._getDefaults (node_modules/felicity/lib/valueGenerator.js:87:24)
      at ObjectExample.generate (node_modules/felicity/lib/valueGenerator.js:55:25)
      at Object.keys.forEach (node_modules/felicity/lib/valueGenerator.js:653:48)
      at Array.forEach (native)
      at ObjectExample._generate (node_modules/felicity/lib/valueGenerator.js:628:53)
      at ObjectExample.generate (node_modules/felicity/lib/valueGenerator.js:63:21)
      at valueGenerator (node_modules/felicity/lib/valueGenerator.js:837:20)
      at Object.exampleGenerator [as example] (node_modules/felicity/lib/exampleGenerator.js:9:27)
WesTyler commented 6 years ago

Yep, sure enough! Thanks for the bug report. I'll see about getting it patched ASAP.

WesTyler commented 6 years ago

Published in v2.4.5 . Thanks again for checking out Felicity and for the report! I appreciate it! :D

gxapplications commented 6 years ago

Hey great, it works :) Thank you for Felicity and your reactivity, I will digg a lot more in it because I will have a lot more complicated cases that will come soon... :)