switch.js 1002 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. 'use strict';
  2. module.exports = function defFunc(ajv) {
  3. if (ajv.RULES.keywords.switch)
  4. return console.warn('Keyword switch is already defined');
  5. var metaSchemaUri = ajv._opts.v5
  6. ? 'https://raw.githubusercontent.com/epoberezkin/ajv/master/lib/refs/json-schema-v5.json#'
  7. : 'http://json-schema.org/draft-04/schema#';
  8. defFunc.definition = {
  9. inline: require('./dotjs/switch'),
  10. statements: true,
  11. errors: 'full',
  12. metaSchema: {
  13. type: 'array',
  14. items: {
  15. required: [ 'then' ],
  16. properties: {
  17. 'if': { $ref: metaSchemaUri },
  18. 'then': {
  19. anyOf: [
  20. { type: 'boolean' },
  21. { $ref: metaSchemaUri }
  22. ]
  23. },
  24. 'continue': { type: 'boolean' }
  25. },
  26. additionalProperties: false,
  27. dependencies: {
  28. 'continue': [ 'if' ]
  29. }
  30. }
  31. }
  32. };
  33. ajv.addKeyword('switch', defFunc.definition);
  34. return ajv;
  35. };