# egg-raml-validate

> Validate parameters via raml for egg.

Latest version **0.6.2** (published 2017-06-10) · MIT license · 0 weekly downloads

## Install

```sh
npm install egg-raml-validate
pnpm add egg-raml-validate
yarn add egg-raml-validate
bun add egg-raml-validate
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.6.2 |
| Published | 2017-06-10 |
| First published | 2017-05-02 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=7.6.0 |
| Dependencies | 6 |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| Author | m31271n |
| Maintainers | m31271n |
| Keywords | raml-validate, validate, egg, egg.js |

## Links

- npm: https://www.npmjs.com/package/egg-raml-validate
- Repository: https://github.com/m31271n/egg-raml-validate
- Homepage: https://github.com/m31271n/egg-raml-validate#readme
- Issues: https://github.com/m31271n/egg-raml-validate/issues
- npm.io page: https://npm.io/package/egg-raml-validate

## Dependencies (6)

- [debug](https://npm.io/package/debug.md) ^2.6.6
- [lodash.get](https://npm.io/package/lodash.get.md) ^4.4.2
- [lodash.set](https://npm.io/package/lodash.set.md) ^4.3.2
- [raml-1-parser](https://npm.io/package/raml-1-parser.md) 1.1.20
- [lodash.isempty](https://npm.io/package/lodash.isempty.md) ^4.4.0
- [egg-path-matching](https://npm.io/package/egg-path-matching.md) ^1.0.0

## Alternatives

- [@sindresorhus/slugify](https://npm.io/package/@sindresorhus/slugify.md) — 3.7M weekly downloads
- [solid-js](https://npm.io/package/solid-js.md) — 2.7M weekly downloads
- [expo-glass-effect](https://npm.io/package/expo-glass-effect.md) — 2.5M weekly downloads
- [nanoassert](https://npm.io/package/nanoassert.md) — 780.8K weekly downloads
- [@ffmpeg/ffmpeg](https://npm.io/package/@ffmpeg/ffmpeg.md) — 529.5K weekly downloads

## Recent versions

- 0.6.2 (latest) — 2017-06-10
- 0.6.1 — 2017-06-08
- 0.6.0 — 2017-05-22
- 0.5.1 — 2017-05-15
- 0.5.0 — 2017-05-11
- 0.4.3 — 2017-05-09
- 0.4.2 — 2017-05-08
- 0.4.1 — 2017-05-08
- 0.3.1 — 2017-05-05
- 0.3.0 — 2017-05-05
- 0.2.3 — 2017-05-03
- 0.2.2 — 2017-05-03
- 0.2.1 — 2017-05-02
- 0.2.0 — 2017-05-02
- 0.1.2 — 2017-05-02
- … 1 more at https://npm.io/package/egg-raml-validate/versions

## README

<h1 align="center">egg-raml-validate</h1>

<p align="center">Validate parameters via RAML for egg.</p>

<p align="center">
<a href="http://standardjs.com/" target="_blank"><img src="https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat" alt="Standard - JavaScript Style Guide"></a>
<a href="http://m31271n.com/" target="_blank"><img src="https://img.shields.io/badge/made%20by-m31271n-brightgreen.svg?style=flat" alt="Made by m31271n"></a>
<img src="https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat" alt="License - MIT">
</p>


## Installation

```sh
npm install -S egg-raml-validate

# and its dependencies
npm install -S egg-validate
```

## Usage

Import it and its dependencies via `config/plugin.js`:

```js
module.exports = {
  ...

  'validate': {
    enable: true,
    package: 'egg-validate'
  },
  'raml-validate': {
    enable: true,
    package: 'egg-raml-validate'
  }

  ...
}
```

Config it via `config/config.<env>.js`:

```
module.exports = {
  ...

  ramlValidate: {
    ramlFile: '/absolute/path/to/raml/file'
  }

  ...
}
```

## Extentions to RAML
Add two annotations to Method:

+ `middlewares` - apply middlewares to current method
+ `controller` - apply controller to current method

## Extentions to egg-validate
### Why?
`egg-raml-validate` will check multiple types of parameters at one time, different from what `egg-validate` does. Therefore, we have to find a way to distinguish different types of validate error.

### Extensions

Extensions of `egg-validate`:

+ Add `in` field for `errors`.

For example, when using `egg-validate`, the response is:

```json
{
    "code": "invalid_param",
    "errors": [
        {
            "code": "missing_field",
            "field": "quantity",
            "message": "required"
        }
    ],
    "message": "Validation Failed"
}
```

But, when using `egg-raml-validate`, the response is:

```json
{
    "code": "invalid_param",
    "errors": [
        {
            "code": "missing_field",
            "field": "quantity",
            "in": "query",
            "message": "required"
        }
    ],
    "message": "Validation Failed"
}
```

You can see, `in` field let you know where the missing field in.


## LICENSE

MIT

---
_Source: https://npm.io/package/egg-raml-validate · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
