arb / celebrate

A joi validation middleware for Express.
MIT License
1.33k stars 66 forks source link

Question: should full mode collect multiple errors per segment? #221

Closed angusfretwell closed 3 years ago

angusfretwell commented 3 years ago

My joi schema looks like this:

export const ratePlan = Joi.object().keys({
  propertyId: Joi.string()
    .uuid()
    .required(),
  cancellationPolicyId: Joi.string()
    .uuid()
    .required(),
  // ...
});

When validating with full mode, I'd expect that all errors would be collected, so in my example, if I send the request with an empty object, I would get an error message for both propertyId and cancellationPolicyId. However, only the first error is being collected.

Is this intended behaviour or is there something not right here?

If it is intended, would you be open to adding a new mode that would collect all errors?

arb commented 3 years ago

Try setting abortEarly: false in the joi options. Check out this test for an example.

arb commented 3 years ago

Closing due to inactivity and solution provided.