Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: correctly get schema for each element of a discriminated array #28

Merged
merged 2 commits into from
Mar 8, 2024

Conversation

nathan-knight
Copy link
Contributor

Also do not attempt to get the schema for null/undefined docs

Summary

After updating the package to the latest version (1.1.0) it started failing when an empty array contained discriminated documents. It would get the child schema using the array as the document instead of an element of the array so it would end up with an undefined schema.

With this change it now gets the schema for each document in the array (unless it is null/undefined) and will also not break if a schema has a discriminator mapping key but no discriminators object (which happens when the schema is configured the way it is in the test).

Examples
I have included a new test, should work on schemas with discriminators in arrays, that failed before but passes now.

Copy link
Member

@vkarpov15 vkarpov15 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks 👍

@vkarpov15 vkarpov15 merged commit e86884f into mongoosejs:master Mar 8, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants