JSON-schema based validator middleware
yarn add @qiwi/mware-validator
npm i @qiwi/mware-validator
import validator from '@qiwi/mware-validator'
import express from 'express'
const app = express()
const schema = {
type: 'object',
properties: {
params: {
id: {
type: 'string',
pattern: '[abc]^\d{2}',
required: true
}
},
query: {
data: {
type: 'object',
required: true
}
}
}
}
app.get('/foo/:id', validator({schema}), (req, res) => {
...
res.send({...})
})
app.listen(...)
MIT