@regionaalenergieloket/nest-class-validator-decorator
v0.0.4
Published
Forked from https://github.com/Bholtland/nest-class-validator-decorator/
Downloads
144
Keywords
Readme
nest-class-validator-decorator
A custom decorator that uses the class-transformer
and class-validator
npm packages under the hood to deserialize method response data and validate it according to a supplied "class-validator" class.
Getting started
Add the decorator as a dependency to your project
npm install -S nest-class-validator-decorator
or yarn add -S nest class-validator-decorator
.
You can now import the decorator into your code like so:
import {ValidateResponse} from "nest-class-validator-decorator"
...
@ValidateResponse(YourSchema)
public yourMethod() {
// Your logic...
}
Any JSON returned from "yourMethod" will now be validated according to "YourSchema".
Options
As a secondary param you can add an "options" object containing ValidatorOptions from "class-validator".