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

Feature request: Assign default value to optional fields ✅ #173

Open
Bullrich opened this issue Jul 21, 2023 · 0 comments
Open

Feature request: Assign default value to optional fields ✅ #173

Bullrich opened this issue Jul 21, 2023 · 0 comments
Labels
enhancement New feature or request

Comments

@Bullrich
Copy link

Bullrich commented Jul 21, 2023

Hi! I have a feature request:

It would be great if we could assign default values to optional fields.

For example:
$.optionalField("superhero", $.str, "superman"),

And if the field "superhero" is empty, it will assign the value "superman".

If no default value is assigned, it will instead be null/undefined.

Use case

This is quite useful for some optional fields.

In our case we have a number value that, if it is not filled, it is 1 by default.

Using JOI we would use: Joi.number().empty(1) and we could forget to validate it.

@Bullrich Bullrich added the enhancement New feature or request label Jul 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant