Skip to content

Commit 4c65bf4

Browse files
author
Carbon Digital
authored
Add more detail to Joi schema section
1 parent a5b8181 commit 4c65bf4

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

content/pipes.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,16 @@ In this case, we want to bind the pipe at the method call level. In our current
295295
2. Pass the context-specific Joi schema in the class constructor of the pipe
296296
3. Bind the pipe to the method
297297

298+
Joi schema example:
299+
300+
```typescript
301+
const createCatSchema = Joi.object({
302+
name: Joi.string().required(),
303+
age: Joi.number().required(),
304+
breed: Joi.string().required(),
305+
})
306+
```
307+
298308
We do that using the `@UsePipes()` decorator as shown below:
299309

300310
```typescript
@@ -315,6 +325,8 @@ async create(createCatDto) {
315325

316326
> info **Hint** The `@UsePipes()` decorator is imported from the `@nestjs/common` package.
317327
328+
> info **Note** When a DTO already uses `class-validator` to validate each data element, the techniques above using both Joi schema and a DTO are not necessary. You only need one level of validation. However, if your DTO does not have `class-validator` in use, then the Joi schema method could be used like the above example, without worrying about breaking "DRY" principles.
329+
318330
#### Class validator
319331

320332
> warning **Warning** The techniques in this section require TypeScript, and are not available if your app is written using vanilla JavaScript.

0 commit comments

Comments
 (0)