-
Notifications
You must be signed in to change notification settings - Fork 4
/
rootSchema.js
65 lines (62 loc) · 1.53 KB
/
rootSchema.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
const joi = require('@hapi/joi');
const R = require('ramda');
const base = joi
.object()
.keys({ quux: joi.string().meta({ isDocumented: false }) });
const listItem = joi
.object()
.keys({
foo: joi.string(),
})
.meta({
name: 'List Item',
filename: 'listItemSchema',
});
module.exports = base
.append({
version: joi
.number()
.meta({ default: '1.0.0' })
.description('Follows semantic versioning.'),
foo: joi
.string()
.required()
.valid(...R.map(R.pipe(R.toString, R.concat('valid')), R.range(0, 4)))
.invalid(...R.map(R.pipe(R.toString, R.concat('invalid')), R.range(0, 4)))
.description('This is a description.'),
bar: joi.alternatives().conditional('foo', {
is: joi.required(),
then: joi.boolean(),
otherwise: joi.forbidden(),
}),
any: joi.any(),
list: joi.array().length(5),
primitiveList: joi
.array()
.items(joi.string(), joi.number(), joi.boolean())
.min(1)
.max(3),
objectList: joi.array().items(listItem),
nestedObjSchema1: joi
.object()
.keys({
foo: joi.string(),
nestedObjSchema2: joi
.object()
.keys({
foo: joi.string(),
})
.meta({
name: 'Nested Object Schema 2',
filename: 'nestedObjSchema2',
}),
})
.meta({
name: 'Nested Object Schema 1',
filename: 'nestedObjSchema1',
}),
})
.meta({
name: 'Root Schema',
filename: 'rootSchema',
});