You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

38 lines
817 B

4 years ago
  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. };