|
| 1 | +=begin |
| 2 | +Swagger Petstore |
| 3 | +
|
| 4 | +This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ |
| 5 | +
|
| 6 | +OpenAPI spec version: 1.0.0 |
| 7 | +Contact: apiteam@swagger.io |
| 8 | +Generated by: https://github.com/swagger-api/swagger-codegen.git |
| 9 | +
|
| 10 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 11 | +you may not use this file except in compliance with the License. |
| 12 | +You may obtain a copy of the License at |
| 13 | +
|
| 14 | +http://www.apache.org/licenses/LICENSE-2.0 |
| 15 | +
|
| 16 | +Unless required by applicable law or agreed to in writing, software |
| 17 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 18 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 19 | +See the License for the specific language governing permissions and |
| 20 | +limitations under the License. |
| 21 | +
|
| 22 | +=end |
| 23 | + |
| 24 | +require 'date' |
| 25 | + |
| 26 | +module Petstore |
| 27 | + |
| 28 | + class ArrayTest |
| 29 | + # Attribute mapping from ruby-style variable name to JSON key. |
| 30 | + def self.attribute_map |
| 31 | + { |
| 32 | + } |
| 33 | + end |
| 34 | + |
| 35 | + # Attribute type mapping. |
| 36 | + def self.swagger_types |
| 37 | + { |
| 38 | + } |
| 39 | + end |
| 40 | + |
| 41 | + # Initializes the object |
| 42 | + # @param [Hash] attributes Model attributes in the form of hash |
| 43 | + def initialize(attributes = {}) |
| 44 | + return unless attributes.is_a?(Hash) |
| 45 | + |
| 46 | + # convert string to symbol for hash key |
| 47 | + attributes = attributes.each_with_object({}){|(k,v), h| h[k.to_sym] = v} |
| 48 | + |
| 49 | + end |
| 50 | + |
| 51 | + # Show invalid properties with the reasons. Usually used together with valid? |
| 52 | + # @return Array for valid properies with the reasons |
| 53 | + def list_invalid_properties |
| 54 | + invalid_properties = Array.new |
| 55 | + return invalid_properties |
| 56 | + end |
| 57 | + |
| 58 | + # Check to see if the all the properties in the model are valid |
| 59 | + # @return true if the model is valid |
| 60 | + def valid? |
| 61 | + end |
| 62 | + |
| 63 | + # Checks equality by comparing each attribute. |
| 64 | + # @param [Object] Object to be compared |
| 65 | + def ==(o) |
| 66 | + return true if self.equal?(o) |
| 67 | + self.class == o.class |
| 68 | + end |
| 69 | + |
| 70 | + # @see the `==` method |
| 71 | + # @param [Object] Object to be compared |
| 72 | + def eql?(o) |
| 73 | + self == o |
| 74 | + end |
| 75 | + |
| 76 | + # Calculates hash code according to all attributes. |
| 77 | + # @return [Fixnum] Hash code |
| 78 | + def hash |
| 79 | + [].hash |
| 80 | + end |
| 81 | + |
| 82 | + # Builds the object from hash |
| 83 | + # @param [Hash] attributes Model attributes in the form of hash |
| 84 | + # @return [Object] Returns the model itself |
| 85 | + def build_from_hash(attributes) |
| 86 | + return nil unless attributes.is_a?(Hash) |
| 87 | + self.class.swagger_types.each_pair do |key, type| |
| 88 | + if type =~ /^Array<(.*)>/i |
| 89 | + # check to ensure the input is an array given that the the attribute |
| 90 | + # is documented as an array but the input is not |
| 91 | + if attributes[self.class.attribute_map[key]].is_a?(Array) |
| 92 | + self.send("#{key}=", attributes[self.class.attribute_map[key]].map{ |v| _deserialize($1, v) } ) |
| 93 | + end |
| 94 | + elsif !attributes[self.class.attribute_map[key]].nil? |
| 95 | + self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]])) |
| 96 | + end # or else data not found in attributes(hash), not an issue as the data can be optional |
| 97 | + end |
| 98 | + |
| 99 | + self |
| 100 | + end |
| 101 | + |
| 102 | + # Deserializes the data based on type |
| 103 | + # @param string type Data type |
| 104 | + # @param string value Value to be deserialized |
| 105 | + # @return [Object] Deserialized data |
| 106 | + def _deserialize(type, value) |
| 107 | + case type.to_sym |
| 108 | + when :DateTime |
| 109 | + DateTime.parse(value) |
| 110 | + when :Date |
| 111 | + Date.parse(value) |
| 112 | + when :String |
| 113 | + value.to_s |
| 114 | + when :Integer |
| 115 | + value.to_i |
| 116 | + when :Float |
| 117 | + value.to_f |
| 118 | + when :BOOLEAN |
| 119 | + if value.to_s =~ /^(true|t|yes|y|1)$/i |
| 120 | + true |
| 121 | + else |
| 122 | + false |
| 123 | + end |
| 124 | + when :Object |
| 125 | + # generic object (usually a Hash), return directly |
| 126 | + value |
| 127 | + when /\AArray<(?<inner_type>.+)>\z/ |
| 128 | + inner_type = Regexp.last_match[:inner_type] |
| 129 | + value.map { |v| _deserialize(inner_type, v) } |
| 130 | + when /\AHash<(?<k_type>.+), (?<v_type>.+)>\z/ |
| 131 | + k_type = Regexp.last_match[:k_type] |
| 132 | + v_type = Regexp.last_match[:v_type] |
| 133 | + {}.tap do |hash| |
| 134 | + value.each do |k, v| |
| 135 | + hash[_deserialize(k_type, k)] = _deserialize(v_type, v) |
| 136 | + end |
| 137 | + end |
| 138 | + else # model |
| 139 | + temp_model = Petstore.const_get(type).new |
| 140 | + temp_model.build_from_hash(value) |
| 141 | + end |
| 142 | + end |
| 143 | + |
| 144 | + # Returns the string representation of the object |
| 145 | + # @return [String] String presentation of the object |
| 146 | + def to_s |
| 147 | + to_hash.to_s |
| 148 | + end |
| 149 | + |
| 150 | + # to_body is an alias to to_hash (backward compatibility) |
| 151 | + # @return [Hash] Returns the object in the form of hash |
| 152 | + def to_body |
| 153 | + to_hash |
| 154 | + end |
| 155 | + |
| 156 | + # Returns the object in the form of hash |
| 157 | + # @return [Hash] Returns the object in the form of hash |
| 158 | + def to_hash |
| 159 | + hash = {} |
| 160 | + self.class.attribute_map.each_pair do |attr, param| |
| 161 | + value = self.send(attr) |
| 162 | + next if value.nil? |
| 163 | + hash[param] = _to_hash(value) |
| 164 | + end |
| 165 | + hash |
| 166 | + end |
| 167 | + |
| 168 | + # Outputs non-array value in the form of hash |
| 169 | + # For object, use to_hash. Otherwise, just return the value |
| 170 | + # @param [Object] value Any valid value |
| 171 | + # @return [Hash] Returns the value in the form of hash |
| 172 | + def _to_hash(value) |
| 173 | + if value.is_a?(Array) |
| 174 | + value.compact.map{ |v| _to_hash(v) } |
| 175 | + elsif value.is_a?(Hash) |
| 176 | + {}.tap do |hash| |
| 177 | + value.each { |k, v| hash[k] = _to_hash(v) } |
| 178 | + end |
| 179 | + elsif value.respond_to? :to_hash |
| 180 | + value.to_hash |
| 181 | + else |
| 182 | + value |
| 183 | + end |
| 184 | + end |
| 185 | + |
| 186 | + end |
| 187 | + |
| 188 | +end |
0 commit comments