Class: Apipie::Generator::Swagger::ParamDescription::Type

Inherits:
Object
  • Object
show all
Defined in:
lib/apipie/generator/swagger/param_description/type.rb

Instance Method Summary collapse

Constructor Details

#initialize(param_description, with_null:, controller_method:) ⇒ Type

Returns a new instance of Type.



2
3
4
5
6
# File 'lib/apipie/generator/swagger/param_description/type.rb', line 2

def initialize(param_description, with_null:, controller_method:)
  @param_description = param_description
  @with_null = with_null
  @controller_method = controller_method
end

Instance Method Details

#to_hashHash

Returns:

  • (Hash)


9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/apipie/generator/swagger/param_description/type.rb', line 9

def to_hash
  type_definition = {}

  case type.to_s
  when 'array'
    type_definition.merge!(for_array_type)
  when 'enum'
    type_definition.merge!(for_enum_type)
  when 'object'
    # We only get here if there is no specification
    # of properties for this object.
    type_definition.merge!(for_object_type)
    warn_hash_without_internal_typespec
  else
    type_definition.merge!({ type: type.to_s })
  end

  if @param_description.is_array?
    type_definition = {
      items: type_definition,
      type: 'array'
    }

    if @with_null
      type_definition[:type] = [type_definition[:type], 'null']
    end
  end

  if @with_null
    type_definition[:type] = [type_definition[:type], 'null']
  end

  type_definition
end