Module: Sinatra::SwaggerExposer::SwaggerUtilities
- Included in:
- SwaggerContentCreator, SwaggerEndpoint, SwaggerEndpointParameter, SwaggerEndpointResponse, SwaggerType, SwaggerTypeProperty
- Defined in:
- lib/sinatra/swagger-exposer/swagger-utilities.rb
Constant Summary collapse
- PRIMITIVE_TYPES =
[ 'integer', 'long', 'float', 'double', 'string', 'byte', 'boolean', 'date', 'dateTime', 'password' ]
Instance Method Summary collapse
- #get_type(type, possible_values) ⇒ Object
- #hash_to_swagger(hash) ⇒ Object
- #type_to_s(value) ⇒ Object
- #white_list_params(params, allowed_params) ⇒ Object
Instance Method Details
#get_type(type, possible_values) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/sinatra/swagger-exposer/swagger-utilities.rb', line 38 def get_type(type, possible_values) @type = type if type.nil? raise SwaggerInvalidException.new('Type is nil') elsif type.is_a?(String) || @type.is_a?(Class) @type = type_to_s(@type) check_type(@type, possible_values) elsif @type.is_a? Array @items = type_to_s(get_array_type(@type)) check_type(@items, possible_values) @type = 'array' else raise SwaggerInvalidException.new("Type [#{@type}] of has an unknown type, should be a class, a string or an array") end end |
#hash_to_swagger(hash) ⇒ Object
22 23 24 25 26 27 28 |
# File 'lib/sinatra/swagger-exposer/swagger-utilities.rb', line 22 def hash_to_swagger(hash) result = {} hash.each_pair do |key, value| result[key] = value.to_swagger end result end |
#type_to_s(value) ⇒ Object
30 31 32 33 34 35 36 |
# File 'lib/sinatra/swagger-exposer/swagger-utilities.rb', line 30 def type_to_s(value) if value.is_a? Class value.to_s.downcase else value end end |
#white_list_params(params, allowed_params) ⇒ Object
54 55 56 57 58 59 60 |
# File 'lib/sinatra/swagger-exposer/swagger-utilities.rb', line 54 def white_list_params(params, allowed_params) params.each_pair do |key, value| unless allowed_params.include? key raise SwaggerInvalidException.new("Unknown property [#{key}] for with value [#{value}], known properties are #{allowed_params.join(', ')}") end end end |