Class: Swagger::Blocks::Nodes::AllOfNode

Inherits:
Swagger::Blocks::Node show all
Defined in:
lib/swagger/blocks/nodes/all_of_node.rb

Constant Summary

Constants inherited from Swagger::Blocks::Node

Swagger::Blocks::Node::VERSION_2, Swagger::Blocks::Node::VERSION_3

Instance Attribute Summary

Attributes inherited from Swagger::Blocks::Node

#name, #version

Instance Method Summary collapse

Methods inherited from Swagger::Blocks::Node

call, #is_openapi_3_0?, #is_swagger_2_0?, #keys, #ref?, #static_ref?, #value_as_json

Instance Method Details

#as_json(options = {}) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/swagger/blocks/nodes/all_of_node.rb', line 5

def as_json(options = {})
  version = options.fetch(:version, '2.0')
  result = []

  self.data.each do |value|
    if value.is_a?(Node)
      result << value.as_json(version: version)
    elsif value.is_a?(Array)
      r = []
      value.each { |v| r << value_as_json(v, version) }
      result << r
    elsif (is_swagger_2_0? || is_openapi_3_0?) && value.is_a?(Hash)
      r = {}
      value.each_pair {|k, v| r[k] = value_as_json(v, version) }
      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



29
30
31
# File 'lib/swagger/blocks/nodes/all_of_node.rb', line 29

def data
  @data ||= []
end

#key(key, value) ⇒ Object

Raises:



33
34
35
# File 'lib/swagger/blocks/nodes/all_of_node.rb', line 33

def key(key, value)
  raise NotSupportedError
end

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



37
38
39
# File 'lib/swagger/blocks/nodes/all_of_node.rb', line 37

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