class Apipie::ResponseDescriptionAdapter::PropDesc
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
Attributes
additional_properties[RW]
desc[R]
description[R]
expected_type[R]
name[R]
options[R]
required[R]
Public Class Methods
new(name, expected_type, options={}, sub_properties=[])
click to toggle source
¶ ↑
# File lib/apipie/response_description_adapter.rb, line 87 def initialize(name, expected_type, options={}, sub_properties=[]) @name = name @required = true @required = false if options[:required] == false @expected_type = expected_type @additional_properties = false options[:desc] ||= options[:description] @description = options[:desc] @options = options @is_array = options[:is_array] || false @sub_properties = [] for prop in sub_properties do add_sub_property(prop) end end
Public Instance Methods
[](key)
click to toggle source
# File lib/apipie/response_description_adapter.rb, line 104 def [](key) return self.send(key) if self.respond_to?(key.to_s) end
add_sub_property(prop_desc)
click to toggle source
# 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' if prop_desc.is_a? PropDesc @sub_properties << prop_desc elsif prop_desc.is_a? Modifier prop_desc.apply(self) else raise "Unrecognized prop_desc type (#{prop_desc.class})" end end
is_array?()
click to toggle source
# File lib/apipie/response_description_adapter.rb, line 135 def is_array? @is_array end
to_json(lang)
click to toggle source
# File lib/apipie/response_description_adapter.rb, line 119 def to_json(lang) { name: name, required: required, validator: validator, description: description, additional_properties: additional_properties, is_array: is_array?, options: options } end
to_s()
click to toggle source
# 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
validator()
click to toggle source
# File lib/apipie/response_description_adapter.rb, line 139 def validator Validator.new(@expected_type, options[:values], @sub_properties) end