Skip to content

Commit b21b36d

Browse files
Merge pull request #3375 from SamWooler/sw/add-param-zod-validation-example
docs(pipes): example of zod validation on specific method parameter
2 parents 24bd64b + 1117d9b commit b21b36d

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

content/pipes.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,18 @@ async create(createCatDto) {
330330

331331
> info **Hint** The `@UsePipes()` decorator is imported from the `@nestjs/common` package.
332332
333+
The `ZodValidationPipe` can be applied to specific parameters and alongside built-in pipes. For example, where we want to validate the route path `id` parameter with the `ParseIntPipe` seperately from the request body:
334+
335+
```typescript
336+
@Put('/:id')
337+
async update(
338+
@Param('id', ParseIntPipe) id: number,
339+
@Body(new ZodValidationPipe(createCatSchema)) body: CreateCatDto
340+
): void {
341+
this.catsService.update(id, body);
342+
}
343+
```
344+
333345
> warning **Warning** `zod` library requires the `strictNullChecks` configuration to be enabled in your `tsconfig.json` file.
334346
335347
#### Class validator

0 commit comments

Comments
 (0)