Class: LambdaOpenApi::BodyProperty

Inherits:
Object
  • Object
show all
Defined in:
lib/lambda_open_api/body_property.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#propsObject

Returns the value of attribute props.



4
5
6
# File 'lib/lambda_open_api/body_property.rb', line 4

def props
  @props
end

Instance Method Details

#generate(hash) ⇒ Object



6
7
8
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
# File 'lib/lambda_open_api/body_property.rb', line 6

def generate(hash)
  @props = {}

  hash.each do |key, value|
    if value.is_a?(Hash)
      hash = LambdaOpenApi::BodyProperty.new
      hash.generate(value)

      props[key.to_s] = {
        "type"=>  "object",
        "properties"=> hash.props
      }
    elsif value.is_a?(Array)
      item_props = {}

      value.each do |item|
        hash = LambdaOpenApi::BodyProperty.new
        hash.generate(item)
        item_props.merge!(hash.props)
      end

      props[key.to_s] = {
        "type"=>  "array",
        "items"=> {
          "type" => "object",
          "properties" => item_props
        }
      }
    else
      props[key.to_s] = {
        "type"=>  value_type(value)
      }
    end
  end
end

#value_type(value) ⇒ Object



42
43
44
45
46
# File 'lib/lambda_open_api/body_property.rb', line 42

def value_type(value)
  klass = value.class.name.downcase
  return "boolean" if klass == "trueclass" || klass == "falseclass"
  klass
end