Skip to content

Conversation

@jackjin1997
Copy link

Fixes #6411.

Currently, validateParam in lib/validation.js uses if (ret && ret.value) to decide whether to update the request parameter with the validator's output. If the validator returns a falsy value (e.g. 0, "", false), the update is skipped. This affects custom validators or cases where the value is coerced to a falsy value.

This PR:

  1. Changes the check to if (ret && ret.value !== undefined) to allow falsy values.
  2. Adds a regression test in test/fix-6411.test.js.
  3. Adds a note in the documentation about anyOf vs nullable for numbers, as anyOf with null as the first branch can lead to unexpected mutation of 0 to null in some Ajv configurations.

Verified with the new test case.

@github-actions github-actions bot added the documentation Improvements or additions to documentation label Feb 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Validation of optional, nullable number where property value is 0 will default to null

1 participant