Name: egg-validate-schema
Owner: egg
Description: validate by json-schema plugin for egg
Created: 2017-08-03 02:11:21.0
Updated: 2018-04-16 07:32:25.0
Pushed: 2017-08-06 08:27:35.0
Homepage: null
Size: 6
Language: JavaScript
GitHub Committers
User | Most Recent Commit | # Commits |
---|
Other Committers
User | Most Recent Commit | # Commits |
---|
Validate with JSON Schema
plugin for egg.
see ajv for more information.
m i egg-validate-schema --save
app_root}/config/plugin.js
rts.validateSchema = {
ckage: 'egg-validate-schema',
fully support ajv
options, see document
app_root}/config/config.{env}.js
rts.validateSchema = {
allErrors: true,
v5: true,
t jsonSchema = {
ype": "object",
roperties": {
"name": {
"type": "string"
},
"info": {
"type": "object"
}
equired": [
"name",
"info"
rts.create = function* () {
if validate fail will response 422 status code
is.validateBySchema(jsonSchema);
pass your own data?default use `this.request.body`
this.validateBySchema(jsonSchema[, your_data]);
validate pass
is.body = this.request.body;
validate fail response detail?
/1.1 422 Unprocessable Entity
essage": "Validation Failed",
rrors": [
{
"keyword": "required",
"dataPath": "",
"schemaPath": "#/required",
"params": { missingProperty: 'name' },
"message": "should have required property 'name'",
}
Please open an issue here.