Class: Swagger::Blocks::AllOfNode

Inherits:
Node
  • Object
show all
Defined in:
lib/swagger/blocks.rb

Instance Attribute Summary

Attributes inherited from Node

#name, #version

Instance Method Summary collapse

Methods inherited from Node

call, #is_swagger_1_2?, #is_swagger_2_0?, #keys

Instance Method Details

#as_jsonObject



624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
# File 'lib/swagger/blocks.rb', line 624

def as_json
  result = []

  self.data.each do |value|
    if value.is_a?(Node)
      result << value.as_json
    elsif value.is_a?(Array)
      r = []
      value.each { |v| r << (v.respond_to?(:as_json) ? v.as_json : v) }
      result << r
    elsif is_swagger_2_0? && value.is_a?(Hash)
      r = {}
      value.each_pair {|k, v| r[k] = (v.respond_to?(:as_json) ? v.as_json : v) }
      result << r
    else
      result = value
    end
  end
  return result if !name
  # If 'name' is given to this node, wrap the data with a root element with the given name.
  {name => result}
end

#dataObject



647
648
649
# File 'lib/swagger/blocks.rb', line 647

def data
  @data ||= []
end

#key(key, value) ⇒ Object

Raises:



651
652
653
# File 'lib/swagger/blocks.rb', line 651

def key(key, value)
  raise NotSupportedError
end

#schema(inline_keys = nil, &block) ⇒ Object



655
656
657
# File 'lib/swagger/blocks.rb', line 655

def schema(inline_keys = nil, &block)
  data << Swagger::Blocks::SchemaNode.call(version: version, inline_keys: inline_keys, &block)
end