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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
|
# File 'lib/wschema.rb', line 13
def self.run_format_schema(schema)
schema&.each_with_object([]) do |field, array|
field_name = field['name']
if (props = field['properties'])
field['properties'] = run_format_schema(props)
end
if field['type'] == 'string' || field['type'] == :string
field.delete('type')
end
if field['label'] &&
(field['label'] == 'id' || labelize(field_name) == field['label'])
field.delete('label')
end
case field_name
when 'os'
field['label'] = 'OS'
when 'guid'
field['label'] = 'GUID'
when 'uuid'
field['label'] = 'UUID'
when 'uri'
field['label'] = 'URI'
end
if field['control_type'] == 'text' || field['control_type'] == :text
field.delete('control_type')
end
if field['type'] == 'boolean' || field['type'] == :boolean
field['control_type'] = 'checkbox'
elsif field['type'] == 'integer' || field['type'] == :integer
field['control_type'] = 'integer'
end
field_info = [field['name'].downcase,
field['label']&.downcase,
field['hint']&.downcase].compact
if field_info.include?('email')
field['control_type'] = 'email'
elsif field_info.include?('phone')
field['control_type'] = 'phone'
elsif field_info.include?('uri')
field['control_type'] = 'url'
elsif field_info.include?('url')
field['control_type'] = 'url'
end
array << {
name: field['name'],
label: field['label'],
hint: field['hint'],
default: field['default'],
sticky: field['sticky'],
optional: field['optional'],
extends_schema: field['extends_schema'],
schema_neutral: field['schema_neutral'],
add_field_label: field['add_field_label'],
sample_data_type: field['sample_data_type'],
custom_properties: field['custom_properties'],
control_type: field['control_type'],
empty_list_title: field['empty_list_title'],
empty_list_text: field['empty_list_text'],
item_label: field['item_label'],
pick_list: field['pick_list'],
toggle_hint: field['toggle_hint'],
toggle_field: field['toggle_field'],
render_input: field['render_input'],
parse_output: field['parse_output'],
type: field['type'],
of: field['of'],
properties: field['properties']
}.compact
end
end
|