-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Closed
Labels
featureNew functionality or improvementNew functionality or improvement
Milestone
Description
What are you trying to achieve or the steps to reproduce ?
The .default method already supports providing a function value. I would like to expand the information returned by .describe() when the default is a function instead of a string.
const randomNumber = function () {
return Math.random();
};
randomNumber.description = 'Generate random number';
const schema = Joi.any().default(randomNumber);
schema.validate(); // { error: null, value: 0.8081045034806544 }
schema.validate(); // { error: null, value: 0.42643964379927235 }Which result you had ?
Using the above schema:
schema.describe();
/*
{ type: 'any', flags: { default: 'Generate random number' } }
*/What did you expect ?
I would like to add details so that describe instead returns:
schema.describe();
/*
{ type: 'any', flags: { default: {
description: 'Generate random number',
function: randomNumber
} } }
*/This would allow for this contrived example to work:
schema.describe().flags.default.function(); // 0.6658680107310528(Full disclosure, I would like to allow for dynamic defaults in Felicity, which is built upon .describe())
Any feedback on this would be appreciated, and I'm 100% willing to add this support if approved.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
featureNew functionality or improvementNew functionality or improvement