Class: SwaggerYard::Parameter
- Inherits:
-
Object
- Object
- SwaggerYard::Parameter
- Defined in:
- lib/swagger_yard/parameter.rb
Instance Attribute Summary collapse
-
#allow_multiple ⇒ Object
readonly
Returns the value of attribute allow_multiple.
-
#allowable_values ⇒ Object
readonly
Returns the value of attribute allowable_values.
-
#description ⇒ Object
Returns the value of attribute description.
-
#name ⇒ Object
Returns the value of attribute name.
-
#param_type ⇒ Object
readonly
Returns the value of attribute param_type.
-
#required ⇒ Object
readonly
Returns the value of attribute required.
Class Method Summary collapse
-
.from_path_param(name) ⇒ Object
TODO: support more variation in scope types.
- .from_yard_tag(tag, operation) ⇒ Object
Instance Method Summary collapse
- #allowable_values_hash ⇒ Object
-
#initialize(name, type, description, options = {}) ⇒ Parameter
constructor
A new instance of Parameter.
- #to_h ⇒ Object
- #type ⇒ Object
Constructor Details
#initialize(name, type, description, options = {}) ⇒ Parameter
Returns a new instance of Parameter.
35 36 37 38 39 40 41 42 |
# File 'lib/swagger_yard/parameter.rb', line 35 def initialize(name, type, description, ={}) @name, @type, @description = name, type, description @required = [:required] || false @param_type = [:param_type] || 'query' @allow_multiple = [:allow_multiple] || false @allowable_values = [:allowable_values] || [] end |
Instance Attribute Details
#allow_multiple ⇒ Object (readonly)
Returns the value of attribute allow_multiple.
4 5 6 |
# File 'lib/swagger_yard/parameter.rb', line 4 def allow_multiple @allow_multiple end |
#allowable_values ⇒ Object (readonly)
Returns the value of attribute allowable_values.
4 5 6 |
# File 'lib/swagger_yard/parameter.rb', line 4 def allowable_values @allowable_values end |
#description ⇒ Object
Returns the value of attribute description.
3 4 5 |
# File 'lib/swagger_yard/parameter.rb', line 3 def description @description end |
#name ⇒ Object
Returns the value of attribute name.
3 4 5 |
# File 'lib/swagger_yard/parameter.rb', line 3 def name @name end |
#param_type ⇒ Object (readonly)
Returns the value of attribute param_type.
4 5 6 |
# File 'lib/swagger_yard/parameter.rb', line 4 def param_type @param_type end |
#required ⇒ Object (readonly)
Returns the value of attribute required.
4 5 6 |
# File 'lib/swagger_yard/parameter.rb', line 4 def required @required end |
Class Method Details
.from_path_param(name) ⇒ Object
TODO: support more variation in scope types
27 28 29 30 31 32 33 |
# File 'lib/swagger_yard/parameter.rb', line 27 def self.from_path_param(name) new(name, Type.new("string"), "Scope response to #{name}", { required: true, allow_multiple: false, param_type: "path" }) end |
.from_yard_tag(tag, operation) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/swagger_yard/parameter.rb', line 6 def self.from_yard_tag(tag, operation) description = tag.text name, = tag.name.split(/[\(\)]/) type = Type.from_type_list(tag.types) = {} operation.model_names << type.name if type.ref? unless .nil? .split(',').map(&:strip).tap do |arr| [:required] = !arr.delete('required').nil? [:allow_multiple] = !arr.delete('multiple').nil? [:param_type] = arr.last end end new(name, type, description, ) end |
Instance Method Details
#allowable_values_hash ⇒ Object
48 49 50 51 52 53 54 55 |
# File 'lib/swagger_yard/parameter.rb', line 48 def allowable_values_hash return nil if allowable_values.empty? { "valueType" => "LIST", "values" => allowable_values } end |
#to_h ⇒ Object
57 58 59 60 61 62 63 64 65 66 |
# File 'lib/swagger_yard/parameter.rb', line 57 def to_h { "paramType" => param_type, "name" => name, "description" => description, "required" => required, "allowMultiple" => !!allow_multiple, "allowableValues" => allowable_values_hash }.merge(@type.to_h).reject {|k,v| v.nil?} end |
#type ⇒ Object
44 45 46 |
# File 'lib/swagger_yard/parameter.rb', line 44 def type @type.name end |