schema.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. const _ = require('lodash');
  2. // JSON schema types
  3. const ARRAY = 'array';
  4. const BOOLEAN = 'boolean';
  5. const OBJECT = 'object';
  6. const STRING = 'string';
  7. const BOOLEAN_SCHEMA = {
  8. type: BOOLEAN
  9. };
  10. const STRING_SCHEMA = {
  11. type: STRING
  12. };
  13. const TYPES = require('./types');
  14. const TYPE_NAMES = _.values(TYPES);
  15. module.exports = {
  16. type: OBJECT,
  17. additionalProperties: false,
  18. properties: {
  19. type: {
  20. type: STRING,
  21. enum: TYPE_NAMES
  22. },
  23. // field type
  24. key: { '$ref': '#' },
  25. value: { '$ref': '#' },
  26. // function type
  27. params: {
  28. type: ARRAY,
  29. items: { '$ref': '#' }
  30. },
  31. 'new': { '$ref': '#' },
  32. 'this': { '$ref': '#' },
  33. result: {'$ref': '#' },
  34. // name expression
  35. name: STRING_SCHEMA,
  36. // record type
  37. fields: {
  38. type: ARRAY,
  39. items: { '$ref': '#' }
  40. },
  41. // type application
  42. expression: { '$ref': '#' },
  43. applications: {
  44. type: ARRAY,
  45. minItems: 1,
  46. maxItems: 2,
  47. items: { '$ref': '#' }
  48. },
  49. // type union
  50. elements: {
  51. type: ARRAY,
  52. minItems: 1,
  53. items: { '$ref': '#' }
  54. },
  55. optional: BOOLEAN_SCHEMA,
  56. nullable: BOOLEAN_SCHEMA,
  57. repeatable: BOOLEAN_SCHEMA,
  58. reservedWord: BOOLEAN_SCHEMA
  59. },
  60. required: ['type']
  61. };