-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Closed
Labels
featureNew functionality or improvementNew functionality or improvement
Milestone
Description
I have an array that contains objects and I need to ensure a specific property is unique in each. It currently compares the entire object and passes validation even though the value of the key is duplicated.
I would like this data to fail validation because the key for both objects is the same.
[{key:'samekey',prop:'prop1'}, {key:'samekey',prop:'prop2'}]
var Joi = require('joi');
var result = Joi.validate(
[{key:'samekey',prop:'prop1'}, {key:'samekey',prop:'prop2'}],
Joi.array().unique()
);
console.log(result);
outputs
{ error: null, value: [ { key: 'samekey', prop: 'prop1' }, { key: 'samekey', prop: 'prop2' } ] }
Currently I am forced to manually map the keys into an array and run a separate validation with this schema - Joi.array().unique()
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
featureNew functionality or improvementNew functionality or improvement