ajv-validator / ajv-validator/ajv-errors

Getting instancePath when using with ajv-keywords and uniqueItemProperties

Đang mở
#145 1 bình luận 0 reaction 0 người được giao Xem trên GitHub
Ngôn ngữ chính
TypeScript
Star
289
Fork
21
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Mô tả

When using alongside `ajv-keywords` and `uniqueItemProperties`, how do I get the `instancePath` of the erroneous record?

My code:

```js
import Ajv from 'ajv';
import addFormats from 'ajv-formats';
import ajvErrors from 'ajv-errors';
import ajvKeywords from 'ajv-keywords';

const ajv = new Ajv({ allErrors: true });
ajvKeywords(ajv, ['uniqueItemProperties']);
addFormats(ajv, { formats: ['date', 'email'], keywords: true });
ajvErrors(ajv);
```
… and my schema:
```js
export const employeeSchema = {
errorMessage: {
uniqueItemProperties: 'What’s going on?',
},
items: {
properties: {
firstName: {
errorMessage: { type: 'required; and must be a string' },
type: 'string',
},
lastName: {
errorMessage: { type: 'required; and must be a string' },
type: 'string',
},
email: {
format: 'email',
type: 'string',
},
},
required: [
'email',
'firstName',
'lastName',
],
type: 'object',
},
type: 'array',
uniqueItemProperties: ['email'],
};
```
And when running against the following data:
```js
[
{
email: 'dhachardy@tamu.edu',
firstName: 2,
lastName: 'Hachard',
},
{
email: 'dhachardy@tamu.edu',
firstName: 'Me',
lastName: 'Hachard',
},
]
```
… I get the following errors reported:
```json
[
{
"instancePath": "",
"schemaPath": "#/errorMessage",
"keyword": "errorMessage",
"params": {
"errors": [
{
"instancePath": "",
"schemaPath": "#/uniqueItemProperties",
"keyword": "uniqueItemProperties",
"params": {},
"message": "must pass \"uniqueItemProperties\" keyword validation",
"emUsed": true
}
]
},
"message": "What’s going on?"
}
]
```

Hướng dẫn đóng góp

Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.