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]
- PROPERTIES =
[:type] + OTHER_PROPERTIES
Constants included from SwaggerUtilities
Sinatra::SwaggerExposer::SwaggerUtilities::PRIMITIVE_TYPES
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, #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' => "#/definitions/#{@items}"} end end else if PRIMITIVE_TYPES.include? @type result[:type] = @type else result['$ref'] = "#/definitions/#{@type}" end end end result end |