Click here to Skip to main content
15,886,724 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
How to validate the dynamic keys in JOI. I am trying to make keys for breakfast, lunch and dinner . These keys contains object inside them with similar properties.

What I have tried:

I have tried fewer codes but these are not running for the keys containing objects inside because I have to verify them if these exists.

 <pre lang="Javascript">
 let schema = Joi.object().keys({
    date: Joi.string().required(),
    id: {
      name: Joi.string().required(),
      image: Joi.string().required(),
      price: {
        lite: Joi.string().required(),
        full: Joi.string().required()
      },
      description: {
        lite: Joi.string().required(),
        full: Joi.string().required()
      }
    }
  })

I want to make id key to be dynamic . It has to be breakfast , lunch or dinner for various inputs.
Posted
Updated 28-Jul-19 23:18pm
v2

1 solution

My point of view to have to declare like this :

const schema = {
   
   params: {
           date: Joi.string().required(),
    id: {
      name: Joi.string().required(),
      image: Joi.string().required(),
      price: {
        lite: Joi.string().required(),
        full: Joi.string().required()
      },
      description: {
        lite: Joi.string().required(),
        full: Joi.string().required()
      }
    }
  }
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900