Skip to content

Commit

Permalink
update documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
atng committed Apr 17, 2023
1 parent 6adf546 commit 445a63d
Showing 1 changed file with 40 additions and 1 deletion.
41 changes: 40 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,11 @@ The keyword allows to check that some properties in array items are unique.

This keyword applies only to arrays. If the data is not an array, the validation succeeds.

The value of this keyword must be an array of strings - property names that should have unique values across all items.
The value of this keyword must be either be an array of strings, an array or array of strings, or a combination of the two.

##### Where Values are Array of Strings

Where the values are an array of strings the strings should be property names that should have unique values across all items.

```javascript
const schema = {
Expand All @@ -293,6 +297,41 @@ const invalidData2 = [
]
```

##### Where Values are Arrays of Array of Strings

Where the values are arrays of array of strings the strings, property names that are used the the nested array should be unique together across all items.

```javascript
const schema = {
type: "array",
uniqueItemProperties: [["id", "name"]],
}

const validData1 = [
{id: 1, name: "taco"},
{id: 2, name: "burrito"},
{id: 3, name: "salsa"},
]

const validData2 = [
{id: 1, name: "taco"},
{id: 1, name: "burrito"}, // duplicate "id"
{id: 3, name: "salsa"},
]

const validData3 = [
{id: 1, name: "taco"},
{id: 2, name: "taco"}, // duplicate "name"
{id: 3, name: "salsa"},
]

const invalidData = [
{id: 1, name: "taco"},
{id: 1, name: "taco"}, // duplicate "name" and 'id
{id: 3, name: "salsa"},
]
```

This keyword is contributed by [@blainesch](https://github.com/blainesch).

**Please note**: currently `uniqueItemProperties` is not supported in [standalone validation code](https://github.com/ajv-validator/ajv/blob/master/docs/standalone.md) - it has to be implemented as [`code` keyword](https://github.com/ajv-validator/ajv/blob/master/docs/keywords.md#define-keyword-with-code-generation-function) to support it (PR is welcome).
Expand Down

0 comments on commit 445a63d

Please sign in to comment.