-
Notifications
You must be signed in to change notification settings - Fork 44
/
Copy pathadditional.js
42 lines (40 loc) · 976 Bytes
/
additional.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// generate errors when additional fields are present
var Schema = require('../..')
, opts = {field: 'root'}
, descriptor = {
type: 'object',
additional: false,
fields: {
address: {
type: 'object',
required: true,
additional: false,
fields: {
street: {type: 'string', required: true},
city: {type: 'string', required: true},
zip: {
type: 'string',
required: true,
len: 8,
message: 'Invalid zip'
}
}
}
}
}
, source = {
id: 'unknown-field',
name: 'unknown-field',
address: {
name: 'unknown-field',
street: 'Mock St',
city: 'Mock City',
zip: '12345678'
}
}
, schema;
require('../../plugin/all');
schema = new Schema(descriptor);
schema.validate(source, opts, function(err, res) {
console.dir(res.errors);
});