NestJS and ‘class validator’ cheat sheet
date
Jun 13, 2022
slug
nestjs-and-class-validator-cheat-sheet
status
Published
tags
nest
validations
summary
NestJs along with `class-validator` is a good combination for validating API responses. Both are well documented but some needed use cases are not covered assuming developer to figure out. Below are some few cheat sheets which helps in defining those cases and you can use these to scale to some extent.
type
Post
external-url
NestJs along with `class-validator` is a good combination for validating API responses. Both are well documented but some needed use cases are not covered assuming developer to figure out. Below are some few cheat sheets which helps in defining those cases and you can use these to scale to some extent.
1️⃣ Validating String
Any String
Specific String
Array of strings
Array of Strings with a custom prefix
2️⃣ Validating Number
Any number
Specific Number
Array of numbers
3️⃣ Custom Object
For example you have a payload like below
To validate such object