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.



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

def initialize(string)
  parse(string)
end

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



54
55
56
# File 'lib/swaggard/swagger/parameters/body.rb', line 54

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.



74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/swaggard/swagger/parameters/body.rb', line 74

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 = Parsers::Type.run(data_type)
  @required = required
  @options = options
end

#required?Boolean

Returns:

  • (Boolean)


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

def required?
  @required
end

#to_docObject



64
65
66
67
68
69
# File 'lib/swaggard/swagger/parameters/body.rb', line 64

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