Skip to content

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

Open

Description

@ujwal-setlur

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?

Activity

  1. ujwal-setlur commented on May 11, 2021

    @ujwal-setlur
    ContributorAuthor

    Will try with custom()

  2. laurence-myers commented on May 17, 2021

    @laurence-myers
    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.

  3. ujwal-setlur commented on Feb 22, 2023

    @ujwal-setlur
    ContributorAuthor

    Any update?

  4. laurence-myers commented on Feb 22, 2023

    @laurence-myers
    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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions