Class: Swagger::Blocks::Node
- Inherits:
-
Object
- Object
- Swagger::Blocks::Node
show all
- Defined in:
- lib/swagger/blocks/node.rb
Overview
Base node for representing every object in the Swagger DSL.
Direct Known Subclasses
Swagger::Blocks::Nodes::AllOfNode, Swagger::Blocks::Nodes::ContactNode, Swagger::Blocks::Nodes::ExampleNode, Swagger::Blocks::Nodes::ExternalDocsNode, Swagger::Blocks::Nodes::HeaderNode, Swagger::Blocks::Nodes::InfoNode, Swagger::Blocks::Nodes::ItemsNode, Swagger::Blocks::Nodes::LicenseNode, Swagger::Blocks::Nodes::OperationNode, Swagger::Blocks::Nodes::ParameterNode, Swagger::Blocks::Nodes::PathNode, Swagger::Blocks::Nodes::PropertiesNode, Swagger::Blocks::Nodes::PropertyNode, Swagger::Blocks::Nodes::ResponseNode, Swagger::Blocks::Nodes::RootNode, Swagger::Blocks::Nodes::SchemaNode, Swagger::Blocks::Nodes::ScopesNode, Swagger::Blocks::Nodes::SecurityRequirementNode, Swagger::Blocks::Nodes::SecuritySchemeNode, Swagger::Blocks::Nodes::TagNode, Swagger::Blocks::Nodes::XmlNode
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name.
5
6
7
|
# File 'lib/swagger/blocks/node.rb', line 5
def name
@name
end
|
#version ⇒ Object
53
54
55
56
57
|
# File 'lib/swagger/blocks/node.rb', line 53
def version
return @version if instance_variable_defined?('@version') && @version
return '2.0' if data.has_key?(:swagger) && data[:swagger] == '2.0'
raise DeclarationError, "You must specify swagger '2.0'"
end
|
Class Method Details
.call(options = {}, &block) ⇒ Object
8
9
10
11
12
13
14
15
16
|
# File 'lib/swagger/blocks/node.rb', line 8
def self.call(options = {}, &block)
instance = new
instance.name = options[:name] if options[:name]
instance.version = options[:version]
instance.keys options[:inline_keys]
instance.instance_eval(&block) if block
instance
end
|
Instance Method Details
#as_json ⇒ Object
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
# File 'lib/swagger/blocks/node.rb', line 18
def as_json
result = {}
self.data.each do |key, value|
if value.is_a?(Node)
result[key] = value.as_json
elsif value.is_a?(Array)
result[key] = []
value.each { |v| result[key] << (v.respond_to?(:as_json) ? v.as_json : v) }
elsif is_swagger_2_0? && value.is_a?(Hash)
result[key] = {}
value.each_pair {|k, v| result[key][k] = (v.respond_to?(:as_json) ? v.as_json : v) }
elsif is_swagger_2_0? && key.to_s.eql?('$ref') && (value.to_s !~ %r{^#/|https?://})
result[key] = "#/definitions/#{value}"
else
result[key] = value
end
end
return result if !name
{name => result}
end
|
#data ⇒ Object
41
42
43
|
# File 'lib/swagger/blocks/node.rb', line 41
def data
@data ||= {}
end
|
#is_swagger_2_0? ⇒ Boolean
59
60
61
|
# File 'lib/swagger/blocks/node.rb', line 59
def is_swagger_2_0?
version == '2.0'
end
|
#key(key, value) ⇒ Object
49
50
51
|
# File 'lib/swagger/blocks/node.rb', line 49
def key(key, value)
self.data[key] = value
end
|
#keys(data) ⇒ Object
45
46
47
|
# File 'lib/swagger/blocks/node.rb', line 45
def keys(data)
self.data.merge!(data) if data
end
|