class GrapeSwagger::DocMethods::DataType

Constants

PRIMITIVE_MAPPINGS

Public Class Methods

call(value) click to toggle source
# File lib/grape-swagger/doc_methods/data_type.rb, line 5
def call(value)
  raw_data_type = value[:type] if value.is_a?(Hash)
  raw_data_type = value unless value.is_a?(Hash)
  raw_data_type ||= 'string'
  case raw_data_type.to_s
  when 'Boolean', 'Date', 'Integer', 'String', 'Float', 'JSON', 'Array'
    raw_data_type.to_s.downcase
  when 'Hash'
    'object'
  when 'Rack::Multipart::UploadedFile', 'File'
    'file'
  when 'Virtus::Attribute::Boolean'
    'boolean'
  when 'BigDecimal'
    'double'
  when 'DateTime', 'Time'
    'dateTime'
  when 'Numeric'
    'long'
  when 'Symbol'
    'string'
  else
    parse_entity_name(raw_data_type)
  end
end
mapping(value) click to toggle source
# File lib/grape-swagger/doc_methods/data_type.rb, line 58
def mapping(value)
  PRIMITIVE_MAPPINGS[value] || 'string'
end
parse_entity_name(model) click to toggle source
# File lib/grape-swagger/doc_methods/data_type.rb, line 31
def parse_entity_name(model)
  if model.respond_to?(:entity_name)
    model.entity_name
  else
    name = model.to_s
    entity_parts = name.split('::')
    entity_parts.reject! { |p| p == 'Entity' || p == 'Entities' }
    entity_parts.join('::')
  end
end
primitive?(type) click to toggle source
# File lib/grape-swagger/doc_methods/data_type.rb, line 46
def primitive?(type)
  primitives.include?(type.to_s.downcase)
end
primitives() click to toggle source
# File lib/grape-swagger/doc_methods/data_type.rb, line 54
def primitives
  PRIMITIVE_MAPPINGS.keys.map(&:downcase)
end
request_primitive?(type) click to toggle source
# File lib/grape-swagger/doc_methods/data_type.rb, line 42
def request_primitive?(type)
  request_primitives.include?(type.to_s.downcase)
end
request_primitives() click to toggle source
# File lib/grape-swagger/doc_methods/data_type.rb, line 50
def request_primitives
  primitives + %w(object string boolean file json array)
end