Class: SwaggerYard::Parameter

Inherits:
Object
  • Object
show all
Defined in:
lib/swagger_yard/parameter.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, type, description, options = {}) ⇒ Parameter

Returns a new instance of Parameter.



37
38
39
40
41
42
43
44
# 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

Instance Attribute Details

#allow_multipleObject

Returns the value of attribute allow_multiple.



3
4
5
# File 'lib/swagger_yard/parameter.rb', line 3

def allow_multiple
  @allow_multiple
end

#descriptionObject

Returns the value of attribute description.



3
4
5
# File 'lib/swagger_yard/parameter.rb', line 3

def description
  @description
end

#nameObject

Returns the value of attribute name.



3
4
5
# File 'lib/swagger_yard/parameter.rb', line 3

def name
  @name
end

#param_typeObject

Returns the value of attribute param_type.



3
4
5
# File 'lib/swagger_yard/parameter.rb', line 3

def param_type
  @param_type
end

#requiredObject

Returns the value of attribute required.



3
4
5
# File 'lib/swagger_yard/parameter.rb', line 3

def required
  @required
end

#typeObject

Returns the value of attribute type.



3
4
5
# File 'lib/swagger_yard/parameter.rb', line 3

def type
  @type
end

Class Method Details

.from_path_param(name) ⇒ Object

TODO: support more variation in scope types



28
29
30
31
32
33
34
35
# 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) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# 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

Instance Method Details

#from_path?Boolean

Returns:

  • (Boolean)


46
47
48
# File 'lib/swagger_yard/parameter.rb', line 46

def from_path?
  @from_path
end