getDiscriminatorByValue.js 621 B

123456789101112131415161718192021222324252627
  1. 'use strict';
  2. const areDiscriminatorValuesEqual = require('./areDiscriminatorValuesEqual');
  3. /*!
  4. * returns discriminator by discriminatorMapping.value
  5. *
  6. * @param {Model} model
  7. * @param {string} value
  8. */
  9. module.exports = function getDiscriminatorByValue(discriminators, value) {
  10. if (discriminators == null) {
  11. return null;
  12. }
  13. for (const name of Object.keys(discriminators)) {
  14. const it = discriminators[name];
  15. if (
  16. it.schema &&
  17. it.schema.discriminatorMapping &&
  18. areDiscriminatorValuesEqual(it.schema.discriminatorMapping.value, value)
  19. ) {
  20. return it;
  21. }
  22. }
  23. return null;
  24. };