-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Request] Add detail to .describe for function defaults #1121
Comments
If the above implementation is not acceptable, but the general goal of the request (having access to the default function in the One thing I hadn't decided on is this behavior for const makeAString = function() { return 'made a string'; };
makeAString.decription = 'Makes strings';
const stringDefault = Joi.any().default('just a string');
const funcDefault = Joi.any().default(makeAString);
funcDefault.describe();
/*
{ type: 'any', flags: { default: {
description: 'Makes strings',
function: makeAString
} } }
*/
stringDefault.describe();
/*
{ type: 'any', flags: { default: {
description: 'just a string'
} } }
--OR--
{ type: 'any', flags: { default: 'just a string' } }
*/ |
If this entails a simple change @ Line 645 in 37b8dc6
I don't see why not |
That's exactly where I was looking :) else if (typeof this._flags[flag] === 'function') {
description.flags[flag] = {
description: this._flags[flag].description,
function : this._flags[flag]
}
} [Redacted due to developer cough me cough error] Going to be pushing up a PR for this sometime this afternoon. |
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.Which result you had ?
Using the above
schema
:What did you expect ?
I would like to add details so that
describe
instead returns:This would allow for this contrived example to work:
(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.
The text was updated successfully, but these errors were encountered: