mockserver-client 1.0.8.pre → 5.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (123) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +5 -1
  3. data/Gemfile.lock +79 -0
  4. data/README.md +89 -229
  5. data/Rakefile +8 -8
  6. data/docs/Body.md +7 -0
  7. data/docs/BodyWithContentType.md +7 -0
  8. data/docs/ConnectionOptions.md +12 -0
  9. data/docs/ControlApi.md +269 -0
  10. data/docs/Delay.md +9 -0
  11. data/docs/Expectation.md +7 -0
  12. data/docs/ExpectationApi.md +51 -0
  13. data/docs/Expectations.md +7 -0
  14. data/docs/HttpClassCallback.md +8 -0
  15. data/docs/HttpError.md +10 -0
  16. data/docs/HttpForward.md +11 -0
  17. data/docs/HttpObjectCallback.md +8 -0
  18. data/docs/HttpOverrideForwardedRequest.md +9 -0
  19. data/docs/HttpRequest.md +15 -0
  20. data/docs/HttpResponse.md +14 -0
  21. data/docs/HttpTemplate.md +10 -0
  22. data/docs/KeyToMultiValue.md +7 -0
  23. data/docs/KeyToValue.md +7 -0
  24. data/docs/Ports.md +8 -0
  25. data/docs/TimeToLive.md +10 -0
  26. data/docs/Times.md +9 -0
  27. data/docs/Verification.md +9 -0
  28. data/docs/VerificationSequence.md +8 -0
  29. data/docs/VerificationTimes.md +9 -0
  30. data/docs/VerifyApi.md +94 -0
  31. data/lib/mockserver-client.rb +62 -15
  32. data/lib/mockserver-client/api/control_api.rb +316 -0
  33. data/lib/mockserver-client/api/expectation_api.rb +73 -0
  34. data/lib/mockserver-client/api/verify_api.rb +127 -0
  35. data/lib/mockserver-client/api_client.rb +388 -0
  36. data/lib/mockserver-client/api_error.rb +38 -0
  37. data/lib/mockserver-client/configuration.rb +202 -0
  38. data/lib/mockserver-client/models/body.rb +174 -0
  39. data/lib/mockserver-client/models/body_with_content_type.rb +174 -0
  40. data/lib/mockserver-client/models/connection_options.rb +219 -0
  41. data/lib/mockserver-client/models/delay.rb +192 -0
  42. data/lib/mockserver-client/models/expectation.rb +174 -0
  43. data/lib/mockserver-client/models/expectations.rb +174 -0
  44. data/lib/mockserver-client/models/http_class_callback.rb +183 -0
  45. data/lib/mockserver-client/models/http_error.rb +201 -0
  46. data/lib/mockserver-client/models/http_forward.rb +244 -0
  47. data/lib/mockserver-client/models/http_object_callback.rb +183 -0
  48. data/lib/mockserver-client/models/http_override_forwarded_request.rb +192 -0
  49. data/lib/mockserver-client/models/http_request.rb +246 -0
  50. data/lib/mockserver-client/models/http_response.rb +237 -0
  51. data/lib/mockserver-client/models/http_template.rb +235 -0
  52. data/lib/mockserver-client/models/key_to_multi_value.rb +174 -0
  53. data/lib/mockserver-client/models/key_to_value.rb +174 -0
  54. data/lib/mockserver-client/models/ports.rb +185 -0
  55. data/lib/mockserver-client/models/time_to_live.rb +235 -0
  56. data/lib/mockserver-client/models/times.rb +192 -0
  57. data/lib/mockserver-client/models/verification.rb +192 -0
  58. data/lib/mockserver-client/models/verification_sequence.rb +185 -0
  59. data/lib/mockserver-client/models/verification_times.rb +192 -0
  60. data/lib/mockserver-client/version.rb +15 -0
  61. data/mockserver-client.gemspec +44 -36
  62. data/spec/api/control_api_spec.rb +102 -0
  63. data/spec/api/expectation_api_spec.rb +46 -0
  64. data/spec/api/verify_api_spec.rb +57 -0
  65. data/spec/api_client_spec.rb +226 -0
  66. data/spec/configuration_spec.rb +42 -0
  67. data/spec/models/body_spec.rb +35 -0
  68. data/spec/models/body_with_content_type_spec.rb +35 -0
  69. data/spec/models/connection_options_spec.rb +65 -0
  70. data/spec/models/delay_spec.rb +47 -0
  71. data/spec/models/expectation_spec.rb +35 -0
  72. data/spec/models/expectations_spec.rb +35 -0
  73. data/spec/models/http_class_callback_spec.rb +41 -0
  74. data/spec/models/http_error_spec.rb +53 -0
  75. data/spec/models/http_forward_spec.rb +63 -0
  76. data/spec/models/http_object_callback_spec.rb +41 -0
  77. data/spec/models/http_override_forwarded_request_spec.rb +47 -0
  78. data/spec/models/http_request_spec.rb +83 -0
  79. data/spec/models/http_response_spec.rb +77 -0
  80. data/spec/models/http_template_spec.rb +57 -0
  81. data/spec/models/key_to_multi_value_spec.rb +35 -0
  82. data/spec/models/key_to_value_spec.rb +35 -0
  83. data/spec/models/ports_spec.rb +41 -0
  84. data/spec/models/time_to_live_spec.rb +57 -0
  85. data/spec/models/times_spec.rb +47 -0
  86. data/spec/models/verification_sequence_spec.rb +41 -0
  87. data/spec/models/verification_spec.rb +47 -0
  88. data/spec/models/verification_times_spec.rb +47 -0
  89. data/spec/spec_helper.rb +103 -53
  90. metadata +225 -158
  91. data/.gitignore +0 -21
  92. data/.rubocop.yml +0 -7
  93. data/bin/mockserver +0 -9
  94. data/lib/cli.rb +0 -146
  95. data/lib/mockserver/abstract_client.rb +0 -111
  96. data/lib/mockserver/mock_server_client.rb +0 -46
  97. data/lib/mockserver/model/array_of.rb +0 -85
  98. data/lib/mockserver/model/body.rb +0 -56
  99. data/lib/mockserver/model/cookie.rb +0 -36
  100. data/lib/mockserver/model/delay.rb +0 -34
  101. data/lib/mockserver/model/enum.rb +0 -47
  102. data/lib/mockserver/model/expectation.rb +0 -139
  103. data/lib/mockserver/model/forward.rb +0 -41
  104. data/lib/mockserver/model/header.rb +0 -43
  105. data/lib/mockserver/model/parameter.rb +0 -43
  106. data/lib/mockserver/model/request.rb +0 -81
  107. data/lib/mockserver/model/response.rb +0 -45
  108. data/lib/mockserver/model/times.rb +0 -61
  109. data/lib/mockserver/proxy_client.rb +0 -9
  110. data/lib/mockserver/utility_methods.rb +0 -59
  111. data/lib/mockserver/version.rb +0 -5
  112. data/pom.xml +0 -118
  113. data/spec/fixtures/forward_mockserver.json +0 -7
  114. data/spec/fixtures/incorrect_login_response.json +0 -20
  115. data/spec/fixtures/post_login_request.json +0 -22
  116. data/spec/fixtures/register_expectation.json +0 -50
  117. data/spec/fixtures/retrieved_request.json +0 -22
  118. data/spec/fixtures/search_request.json +0 -6
  119. data/spec/fixtures/times_once.json +0 -6
  120. data/spec/integration/mock_client_integration_spec.rb +0 -82
  121. data/spec/mockserver/builder_spec.rb +0 -90
  122. data/spec/mockserver/mock_client_spec.rb +0 -80
  123. data/spec/mockserver/proxy_client_spec.rb +0 -38
