class Apipie::ResponseDescription

Attributes

code[R]
description[R]
hash_validator[R]
is_array_of[R]
scope[R]
type_ref[R]

Public Class Methods

from_dsl_data(method_description, code, args) click to toggle source
# File lib/apipie/response_description.rb, line 70
def self.from_dsl_data(method_description, code, args)
  options, scope, block, adapter = args

  Apipie::ResponseDescription.new(method_description,
                                  code,
                                  options,
                                  scope,
                                  block,
                                  adapter)
end
new(method_description, code, options, scope, block, adapter) click to toggle source
# File lib/apipie/response_description.rb, line 81
def initialize(method_description, code, options, scope, block, adapter)

  @type_ref = options[:param_group]
  @is_array_of = options[:array_of] || false
  raise ReturnsMultipleDefinitionError, options if @is_array_of && @type_ref

  @type_ref ||= @is_array_of

  @method_description = method_description

  @code =
    if code.is_a? Symbol
      begin
        Rack::Utils.status_code(code)
      rescue ArgumentError
        nil
      end
    else
      code
    end

  @description = options[:desc]
  if @description.nil?
    @description = Rack::Utils::HTTP_STATUS_CODES[@code]
    raise "Cannot infer description from status code #{@code}" if @description.nil?
  end
  @scope = scope

  if adapter
    @response_object = adapter
  else
    @response_object = ResponseObject.new(method_description, scope, block, @type_ref)
  end

  @response_object.additional_properties ||= options[:additional_properties]
end

Public Instance Methods

additional_properties() click to toggle source
# File lib/apipie/response_description.rb, line 134
def additional_properties
  !!@response_object.additional_properties
end
Also aliased as: allow_additional_properties
allow_additional_properties()
headers() click to toggle source

@return [Array<Hash>]

# File lib/apipie/response_description.rb, line 140
def headers
  # TODO: Support headers for Apipie::ResponseDescriptionAdapter
  if @response_object.is_a?(Apipie::ResponseDescriptionAdapter)
    return []
  end

  @response_object.headers
end
is_array?() click to toggle source
# File lib/apipie/response_description.rb, line 118
def is_array?
  @is_array_of != false
end
param_description() click to toggle source
# File lib/apipie/response_description.rb, line 126
def param_description
  nil
end
params_ordered() click to toggle source
# File lib/apipie/response_description.rb, line 130
def params_ordered
  @response_object.params_ordered
end
to_json(lang = nil) click to toggle source

@return [Hash{Symbol->TrueClass | FalseClass}]

# File lib/apipie/response_description.rb, line 150
def to_json(lang = nil)
  {
      :code => code,
      :description => Apipie.app.translate(description, lang),
      :is_array => is_array?,
      :returns_object => params_ordered.map{ |param| param.to_json(lang).tap{|h| h.delete(:validations) }}.flatten,
      :additional_properties => additional_properties,
      :headers => headers
  }
end
typename() click to toggle source
# File lib/apipie/response_description.rb, line 122
def typename
  @response_object.typename
end