Class: SwaggerApi::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.



4
5
6
# File 'lib/swagger_api/column_schema.rb', line 4

def column
  @column
end

Instance Method Details

#createObject



6
7
8
9
10
11
12
13
14
# File 'lib/swagger_api/column_schema.rb', line 6

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



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

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



16
17
18
19
20
21
22
23
24
# File 'lib/swagger_api/column_schema.rb', line 16

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