@@ -0,0 +1,192 @@
1
+ =begin
2
+ #Mock Server API
3
+
4
+ #MockServer enables easy mocking of any system you integrate with via HTTP or HTTPS with clients written in Java, JavaScript and Ruby and a simple REST API (as shown below). MockServer Proxy is a proxy that introspects all proxied traffic including encrypted SSL traffic and supports Port Forwarding, Web Proxying (i.e. HTTP proxy), HTTPS Tunneling Proxying (using HTTP CONNECT) and SOCKS Proxying (i.e. dynamic port forwarding). Both MockServer and the MockServer Proxy record all received requests so that it is possible to verify exactly what requests have been sent by the system under test.
5
+
6
+ OpenAPI spec version: 5.3.0
7
+
8
+ Generated by: https://openapi-generator.tech
9
+ OpenAPI Generator version: 3.3.1
10
+
11
+ =end
12
+
13
+ require 'date'
14
+
15
+ module MockServer
16
+ class Verification
17
+ attr_accessor :http_request
18
+
19
+ attr_accessor :times
20
+
21
+ # Attribute mapping from ruby-style variable name to JSON key.
22
+ def self.attribute_map
23
+ {
24
+ :'http_request' => :'httpRequest',
25
+ :'times' => :'times'
26
+ }
27
+ end
28
+
29
+ # Attribute type mapping.
30
+ def self.openapi_types
31
+ {
32
+ :'http_request' => :'HttpRequest',
33
+ :'times' => :'VerificationTimes'
34
+ }
35
+ end
36
+
37
+ # Initializes the object
38
+ # @param [Hash] attributes Model attributes in the form of hash
39
+ def initialize(attributes = {})
40
+ return unless attributes.is_a?(Hash)
41
+
42
+ # convert string to symbol for hash key
43
+ attributes = attributes.each_with_object({}) { |(k, v), h| h[k.to_sym] = v }
44
+
45
+ if attributes.has_key?(:'httpRequest')
46
+ self.http_request = attributes[:'httpRequest']
47
+ end
48
+
49
+ if attributes.has_key?(:'times')
50
+ self.times = attributes[:'times']
51
+ end
52
+ end
53
+
54
+ # Show invalid properties with the reasons. Usually used together with valid?
55
+ # @return Array for valid properties with the reasons
56
+ def list_invalid_properties
57
+ invalid_properties = Array.new
58
+ invalid_properties
59
+ end
60
+
61
+ # Check to see if the all the properties in the model are valid
62
+ # @return true if the model is valid
63
+ def valid?
64
+ true
65
+ end
66
+
67
+ # Checks equality by comparing each attribute.
68
+ # @param [Object] Object to be compared
69
+ def ==(o)
70
+ return true if self.equal?(o)
71
+ self.class == o.class &&
72
+ http_request == o.http_request &&
73
+ times == o.times
74
+ end
75
+
76
+ # @see the `==` method
77
+ # @param [Object] Object to be compared
78
+ def eql?(o)
79
+ self == o
80
+ end
81
+
82
+ # Calculates hash code according to all attributes.
83
+ # @return [Fixnum] Hash code
84
+ def hash
85
+ [http_request, times].hash
86
+ end
87
+
88
+ # Builds the object from hash
89
+ # @param [Hash] attributes Model attributes in the form of hash
90
+ # @return [Object] Returns the model itself
91
+ def build_from_hash(attributes)
92
+ return nil unless attributes.is_a?(Hash)
93
+ self.class.openapi_types.each_pair do |key, type|
94
+ if type =~ /\AArray<(.*)>/i
95
+ # check to ensure the input is an array given that the the attribute
96
+ # is documented as an array but the input is not
97
+ if attributes[self.class.attribute_map[key]].is_a?(Array)
98
+ self.send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) })
99
+ end
100
+ elsif !attributes[self.class.attribute_map[key]].nil?
101
+ self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
102
+ end # or else data not found in attributes(hash), not an issue as the data can be optional
103
+ end
104
+
105
+ self
106
+ end
107
+
108
+ # Deserializes the data based on type
109
+ # @param string type Data type
110
+ # @param string value Value to be deserialized
111
+ # @return [Object] Deserialized data
112
+ def _deserialize(type, value)
113
+ case type.to_sym
114
+ when :DateTime
115
+ DateTime.parse(value)
116
+ when :Date
117
+ Date.parse(value)
118
+ when :String
119
+ value.to_s
120
+ when :Integer
121
+ value.to_i
122
+ when :Float
123
+ value.to_f
124
+ when :BOOLEAN
125
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
126
+ true
127
+ else
128
+ false
129
+ end
130
+ when :Object
131
+ # generic object (usually a Hash), return directly
132
+ value
133
+ when /\AArray<(?<inner_type>.+)>\z/
134
+ inner_type = Regexp.last_match[:inner_type]
135
+ value.map { |v| _deserialize(inner_type, v) }
136
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
137
+ k_type = Regexp.last_match[:k_type]
138
+ v_type = Regexp.last_match[:v_type]
139
+ {}.tap do |hash|
140
+ value.each do |k, v|
141
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
142
+ end
143
+ end
144
+ else # model
145
+ temp_model = MockServer.const_get(type).new
146
+ temp_model.build_from_hash(value)
147
+ end
148
+ end
149
+
150
+ # Returns the string representation of the object
151
+ # @return [String] String presentation of the object
152
+ def to_s
153
+ to_hash.to_s
154
+ end
155
+
156
+ # to_body is an alias to to_hash (backward compatibility)
157
+ # @return [Hash] Returns the object in the form of hash
158
+ def to_body
159
+ to_hash
160
+ end
161
+
162
+ # Returns the object in the form of hash
163
+ # @return [Hash] Returns the object in the form of hash
164
+ def to_hash
165
+ hash = {}
166
+ self.class.attribute_map.each_pair do |attr, param|
167
+ value = self.send(attr)
168
+ next if value.nil?
169
+ hash[param] = _to_hash(value)
170
+ end
171
+ hash
172
+ end
173
+
174
+ # Outputs non-array value in the form of hash
175
+ # For object, use to_hash. Otherwise, just return the value
176
+ # @param [Object] value Any valid value
177
+ # @return [Hash] Returns the value in the form of hash
178
+ def _to_hash(value)
179
+ if value.is_a?(Array)
180
+ value.compact.map { |v| _to_hash(v) }
181
+ elsif value.is_a?(Hash)
182
+ {}.tap do |hash|
183
+ value.each { |k, v| hash[k] = _to_hash(v) }
184
+ end
185
+ elsif value.respond_to? :to_hash
186
+ value.to_hash
187
+ else
188
+ value
189
+ end
190
+ end
191
+ end
192
+ end
@@ -0,0 +1,185 @@
1
+ =begin
2
+ #Mock Server API
3
+
4
+ #MockServer enables easy mocking of any system you integrate with via HTTP or HTTPS with clients written in Java, JavaScript and Ruby and a simple REST API (as shown below). MockServer Proxy is a proxy that introspects all proxied traffic including encrypted SSL traffic and supports Port Forwarding, Web Proxying (i.e. HTTP proxy), HTTPS Tunneling Proxying (using HTTP CONNECT) and SOCKS Proxying (i.e. dynamic port forwarding). Both MockServer and the MockServer Proxy record all received requests so that it is possible to verify exactly what requests have been sent by the system under test.
5
+
6
+ OpenAPI spec version: 5.3.0
7
+
8
+ Generated by: https://openapi-generator.tech
9
+ OpenAPI Generator version: 3.3.1
10
+
11
+ =end
12
+
13
+ require 'date'
14
+
15
+ module MockServer
16
+ class VerificationSequence
17
+ attr_accessor :http_requests
18
+
19
+ # Attribute mapping from ruby-style variable name to JSON key.
20
+ def self.attribute_map
21
+ {
22
+ :'http_requests' => :'httpRequests'
23
+ }
24
+ end
25
+
26
+ # Attribute type mapping.
27
+ def self.openapi_types
28
+ {
29
+ :'http_requests' => :'Array<HttpRequest>'
30
+ }
31
+ end
32
+
33
+ # Initializes the object
34
+ # @param [Hash] attributes Model attributes in the form of hash
35
+ def initialize(attributes = {})
36
+ return unless attributes.is_a?(Hash)
37
+
38
+ # convert string to symbol for hash key
39
+ attributes = attributes.each_with_object({}) { |(k, v), h| h[k.to_sym] = v }
40
+
41
+ if attributes.has_key?(:'httpRequests')
42
+ if (value = attributes[:'httpRequests']).is_a?(Array)
43
+ self.http_requests = value
44
+ end
45
+ end
46
+ end
47
+
48
+ # Show invalid properties with the reasons. Usually used together with valid?
49
+ # @return Array for valid properties with the reasons
50
+ def list_invalid_properties
51
+ invalid_properties = Array.new
52
+ invalid_properties
53
+ end
54
+
55
+ # Check to see if the all the properties in the model are valid
56
+ # @return true if the model is valid
57
+ def valid?
58
+ true
59
+ end
60
+
61
+ # Checks equality by comparing each attribute.
62
+ # @param [Object] Object to be compared
63
+ def ==(o)
64
+ return true if self.equal?(o)
65
+ self.class == o.class &&
66
+ http_requests == o.http_requests
67
+ end
68
+
69
+ # @see the `==` method
70
+ # @param [Object] Object to be compared
71
+ def eql?(o)
72
+ self == o
73
+ end
74
+
75
+ # Calculates hash code according to all attributes.
76
+ # @return [Fixnum] Hash code
77
+ def hash
78
+ [http_requests].hash
79
+ end
80
+
81
+ # Builds the object from hash
82
+ # @param [Hash] attributes Model attributes in the form of hash
83
+ # @return [Object] Returns the model itself
84
+ def build_from_hash(attributes)
85
+ return nil unless attributes.is_a?(Hash)
86
+ self.class.openapi_types.each_pair do |key, type|
87
+ if type =~ /\AArray<(.*)>/i
88
+ # check to ensure the input is an array given that the the attribute
89
+ # is documented as an array but the input is not
90
+ if attributes[self.class.attribute_map[key]].is_a?(Array)
91
+ self.send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) })
92
+ end
93
+ elsif !attributes[self.class.attribute_map[key]].nil?
94
+ self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
95
+ end # or else data not found in attributes(hash), not an issue as the data can be optional
96
+ end
97
+
98
+ self
99
+ end
100
+
101
+ # Deserializes the data based on type
102
+ # @param string type Data type
103
+ # @param string value Value to be deserialized
104
+ # @return [Object] Deserialized data
105
+ def _deserialize(type, value)
106
+ case type.to_sym
107
+ when :DateTime
108
+ DateTime.parse(value)
109
+ when :Date
110
+ Date.parse(value)
111
+ when :String
112
+ value.to_s
113
+ when :Integer
114
+ value.to_i
115
+ when :Float
116
+ value.to_f
117
+ when :BOOLEAN
118
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
119
+ true
120
+ else
121
+ false
122
+ end
123
+ when :Object
124
+ # generic object (usually a Hash), return directly
125
+ value
126
+ when /\AArray<(?<inner_type>.+)>\z/
127
+ inner_type = Regexp.last_match[:inner_type]
128
+ value.map { |v| _deserialize(inner_type, v) }
129
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
130
+ k_type = Regexp.last_match[:k_type]
131
+ v_type = Regexp.last_match[:v_type]
132
+ {}.tap do |hash|
133
+ value.each do |k, v|
134
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
135
+ end
136
+ end
137
+ else # model
138
+ temp_model = MockServer.const_get(type).new
139
+ temp_model.build_from_hash(value)
140
+ end
141
+ end
142
+
143
+ # Returns the string representation of the object
144
+ # @return [String] String presentation of the object
145
+ def to_s
146
+ to_hash.to_s
147
+ end
148
+
149
+ # to_body is an alias to to_hash (backward compatibility)
150
+ # @return [Hash] Returns the object in the form of hash
151
+ def to_body
152
+ to_hash
153
+ end
154
+
155
+ # Returns the object in the form of hash
156
+ # @return [Hash] Returns the object in the form of hash
157
+ def to_hash
158
+ hash = {}
159
+ self.class.attribute_map.each_pair do |attr, param|
160
+ value = self.send(attr)
161
+ next if value.nil?
162
+ hash[param] = _to_hash(value)
163
+ end
164
+ hash
165
+ end
166
+
167
+ # Outputs non-array value in the form of hash
168
+ # For object, use to_hash. Otherwise, just return the value
169
+ # @param [Object] value Any valid value
170
+ # @return [Hash] Returns the value in the form of hash
171
+ def _to_hash(value)
172
+ if value.is_a?(Array)
173
+ value.compact.map { |v| _to_hash(v) }
174
+ elsif value.is_a?(Hash)
175
+ {}.tap do |hash|
176
+ value.each { |k, v| hash[k] = _to_hash(v) }
177
+ end
178
+ elsif value.respond_to? :to_hash
179
+ value.to_hash
180
+ else
181
+ value
182
+ end
183
+ end
184
+ end
185
+ end
@@ -0,0 +1,192 @@
1
+ =begin
2
+ #Mock Server API
3
+
4
+ #MockServer enables easy mocking of any system you integrate with via HTTP or HTTPS with clients written in Java, JavaScript and Ruby and a simple REST API (as shown below). MockServer Proxy is a proxy that introspects all proxied traffic including encrypted SSL traffic and supports Port Forwarding, Web Proxying (i.e. HTTP proxy), HTTPS Tunneling Proxying (using HTTP CONNECT) and SOCKS Proxying (i.e. dynamic port forwarding). Both MockServer and the MockServer Proxy record all received requests so that it is possible to verify exactly what requests have been sent by the system under test.
5
+
6
+ OpenAPI spec version: 5.3.0
7
+
8
+ Generated by: https://openapi-generator.tech
9
+ OpenAPI Generator version: 3.3.1
10
+
11
+ =end
12
+
13
+ require 'date'
14
+
15
+ module MockServer
16
+ class VerificationTimes
17
+ attr_accessor :count
18
+
19
+ attr_accessor :exact
20
+
21
+ # Attribute mapping from ruby-style variable name to JSON key.
22
+ def self.attribute_map
23
+ {
24
+ :'count' => :'count',
25
+ :'exact' => :'exact'
26
+ }
27
+ end
28
+
29
+ # Attribute type mapping.
30
+ def self.openapi_types
31
+ {
32
+ :'count' => :'Integer',
33
+ :'exact' => :'BOOLEAN'
34
+ }
35
+ end
36
+
37
+ # Initializes the object
38
+ # @param [Hash] attributes Model attributes in the form of hash
39
+ def initialize(attributes = {})
40
+ return unless attributes.is_a?(Hash)
41
+
42
+ # convert string to symbol for hash key
43
+ attributes = attributes.each_with_object({}) { |(k, v), h| h[k.to_sym] = v }
44
+
45
+ if attributes.has_key?(:'count')
46
+ self.count = attributes[:'count']
47
+ end
48
+
49
+ if attributes.has_key?(:'exact')
50
+ self.exact = attributes[:'exact']
51
+ end
52
+ end
53
+
54
+ # Show invalid properties with the reasons. Usually used together with valid?
55
+ # @return Array for valid properties with the reasons
56
+ def list_invalid_properties
57
+ invalid_properties = Array.new
58
+ invalid_properties
59
+ end
60
+
61
+ # Check to see if the all the properties in the model are valid
62
+ # @return true if the model is valid
63
+ def valid?
64
+ true
65
+ end
66
+
67
+ # Checks equality by comparing each attribute.
68
+ # @param [Object] Object to be compared
69
+ def ==(o)
70
+ return true if self.equal?(o)
71
+ self.class == o.class &&
72
+ count == o.count &&
73
+ exact == o.exact
74
+ end
75
+
76
+ # @see the `==` method
77
+ # @param [Object] Object to be compared
78
+ def eql?(o)
79
+ self == o
80
+ end
81
+
82
+ # Calculates hash code according to all attributes.
83
+ # @return [Fixnum] Hash code
84
+ def hash
85
+ [count, exact].hash
86
+ end
87
+
88
+ # Builds the object from hash
89
+ # @param [Hash] attributes Model attributes in the form of hash
90
+ # @return [Object] Returns the model itself
91
+ def build_from_hash(attributes)
92
+ return nil unless attributes.is_a?(Hash)
93
+ self.class.openapi_types.each_pair do |key, type|
94
+ if type =~ /\AArray<(.*)>/i
95
+ # check to ensure the input is an array given that the the attribute
96
+ # is documented as an array but the input is not
97
+ if attributes[self.class.attribute_map[key]].is_a?(Array)
98
+ self.send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) })
99
+ end
100
+ elsif !attributes[self.class.attribute_map[key]].nil?
101
+ self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
102
+ end # or else data not found in attributes(hash), not an issue as the data can be optional
103
+ end
104
+
105
+ self
106
+ end
107
+
108
+ # Deserializes the data based on type
109
+ # @param string type Data type
110
+ # @param string value Value to be deserialized
111
+ # @return [Object] Deserialized data
112
+ def _deserialize(type, value)
113
+ case type.to_sym
114
+ when :DateTime
115
+ DateTime.parse(value)
116
+ when :Date
117
+ Date.parse(value)
118
+ when :String
119
+ value.to_s
120
+ when :Integer
121
+ value.to_i
122
+ when :Float
123
+ value.to_f
124
+ when :BOOLEAN
125
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
126
+ true
127
+ else
128
+ false
129
+ end
130
+ when :Object
131
+ # generic object (usually a Hash), return directly
132
+ value
133
+ when /\AArray<(?<inner_type>.+)>\z/
134
+ inner_type = Regexp.last_match[:inner_type]
135
+ value.map { |v| _deserialize(inner_type, v) }
136
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
137
+ k_type = Regexp.last_match[:k_type]
138
+ v_type = Regexp.last_match[:v_type]
139
+ {}.tap do |hash|
140
+ value.each do |k, v|
141
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
142
+ end
143
+ end
144
+ else # model
145
+ temp_model = MockServer.const_get(type).new
146
+ temp_model.build_from_hash(value)
147
+ end
148
+ end
149
+
150
+ # Returns the string representation of the object
151
+ # @return [String] String presentation of the object
152
+ def to_s
153
+ to_hash.to_s
154
+ end
155
+
156
+ # to_body is an alias to to_hash (backward compatibility)
157
+ # @return [Hash] Returns the object in the form of hash
158
+ def to_body
159
+ to_hash
160
+ end
161
+
162
+ # Returns the object in the form of hash
163
+ # @return [Hash] Returns the object in the form of hash
164
+ def to_hash
165
+ hash = {}
166
+ self.class.attribute_map.each_pair do |attr, param|
167
+ value = self.send(attr)
168
+ next if value.nil?
169
+ hash[param] = _to_hash(value)
170
+ end
171
+ hash
172
+ end
173
+
174
+ # Outputs non-array value in the form of hash
175
+ # For object, use to_hash. Otherwise, just return the value
176
+ # @param [Object] value Any valid value
177
+ # @return [Hash] Returns the value in the form of hash
178
+ def _to_hash(value)
179
+ if value.is_a?(Array)
180
+ value.compact.map { |v| _to_hash(v) }
181
+ elsif value.is_a?(Hash)
182
+ {}.tap do |hash|
183
+ value.each { |k, v| hash[k] = _to_hash(v) }
184
+ end
185
+ elsif value.respond_to? :to_hash
186
+ value.to_hash
187
+ else
188
+ value
189
+ end
190
+ end
191
+ end
192
+ end