Skip to content
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

Custom dynamicDefaults functions don't work with default parameters and no args given in schema #139

Open
ottomata opened this issue Oct 29, 2020 · 0 comments

Comments

@ottomata
Copy link

The examples of how to add a custom uuid function dynamicDefaults wrap uuid.v4(). However, I'd expect to be able to use either just uuid (which calls uuid.v4) or uuid.v4 itself, without a function uuidv4() wrapper.

It seems that the code in dynamicDefaults uses `func.length figure out if the value of the custom dynamicDefault should be called with arguments.

funcs[key] = func.length ? func(d.args) : func;

(I didn't know this, but In javascript, Function.length is the number of arguments.)

> uuid = require('uuid');
{ [Function: v4] v1: [Function: v1], v4: [Circular] }
> uuid.length
3

I guess func.length is being used to figure out if arguments should be passed to the func as defined in the schema via {func: "uuid", args }, but perhaps a better way would be to just check if args is defined?

It'd be nice if I didn't have to make a wrapper for functions that have default parameters.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant