Class: Sinatra::SwaggerExposer::SwaggerEndpointResponse
- Inherits:
-
Object
- Object
- Sinatra::SwaggerExposer::SwaggerEndpointResponse
- Includes:
- SwaggerUtilities
- Defined in:
- lib/sinatra/swagger-exposer/swagger-endpoint-response.rb
Constant Summary collapse
- RESPONSE_PRIMITIVES_FILES =
PRIMITIVE_TYPES + [TYPE_FILE]
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, 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, #list_or_none, #ref_to_type, #type_to_s, #white_list_params
Constructor Details
#initialize(type, description, known_types) ⇒ SwaggerEndpointResponse
Returns a new instance of SwaggerEndpointResponse.
14 15 16 17 18 19 |
# File 'lib/sinatra/swagger-exposer/swagger-endpoint-response.rb', line 14 def initialize(type, description, known_types) get_type(type, known_types + RESPONSE_PRIMITIVES_FILES) if description @description = description end end |
Instance Method Details
#to_s ⇒ Object
51 52 53 54 55 56 57 |
# File 'lib/sinatra/swagger-exposer/swagger-endpoint-response.rb', line 51 def to_s { :type => @type, :items => @items, :description => @description, }.to_json end |
#to_swagger ⇒ Object
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 48 49 |
# File 'lib/sinatra/swagger-exposer/swagger-endpoint-response.rb', line 21 def to_swagger result = {} if @type if @type == 'array' schema = {:type => 'array'} if @items if RESPONSE_PRIMITIVES_FILES.include? @items schema[:items] = {:type => @items} else schema[:items] = ref_to_type(@items) end end result[:schema] = schema else if RESPONSE_PRIMITIVES_FILES.include? @type result[:schema] = {:type => @type} else result[:schema] = ref_to_type(@type) end end end if @description result[:description] = @description end result end |