-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathschema.libsonnet
More file actions
56 lines (56 loc) · 1.4 KB
/
schema.libsonnet
File metadata and controls
56 lines (56 loc) · 1.4 KB
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
{
local root = self,
'$ref': '#/$defs/element',
'$defs': {
tag: {
type: 'object',
properties: {
type: { const: 'tag' },
name: { type: 'string' },
attributes: { type: 'array', item: { type: 'object' } },
elements: { type: 'array', item: { type: 'object' } },
},
required: ['name'],
toJsonML(obj):
[obj.name]
+ (if 'attributes' in obj
then [
std.foldl(
function(acc, attr)
acc + root['$defs'].attribute.toJsonML(attr),
obj.attributes,
{},
),
]
else [])
+ (if 'elements' in obj
then
std.foldl(
function(acc, el)
acc + [root['$defs'][el.type].toJsonML(el)] + ['\n'],
obj.elements,
['\n']
)
else []),
},
literal: {
type: 'object',
properties: {
type: { const: 'literal' },
value: { type: 'string' },
},
required: ['value'],
toJsonML(obj): obj.value,
},
attribute: {
type: 'object',
properties: {
type: { const: 'attribute' },
name: { type: 'string' },
value: { type: ['string', 'number', 'boolean', 'null'] },
},
required: ['name', 'value'],
toJsonML(obj): { [obj.name]: obj.value },
},
},
}