Class: Raml::Body

Inherits:
PropertiesNode show all
Includes:
Global, Merge, Parent, Validation
Defined in:
lib/raml/node/body.rb

Constant Summary collapse

MEDIA_TYPE_RE =
%r{[a-z\d][-\w.+!#$&^]{0,63}/[a-z\d][-\w.+!#$&^]{0,63}(;.*)?}oi

Instance Attribute Summary collapse

Attributes included from Parent

#children

Attributes inherited from PropertiesNode

#optional

Attributes inherited from Node

#name, #parent

Instance Method Summary collapse

Methods included from Validation

#classes_to_s, #validate_array, #validate_hash, #validate_property, #validate_string

Methods included from Merge

#merge_properties

Methods included from Global

#default_media_type, #resource_type_declarations, #schema_declarations, #security_scheme_declarations, #trait_declarations

Methods inherited from PropertiesNode

#_regexp_property, #initialize, #non_scalar_properties, #scalar_properties

Methods inherited from Node

#initialize

Constructor Details

This class inherits a constructor from Raml::PropertiesNode

Instance Attribute Details

#exampleString?

Returns an example of a valid body.

Returns:

  • (String, nil)

    an example of a valid body.



# File 'lib/raml/node/body.rb', line 13

#form_parametersHash<String, Raml::Parameter::FormParameter> (readonly)

Returns the form parameters, keyed by the parameter name. Only valid for “application/x-www-form-urlencoded” and “multipart/form-data” media types.

Returns:

  • (Hash<String, Raml::Parameter::FormParameter>)

    the form parameters, keyed by the parameter name. Only valid for “application/x-www-form-urlencoded” and “multipart/form-data” media types.



# File 'lib/raml/node/body.rb', line 16

#media\_typeString (readonly)

Returns media type of the of body. An alias for #name.

Returns:

  • (String)

    media type of the of body. An alias for #name.



28
# File 'lib/raml/node/body.rb', line 28

scalar_property     :example

#schemaRaml::Schema? (readonly)

Returns the body’s schema. Only valid if the media type is not one of “application/x-www-form-urlencoded” or “multipart/form-data”.

Returns:

  • (Raml::Schema, nil)

    the body’s schema. Only valid if the media type is not one of “application/x-www-form-urlencoded” or “multipart/form-data”.



# File 'lib/raml/node/body.rb', line 21

Instance Method Details

#merge(other) ⇒ Object

Raises:



45
46
47
48
49
50
51
52
53
54
55
56
57
58
# 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?Boolean

Returns whether the body is a web form. Returns true for “application/x-www-form-urlencoded” and “multipart/form-data” media types.

Returns:

  • (Boolean)

    true if the body is a web form, false otherwise.



40
41
42
# File 'lib/raml/node/body.rb', line 40

def web_form?
  [ 'application/x-www-form-urlencoded', 'multipart/form-data' ].include? media_type
end