data.js 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. 'use strict';
  2. var KEYWORDS = [
  3. 'multipleOf',
  4. 'maximum',
  5. 'exclusiveMaximum',
  6. 'minimum',
  7. 'exclusiveMinimum',
  8. 'maxLength',
  9. 'minLength',
  10. 'pattern',
  11. 'additionalItems',
  12. 'maxItems',
  13. 'minItems',
  14. 'uniqueItems',
  15. 'maxProperties',
  16. 'minProperties',
  17. 'required',
  18. 'additionalProperties',
  19. 'enum',
  20. 'format',
  21. 'const'
  22. ];
  23. module.exports = function (metaSchema, keywordsJsonPointers) {
  24. for (var i=0; i<keywordsJsonPointers.length; i++) {
  25. metaSchema = JSON.parse(JSON.stringify(metaSchema));
  26. var segments = keywordsJsonPointers[i].split('/');
  27. var keywords = metaSchema;
  28. var j;
  29. for (j=1; j<segments.length; j++)
  30. keywords = keywords[segments[j]];
  31. for (j=0; j<KEYWORDS.length; j++) {
  32. var key = KEYWORDS[j];
  33. var schema = keywords[key];
  34. if (schema) {
  35. keywords[key] = {
  36. anyOf: [
  37. schema,
  38. { $ref: 'https://raw.githubusercontent.com/epoberezkin/ajv/master/lib/refs/data.json#' }
  39. ]
  40. };
  41. }
  42. }
  43. }
  44. return metaSchema;
  45. };