Class: Sinatra::SwaggerExposer::Configuration::SwaggerEndpointParameter
- Inherits:
-
Object
- Object
- Sinatra::SwaggerExposer::Configuration::SwaggerEndpointParameter
- Defined in:
- lib/sinatra/swagger-exposer/configuration/swagger-endpoint-parameter.rb
Constant Summary
Constants included from SwaggerParameterHelper
SwaggerParameterHelper::HOW_TO_PASS, SwaggerParameterHelper::HOW_TO_PASS_BODY, SwaggerParameterHelper::HOW_TO_PASS_HEADER, SwaggerParameterHelper::HOW_TO_PASS_PATH, SwaggerParameterHelper::HOW_TO_PASS_QUERY, SwaggerParameterHelper::PARAMS_DEFAULT, SwaggerParameterHelper::PARAMS_EXAMPLE, SwaggerParameterHelper::PARAMS_EXCLUSIVE_MAXIMUM, SwaggerParameterHelper::PARAMS_EXCLUSIVE_MINIMUM, SwaggerParameterHelper::PARAMS_FORMAT, SwaggerParameterHelper::PARAMS_LIST, SwaggerParameterHelper::PARAMS_MAXIMUM, SwaggerParameterHelper::PARAMS_MAX_LENGTH, SwaggerParameterHelper::PARAMS_MINIMUM, SwaggerParameterHelper::PARAMS_MIN_LENGTH, SwaggerParameterHelper::PRIMITIVE_TYPES, SwaggerParameterHelper::PRIMITIVE_TYPES_FOR_NON_BODY, SwaggerParameterHelper::TYPE_ARRAY, SwaggerParameterHelper::TYPE_BOOLEAN, SwaggerParameterHelper::TYPE_BYTE, SwaggerParameterHelper::TYPE_DATE, SwaggerParameterHelper::TYPE_DATE_TIME, SwaggerParameterHelper::TYPE_DOUBLE, SwaggerParameterHelper::TYPE_FILE, SwaggerParameterHelper::TYPE_FLOAT, SwaggerParameterHelper::TYPE_INTEGER, SwaggerParameterHelper::TYPE_LONG, SwaggerParameterHelper::TYPE_NUMBER, SwaggerParameterHelper::TYPE_PASSWORD, SwaggerParameterHelper::TYPE_STRING
Instance Attribute Summary collapse
-
#default ⇒ Object
readonly
Returns the value of attribute default.
-
#how_to_pass ⇒ Object
readonly
Returns the value of attribute how_to_pass.
-
#items ⇒ Object
readonly
Returns the value of attribute items.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#params ⇒ Object
readonly
Returns the value of attribute params.
-
#required ⇒ Object
readonly
Returns the value of attribute required.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
-
#initialize(name, description, how_to_pass, required, type, params, known_types) ⇒ SwaggerEndpointParameter
constructor
Create a new instance.
- #to_s ⇒ Object
-
#to_swagger ⇒ Hash
Return the swagger version.
Methods included from SwaggerParameterValidationHelper
#check_boolean, #validate_length_parameter, #validate_length_parameters, #validate_limit_parameter, #validate_limit_parameters, #validate_params
Methods included from SwaggerConfigurationUtilities
#check_name, #get_type, #hash_to_swagger, #list_or_none, #ref_to_type, #type_to_s, #white_list_params
Constructor Details
#initialize(name, description, how_to_pass, required, type, params, known_types) ⇒ SwaggerEndpointParameter
Create a new instance
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/sinatra/swagger-exposer/configuration/swagger-endpoint-parameter.rb', line 28 def initialize(name, description, how_to_pass, required, type, params, known_types) check_name(name) @name = name if description @description = description end how_to_pass = how_to_pass.to_s unless HOW_TO_PASS.include? how_to_pass raise SwaggerInvalidException.new("Unknown how to pass value [#{how_to_pass}]#{list_or_none(HOW_TO_PASS, 'registered types')}") end @how_to_pass = how_to_pass if @how_to_pass == HOW_TO_PASS_BODY get_type(type, PRIMITIVE_TYPES + known_types) else get_type(type, PRIMITIVE_TYPES_FOR_NON_BODY) end unless [true, false].include? required raise SwaggerInvalidException.new("Required should be a boolean instead of [#{required}]") end @required = required params = white_list_params(params, PARAMS_LIST, SwaggerTypeProperty::PROPERTIES) validate_params(@type == TYPE_ARRAY ? @items : @type, params) @default = params[PARAMS_DEFAULT] @params = params end |
Instance Attribute Details
#default ⇒ Object (readonly)
Returns the value of attribute default.
18 19 20 |
# File 'lib/sinatra/swagger-exposer/configuration/swagger-endpoint-parameter.rb', line 18 def default @default end |
#how_to_pass ⇒ Object (readonly)
Returns the value of attribute how_to_pass.
18 19 20 |
# File 'lib/sinatra/swagger-exposer/configuration/swagger-endpoint-parameter.rb', line 18 def how_to_pass @how_to_pass end |
#items ⇒ Object (readonly)
Returns the value of attribute items.
18 19 20 |
# File 'lib/sinatra/swagger-exposer/configuration/swagger-endpoint-parameter.rb', line 18 def items @items end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
18 19 20 |
# File 'lib/sinatra/swagger-exposer/configuration/swagger-endpoint-parameter.rb', line 18 def name @name end |
#params ⇒ Object (readonly)
Returns the value of attribute params.
18 19 20 |
# File 'lib/sinatra/swagger-exposer/configuration/swagger-endpoint-parameter.rb', line 18 def params @params end |
#required ⇒ Object (readonly)
Returns the value of attribute required.
18 19 20 |
# File 'lib/sinatra/swagger-exposer/configuration/swagger-endpoint-parameter.rb', line 18 def required @required end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
18 19 20 |
# File 'lib/sinatra/swagger-exposer/configuration/swagger-endpoint-parameter.rb', line 18 def type @type end |
Instance Method Details
#to_s ⇒ Object
98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/sinatra/swagger-exposer/configuration/swagger-endpoint-parameter.rb', line 98 def to_s { :name => @name, :in => @how_to_pass, :required => @required, :type => @type, :items => @items, :description => @description, :params => @params, }.to_json end |
#to_swagger ⇒ Hash
Return the swagger version
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/sinatra/swagger-exposer/configuration/swagger-endpoint-parameter.rb', line 62 def to_swagger result = { :name => @name, :in => @how_to_pass, :required => @required } if @type if @type == TYPE_ARRAY result[:type] = TYPE_ARRAY if @items if PRIMITIVE_TYPES.include? @items result[:items] = {:type => @items} else result[:schema] = ref_to_type(@items) end end else if PRIMITIVE_TYPES.include? @type result[:type] = @type else result[:schema] = ref_to_type(@type) end end end if @description result[:description] = @description end unless @params.empty? result.merge!(@params) end result end |