Class: Swaggard::Swagger::Parameters::Body::Property

Inherits:
Object
  • Object
show all
Defined in:
lib/swaggard/swagger/parameters/body.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(string) ⇒ Property

Returns a new instance of Property.



59
60
61
# File 'lib/swaggard/swagger/parameters/body.rb', line 59

def initialize(string)
  parse(string)
end

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



57
58
59
# File 'lib/swaggard/swagger/parameters/body.rb', line 57

def id
  @id
end

Instance Method Details

#parse(string) ⇒ Object

Example: [Array] status Filter by status. (e.g. status[]=1&status=2&status[]=3) Example: [Array] status(required) Filter by status. (e.g. status[]=1&status=2&status[]=3) Example: [Integer] media ID of the desired media type.



77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/swaggard/swagger/parameters/body.rb', line 77

def parse(string)
  string.gsub!("\n", ' ')
  data_type, required, name, options_and_description = string.match(/\A\[(\S*)\](!)?\s*([\w\[\]]*)\s*(.*)\Z/).captures
  allow_multiple = name.gsub!('[]', '')
  options, description = options_and_description.match(/\A(\[.*\])?(.*)\Z/).captures
  options = options ? options.gsub(/\[?\]?\s?/, '').split(',') : []

  @id = name
  @description = description if description.present?
  @type = Type.new([data_type])
  @required = required
  @options = options
end

#required?Boolean

Returns:

  • (Boolean)


63
64
65
# File 'lib/swaggard/swagger/parameters/body.rb', line 63

def required?
  @required
end

#to_docObject



67
68
69
70
71
72
# File 'lib/swaggard/swagger/parameters/body.rb', line 67

def to_doc
  result = @type.to_doc
  result['description'] = @description if @description
  result['enum'] = @options if @options.present?
  result
end