Skip to content

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() {

@vkarpov15 vkarpov15 merged commit 6e7f825 into master Jul 22, 2025
105 of 106 checks passed
@hasezoey hasezoey deleted the vkarpov15/maps-required branch July 22, 2025 16:32
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