switch.js 817 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. 'use strict';
  2. var util = require('./_util');
  3. module.exports = function defFunc(ajv) {
  4. if (ajv.RULES.keywords.switch && ajv.RULES.keywords.if) return;
  5. var metaSchemaRef = util.metaSchemaRef(ajv);
  6. defFunc.definition = {
  7. inline: require('./dotjs/switch'),
  8. statements: true,
  9. errors: 'full',
  10. metaSchema: {
  11. type: 'array',
  12. items: {
  13. required: [ 'then' ],
  14. properties: {
  15. 'if': metaSchemaRef,
  16. 'then': {
  17. anyOf: [
  18. { type: 'boolean' },
  19. metaSchemaRef
  20. ]
  21. },
  22. 'continue': { type: 'boolean' }
  23. },
  24. additionalProperties: false,
  25. dependencies: {
  26. 'continue': [ 'if' ]
  27. }
  28. }
  29. }
  30. };
  31. ajv.addKeyword('switch', defFunc.definition);
  32. return ajv;
  33. };