Class: Sinatra::SwaggerExposer::SwaggerTypeProperty
- Inherits:
-
Object
- Object
- Sinatra::SwaggerExposer::SwaggerTypeProperty
- Includes:
- SwaggerUtilities
- Defined in:
- lib/sinatra/swagger-exposer/swagger-type-property.rb
Overview
A property of a type
Constant Summary collapse
- OTHER_PROPERTIES =
[:example, :description, :format, :minLength, :maxLength]
- PROPERTIES =
[:type] + OTHER_PROPERTIES
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(type_name, property_name, property_properties, known_types) ⇒ SwaggerTypeProperty
constructor
A new instance of SwaggerTypeProperty.
- #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(type_name, property_name, property_properties, known_types) ⇒ SwaggerTypeProperty
Returns a new instance of SwaggerTypeProperty.
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/sinatra/swagger-exposer/swagger-type-property.rb', line 16 def initialize(type_name, property_name, property_properties, known_types) @name = property_name unless property_properties.is_a? Hash raise SwaggerInvalidException.new("Property [#{property_name}] value [#{property_properties}] of [#{type_name}] should be a hash") end if property_properties.key? :type get_type(property_properties[:type], PRIMITIVE_TYPES + known_types) end white_list_params(property_properties, PROPERTIES) @other_properties = property_properties.select do |key, value| OTHER_PROPERTIES.include? key end end |
Instance Method Details
#to_s ⇒ Object
60 61 62 63 64 65 66 67 |
# File 'lib/sinatra/swagger-exposer/swagger-type-property.rb', line 60 def to_s { :name => @name, :type => @type, :items => @items, :other_properties => @other_properties, }.to_json end |
#to_swagger ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/sinatra/swagger-exposer/swagger-type-property.rb', line 35 def to_swagger result = @other_properties.clone if @type if @type == 'array' result[:type] = 'array' if @items if PRIMITIVE_TYPES.include? @items result[:items] = {:type => @items} else result[:items] = ref_to_type(@items) end end else if PRIMITIVE_TYPES.include? @type result[:type] = @type else result['$ref'] = "#/definitions/#{@type}" end end end result end |