https://github.com/mikeibberson/m2e-validator
Convert mongoose schema into an express-validator chain
https://github.com/mikeibberson/m2e-validator
expressjs mongoose nodejs validate-js
Last synced: 5 months ago
JSON representation
Convert mongoose schema into an express-validator chain
- Host: GitHub
- URL: https://github.com/mikeibberson/m2e-validator
- Owner: MikeIbberson
- License: mit
- Created: 2019-11-27T01:00:12.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2023-03-04T05:17:35.000Z (over 3 years ago)
- Last Synced: 2025-02-08T19:13:04.094Z (over 1 year ago)
- Topics: expressjs, mongoose, nodejs, validate-js
- Language: JavaScript
- Homepage: https://www.npmjs.com/package/m2e-validator
- Size: 986 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 23
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
🔌 Mongoose to Express-Validator adapter
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.
The plugin
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.
``` Javascript
// coming soon
```
The schemas
All 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 |
| Email | -- | Auto normalizes |
| Phone | -- | |