Skip to content

Commit

Permalink
Update index.js
Browse files Browse the repository at this point in the history
  • Loading branch information
vkarpov15 authored Mar 8, 2024
1 parent 0017585 commit 7fbffe5
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,14 @@ function getSchemaForDoc(schema, res) {
}

const discriminatorValue = res[schema.discriminatorMapping.key];
const childSchema = Object.entries(schema.discriminators).find(([modelName, childSchema]) => {
// Match against an explicit discriminator value if present
let childSchema = undefined;
for (const name of Object.keys(schema.discriminators)) {
const matchValue = childSchema.discriminatorMapping.value || modelName;
return discriminatorValue === matchValue;
})[1];
if (matchValue === discriminatorValue) {
childSchema = schema.discriminators[name];
break;
}
}
return childSchema;
}

Expand Down

0 comments on commit 7fbffe5

Please sign in to comment.