javascript - Joi nested schemas and default values -


i'm trying joi enforce default values on secondary schema referenced another. have 2 schemas so:

const schemaa = joi.object().keys({   title: joi.string().default(''),   time: joi.number().min(1).default(5000) })  const schemab = joi.object().keys({   enabled: joi.bool().default(false),   a: schemaa }) 

what want provide object a not defined , have joi apply default values instead this:

const input = {enabled: true}  const {value} = schemab.validate(input)  //expect value equal this: const expected = {   enabled: true,   a: {     title: '',     time: 5000   } } 

the problem since key optional not enforced. want optional yet filled schemaa defaults if not present. i've been looking through documentation, can't seem find info on though i'm missing obvious. tips?


Comments

Popular posts from this blog

php - Embed BBCode within itself not working -

three.js - how to load gltf in three JS -

sql server - T-SQL: Access DB objects in same schema without qualifying? -