ajv-errors
ajv-errors copied to clipboard
ErrorMessage with Array of strings
Hey everybody,
I have some issues when i'm trying to put errorMessage with an array, for example, this is my schema :
"pictures": {
"type": "array",
"items": {
"type": "string",
"pattern": "A_SPECIFIC_PATTERN_TO_PUT_HERE"
},
"errorMessage": {
"type": "INVALID_MEDIA_PICTURES_ITEMS",
}
},
When the pattern doesn't match, I don't receive errorMessage keyword, but instead :
error {
keyword: 'pattern',
dataPath: '/media/pictures/0',
schemaPath: 'media-schema.json/properties/pictures/items/pattern',
params: {
pattern: 'A_SPECIFIC_PATTERN_TO_PUT_HERE'
},
message: 'should match pattern A_SPECIFIC_PATTERN_TO_PUT_HERE'
}
I would like to receive my INVALID_MEDIA_PICTURES_ITEMS
. I have the feeling errorMessage only works with type: object
Am I missing something here ?
Does any one have solution?
Bump
I'm having the same issues with getting the 'errorMessage' when it's a pattern in an array...
banks: {
type: "array",
items: {
type: "object",
additionalProperties: false,
properties: {
bsbNumber: {
type: "string",
pattern: "^[0-9]{3}-[0-9]{3}$"
}
},
errorMessage: {
properties: {
bsbNumber: "BSB number must be in the format 000-000."
}
}
}
}
the actual error does not contain the keyword "errorMessage", only the keyword "pattern" as bellow
{
"instancePath": "/banks/0/bsbNumber",
"schemaPath": "#/properties/banks/items/properties/bsbNumber/pattern",
"keyword": "pattern",
"params": {
"pattern": "^[0-9]{3}-[0-9]{3}$"
},
"message": "must match pattern \"^[0-9]{3}-[0-9]{3}$\"",
"schema": "^[0-9]{3}-[0-9]{3}$",
"parentSchema": {
"type": "string",
"pattern": "^[0-9]{3}-[0-9]{3}$"
},
"data": ""
}