class Raml::Root
RAML root node. Its parent is itself.
Public Class Methods
new(root_data)
click to toggle source
Calls superclass method
Raml::PropertiesNode::new
# File lib/raml/node/root.rb, line 76 def initialize(root_data) super nil, root_data, self end
Public Instance Methods
expand()
click to toggle source
Applies resource types and traits, and inlines schemas. It should be called before documentation is generated.
# File lib/raml/node/root.rb, line 82 def expand unless @expanded resources.values.each(&:apply_resource_type) resources.values.each(&:apply_traits) inline_reference SchemaReference, schemas, @children @expanded = true end end
resource_path()
click to toggle source
@private
# File lib/raml/node/root.rb, line 92 def resource_path '' end
Private Instance Methods
_validate_base_uri()
click to toggle source
# File lib/raml/node/root.rb, line 109 def _validate_base_uri validate_string :base_uri, base_uri # Check whether its a URL. uri = parse_uri base_uri # If the parser doesn't think its a URL or the URL is not for HTTP or HTTPS, # try to parse it as a URL template. if uri.nil? and not uri.kind_of? URI::HTTP template = parse_template # The template parser did not complain, but does it generate valid URLs? uri = template.expand Hash[ template.variables.map {|var| [ var, 'a'] } ] uri = parse_uri uri raise InvalidProperty, 'baseUri property is not a URL or a URL template.' unless uri and uri.kind_of? URI::HTTP raise RequiredPropertyMissing, 'version property is required when baseUri template has version parameter' if template.variables.include? 'version' and version.nil? end end
inline_reference(reference_type, map, nodes)
click to toggle source
# File lib/raml/node/root.rb, line 243 def inline_reference(reference_type, map, nodes) nodes.map! do |node| if node.is_a? reference_type map[node.name] else inline_reference reference_type, map, node.children if node.respond_to? :children node end end end
parse_base_uri_parameters(base_uri_parameters)
click to toggle source
# File lib/raml/node/root.rb, line 165 def parse_base_uri_parameters(base_uri_parameters) validate_hash :base_uri_parameters, base_uri_parameters, String, Hash raise InvalidProperty, 'baseUriParameters property can\'t contain reserved "version" parameter' if base_uri_parameters.include? 'version' base_uri_parameters.map { |name, data| Parameter::BaseUriParameter.new name, data, self } end
parse_documentation(documentation)
click to toggle source
# File lib/raml/node/root.rb, line 174 def parse_documentation(documentation) validate_array :documentation, documentation raise InvalidProperty, 'documentation property must include at least one document or not be included' if documentation.empty? documentation.map { |doc| doc = doc.dup; Documentation.new doc.delete("title"), doc, self } end
parse_resource_types(types)
click to toggle source
# File lib/raml/node/root.rb, line 199 def parse_resource_types(types) validate_array :resource_types, types, Hash raise InvalidProperty, 'resourceTypes property must be an array of maps with string keys' unless types.all? {|t| t.keys.all? {|k| k.is_a? String }} raise InvalidProperty, 'resourceTypes property must be an array of maps with map values' unless types.all? {|t| t.values.all? {|v| v.is_a? Hash }} raise InvalidProperty, 'resourceTypes property contains duplicate type names' unless types.map(&:keys).flatten.uniq!.nil? types.reduce({}) { |memo, map | memo.merge! map }. map { |name, data| ResourceType.new name, data, self } end
parse_schemas(schemas)
click to toggle source
# File lib/raml/node/root.rb, line 149 def parse_schemas(schemas) validate_array :schemas, schemas, Hash raise InvalidProperty, 'schemas property must be an array of maps with string keys' unless schemas.all? {|s| s.keys.all? {|k| k.is_a? String }} raise InvalidProperty, 'schemas property must be an array of maps with string values' unless schemas.all? {|s| s.values.all? {|v| v.is_a? String }} raise InvalidProperty, 'schemas property contains duplicate schema names' unless schemas.map(&:keys).flatten.uniq!.nil? schemas.reduce({}) { |memo, map | memo.merge! map }. map { |name, data| Schema.new name, data, self } end
parse_security_schemes(data)
click to toggle source
# File lib/raml/node/root.rb, line 183 def parse_security_schemes(data) validate_array :security_schemes, data, Hash raise InvalidProperty, 'securitySchemes property must be an array of maps with string keys' unless data.all? {|t| t.keys.all? {|k| k.is_a? String }} raise InvalidProperty, 'securitySchemes property must be an array of maps with map values' unless data.all? {|t| t.values.all? {|v| v.is_a? Hash }} raise InvalidProperty, 'securitySchemes property contains duplicate type names' unless data.map(&:keys).flatten.uniq!.nil? data.reduce({}) { |memo, map | memo.merge! map }. map { |name, data| SecurityScheme.new name, data, self } end
parse_template()
click to toggle source
# File lib/raml/node/root.rb, line 237 def parse_template URITemplate::RFC6570.new base_uri rescue URITemplate::RFC6570::Invalid raise InvalidProperty, 'baseUri property is not a URL or a URL template.' end
parse_traits(traits)
click to toggle source
# File lib/raml/node/root.rb, line 215 def parse_traits(traits) validate_array :traits, traits, Hash raise InvalidProperty, 'traits property must be an array of maps with string keys' unless traits.all? {|t| t.keys.all? {|k| k.is_a? String }} raise InvalidProperty, 'traits property must be an array of maps with map values' unless traits.all? {|t| t.values.all? {|v| v.is_a? Hash }} raise InvalidProperty, 'traits property contains duplicate trait names' unless traits.map(&:keys).flatten.uniq!.nil? traits.reduce({}) { |memo, map | memo.merge! map }. map { |name, data| Trait.new name, data, self } end
parse_uri(uri)
click to toggle source
# File lib/raml/node/root.rb, line 231 def parse_uri(uri) URI.parse uri rescue URI::InvalidURIError nil end
validate()
click to toggle source
# File lib/raml/node/root.rb, line 98 def validate raise RequiredPropertyMissing, 'Missing root title property.' if title.nil? raise RequiredPropertyMissing, 'Missing root baseUri property' if base_uri.nil? _validate_base_uri _validate_secured_by end
validate_media_type()
click to toggle source
# File lib/raml/node/root.rb, line 142 def validate_media_type if media_type validate_string :media_type, media_type raise InvalidProperty, 'mediaType property is malformed' unless media_type =~ Body::MEDIA_TYPE_RE end end
validate_protocols()
click to toggle source
# File lib/raml/node/root.rb, line 131 def validate_protocols if protocols validate_array :protocols, protocols, String @protocols.map!(&:upcase) raise InvalidProperty, 'protocols property elements must be HTTP or HTTPS' unless protocols.all? { |p| [ 'HTTP', 'HTTPS'].include? p } end end
validate_title()
click to toggle source
# File lib/raml/node/root.rb, line 105 def validate_title validate_string :title, title end