Skip to content

Latest commit

 

History

History
40 lines (32 loc) · 829 Bytes

use-validation-pipe.md

File metadata and controls

40 lines (32 loc) · 829 Bytes

Use pipe ValidationPipe for data validation (use-validation-pipe)

Pipes can overtake the validation responsibility, since it's possible to throw an exception when the data isn't correct.

Rule Details

The following patterns are considered warnings (fail):

class CatController {
    @Post()
    async create(@Body() createCatDto: CreateCatDto) { }
}

The following patterns are not warnings (pass):

@UsePipes(new ValidationPipe())
class CatController {
    @Post()
    async create(@Body() createCatDto: CreateCatDto) { }
}
class CatController {
    @Post()
    async create(@Body(new ValidationPipe()) createCatDto: CreateCatDto) { }
}
class { 
    @Post() 
    async create(@Body() createCatDto: any) {  } 
}

Further Reading

Pipes