Class: Swagger::Api::ColumnSchema

Inherits:
Object
  • Object
show all
Includes:
ActiveAttr::Model
Defined in:
lib/swagger/api/column_schema.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#columnObject

Returns the value of attribute column.



5
6
7
# File 'lib/swagger/api/column_schema.rb', line 5

def column
  @column
end

Instance Method Details

#createObject



7
8
9
10
11
12
13
14
15
# File 'lib/swagger/api/column_schema.rb', line 7

def create
  schema = {
    type: type_from_column,
    format: format_from_column
  }
  schema[:minimum] = 1 if column.type == :integer && column.name.to_s.ends_with?('id')
  schema[:minimum] = 0 if column.type == :integer && !column.name.to_s.ends_with?('id')
  schema
end

#format_from_columnObject



27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/swagger/api/column_schema.rb', line 27

def format_from_column
  case column.type
    when :datetime
      'date-time'
    when :integer
      :int64
    else
      if column.name.to_s == 'email'
        :email
      else
        column.type
      end
  end
end

#type_from_columnObject



17
18
19
20
21
22
23
24
25
# File 'lib/swagger/api/column_schema.rb', line 17

def type_from_column
  if i(datetime date time).include?(column.type)
    :string
  elsif i(float double).include?(column.type)
    :number
  else
    column.type
  end
end