• Jobs
  • About Us
  • professionals
    • Home
    • Jobs
    • Courses and challenges
  • business
    • Home
    • Post vacancy
    • Our process
    • Pricing
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Salary Calculator

0

181
Views
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

about 3 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Our process Sales
Legal
Terms and conditions Privacy policy
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recommend me some offers
I have an error