ajv-validator / ajv-validator/ajv-errors

Value and field name

Đang mở
#15 3 bình luận 0 reaction 0 người được giao Xem trên GitHub
question
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ả

Hello.

How can i get value and field which cause validation error in errors object?

Here's mine scheme
```JSON
{
"type": "object",
"properties": {
"first_name": {
"type": "string"
},
"last_name": {
"type": "string"
},
"email": {
"type": "string",
"format": "email"
},
"position": {
"type": "number"
},
"shifts": {
"type": "object",
"required": ["0", "1", "2", "3"],
"properties": {
"0": { "type": "boolean" },
"1": { "type": "boolean" },
"2": { "type": "boolean" },
"3": { "type": "boolean" }
},
"errorMessage": {
"required": {
"0": "Parameter \"morning_shift\" is not provided!",
"1": "Parameter \"noon_shift\" is not provided!",
"2": "Parameter \"evening_shift\" is not provided!",
"3": "Parameter \"night_shift\" is not provided!"
},
"additionalProperties": "Shifts should not contains additional properties!"
},
"additionalProperties": false
},
"jumper": {
"type": "number"
},
"manager": {
"type": "number"
}
},
"required": [
"first_name",
"last_name",
"email",
"position",
"shifts",
"jumper",
"manager"
],
"errorMessage": {
"required": {
"first_name": "Parameter \"first_name\" is not provided!",
"last_name": "Parameter \"first_name\" is not provided!",
"email": "Parameter \"first_name\" is not provided!",
"position": "Parameter \"first_name\" is not provided!",
"shifts": "Parameter \"shifts\" is not provided!",
"jumper": "Parameter \"jumper_unit\" is not provided!",
"manager": "Parameter \"manager_unit\" is not provided!"
},
"properties": {
"first_name": "First name is invalid, given \"${/first_name}!\"",
"last_name": "Last name is invalid, given \"${/last_name}!\"",
"email": "Email name is invalid, given \"${/email}!\"",
"position": "Position is invalid, given \"${/position}!\"",
"shifts": "Shifts is invalid, given \"${/shifts}!\"",
"jumper": "Jumper is invalid, given \"${/jumper}!\"",
"manager": "Manager is invalid, given \"${/manager}!\""
},
"additionalProperties": "File should not contains additional properties!"
},
"additionalProperties": false
}
```

Depend on response, error contains `dataPath`, `message` and in **verbose** mode `data` fields.
What i need is the real **field name** which cause error, and real **value** which this field has.

I it's **not provided** then i need only field name.

Is there any way to get it, or to put it in errors?

Here's my kinda fake data for showing errors:
```JSON
[
{
"first_name": "Hello 1",
"last_name": "World 1",
"position": 111,
"jumper": "131",
"shifts": {
"0": true,
"1": true,
"2": false
}
},
{
"first_name": "Hello 2",
"last_name": "World 2",
"position": 131090,
"jumper": "131103",
"shifts": {
"0": true,
"1": true,
"2": true
}
}
]
```

Thank you.

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.