index.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. 'use strict';
  2. module.exports = function (ajv, options) {
  3. if (!ajv._opts.allErrors) throw new Error('ajv-errors: Ajv option allErrors must be true');
  4. if (!ajv._opts.jsonPointers) {
  5. console.warn('ajv-errors: Ajv option jsonPointers changed to true');
  6. ajv._opts.jsonPointers = true;
  7. }
  8. ajv.addKeyword('errorMessage', {
  9. inline: require('./lib/dotjs/errorMessage'),
  10. statements: true,
  11. valid: true,
  12. errors: 'full',
  13. config: {
  14. KEYWORD_PROPERTY_PARAMS: {
  15. required: 'missingProperty',
  16. dependencies: 'property'
  17. },
  18. options: options || {}
  19. },
  20. metaSchema: {
  21. 'type': ['string', 'object'],
  22. properties: {
  23. properties: {$ref: '#/definitions/stringMap'},
  24. items: {$ref: '#/definitions/stringList'},
  25. required: {$ref: '#/definitions/stringOrMap'},
  26. dependencies: {$ref: '#/definitions/stringOrMap'}
  27. },
  28. additionalProperties: {'type': 'string'},
  29. definitions: {
  30. stringMap: {
  31. 'type': ['object'],
  32. additionalProperties: {'type': 'string'}
  33. },
  34. stringOrMap: {
  35. 'type': ['string', 'object'],
  36. additionalProperties: {'type': 'string'}
  37. },
  38. stringList: {
  39. 'type': ['array'],
  40. items: {'type': 'string'}
  41. }
  42. }
  43. }
  44. });
  45. return ajv;
  46. };