subshape
subshape copied to clipboard
Feature request: Assign default value to optional fields ✅
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.