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
|
# File 'lib/json/schema/lite/object.rb', line 5
def self.define(definition)
option = definition.is_a?(Hash) ? definition.delete(:option) || {} : {}
{}.tap do |json_schema|
if definition.is_a? Hash
definition.each_pair do |k, v|
if k.to_s == 'properties' || option[:properties]
v[:option] = { properties: true } if v.is_a?(Hash) && v[:properties].nil?
json_schema[k] = define v
else
json_schema[k] = v
end
end
elsif definition.is_a? Array
if definition.size == 1
json_schema[:type] = :array
json_schema[:items] = define definition[0]
else
json_schema[:anyOf] = definition.map { |d| { type: d } }
end
else
json_schema[:type] = definition
end
end
end
|