This package converts Mongoose schema into a validation chain for Express. Currently, it supports most default schema types as well as a few custom ones. For instance, schema types named Email or Phone match validator's implementation. See the full list of supported properties below.
This module works through a custom Mongoose plugin that appends two static methods, getSchemaPaths and getChildPaths. Both work recursively and support child and discriminator schemas. To access a discriminator, though, the request object must contain a reference to its key. See the examples below for more detail.
// coming soonAll schema types support required and systemOnly properties. The latter omits the field from validation altogether.
| Name | Options | Notes |
|---|---|---|
| String | minLength, maxLength, enum | Auto escapes and trims |
| Number | min, max | |
| ObjectId | ||
| SchemaArray | ||
| Date | Auto converts to ISO string | |
| Boolean | Auto converts any non-falsy value to true | |
| URL | -- | Auto normalizes |
| -- | Auto normalizes | |
| Phone | -- |