Class: Sinatra::SwaggerExposer::SwaggerInfo
- Inherits:
-
Object
- Object
- Sinatra::SwaggerExposer::SwaggerInfo
- Includes:
- SwaggerUtilities
- Defined in:
- lib/sinatra/swagger-exposer/swagger-info.rb
Overview
The info declaration
Constant Summary collapse
- INFO_FIELDS =
Known fields for the info field
{ :version => String, :title => String, :description => String, :termsOfService => String, :contact => {:name => String, :email => String, :url => String}, :license => {:name => String, :url => String}, }
Constants included from SwaggerParameterHelper
Sinatra::SwaggerExposer::SwaggerParameterHelper::HOW_TO_PASS, Sinatra::SwaggerExposer::SwaggerParameterHelper::HOW_TO_PASS_BODY, Sinatra::SwaggerExposer::SwaggerParameterHelper::HOW_TO_PASS_HEADER, Sinatra::SwaggerExposer::SwaggerParameterHelper::HOW_TO_PASS_PATH, Sinatra::SwaggerExposer::SwaggerParameterHelper::HOW_TO_PASS_QUERY, Sinatra::SwaggerExposer::SwaggerParameterHelper::PARAMS_DEFAULT, Sinatra::SwaggerExposer::SwaggerParameterHelper::PARAMS_EXAMPLE, Sinatra::SwaggerExposer::SwaggerParameterHelper::PARAMS_EXCLUSIVE_MAXIMUM, Sinatra::SwaggerExposer::SwaggerParameterHelper::PARAMS_EXCLUSIVE_MINIMUM, Sinatra::SwaggerExposer::SwaggerParameterHelper::PARAMS_FORMAT, Sinatra::SwaggerExposer::SwaggerParameterHelper::PARAMS_LIST, Sinatra::SwaggerExposer::SwaggerParameterHelper::PARAMS_MAXIMUM, Sinatra::SwaggerExposer::SwaggerParameterHelper::PARAMS_MAX_LENGTH, Sinatra::SwaggerExposer::SwaggerParameterHelper::PARAMS_MINIMUM, Sinatra::SwaggerExposer::SwaggerParameterHelper::PARAMS_MIN_LENGTH, Sinatra::SwaggerExposer::SwaggerParameterHelper::PRIMITIVE_TYPES, Sinatra::SwaggerExposer::SwaggerParameterHelper::PRIMITIVE_TYPES_FOR_NON_BODY, Sinatra::SwaggerExposer::SwaggerParameterHelper::TYPE_BOOLEAN, Sinatra::SwaggerExposer::SwaggerParameterHelper::TYPE_BYTE, Sinatra::SwaggerExposer::SwaggerParameterHelper::TYPE_DATE, Sinatra::SwaggerExposer::SwaggerParameterHelper::TYPE_DATE_TIME, Sinatra::SwaggerExposer::SwaggerParameterHelper::TYPE_DOUBLE, Sinatra::SwaggerExposer::SwaggerParameterHelper::TYPE_FILE, Sinatra::SwaggerExposer::SwaggerParameterHelper::TYPE_FLOAT, Sinatra::SwaggerExposer::SwaggerParameterHelper::TYPE_INTEGER, Sinatra::SwaggerExposer::SwaggerParameterHelper::TYPE_LONG, Sinatra::SwaggerExposer::SwaggerParameterHelper::TYPE_NUMBER, Sinatra::SwaggerExposer::SwaggerParameterHelper::TYPE_PASSWORD, Sinatra::SwaggerExposer::SwaggerParameterHelper::TYPE_STRING
Instance Method Summary collapse
-
#initialize(values) ⇒ SwaggerInfo
constructor
A new instance of SwaggerInfo.
-
#process(current_hash, current_field_name, current_fields, top_level_hash) ⇒ Object
Recursive function.
- #to_s ⇒ Object
- #to_swagger ⇒ Object
Methods included from SwaggerUtilities
#get_type, #hash_to_swagger, #list_or_none, #ref_to_type, #type_to_s, #white_list_params
Constructor Details
#initialize(values) ⇒ SwaggerInfo
Returns a new instance of SwaggerInfo.
13 14 15 |
# File 'lib/sinatra/swagger-exposer/swagger-info.rb', line 13 def initialize(values) @values = process(values, 'info', INFO_FIELDS, values) end |
Instance Method Details
#process(current_hash, current_field_name, current_fields, top_level_hash) ⇒ Object
Recursive function
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/swagger-info.rb', line 28 def process(current_hash, current_field_name, current_fields, top_level_hash) result = {} current_hash.each_pair do |current_key, current_value| key_sym = current_key.to_sym if current_fields.key? key_sym field_content = current_fields[key_sym] if field_content == String if current_value.is_a? String result[key_sym] = current_value else raise SwaggerInvalidException.new("Property [#{current_key}] value [#{current_value}] should be a String for #{current_field_name}: #{top_level_hash}") end else if current_value.is_a? Hash sub_params = process(current_value, current_field_name, field_content, top_level_hash) if sub_params result[key_sym] = sub_params end else raise SwaggerInvalidException.new("Property [#{current_key}] value [#{current_value}] should be a Hash for #{current_field_name}: #{top_level_hash}") end end else raise SwaggerInvalidException.new("Unknown property [#{current_key}] for #{current_field_name}#{list_or_none(current_fields.keys, 'values')}") end end result.empty? ? nil : result end |
#to_s ⇒ Object
63 64 65 |
# File 'lib/sinatra/swagger-exposer/swagger-info.rb', line 63 def to_s @values.to_json end |
#to_swagger ⇒ Object
59 60 61 |
# File 'lib/sinatra/swagger-exposer/swagger-info.rb', line 59 def to_swagger @values end |