schemas.js 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. "use strict";
  2. var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
  3. Object.defineProperty(exports, "__esModule", {
  4. value: true
  5. });
  6. exports.generateObjSchema = exports.enumArraySchema = exports.arraySchema = void 0;
  7. var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
  8. function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
  9. function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2["default"])(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
  10. /**
  11. * JSON schema to accept an array of unique strings
  12. */
  13. var arraySchema = {
  14. type: 'array',
  15. items: {
  16. type: 'string'
  17. },
  18. uniqueItems: true,
  19. additionalItems: false
  20. };
  21. /**
  22. * JSON schema to accept an array of unique strings from an enumerated list.
  23. */
  24. exports.arraySchema = arraySchema;
  25. var enumArraySchema = function enumArraySchema() {
  26. var enumeratedList = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
  27. var minItems = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
  28. return _objectSpread(_objectSpread({}, arraySchema), {}, {
  29. items: {
  30. type: 'string',
  31. "enum": enumeratedList
  32. },
  33. minItems
  34. });
  35. };
  36. /**
  37. * Factory function to generate an object schema
  38. * with specified properties object
  39. */
  40. exports.enumArraySchema = enumArraySchema;
  41. var generateObjSchema = function generateObjSchema() {
  42. var properties = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  43. var required = arguments.length > 1 ? arguments[1] : undefined;
  44. return {
  45. type: 'object',
  46. properties,
  47. required
  48. };
  49. };
  50. exports.generateObjSchema = generateObjSchema;