allRequired.js 474 B

123456789101112131415161718
  1. 'use strict';
  2. module.exports = function defFunc(ajv) {
  3. defFunc.definition = {
  4. type: 'object',
  5. macro: function (schema, parentSchema) {
  6. if (!schema) return true;
  7. var properties = Object.keys(parentSchema.properties);
  8. if (properties.length == 0) return true;
  9. return {required: properties};
  10. },
  11. metaSchema: {type: 'boolean'},
  12. dependencies: ['properties']
  13. };
  14. ajv.addKeyword('allRequired', defFunc.definition);
  15. return ajv;
  16. };