You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
29 lines
653 B
JavaScript
29 lines
653 B
JavaScript
11 months ago
|
'use strict';
|
||
|
|
||
|
const areDiscriminatorValuesEqual = require('./areDiscriminatorValuesEqual');
|
||
|
|
||
|
/**
|
||
|
* returns discriminator by discriminatorMapping.value
|
||
|
*
|
||
|
* @param {Object} discriminators
|
||
|
* @param {string} value
|
||
|
* @api private
|
||
|
*/
|
||
|
|
||
|
module.exports = function getDiscriminatorByValue(discriminators, value) {
|
||
|
if (discriminators == null) {
|
||
|
return null;
|
||
|
}
|
||
|
for (const name of Object.keys(discriminators)) {
|
||
|
const it = discriminators[name];
|
||
|
if (
|
||
|
it.schema &&
|
||
|
it.schema.discriminatorMapping &&
|
||
|
areDiscriminatorValuesEqual(it.schema.discriminatorMapping.value, value)
|
||
|
) {
|
||
|
return it;
|
||
|
}
|
||
|
}
|
||
|
return null;
|
||
|
};
|