1.0.6 • Published 6 years ago
koa-validate-json v1.0.6
koa-validate-json
- 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来生成