Skip to content

fix(mongodb): let objectid keyword fail validation#3691

Open
puneetdixit200 wants to merge 1 commit into
feathersjs:dovefrom
puneetdixit200:fix/3685-objectid-union-validation
Open

fix(mongodb): let objectid keyword fail validation#3691
puneetdixit200 wants to merge 1 commit into
feathersjs:dovefrom
puneetdixit200:fix/3685-objectid-union-validation

Conversation

@puneetdixit200

Copy link
Copy Markdown

Summary

  • Tell us about the problem your pull request is solving.

keywordObjectId currently throws when a string cannot be converted to a MongoDB ObjectId. That prevents AJV from treating the keyword as a normal branch failure, so anyOf / oneOf schemas cannot continue to another valid branch such as null.

This changes the keyword validator to return false on invalid ObjectId conversion, which lets AJV report a standard validation failure and continue evaluating union branches.

  • Are there any open issues that are related to this?

Closes #3685.

  • Is this PR dependent on PRs in other repos?

No.

Other Information

Added regression coverage for nullable union validation and updated the invalid ObjectId test to assert a normal AJV validation failure instead of an uncaught exception.

Verification:

source ~/.nvm/nvm.sh && nvm use 18.20.8 >/dev/null && npm_config_cache=/tmp/feathers-107-npm-cache npm test --workspace @feathersjs/mongodb -- --grep "objectid keyword"
source ~/.nvm/nvm.sh && nvm use 18.20.8 >/dev/null && npm_config_cache=/tmp/feathers-107-npm-cache npm test --workspace @feathersjs/mongodb -- --grep "ObjectId resolvers|objectid keyword"
source ~/.nvm/nvm.sh && nvm use 18.20.8 >/dev/null && npm_config_cache=/tmp/feathers-107-npm-cache npm run compile --workspace @feathersjs/mongodb
source ~/.nvm/nvm.sh && nvm use 18.20.8 >/dev/null && npm_config_cache=/tmp/feathers-107-npm-cache npx prettier --check packages/mongodb/src/converters.ts packages/mongodb/test/converters.test.ts
source ~/.nvm/nvm.sh && nvm use 18.20.8 >/dev/null && npm_config_cache=/tmp/feathers-107-npm-cache npx eslint packages/mongodb/src/converters.ts packages/mongodb/test/converters.test.ts
git diff --check

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.

keywordObjectId throws instead of returning false, breaking anyOf / union validation

1 participant