Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

619
Vistas
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 Respuestas
Responde la pregunta

0

I solved it with

Joi.object<MyModel>.keys({/*My keys*/}).required().min(1)
over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda