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

955
Views
Joi validation - not allowed empty object

Through an HTTP request, I receive from client side the following body:

{
    a: string,
    b: string,
    c: string
}

I want to validate them with joi, so I do:

const MySchema = Joi.Object<MyModel>().keys({
    a: Joi.string().alfanum().min(1).max(150).optional(),
    b: Joi.string().alfanum().min(1).max(150).optional(),
    c: Joi.string().alfanum().min(1).max(150).optional(),
}).required()

This allows empy objects.

How can I say to joi to not allow empty object? I want the body request to have at least one of those keys. For now I haven't found the solution.

I know that I can handle it in the API but I don't want to write useless code.

Thank you!

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

I solved it with

Joi.object<MyModel>.keys({/*My keys*/}).required().min(1)
over 4 years ago · Santiago Trujillo 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!