Skip to content

fix(map): avoid throwing required error if saving map of primitives with required: true #15542

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

vkarpov15
Copy link
Collaborator

Summary

If you create a map path using type: { Map, of: String }, you can store null values in that map. However, currently, if you try to set required: true on a map value path you get a validation error on map.$* whenever you try to validate a document.

Examples

@vkarpov15 vkarpov15 added this to the 8.16.5 milestone Jul 17, 2025
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes a bug where maps with required schema values were incorrectly throwing validation errors on the internal $* path representation instead of validating the actual map entries properly.

  • Adds logic to skip validation of $* paths which represent map schemas rather than actual document paths
  • Includes comprehensive test coverage for the required validation behavior in maps
  • Updates existing test to use async/await pattern for consistency

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
lib/document.js Adds check to skip validation of $* paths in _getPathsToValidate function
test/types.map.test.js Adds new test case for required validation in maps and updates existing test to async
Comments suppressed due to low confidence (1)

test/types.map.test.js:108

  • [nitpick] The test name 'handles required in maps' is somewhat vague. Consider a more descriptive name like 'should validate required fields in map values' or 'should enforce required validation on map entries'.
  it('handles required in maps', async function() {

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.

3 participants