subshape icon indicating copy to clipboard operation
subshape copied to clipboard

Feature request: Assign default value to optional fields ✅

Open Bullrich opened this issue 1 year ago • 0 comments

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 avatar Jul 21 '23 12:07 Bullrich