koa-validate-json

1.0.6 • Public • Published

koa-validate-json

NPM version license

  • koa拦截校验字段

使用

const schema = require('koa-validate-json')
 
router.post('/article', schema({
  type: 'object',
  properties: {
    title: { type: 'string', maxLength: 100 },
    content: { type: 'string' },
    tags: {
      type: 'array',
      items: { type: 'string', maxLength: 20 }
    },
    public: { type: 'boolean' }
  },
  required: [ 'title', 'content', 'tags' ],
  additionalProperties: false
}), async () => { 
  //controller function
})
  • 通常这个schema中的json校验可以通过Joi和jsonschema来生成

Readme

Keywords

Package Sidebar

Install

npm i koa-validate-json

Weekly Downloads

5

Version

1.0.6

License

MIT

Unpacked Size

3.03 kB

Total Files

4

Last publish

Collaborators

  • alfieri