forked from jirikuncar/marc-json-schema
-
Notifications
You must be signed in to change notification settings - Fork 0
/
jsonschema.tpl
58 lines (58 loc) · 1.82 KB
/
jsonschema.tpl
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
{%- macro render_object(field) -%}
{%- set indicator1 = get_indicator(1, field) -%}
{%- set indicator2 = get_indicator(2, field) -%}
{%- if indicator1.get('name') %}
"{{ indicator1['name'] }}": {
"enum": {{ tojson(set(indicator1.get('values', {}).values())) }}
},
{%- endif %}
{%- if indicator2.get('name') %}
"{{ indicator2['name'] }}": {
"enum": {{ tojson(set(indicator2.get('values', {}).values())) }}
},
{%- endif %}
{%- for code, subfield in field.get('subfields').iteritems() %}
{%- if subfield.get('repeatable', False) %}
"{{ clean_name(subfield['name']) }}": {
"type": "array",
"items": {
"type": "string"
}
}{{ ',' if not loop.last }}
{%- else %}
"{{ clean_name(subfield['name']) }}": {
"type": "string"
}{{ ',' if not loop.last }}
{%- endif %}
{%- endfor %}
{%- endmacro -%}
{
"type": "object",
"properties": {
{%- for tag, field in data if tag|length() == 3 %}
{%- if 'subfields' in field %}
"{{ clean_name(field.name) }}": {
"description": "{{ field.name }}",
{%- if field.repeatable %}
"type": "array",
"items": {
"type": "object",
"properties": {
{{- render_object(field)|indent(12) }}
}
}
{%- else %}
"properties": {
{{- render_object(field)|indent(8) }}
}
{%- endif %}
}{{ ',' if not loop.last }}
{%- else %}
"{{ clean_name(field.name) }}": {
"description": "{{ field.name }}",
"type": "string"
}{{ ',' if not loop.last }}
{%- endif %}
{%- endfor %}
}
}