tlivings / enjoi

Converts a JSON schema to a Joi schema.
Apache License 2.0
283 stars 57 forks source link

feature: allow unique keys on array schema #93

Open ederEnriquez opened 4 years ago

ederEnriquez commented 4 years ago

1 Uniques by key

Example: I have an array of objects and need uniques elements by "key1", "key2", "key3"

Schema should have{type:"array", uniques:[ "key1", "key2", "key3"]}

Valid schema

[
{key1: "200-300", key2: "wishlist_1", key3: "bid1.", indicator: true},
{key1: "200-300", key2: "wishlist_2", key3: "bid1.", indicator: false},
{key1: "200-300", key2: "wishlist_3", key3: "bid1.", indicator: true},
]

Invalid schema. Has duplicates values for keys ("key1", "key2", "key3")

[
{key1: "200-300", key2: "wishlist_1", key3: "bid1.", indicator: true},
{key1: "200-300", key2: "wishlist_1", key3: "bid1.", indicator: false},
{key1: "200-300", key2: "wishlist_3", key3: "bid1.", indicator: true},
]

2 Add label by description

3 Add greater and less using Joi reference

tlivings commented 4 years ago

Is this valid JSON schema? Can you point to the spec? I couldn't find it.