Class: Apipie::ResponseDescriptionAdapter::PropDesc
- Inherits:
-
Object
- Object
- Apipie::ResponseDescriptionAdapter::PropDesc
- Defined in:
- lib/apipie/response_description_adapter.rb
Overview
A ResponseDescriptionAdapter::PropDesc object pretends to be an Apipie::Param in a ResponseDescription
To successfully masquerade as such, it needs to:
respond_to?('name') and/or ['name'] returning the name of the parameter
respond_to?('required') and/or ['required'] returning boolean
respond_to?('additional_properties') and/or ['additional_properties'] returning boolean
respond_to?('validator') and/or ['validator'] returning 'nil' (so type is 'string'), or an object that:
1) describes a type. currently type is inferred as follows:
if validator.is_a? Apipie::Validator::EnumValidator --> respond_to? 'values' (returns array). Type is enum or boolean
else: use v.expected_type(). This is expected to be the swagger type, or:
numeric ==> swagger type is 'number'
hash ==> swagger type is 'object' and validator should respond_to? 'params_ordered'
array ==> swagger type is array and validator (FUTURE) should indicate type of element
Defined Under Namespace
Classes: Validator
Instance Attribute Summary collapse
-
#additional_properties ⇒ Object
Returns the value of attribute additional_properties.
-
#description ⇒ Object
(also: #desc)
readonly
Returns the value of attribute description.
-
#expected_type ⇒ Object
readonly
Returns the value of attribute expected_type.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#required ⇒ Object
readonly
Returns the value of attribute required.
Instance Method Summary collapse
- #[](key) ⇒ Object
- #add_sub_property(prop_desc) ⇒ Object
-
#initialize(name, expected_type, options = {}, sub_properties = []) ⇒ PropDesc
constructor
A new instance of PropDesc.
- #is_array? ⇒ Boolean
- #to_json(lang) ⇒ Object
- #to_s ⇒ Object
- #validator ⇒ Object
Constructor Details
#initialize(name, expected_type, options = {}, sub_properties = []) ⇒ PropDesc
Returns a new instance of PropDesc.
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/apipie/response_description_adapter.rb', line 87 def initialize(name, expected_type, = {}, sub_properties = []) @name = name @required = true @required = false if [:required] == false @expected_type = expected_type @additional_properties = false [:desc] ||= [:description] @description = [:desc] @options = @is_array = [:is_array] || false @sub_properties = [] for prop in sub_properties do add_sub_property(prop) end end |
Instance Attribute Details
#additional_properties ⇒ Object
Returns the value of attribute additional_properties.
132 133 134 |
# File 'lib/apipie/response_description_adapter.rb', line 132 def additional_properties @additional_properties end |
#description ⇒ Object (readonly) Also known as: desc
Returns the value of attribute description.
131 132 133 |
# File 'lib/apipie/response_description_adapter.rb', line 131 def description @description end |
#expected_type ⇒ Object (readonly)
Returns the value of attribute expected_type.
131 132 133 |
# File 'lib/apipie/response_description_adapter.rb', line 131 def expected_type @expected_type end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
131 132 133 |
# File 'lib/apipie/response_description_adapter.rb', line 131 def name @name end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
131 132 133 |
# File 'lib/apipie/response_description_adapter.rb', line 131 def @options end |
#required ⇒ Object (readonly)
Returns the value of attribute required.
131 132 133 |
# File 'lib/apipie/response_description_adapter.rb', line 131 def required @required end |
Instance Method Details
#[](key) ⇒ Object
104 105 106 |
# File 'lib/apipie/response_description_adapter.rb', line 104 def [](key) self.send(key) if self.respond_to?(key.to_s) end |
#add_sub_property(prop_desc) ⇒ Object
108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/apipie/response_description_adapter.rb', line 108 def add_sub_property(prop_desc) raise "Only properties with expected_type 'object' can have sub-properties" unless @expected_type == 'object' case prop_desc when PropDesc @sub_properties << prop_desc when Modifier prop_desc.apply(self) else raise "Unrecognized prop_desc type (#{prop_desc.class})" end end |
#is_array? ⇒ Boolean
136 137 138 |
# File 'lib/apipie/response_description_adapter.rb', line 136 def is_array? @is_array end |
#to_json(lang) ⇒ Object
120 121 122 123 124 125 126 127 128 129 130 |
# File 'lib/apipie/response_description_adapter.rb', line 120 def to_json(lang) { name: name, required: required, validator: validator, description: description, additional_properties: additional_properties, is_array: is_array?, options: } end |
#to_s ⇒ Object
49 50 51 |
# File 'lib/apipie/response_description_adapter.rb', line 49 def to_s "PropDesc -- name: #{@name} type: #{@expected_type} required: #{@required} options: #{@options} subprop count: #{@sub_properties.length} additional properties: #{@additional_properties}" end |