ajv-validator/ajv-errors

Custom error messages for patternProperties

leoamp opened this issue · 1 comments

Is there any way where one can add custom error message for pathPattern attributes? Example:

Json schema:

"patternProperties": {
    "^[a-zA-Z0-9]*$":{
        "properties": {
              "model":{"type":"string"},
              "made":{"type":"string"},
              "year":{"type":"string"}
         }
    }
  },
  "additionalProperties":false
 }

Json:

{
  "efgh56789": {
    "model": "civic"
    "made": "toyota"
    "year": "2014"
  }
}

Here, how to add custom error message (ex: Can contain only alphanumeric characters) for the attribute 'efgh56789' in above schema?
Note: The schema can be a nested schema where few of them are 'patternProperties' & few of them are regular ones.

I have asked the same question in SoF:
Ref: link

patternProperties will catch all the properties that matches that pattern and anything else is considered additionalProperties so in my case I changed the error message of the additionalProperties and set its value to false to match my requirements