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



601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
# File 'lib/swagger/blocks.rb', line 601

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



624
625
626
# File 'lib/swagger/blocks.rb', line 624

def data
  @data ||= []
end

#key(key, value) ⇒ Object

Raises:



628
629
630
# File 'lib/swagger/blocks.rb', line 628

def key(key, value)
  raise NotSupportedError
end

#schema(&block) ⇒ Object



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

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