Class: OpenApi::DSL::ExampleObj

Inherits:
Hash
  • Object
show all
Includes:
Helpers
Defined in:
lib/oas_objs/example_obj.rb

Overview

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Helpers

#_combined_schema, #arrow_writing_support, #process_schema_input

Constructor Details

#initialize(exp, keys_of_value = nil, multiple: false) ⇒ ExampleObj

Returns a new instance of ExampleObj.



14
15
16
17
# File 'lib/oas_objs/example_obj.rb', line 14

def initialize(exp, keys_of_value = nil, multiple: false)
  multiple ? self.examples_hash = exp : self.example_value = exp
  self.keys_of_value = keys_of_value
end

Instance Attribute Details

#example_valueObject

Returns the value of attribute example_value.



12
13
14
# File 'lib/oas_objs/example_obj.rb', line 12

def example_value
  @example_value
end

#examples_hashObject

Returns the value of attribute examples_hash.



12
13
14
# File 'lib/oas_objs/example_obj.rb', line 12

def examples_hash
  @examples_hash
end

#keys_of_valueObject

Returns the value of attribute keys_of_value.



12
13
14
# File 'lib/oas_objs/example_obj.rb', line 12

def keys_of_value
  @keys_of_value
end

Instance Method Details

#processObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/oas_objs/example_obj.rb', line 19

def process
  return example_value if example_value
  return unless examples_hash

  examples_hash.map do |(name, value)|
    value =
        if keys_of_value.present? && value.is_a?(Array)
          { value: Hash[keys_of_value.zip(value)] }
        elsif value.is_a?(Symbol) && value['$']
          RefObj.new(value.to_s.delete('$'), :example).process
        else
          { value: value }
        end

    { name => value }
  end
end