Ecosyste.ms: Awesome

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

Awesome Lists | Featured Topics | Projects

https://github.com/zhaoyao91/moleculer-json-schema-validator

Validate moleculer action params via JSON Schema.
https://github.com/zhaoyao91/moleculer-json-schema-validator

Last synced: 2 months ago
JSON representation

Validate moleculer action params via JSON Schema.

Awesome Lists containing this project

README

        

# Moleculer JSON Schema Validator

Validate moleculer action params via JSON Schema.

## Current Version (v1.0.0)

- support [json schema draft-7](http://json-schema.org/specification-links.html#draft-7)
- support [moleculer ^0.11.x](https://github.com/ice-services/moleculer)
- using [ajv ^6.x.x](https://github.com/epoberezkin/ajv)

## Install

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

## Usage

```js
// moleculer.config.js

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

module.exports = {
...
validator: new Validator()
}
```

```js
// service.js

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

## License

MIT