Skip to content

Commit

Permalink
Update cast.js
Browse files Browse the repository at this point in the history
  • Loading branch information
vkarpov15 authored Oct 5, 2023
1 parent ffef7c9 commit 29aa4fc
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions lib/cast.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,13 @@ module.exports = function cast(schema, obj, options, context) {
if (val[k] == null || typeof val[k] !== 'object') {
throw new CastError('Object', val[k], path + '.' + k);
}
const discrim = getSchemaDiscriminatorByValue(context.schema, val[k][schema.options.discriminatorKey]);
val[k] = cast(discrim ? discrim : schema, val[k], options, context);

const discriminatorValue = val[k][schema.options.discriminatorKey];
if (discriminatorValue == null) {
val[k] = cast(schema, val[k], options, context);
} else {
const discriminatorSchema = getSchemaDiscriminatorByValue(context.schema, discriminatorValue);
val[k] = cast(discriminatorSchema ? discriminatorSchema : schema, val[k], options, context);
}
}
} else if (path === '$where') {
type = typeof val;
Expand Down

0 comments on commit 29aa4fc

Please sign in to comment.