0.6.2 • Published 7 years ago

egg-raml-validate v0.6.2

Weekly downloads
2
License
MIT
Repository
github
Last release
7 years ago

Installation

npm install -S egg-raml-validate

# and its dependencies
npm install -S egg-validate

Usage

Import it and its dependencies via config/plugin.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:

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

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

{
    "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

0.6.2

7 years ago

0.6.1

7 years ago

0.6.0

7 years ago

0.5.1

7 years ago

0.5.0

7 years ago

0.4.3

7 years ago

0.4.2

7 years ago

0.4.1

7 years ago

0.3.1

7 years ago

0.3.0

7 years ago

0.2.3

7 years ago

0.2.2

7 years ago

0.2.1

7 years ago

0.2.0

7 years ago

0.1.2

7 years ago

0.1.1

7 years ago