diff --git a/src/services/joi_validation_error_converter.js b/src/services/joi_validation_error_converter.js index 8825df4..0f5c445 100644 --- a/src/services/joi_validation_error_converter.js +++ b/src/services/joi_validation_error_converter.js @@ -1,9 +1,7 @@ const ValidationError = require('../errors/validation') module.exports = (error, pathPrefix = null) => { - const detail = error.details.reduce((mostSpecific, detail) => - mostSpecific.path.length >= detail.path.length ? mostSpecific : detail - ) + const detail = error.details[0] let path = detail.path.reduce( (accumulator, value, index) => diff --git a/test/src/services/joi_validation_error_converter.js b/test/src/services/joi_validation_error_converter.js index 07a8761..42d3533 100644 --- a/test/src/services/joi_validation_error_converter.js +++ b/test/src/services/joi_validation_error_converter.js @@ -23,21 +23,6 @@ test('uses optional path prefix as path if no path exists', () => { ) }) -test('uses the most specific error detail (by path length)', () => { - const { error } = Joi.alternatives() - .try( - Joi.string(), - Joi.object().keys({ - invalid: Joi.number(), - }) - ) - .validate({ invalid: 'invalid' }) - - expect(joiValidationErrorConverter(error)).toEqual( - new ValidationError('invalid must be a number') - ) -}) - test('delineates path segments with []', () => { const { error } = Joi.object() .keys({