pibi / moleculer-json-schema-validator

Validate moleculer action params via JSON Schema.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Moleculer JSON Schema Validator

Validate moleculer action params via JSON Schema.

Install

npm install --save moleculer-json-schema-validator

Usage

// moleculer.config.js

const Validator = require('moleculer-json-schema-validator')

module.exports = {
  ...
  validator: new Validator()
}
// service.js

module.exports = {
  actions: {
    hello: {
      jsonSchema: {
        properties: {
          "name": {type: "string"}
        },
        required: ["name"]
      },
      handler (ctx) {
        const {name} = ctx.params
        return `Hello ${name}`
      }
    }
  }
}

License

MIT

About

Validate moleculer action params via JSON Schema.


Languages

Language:JavaScript 100.0%