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

246
Views
Why does Joi validate an array of objects with "contains a duplicate value"?

My schema is:

const scenerioSchema = Joi.object({
  drawingNode: Joi.object({
    moduleRackOutputs: Joi.array()
      .items(
        Joi.object({
          moduleId: Joi.string().required()
        })
      )
      .unique((a, b) => a.moduleId !== b.moduleId)
  })
})

My data is:

const mockScenario1 = {
  drawingNode: {
    moduleRackOutputs: [
      {
        moduleId: 'module1'
      },
      {
        moduleId: 'module2'
      }
    ]
  }
}

When I validate with:

const validationResponse = scenerioSchema.validate(mockScenario1)

I get:

{
      validationResponse: {
        value: { drawingNode: [Object] },
        error: [Error [ValidationError]: "drawingNode.moduleRackOutputs[1]" contains a duplicate value] {
          _original: [Object],
          details: [Array]
        }
      }
    }

But (a) that's not true - the items are not duplicates and (b) I want an error to occur if the moduleId is different.

What am I doing wrong?

over 4 years ago · Santiago Trujillo
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!