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

unique() does not allow nested duplication check of array of objects #208

Open
ujwal-setlur opened this issue May 11, 2021 · 4 comments
Open

Comments

@ujwal-setlur
Copy link
Contributor

I have the same problem as in https://stackoverflow.com/questions/53243306/validating-unique-key-pairs-in-a-nested-object-with-joi-and-nodejs

I essentially have an array of objects, and I want to validate that a certain key/value pair is not duplicated amongst the array elements of objects.

This can be solved in joi with providing a comparator to the unique() function.

However, in joiful, I cannot pass a comparator to unique().

Is there a different way to do this?

@ujwal-setlur
Copy link
Contributor Author

Will try with custom()

@laurence-myers
Copy link
Member

Looks like joiful is accidentally missing this functionality. Should be an easy fix.

https://github.com/joiful-ts/joiful/blob/master/src/decorators/array.ts#L109

Change unique to accept the same args: either a comparator function; or a string and an optional "options" object. @types/joi can help us work out what the arg types should be. Then update the interface ArraySchemaModifiers, and add tests.

@ujwal-setlur
Copy link
Contributor Author

Any update?

@laurence-myers
Copy link
Member

No update from me, sorry. I'd welcome a Pull Request. 😁

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

No branches or pull requests

2 participants