class Raml::Body

Constants

MEDIA_TYPE_RE

@private

Public Instance Methods

merge(other) click to toggle source

@private

Calls superclass method Raml::Merge#merge
# File lib/raml/node/body.rb, line 45
def merge(other)
  raise MergeError, "Media types don't match." if media_type != other.media_type

  super

  merge_properties other, :form_parameters

  if other.schema
    @children.delete_if { |c| [ Schema, SchemaReference ].include? c.class } if schema
    @children << other.schema
  end

  self
end
web_form?() click to toggle source

Returns whether the body is a web form. Returns true for “application/x-www-form-urlencoded” and “multipart/form-data” media types. @return [Boolean] true if the body is a web form, false otherwise.

# File lib/raml/node/body.rb, line 40
def web_form?
  [ 'application/x-www-form-urlencoded', 'multipart/form-data' ].include? media_type
end

Private Instance Methods

parse_form_parameters(value) click to toggle source
# File lib/raml/node/body.rb, line 70
def parse_form_parameters(value)
  validate_hash 'formParameters', value, String, Hash

  value.map do |name, form_parameter_data|
    Parameter::FormParameter.new name, form_parameter_data, self
  end
end
parse_schema(value) click to toggle source
# File lib/raml/node/body.rb, line 78
def parse_schema(value)
  validate_string :schema, value

  if schema_declarations.include? value
    SchemaReference.new value, self
  else
    Schema.new '_', value, self
  end
end
valid_media_type?() click to toggle source
# File lib/raml/node/body.rb, line 66
def valid_media_type?
   media_type =~ Body::MEDIA_TYPE_RE || media_type == '*/*'
end
validate() click to toggle source
# File lib/raml/node/body.rb, line 88
def validate
  if web_form?
    raise InvalidProperty, 'schema property can\'t be defined for web forms.' if schema
    raise RequiredPropertyMissing, 'formParameters property must be specified for web forms.' if
      form_parameters.empty?
  end
end
validate_name() click to toggle source
# File lib/raml/node/body.rb, line 62
def validate_name
  raise InvalidMediaType, 'body media type is invalid' unless valid_media_type?
end