Module: Swaggard::Parsers::Property

Defined in:
lib/swaggard/parsers/property.rb

Class Method Summary collapse

Class Method Details

.run(yard_object) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/swaggard/parsers/property.rb', line 6

def self.run(yard_object)
  name = yard_object.name.dup
  options_and_description = yard_object.text&.dup || ''

  options_and_description.gsub!("\n", ' ')
  options, description = options_and_description.match(/\A(\[.*\])?(.*)\Z/).captures
  options = options ? options.gsub(/\[?\]?\s?/, '').split(',') : []
  description = description.strip
  required = name.gsub!(/^!/, '')
  type = Parsers::Type.run(yard_object.types.first)

  Swaggard::Swagger::Property.new(name, type, description, required.present?, options)
end