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
|
# File 'lib/swagger/blocks/schema_builder.rb', line 26
def build_model_schema(model_class, include_only_required_fields=false)
required_fields = get_required_fields(model_class)
key :required, required_fields
model_class.fields.each do |name, options|
type = options.type.to_s
defaul_value = options.options[:default]
next unless SUPPORTED_TYPES.include?(type)
if include_only_required_fields
next if name == '_id'
next unless required_fields.include?(name.to_sym)
end
property name do
case type
when 'Symbol'
klass = options.options[:klass].to_s
constant = name.sub('_', '').upcase
values = "#{klass}::#{constant}".constantize
key :type, :string
key :enum, values
when 'Array'
key :type, :array
items do
key :type, :string
end
when 'BSON::ObjectId'
key :type, :string
key :format, :uuid
when 'Date'
key :type, :string
key :format, :date
when 'Time'
key :type, :string
key :format, 'date-time'
when 'Mongoid::Boolean'
key :type, :boolean
key :default, defaul_value
when 'Integer'
key :type, :integer
key :default, defaul_value.to_i
else
key :type, :string
key :default, defaul_value.to_s
end
end
end
end
|