Parameter Validation
We often need to perform type checking and parameter conversion operations when calling methods. Midway provides a simple capability to quickly check parameter types.
This module replaces the @midwayjs/validate component starting from v4.0.0.
The new version provides a more flexible validator extension mechanism, supports seamless switching between multiple validators (such as Joi, Zod, etc.), and provides better type support and performance optimization.
Related information:
| Description | |
|---|---|
| Can be used for standard projects | ✅ |
| Can be used for Serverless | ✅ |
| Can be used for integration | ✅ |
| Contains independent main framework | ❌ |
| Contains independent logs | ❌ |
Background
The most commonly used place for parameter validation is the controller (Controller), and you can also use this capability in any Class.
We'll use the controller (Controller) as an example.
➜ my_midway_app tree
.
├── src
│ ├── controller
│ │ └── user.ts
│ ├── interface.ts
│ └── service
│ └── user.ts
├── test
├── package.json