0

Can I check for previously generated validation errors, while validating the custom keyword?

This is the best I could come up with so far:

ajv.addKeyword('fromInput',{
  modifying:true,
  compile: function (schema, parentSchema, it){
    return function () {
      // console.log(it)
      return true;
    }
  },
  errors: true
});

Please note that I used the option to define "compile:" fn only because this option allows the "it" context, so from there I can access "it" or "it.self".

To be clear, and also to confirm that I interpreting this feature correctly (?), I placed the custom keyword as very last in the schema, so I assume that at validation time all previous keywords will be validated and errors generated.

So during validation of this custom keyword, I need to access those validation errors and make some decisions based on that.

However, I don't know where to go from here (see above code), because in the debugger I don't see any errors.

it.self does have an "errors" property, but it's =null.

Grant Miller
  • 27,532
  • 16
  • 147
  • 165
Nenad
  • 1
  • 1

1 Answers1

0

According to the author of ajv, "Only inline keywords have access to validation errors at the moment."

Here's a link to the comment and another link mentioning the same thing.

Inline keywords also have access to 'it' which is the "Schema Compilation Context"

Dean Stamler
  • 382
  • 4
  • 13