An open API service indexing awesome lists of open source software.

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

Awesome Lists containing this project

README

          

🔌 Mongoose to Express-Validator adapter



Status
Coverage Status



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 | -- | |