Skip to content

Commit 29aa4fc

Browse files
authored
Update cast.js
1 parent ffef7c9 commit 29aa4fc

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

lib/cast.js

+7-3
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,13 @@ module.exports = function cast(schema, obj, options, context) {
6868
if (val[k] == null || typeof val[k] !== 'object') {
6969
throw new CastError('Object', val[k], path + '.' + k);
7070
}
71-
const discrim = getSchemaDiscriminatorByValue(context.schema, val[k][schema.options.discriminatorKey]);
72-
val[k] = cast(discrim ? discrim : schema, val[k], options, context);
73-
71+
const discriminatorValue = val[k][schema.options.discriminatorKey];
72+
if (discriminatorValue == null) {
73+
val[k] = cast(schema, val[k], options, context);
74+
} else {
75+
const discriminatorSchema = getSchemaDiscriminatorByValue(context.schema, discriminatorValue);
76+
val[k] = cast(discriminatorSchema ? discriminatorSchema : schema, val[k], options, context);
77+
}
7478
}
7579
} else if (path === '$where') {
7680
type = typeof val;

0 commit comments

Comments
 (0)