'Firestore Schema Validator - Set default value for the nested optional fields

I am using the firestore schema validator to validate the Input to REST API system. I have a input validation schema defined as below:

const userDataSchema = schema({
   field1 : field("field1").integer().default(1000).optional(),
   field2 : field("field2").integer().default(10).optional(),
});

module.exports = {
   testInput : ({
      userName : field("userName").string().trim(),
      userData : field("userData").objectOf(userDataSchema).optional(),
   })
}

userData is an optional field, and if we do not provide the userData field the default values are not getting assigned to field1 and field2. However if I provide userData without any fields the field1 and field2 are assigned with the default values.

Is there a way I can assign the default values to field1 and field2 if we do not pass userData?

Thank you,
KK

Is there a workaround to



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source