Class: Apipie::ResponseDescription

Inherits:
Object
  • Object
show all
Includes:
DSL::Base, DSL::Param
Defined in:
lib/apipie/response_description.rb,
lib/apipie/response_description.rb

Defined Under Namespace

Classes: ResponseObject

Instance Attribute Summary collapse

Attributes included from DSL::Base

#api_params, #apipie_resource_descriptions

Class Method Summary collapse

Instance Method Summary collapse

Methods included from DSL::Param

#_default_param_group_scope, #param, #param_group, #property, #returns

Methods included from DSL::Base

#_apipie_eval_dsl

Constructor Details

#initialize(method_description, code, options, scope, block, adapter) ⇒ ResponseDescription

Returns a new instance of ResponseDescription.



76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/apipie/response_description.rb', line 76

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

  if code.is_a? Symbol
    @code = Rack::Utils::SYMBOL_TO_STATUS_CODE[code]
  else
    @code = 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

Instance Attribute Details

#codeObject (readonly)

Returns the value of attribute code.



54
55
56
# File 'lib/apipie/response_description.rb', line 54

def code
  @code
end

#descriptionObject (readonly)

Returns the value of attribute description.



54
55
56
# File 'lib/apipie/response_description.rb', line 54

def description
  @description
end

#hash_validatorObject (readonly)

Returns the value of attribute hash_validator.



54
55
56
# File 'lib/apipie/response_description.rb', line 54

def hash_validator
  @hash_validator
end

#is_array_ofObject (readonly)

Returns the value of attribute is_array_of.



54
55
56
# File 'lib/apipie/response_description.rb', line 54

def is_array_of
  @is_array_of
end

#scopeObject (readonly)

Returns the value of attribute scope.



54
55
56
# File 'lib/apipie/response_description.rb', line 54

def scope
  @scope
end

#type_refObject (readonly)

Returns the value of attribute type_ref.



54
55
56
# File 'lib/apipie/response_description.rb', line 54

def type_ref
  @type_ref
end

Class Method Details

.from_dsl_data(method_description, code, args) ⇒ Object



56
57
58
59
60
61
62
63
64
65
# File 'lib/apipie/response_description.rb', line 56

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

Instance Method Details

#additional_propertiesObject Also known as: allow_additional_properties



116
117
118
# File 'lib/apipie/response_description.rb', line 116

def additional_properties
  !!@response_object.additional_properties
end

#is_array?Boolean

Returns:

  • (Boolean)


67
68
69
# File 'lib/apipie/response_description.rb', line 67

def is_array?
  @is_array_of != false
end

#param_descriptionObject



108
109
110
# File 'lib/apipie/response_description.rb', line 108

def param_description
  nil
end

#params_orderedObject



112
113
114
# File 'lib/apipie/response_description.rb', line 112

def params_ordered
  @response_object.params_ordered
end

#to_json(lang = nil) ⇒ Object



121
122
123
124
125
126
127
128
129
# File 'lib/apipie/response_description.rb', line 121

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,
  }
end

#typenameObject



71
72
73
# File 'lib/apipie/response_description.rb', line 71

def typename
  @response_object.typename
end