Ohm-Management - Projektarbeit B-ME
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.

applyPlugins.js 1.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. 'use strict';
  2. module.exports = function applyPlugins(schema, plugins, options, cacheKey) {
  3. if (schema[cacheKey]) {
  4. return;
  5. }
  6. schema[cacheKey] = true;
  7. if (!options || !options.skipTopLevel) {
  8. for (let i = 0; i < plugins.length; ++i) {
  9. schema.plugin(plugins[i][0], plugins[i][1]);
  10. }
  11. }
  12. options = Object.assign({}, options);
  13. delete options.skipTopLevel;
  14. if (options.applyPluginsToChildSchemas !== false) {
  15. for (const path of Object.keys(schema.paths)) {
  16. const type = schema.paths[path];
  17. if (type.schema != null) {
  18. applyPlugins(type.schema, plugins, options, cacheKey);
  19. // Recompile schema because plugins may have changed it, see gh-7572
  20. type.caster.prototype.$__setSchema(type.schema);
  21. }
  22. }
  23. }
  24. const discriminators = schema.discriminators;
  25. if (discriminators == null) {
  26. return;
  27. }
  28. const applyPluginsToDiscriminators = options.applyPluginsToDiscriminators;
  29. const keys = Object.keys(discriminators);
  30. for (let i = 0; i < keys.length; ++i) {
  31. const discriminatorKey = keys[i];
  32. const discriminatorSchema = discriminators[discriminatorKey];
  33. applyPlugins(discriminatorSchema, plugins,
  34. { skipTopLevel: !applyPluginsToDiscriminators }, cacheKey);
  35. }
  36. };