class-validator icon indicating copy to clipboard operation
class-validator copied to clipboard

fix: Special token $value

Open zampoukos opened this issue 2 years ago • 4 comments

Description

$value token does not get replaced on validation.

@Max(120, {
    message:
      "Maximum $property is $constraint1. $target can't be $value years old",
  })

Expected behavior

$value should be replaced with whatever the user has passed as an argument on the request

{
    "statusCode": 400,
    "message": [
        "Maximum age is 120. User can't be 122 years old"
    ],
    "error": "Bad Request"
}

Actual behavior

This clearly doesn't work and the response contains '$value' as string

{
    "statusCode": 400,
    "message": [
        "Maximum age is 120. User can't be $value years old"
    ],
    "error": "Bad Request"
}
Screenshot 2023-03-15 at 5 01 21 PM Screenshot 2023-03-15 at 5 01 07 PM

zampoukos avatar Mar 15 '23 15:03 zampoukos

Do we have any updates on this one? Am I missing something?

zampoukos avatar May 04 '23 13:05 zampoukos

experiencing the same

tlowande avatar May 09 '23 21:05 tlowande

It only works for string value.

And it was actually fixed half a year ago in this commit: https://github.com/typestack/class-validator/commit/d325cc7c45bffc45ce8b328bddc43f4e814fbe6b#diff-c5095b550c2b7842df845f7666600b194bdc62e369fecec22efc84ddab6fba38

But this fix is not in the master branch yet.

stasgm avatar Jun 01 '23 11:06 stasgm

Waiting for an update on this

ramirezsandin avatar Jul 26 '23 09:07 ramirezsandin