ajv-errors icon indicating copy to clipboard operation
ajv-errors copied to clipboard

ErrorMessage with Array of strings

Open jlgouwyapizr opened this issue 4 years ago • 4 comments

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 ?

jlgouwyapizr avatar Oct 13 '20 09:10 jlgouwyapizr

Does any one have solution?

dontbesatisfied avatar Feb 28 '22 08:02 dontbesatisfied

Bump

AldrinSalazar avatar Jun 02 '23 15:06 AldrinSalazar

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": ""
}

outbackStack avatar Jun 09 '23 00:06 outbackStack