Class: WeakSwaggerParameters::Services::SwaggerOptionsAdapter

Inherits:
Object
  • Object
show all
Defined in:
lib/weak_swagger_parameters/services/swagger_options_adapter.rb

Constant Summary collapse

KNOWN_TYPES =
{
  integer: { type: :integer, format: :int32 },
  long: { type: :integer, format: :int64 },
  float: { type: :number, format: :float },
  double: { type: :number, format: :double },
  string: { type: :string },
  byte: { type: :string, format: :byte },
  binary: { type: :string, format: :binary },
  boolean: { type: :boolean },
  date: { type: :string, format: :date },
  dateTime: { type: :string, format: :'date-time' },
  password: { type: :string, format: :password }
}.freeze

Class Method Summary collapse

Class Method Details

.about_options(options) ⇒ Object



35
36
37
38
39
40
41
# File 'lib/weak_swagger_parameters/services/swagger_options_adapter.rb', line 35

def self.about_options(options)
  result = {}
  result = result.merge(name: options[:name]) if options[:name].present?
  result = result.merge(description: options[:description]) if options[:description].present?
  result = result.merge(in: options[:location]) if options[:location].present?
  result
end

.adapt(options) ⇒ Object



20
21
22
23
24
25
26
27
28
29
# File 'lib/weak_swagger_parameters/services/swagger_options_adapter.rb', line 20

def self.adapt(options)
  result = {}
  result = result.merge(about_options(options))
  result = result.merge(enum_options(options))
  result = result.merge(default_options(options))
  result = result.merge(type_options(options))
  result = result.merge(required_options(options))
  result = result.merge(range_options(options))
  result
end

.default_options(options) ⇒ Object



57
58
59
# File 'lib/weak_swagger_parameters/services/swagger_options_adapter.rb', line 57

def self.default_options(options)
  options[:default].present? ? { default: options[:default] } : {}
end

.enum_options(options) ⇒ Object



61
62
63
# File 'lib/weak_swagger_parameters/services/swagger_options_adapter.rb', line 61

def self.enum_options(options)
  options[:enum].present? ? { enum: options[:enum] } : {}
end

.range_options(options) ⇒ Object



50
51
52
53
54
55
# File 'lib/weak_swagger_parameters/services/swagger_options_adapter.rb', line 50

def self.range_options(options)
  result = {}
  result = result.merge(minimum: options[:min]) if options[:min].present?
  result = result.merge(maximum: options[:max]) if options[:max].present?
  result
end

.required_options(options) ⇒ Object



43
44
45
46
47
48
# File 'lib/weak_swagger_parameters/services/swagger_options_adapter.rb', line 43

def self.required_options(options)
  result = {}
  result = result.merge(required: true) if options[:location] == :path
  result = result.merge(required: options[:required]) if options[:required]
  result
end

.type_options(options) ⇒ Object



31
32
33
# File 'lib/weak_swagger_parameters/services/swagger_options_adapter.rb', line 31

def self.type_options(options)
  KNOWN_TYPES[options[:type]]
end