Class: Sinatra::SwaggerExposer::SwaggerEndpointResponse
- Inherits:
-
Object
- Object
- Sinatra::SwaggerExposer::SwaggerEndpointResponse
- Includes:
- SwaggerUtilities
- Defined in:
- lib/sinatra/swagger-exposer/swagger-endpoint-response.rb
Constant Summary
Constants included from SwaggerUtilities
Sinatra::SwaggerExposer::SwaggerUtilities::PRIMITIVE_TYPES
Instance Method Summary collapse
-
#initialize(type, description, known_types) ⇒ SwaggerEndpointResponse
constructor
A new instance of SwaggerEndpointResponse.
- #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, description, known_types) ⇒ SwaggerEndpointResponse
Returns a new instance of SwaggerEndpointResponse.
12 13 14 15 16 17 |
# File 'lib/sinatra/swagger-exposer/swagger-endpoint-response.rb', line 12 def initialize(type, description, known_types) get_type(type, known_types + PRIMITIVE_TYPES) if description @description = description end end |
Instance Method Details
#to_s ⇒ Object
49 50 51 52 53 54 55 |
# File 'lib/sinatra/swagger-exposer/swagger-endpoint-response.rb', line 49 def to_s { :type => @type, :items => @items, :description => @description, }.to_json end |
#to_swagger ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/sinatra/swagger-exposer/swagger-endpoint-response.rb', line 19 def to_swagger result = {} if @type if @type == 'array' schema = {:type => 'array'} if @items if PRIMITIVE_TYPES.include? @items schema[:items] = {:type => @items} else schema[:items] = {'$ref' => "#/definitions/#{@items}"} end end result[:schema] = schema else if PRIMITIVE_TYPES.include? @type result[:schema] = {:type => @type} else result[:schema] = {'$ref' => "#/definitions/#{@type}"} end end end if @description result[:description] = @description end result end |