Skip to content

Commit

Permalink
fix(discriminator): avoid removing nested path if both base and discr…
Browse files Browse the repository at this point in the history
…iminator schema have the same nested path

Fix #9362
  • Loading branch information
vkarpov15 committed Aug 31, 2020
1 parent 7aad624 commit 5cd10cf
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/helpers/model/discriminator.js
@@ -1,5 +1,6 @@
'use strict';

const Mixed = require('../../schema/mixed');
const defineKey = require('../document/compile').defineKey;
const get = require('../get');
const utils = require('../../utils');
Expand Down Expand Up @@ -89,11 +90,12 @@ module.exports = function discriminator(model, name, schema, tiedValue, applyPlu
if (path.indexOf('.') === -1) {
continue;
}
const sp = path.split('.');
const sp = path.split('.').slice(0, -1);
let cur = '';
for (const piece of sp) {
cur += (cur.length ? '.' : '') + piece;
if (schema.paths[cur] || schema.singleNestedPaths[cur]) {
if (schema.paths[cur] instanceof Mixed ||
schema.singleNestedPaths[cur] instanceof Mixed) {
conflictingPaths.push(path);
}
}
Expand Down

0 comments on commit 5cd10cf

Please sign in to comment.