ajv-validator / ajv-validator/ajv-errors

Value and field name

Aperta
#15 3 commenti 0 reazioni 0 assegnatari Vedi su GitHub
question
Lingua principale
TypeScript
Stelle
289
Fork
21
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

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.

Guida per i contributori

Nessuna guida per i contributori indicizzata per questo repository

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.