fix: allow numbers and booleans as validation message "$value" tokens
PR Checklist
Please check if your PR fulfills the following requirements:
- [x] The commit message follows our guidelines: https://github.com/nestjs/nest/blob/master/CONTRIBUTING.md
- [x] Tests for the changes have been added (for bug fixes / features)
- [ ] Docs have been added / updated (for bug fixes / features)
PR Type
What kind of change does this PR introduce?
- [x] Bugfix
- [ ] Feature
- [ ] Code style update (formatting, local variables)
- [ ] Refactoring (no functional changes, no api changes)
- [ ] Build related changes
- [ ] CI related changes
- [ ] Other... Please describe:
What is the current behavior?
The $value token placed in the validation message is parsed as expected only when the provided value is of type string, which results in commonly used validators with non-string values such as @MinLength, @Min, @MaxLength, @Max ect. leaving the $value token in the validation message without replacing it. This PR relaxes the runtime typecheck performed when constructing the validation message by allowing types boolean and number (alongside string) to act as $value token replacements.
Documented in issues: typestack/class-validator#921, typestack/class-validator#1046, also reported in the NestJS repo as nestjs/nest#6431
What is the new behavior?
As documented in README examples - $value tokens will be replaced in the validation error message even if the underlying value is a number or a boolean.
Does this PR introduce a breaking change?
- [ ] Yes
- [x] No
Other information
Thanks for taking the time to create this fork. I have opened a PR with the same changes against the original repo, but given its rather stale maintenance status I thought that I might as well do it here.
I have also fixed formatting of the PR template file which was causing the CI pipeline to fail.