class SwaggerYard::Parameter

Attributes

allow_multiple[RW]
description[RW]
name[RW]
param_type[RW]
required[RW]
type[RW]

Public Class Methods

from_path_param(name) click to toggle source

TODO: support more variation in scope types

# File lib/swagger_yard/parameter.rb, line 28
def self.from_path_param(name)
  new(name, Type.new("string"), "Scope response to #{name}", {
    required: true,
    allow_multiple: false,
    param_type: "path",
    from_path: true
  })
end
from_yard_tag(tag) click to toggle source
# File lib/swagger_yard/parameter.rb, line 5
def self.from_yard_tag(tag)
  tag = SwaggerYard.requires_name_and_type(tag)
  return nil unless tag

  name, options_string = tag.name.split(/[\(\)]/)
  description = tag.text
  description = name if description.nil? || description.strip.empty?
  type = Type.from_type_list(tag.types)

  options = {}

  unless options_string.nil?
    options_string.split(',').map(&:strip).tap do |arr|
      options[:required] = !arr.delete('required').nil?
      options[:allow_multiple] = !arr.delete('multiple').nil?
      options[:param_type] = arr.last
    end
  end

  new(name, type, description, options)
end
new(name, type, description, options={}) click to toggle source
# File lib/swagger_yard/parameter.rb, line 37
def initialize(name, type, description, options={})
  @name, @type, @description = name, type, description

  @required = options[:required] || false
  @param_type = options[:param_type] || 'query'
  @allow_multiple = options[:allow_multiple] || false
  @from_path      = options[:from_path] || false
end

Public Instance Methods

from_path?() click to toggle source
# File lib/swagger_yard/parameter.rb, line 46
def from_path?
  @from_path
end