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?

Instance Method Details

#as_jsonObject



610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
# File 'lib/swagger/blocks.rb', line 610

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



633
634
635
# File 'lib/swagger/blocks.rb', line 633

def data
  @data ||= []
end

#key(key, value) ⇒ Object

Raises:



637
638
639
# File 'lib/swagger/blocks.rb', line 637

def key(key, value)
  raise NotSupportedError
end

#schema(&block) ⇒ Object



641
642
643
# File 'lib/swagger/blocks.rb', line 641

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