Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validate middleware didn't throw all error messages #124

Closed
bwyx opened this issue Jun 8, 2021 · 3 comments
Closed

Validate middleware didn't throw all error messages #124

bwyx opened this issue Jun 8, 2021 · 3 comments

Comments

@bwyx
Copy link
Contributor

bwyx commented Jun 8, 2021

hi @hagopj13, first of all, thank you for this boilerplate, it's very useful for my learning path.

I think I found an unintended contradictive statement

Joi compiled schema without abortEarly option set to false at validate.js#L11 :

const { value, error } = Joi.compile(validSchema)
    .prefs({ errors: { label: 'key' } })
    .validate(object);

therefore Joi will not return all errors it finds, only the first one.

but, on next line #14, errorMessage assigned from merged error.details which is always only one:

const errorMessage = error.details.map((details) => details.message).join(', ');

is it supposed to be?

I'll gladly make a PR about this.
thank you. 😄

@bwyx bwyx changed the title Validate middleware didn't throw all error Validate middleware didn't throw all error message Jun 8, 2021
@bwyx bwyx changed the title Validate middleware didn't throw all error message Validate middleware didn't throw all error messages Jun 8, 2021
@vishnubhadoriya
Copy link

by default abortEarly is true so its stops validation on first value
in order to validate all you need to enable or set abortEarly : false

const { value, error } = Joi.compile(validSchema) .prefs({ errors: { label: 'key' } }) .validate(object, { abortEarly: false, });

@hagopj13
Copy link
Owner

hagopj13 commented Jul 4, 2021

@bwyx thanks for the tip!

@bwyx
Copy link
Contributor Author

bwyx commented Jul 15, 2021

@vishnubhadoriya that's my point

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants