Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

233
Views
Joi validate 2 schemas conditionally - Invalid schema content

I'm trying to add conidial schema according of the value of the isCat field in the request body, here is what I have so far: ror [ERR_ASSERTION]: Invalid schema content` error.
What am I missing? Thanks.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Try this

Joi.object({
  params: Joi.object({
    id: Joi.number().required().integer().min(1),
  }),
  body: Joi.object({
    code: Joi.string().required(),
  }).when(Joi.ref("$isValid"), {
    is: Joi.equal(true),
    then: Joi.object({
      body: Joi.object({
        ...entity,
      }),
    }),
    otherwise: Joi.object({
      body: Joi.object({
        ...put,
      }),
    }),
  }),
});

Verify the reference given by you is right Joi.ref("$isValid").
If you provide right reference, this schema will work as you expect.

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

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!