6

I am trying to create conditional validation using if / then / else keywords from ajv-keywords, however I am getting the following error in my browser console: “Uncaught Error: Keyword if is already defined”.

What am I doing wrong?

import * as ajvErrors from 'ajv-errors';
import * as ajvKeywords from 'ajv-keywords';

const ajv = new Ajv({ allErrors: true, jsonPointers: true });
ajvErrors(ajv);
ajvKeywords(ajv);

const schema = {
  if: {
    properties: {
      fundraiser: { type: 'string' }
    }
  },
  then: {
    required: ['title'],
  }
}
Patrick Hund
  • 19,163
  • 11
  • 66
  • 95
Ruth
  • 614
  • 2
  • 6
  • 20
  • 1
    If you are using ajv beta it already includes if/then/else, you don’t need ajv-keywords (or you need to use beta as well) – esp Dec 01 '17 at 15:40

0 Answers0