Class: Apipie::ResponseDescription
- Inherits:
-
Object
- Object
- Apipie::ResponseDescription
- 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
-
#code ⇒ Object
readonly
Returns the value of attribute code.
-
#description ⇒ Object
readonly
Returns the value of attribute description.
-
#hash_validator ⇒ Object
readonly
Returns the value of attribute hash_validator.
-
#is_array_of ⇒ Object
readonly
Returns the value of attribute is_array_of.
-
#scope ⇒ Object
readonly
Returns the value of attribute scope.
-
#type_ref ⇒ Object
readonly
Returns the value of attribute type_ref.
Attributes included from DSL::Base
#api_params, #apipie_resource_descriptions
Class Method Summary collapse
Instance Method Summary collapse
- #additional_properties ⇒ Object (also: #allow_additional_properties)
- #headers ⇒ Array<Hash>
-
#initialize(method_description, code, options, scope, block, adapter) ⇒ ResponseDescription
constructor
A new instance of ResponseDescription.
- #is_array? ⇒ Boolean
- #param_description ⇒ Object
- #params_ordered ⇒ Object
-
#to_json(lang = nil) ⇒ Hash{Symbol->TrueClass | FalseClass
].
- #typename ⇒ Object
Methods included from DSL::Param
#_default_param_group_scope, #param, #param_group, #property, #returns
Methods included from DSL::Base
Constructor Details
#initialize(method_description, code, options, scope, block, adapter) ⇒ ResponseDescription
Returns a new instance of ResponseDescription.
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 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/apipie/response_description.rb', line 81 def initialize(method_description, code, , scope, block, adapter) @type_ref = [:param_group] @is_array_of = [:array_of] || false raise ReturnsMultipleDefinitionError, 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 = [: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 ||= [:additional_properties] end |
Instance Attribute Details
#code ⇒ Object (readonly)
Returns the value of attribute code.
68 69 70 |
# File 'lib/apipie/response_description.rb', line 68 def code @code end |
#description ⇒ Object (readonly)
Returns the value of attribute description.
68 69 70 |
# File 'lib/apipie/response_description.rb', line 68 def description @description end |
#hash_validator ⇒ Object (readonly)
Returns the value of attribute hash_validator.
68 69 70 |
# File 'lib/apipie/response_description.rb', line 68 def hash_validator @hash_validator end |
#is_array_of ⇒ Object (readonly)
Returns the value of attribute is_array_of.
68 69 70 |
# File 'lib/apipie/response_description.rb', line 68 def is_array_of @is_array_of end |
#scope ⇒ Object (readonly)
Returns the value of attribute scope.
68 69 70 |
# File 'lib/apipie/response_description.rb', line 68 def scope @scope end |
#type_ref ⇒ Object (readonly)
Returns the value of attribute type_ref.
68 69 70 |
# File 'lib/apipie/response_description.rb', line 68 def type_ref @type_ref end |
Class Method Details
.from_dsl_data(method_description, code, args) ⇒ Object
70 71 72 73 74 75 76 77 78 79 |
# File 'lib/apipie/response_description.rb', line 70 def self.from_dsl_data(method_description, code, args) , scope, block, adapter = args Apipie::ResponseDescription.new(method_description, code, , scope, block, adapter) end |
Instance Method Details
#additional_properties ⇒ Object Also known as: allow_additional_properties
134 135 136 |
# File 'lib/apipie/response_description.rb', line 134 def additional_properties !!@response_object.additional_properties end |
#headers ⇒ Array<Hash>
140 141 142 143 144 145 146 147 |
# 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? ⇒ Boolean
118 119 120 |
# File 'lib/apipie/response_description.rb', line 118 def is_array? @is_array_of != false end |
#param_description ⇒ Object
126 127 128 |
# File 'lib/apipie/response_description.rb', line 126 def param_description nil end |
#params_ordered ⇒ Object
130 131 132 |
# File 'lib/apipie/response_description.rb', line 130 def params_ordered @response_object.params_ordered end |
#to_json(lang = nil) ⇒ Hash{Symbol->TrueClass | FalseClass
Returns ].
150 151 152 153 154 155 156 157 158 159 |
# 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 ⇒ Object
122 123 124 |
# File 'lib/apipie/response_description.rb', line 122 def typename @response_object.typename end |