the regexp keyword cashes pattern without taking flags into account

this is specifically caused by the presence of the first schema, the regexp keyword looks up patterns in the same dictionary, by pattern, without taking flags into account… So this would do the same:

const Ajv = require('ajv').default
const ajv = new Ajv()
const ajvKeywords = require('ajv-keywords')
ajvKeywords(ajv)
const stringSchema1 = {
  type: 'string',
  regexp: {
    pattern: 'a'
  }
}
const stringSchema2 = {
  $id: 'regexp',
  type: 'string',
  regexp: {
    pattern: 'a',
    flags: 'i'
  }
}
console.log(ajv.validate(stringSchema1, "a")) // true
console.log(ajv.validate(stringSchema1, "A")) // false
console.log(ajv.validate(stringSchema2, "A")) // false, even though it should be true (and it is true in case there is no first schema)

Read more here: Source link