class Swaggard::Swagger::Parameters::List

Public Class Methods

new(string) click to toggle source
# File lib/swaggard/swagger/parameters/list.rb, line 7
def initialize(string)
  @in = 'query'
  parse(string)
end

Public Instance Methods

to_doc() click to toggle source
# File lib/swaggard/swagger/parameters/list.rb, line 12
def to_doc
  doc = super

  doc.merge(
    {
      'type'            => 'array',
      'items'           => { 'type' => @data_type },
      'enum'            => @list_values
    }
  )
end

Private Instance Methods

parse(string) click to toggle source

Example: [String] sort_order Orders ownerships by fields. (e.g. sort_order=created_at)

[List]      id
[List]      begin_at
[List]      end_at
[List]      created_at
# File lib/swaggard/swagger/parameters/list.rb, line 31
def parse(string)
  data_type, name, required, description, set_string = string.match(/\A\[(\w*)\]\s*(\w*)(\(required\))?\s*(.*)\n([.\s\S]*)\Z/).captures

  @list_values = set_string.split('[List]').map(&:strip).reject { |string| string.empty? }

  @name = name
  @description = description
  @data_type = data_type.downcase
  @is_required = required.present?
end