prohibited.js 553 B

12345678910111213141516171819202122232425
  1. 'use strict';
  2. module.exports = function defFunc(ajv) {
  3. defFunc.definition = {
  4. type: 'object',
  5. macro: function (schema) {
  6. if (schema.length == 0) return {};
  7. if (schema.length == 1) return { not: { required: schema } };
  8. var schemas = schema.map(function (prop) {
  9. return { required: [prop] };
  10. });
  11. return { not: { anyOf: schemas } };
  12. },
  13. metaSchema: {
  14. type: 'array',
  15. items: {
  16. type: 'string'
  17. }
  18. }
  19. };
  20. ajv.addKeyword('prohibited', defFunc.definition);
  21. return ajv;
  22. };