Validate moleculer action params via JSON Schema.
- support json schema draft-7
- support moleculer ^0.11.x
- using ajv ^6.x.x
npm install --save moleculer-json-schema-validator
// moleculer.config.js
const Validator = require('moleculer-json-schema-validator')
module.exports = {
...
validator: new Validator()
}
// service.js
module.exports = {
actions: {
hello: {
params: {
properties: {
"name": {type: "string"}
},
required: ["name"]
},
handler (ctx) {
const {name} = ctx.params
return `Hello ${name}`
}
}
}
}
MIT