ajv.js 980 B

12345678910111213141516171819202122232425262728293031323334
  1. /**
  2. * @fileoverview The instance of Ajv validator.
  3. * @author Evgeny Poberezkin
  4. */
  5. "use strict";
  6. //------------------------------------------------------------------------------
  7. // Requirements
  8. //------------------------------------------------------------------------------
  9. const Ajv = require("ajv"),
  10. metaSchema = require("ajv/lib/refs/json-schema-draft-04.json");
  11. //------------------------------------------------------------------------------
  12. // Public Interface
  13. //------------------------------------------------------------------------------
  14. module.exports = (additionalOptions = {}) => {
  15. const ajv = new Ajv({
  16. meta: false,
  17. useDefaults: true,
  18. validateSchema: false,
  19. missingRefs: "ignore",
  20. verbose: true,
  21. schemaId: "auto",
  22. ...additionalOptions
  23. });
  24. ajv.addMetaSchema(metaSchema);
  25. // eslint-disable-next-line no-underscore-dangle
  26. ajv._opts.defaultMeta = metaSchema.id;
  27. return ajv;
  28. };