patch_ruby 1.9.0 → 1.11.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +18 -0
- data/Gemfile +1 -2
- data/Gemfile.lock +40 -44
- data/Makefile +2 -2
- data/lib/patch_ruby/api/estimates_api.rb +33 -25
- data/lib/patch_ruby/api/orders_api.rb +21 -16
- data/lib/patch_ruby/api/preferences_api.rb +17 -13
- data/lib/patch_ruby/api/projects_api.rb +9 -7
- data/lib/patch_ruby/api_client.rb +51 -49
- data/lib/patch_ruby/api_error.rb +1 -1
- data/lib/patch_ruby/configuration.rb +38 -9
- data/lib/patch_ruby/models/allocation.rb +21 -11
- data/lib/patch_ruby/models/create_bitcoin_estimate_request.rb +25 -19
- data/lib/patch_ruby/models/create_ethereum_estimate_request.rb +26 -21
- data/lib/patch_ruby/models/create_flight_estimate_request.rb +323 -0
- data/lib/patch_ruby/models/create_mass_estimate_request.rb +22 -13
- data/lib/patch_ruby/models/create_order_request.rb +21 -11
- data/lib/patch_ruby/models/create_preference_request.rb +21 -11
- data/lib/patch_ruby/models/create_shipping_estimate_request.rb +371 -0
- data/lib/patch_ruby/models/create_success_response.rb +247 -0
- data/lib/patch_ruby/models/create_vehicle_estimate_request.rb +326 -0
- data/lib/patch_ruby/models/error_response.rb +22 -13
- data/lib/patch_ruby/models/estimate.rb +22 -13
- data/lib/patch_ruby/models/estimate_list_response.rb +22 -13
- data/lib/patch_ruby/models/estimate_response.rb +22 -13
- data/lib/patch_ruby/models/meta_index_object.rb +23 -15
- data/lib/patch_ruby/models/order.rb +23 -15
- data/lib/patch_ruby/models/order_list_response.rb +22 -13
- data/lib/patch_ruby/models/order_response.rb +22 -13
- data/lib/patch_ruby/models/photo.rb +21 -11
- data/lib/patch_ruby/models/preference.rb +21 -11
- data/lib/patch_ruby/models/preference_list_response.rb +22 -13
- data/lib/patch_ruby/models/preference_response.rb +22 -13
- data/lib/patch_ruby/models/project.rb +24 -17
- data/lib/patch_ruby/models/project_list_response.rb +22 -13
- data/lib/patch_ruby/models/project_response.rb +22 -13
- data/lib/patch_ruby/models/sdg.rb +21 -11
- data/lib/patch_ruby/models/standard.rb +21 -11
- data/lib/patch_ruby/version.rb +2 -2
- data/lib/patch_ruby.rb +5 -1
- data/patch_ruby.gemspec +8 -3
- data/spec/api_client_spec.rb +34 -13
- data/spec/configuration_spec.rb +1 -1
- data/spec/integration/estimates_spec.rb +17 -1
- data/spec/integration/preferences_spec.rb +1 -1
- data/spec/models/create_mass_estimate_request_spec.rb +1 -1
- data/spec/models/error_response_spec.rb +1 -1
- data/spec/models/estimate_list_response_spec.rb +1 -1
- data/spec/models/estimate_response_spec.rb +1 -1
- data/spec/models/estimate_spec.rb +1 -1
- data/spec/models/meta_index_object_spec.rb +1 -1
- data/spec/models/order_list_response_spec.rb +1 -1
- data/spec/models/order_response_spec.rb +1 -1
- data/spec/models/order_spec.rb +1 -1
- data/spec/models/preference_list_response_spec.rb +1 -1
- data/spec/models/preference_response_spec.rb +1 -1
- data/spec/models/project_list_response_spec.rb +1 -1
- data/spec/models/project_response_spec.rb +1 -1
- data/spec/models/project_spec.rb +1 -1
- data/spec/spec_helper.rb +69 -61
- metadata +56 -58
- data/lib/patch_ruby/.api_client.rb.un~ +0 -0
- data/lib/patch_ruby/.configuration.rb.un~ +0 -0
- data/lib/patch_ruby/.version.rb.un~ +0 -0
- data/lib/patch_ruby/api/.orders_api.rb.un~ +0 -0
- data/lib/patch_ruby/models/.create_ethereum_estimate_request.rb.un~ +0 -0
- data/spec/.spec_helper.rb.un~ +0 -0
- data/spec/integration/.estimates_spec.rb.un~ +0 -0
- data/spec/integration/.orders_spec.rb.un~ +0 -0
- data/spec/integration/.preferences_spec.rb.un~ +0 -0
- data/spec/integration/.projects_spec.rb.un~ +0 -0
@@ -6,7 +6,7 @@
|
|
6
6
|
The version of the OpenAPI document: v1
|
7
7
|
Contact: developers@usepatch.com
|
8
8
|
Generated by: https://openapi-generator.tech
|
9
|
-
OpenAPI Generator version:
|
9
|
+
OpenAPI Generator version: 5.2.1
|
10
10
|
|
11
11
|
=end
|
12
12
|
|
@@ -66,15 +66,16 @@ module Patch
|
|
66
66
|
form_params = opts[:form_params] || {}
|
67
67
|
|
68
68
|
# http body (model)
|
69
|
-
post_body = opts[:
|
69
|
+
post_body = opts[:debug_body] || @api_client.object_to_http_body(create_preference_request)
|
70
70
|
|
71
71
|
# return_type
|
72
|
-
return_type = opts[:
|
72
|
+
return_type = opts[:debug_return_type] || 'PreferenceResponse'
|
73
73
|
|
74
74
|
# auth_names
|
75
|
-
auth_names = opts[:
|
75
|
+
auth_names = opts[:debug_auth_names] || ['bearer_auth']
|
76
76
|
|
77
77
|
new_options = opts.merge(
|
78
|
+
:operation => :"PreferencesApi.create_preference",
|
78
79
|
:header_params => header_params,
|
79
80
|
:query_params => query_params,
|
80
81
|
:form_params => form_params,
|
@@ -128,15 +129,16 @@ module Patch
|
|
128
129
|
form_params = opts[:form_params] || {}
|
129
130
|
|
130
131
|
# http body (model)
|
131
|
-
post_body = opts[:
|
132
|
+
post_body = opts[:debug_body]
|
132
133
|
|
133
134
|
# return_type
|
134
|
-
return_type = opts[:
|
135
|
+
return_type = opts[:debug_return_type] || 'PreferenceResponse'
|
135
136
|
|
136
137
|
# auth_names
|
137
|
-
auth_names = opts[:
|
138
|
+
auth_names = opts[:debug_auth_names] || ['bearer_auth']
|
138
139
|
|
139
140
|
new_options = opts.merge(
|
141
|
+
:operation => :"PreferencesApi.delete_preference",
|
140
142
|
:header_params => header_params,
|
141
143
|
:query_params => query_params,
|
142
144
|
:form_params => form_params,
|
@@ -190,15 +192,16 @@ module Patch
|
|
190
192
|
form_params = opts[:form_params] || {}
|
191
193
|
|
192
194
|
# http body (model)
|
193
|
-
post_body = opts[:
|
195
|
+
post_body = opts[:debug_body]
|
194
196
|
|
195
197
|
# return_type
|
196
|
-
return_type = opts[:
|
198
|
+
return_type = opts[:debug_return_type] || 'PreferenceResponse'
|
197
199
|
|
198
200
|
# auth_names
|
199
|
-
auth_names = opts[:
|
201
|
+
auth_names = opts[:debug_auth_names] || ['bearer_auth']
|
200
202
|
|
201
203
|
new_options = opts.merge(
|
204
|
+
:operation => :"PreferencesApi.retrieve_preference",
|
202
205
|
:header_params => header_params,
|
203
206
|
:query_params => query_params,
|
204
207
|
:form_params => form_params,
|
@@ -249,15 +252,16 @@ module Patch
|
|
249
252
|
form_params = opts[:form_params] || {}
|
250
253
|
|
251
254
|
# http body (model)
|
252
|
-
post_body = opts[:
|
255
|
+
post_body = opts[:debug_body]
|
253
256
|
|
254
257
|
# return_type
|
255
|
-
return_type = opts[:
|
258
|
+
return_type = opts[:debug_return_type] || 'PreferenceListResponse'
|
256
259
|
|
257
260
|
# auth_names
|
258
|
-
auth_names = opts[:
|
261
|
+
auth_names = opts[:debug_auth_names] || ['bearer_auth']
|
259
262
|
|
260
263
|
new_options = opts.merge(
|
264
|
+
:operation => :"PreferencesApi.retrieve_preferences",
|
261
265
|
:header_params => header_params,
|
262
266
|
:query_params => query_params,
|
263
267
|
:form_params => form_params,
|
@@ -6,7 +6,7 @@
|
|
6
6
|
The version of the OpenAPI document: v1
|
7
7
|
Contact: developers@usepatch.com
|
8
8
|
Generated by: https://openapi-generator.tech
|
9
|
-
OpenAPI Generator version:
|
9
|
+
OpenAPI Generator version: 5.2.1
|
10
10
|
|
11
11
|
=end
|
12
12
|
|
@@ -62,15 +62,16 @@ module Patch
|
|
62
62
|
form_params = opts[:form_params] || {}
|
63
63
|
|
64
64
|
# http body (model)
|
65
|
-
post_body = opts[:
|
65
|
+
post_body = opts[:debug_body]
|
66
66
|
|
67
67
|
# return_type
|
68
|
-
return_type = opts[:
|
68
|
+
return_type = opts[:debug_return_type] || 'ProjectResponse'
|
69
69
|
|
70
70
|
# auth_names
|
71
|
-
auth_names = opts[:
|
71
|
+
auth_names = opts[:debug_auth_names] || ['bearer_auth']
|
72
72
|
|
73
73
|
new_options = opts.merge(
|
74
|
+
:operation => :"ProjectsApi.retrieve_project",
|
74
75
|
:header_params => header_params,
|
75
76
|
:query_params => query_params,
|
76
77
|
:form_params => form_params,
|
@@ -130,15 +131,16 @@ module Patch
|
|
130
131
|
form_params = opts[:form_params] || {}
|
131
132
|
|
132
133
|
# http body (model)
|
133
|
-
post_body = opts[:
|
134
|
+
post_body = opts[:debug_body]
|
134
135
|
|
135
136
|
# return_type
|
136
|
-
return_type = opts[:
|
137
|
+
return_type = opts[:debug_return_type] || 'ProjectListResponse'
|
137
138
|
|
138
139
|
# auth_names
|
139
|
-
auth_names = opts[:
|
140
|
+
auth_names = opts[:debug_auth_names] || ['bearer_auth']
|
140
141
|
|
141
142
|
new_options = opts.merge(
|
143
|
+
:operation => :"ProjectsApi.retrieve_projects",
|
142
144
|
:header_params => header_params,
|
143
145
|
:query_params => query_params,
|
144
146
|
:form_params => form_params,
|
@@ -6,7 +6,7 @@
|
|
6
6
|
The version of the OpenAPI document: v1
|
7
7
|
Contact: developers@usepatch.com
|
8
8
|
Generated by: https://openapi-generator.tech
|
9
|
-
OpenAPI Generator version:
|
9
|
+
OpenAPI Generator version: 5.2.1
|
10
10
|
|
11
11
|
=end
|
12
12
|
|
@@ -14,6 +14,7 @@ require 'date'
|
|
14
14
|
require 'json'
|
15
15
|
require 'logger'
|
16
16
|
require 'tempfile'
|
17
|
+
require 'time'
|
17
18
|
require 'typhoeus'
|
18
19
|
|
19
20
|
module Patch
|
@@ -30,7 +31,7 @@ module Patch
|
|
30
31
|
# @option config [Configuration] Configuration for initializing the object, default to Configuration.default
|
31
32
|
def initialize(config = Configuration.default)
|
32
33
|
@config = config
|
33
|
-
@user_agent = "
|
34
|
+
@user_agent = "patch-ruby/1.11.0"
|
34
35
|
@default_headers = {
|
35
36
|
'Content-Type' => 'application/json',
|
36
37
|
'User-Agent' => @user_agent
|
@@ -86,7 +87,7 @@ module Patch
|
|
86
87
|
# @option opts [Object] :body HTTP body (JSON/XML)
|
87
88
|
# @return [Typhoeus::Request] A Typhoeus Request
|
88
89
|
def build_request(http_method, path, opts = {})
|
89
|
-
url = build_request_url(path)
|
90
|
+
url = build_request_url(path, opts)
|
90
91
|
http_method = http_method.to_sym.downcase
|
91
92
|
|
92
93
|
header_params = @default_headers.merge(opts[:header_params] || {})
|
@@ -155,6 +156,44 @@ module Patch
|
|
155
156
|
data
|
156
157
|
end
|
157
158
|
|
159
|
+
# Save response body into a file in (the defined) temporary folder, using the filename
|
160
|
+
# from the "Content-Disposition" header if provided, otherwise a random filename.
|
161
|
+
# The response body is written to the file in chunks in order to handle files which
|
162
|
+
# size is larger than maximum Ruby String or even larger than the maximum memory a Ruby
|
163
|
+
# process can use.
|
164
|
+
#
|
165
|
+
# @see Configuration#temp_folder_path
|
166
|
+
def download_file(request)
|
167
|
+
tempfile = nil
|
168
|
+
encoding = nil
|
169
|
+
request.on_headers do |response|
|
170
|
+
content_disposition = response.headers['Content-Disposition']
|
171
|
+
if content_disposition && content_disposition =~ /filename=/i
|
172
|
+
filename = content_disposition[/filename=['"]?([^'"\s]+)['"]?/, 1]
|
173
|
+
prefix = sanitize_filename(filename)
|
174
|
+
else
|
175
|
+
prefix = 'download-'
|
176
|
+
end
|
177
|
+
prefix = prefix + '-' unless prefix.end_with?('-')
|
178
|
+
encoding = response.body.encoding
|
179
|
+
tempfile = Tempfile.open(prefix, @config.temp_folder_path, encoding: encoding)
|
180
|
+
@tempfile = tempfile
|
181
|
+
end
|
182
|
+
request.on_body do |chunk|
|
183
|
+
chunk.force_encoding(encoding)
|
184
|
+
tempfile.write(chunk)
|
185
|
+
end
|
186
|
+
request.on_complete do |response|
|
187
|
+
if tempfile
|
188
|
+
tempfile.close
|
189
|
+
@config.logger.info "Temp file written to #{tempfile.path}, please copy the file to a proper folder "\
|
190
|
+
"with e.g. `FileUtils.cp(tempfile.path, '/new/file/path')` otherwise the temp file "\
|
191
|
+
"will be deleted automatically with GC. It's also recommended to delete the temp file "\
|
192
|
+
"explicitly with `tempfile.delete`"
|
193
|
+
end
|
194
|
+
end
|
195
|
+
end
|
196
|
+
|
158
197
|
# Check if the given MIME is a JSON MIME.
|
159
198
|
# JSON MIME examples:
|
160
199
|
# application/json
|
@@ -191,7 +230,7 @@ module Patch
|
|
191
230
|
begin
|
192
231
|
data = JSON.parse("[#{body}]", :symbolize_names => true)[0]
|
193
232
|
rescue JSON::ParserError => e
|
194
|
-
if %w(String Date
|
233
|
+
if %w(String Date Time).include?(return_type)
|
195
234
|
data = body
|
196
235
|
else
|
197
236
|
raise e
|
@@ -216,9 +255,9 @@ module Patch
|
|
216
255
|
data.to_f
|
217
256
|
when 'Boolean'
|
218
257
|
data == true
|
219
|
-
when '
|
258
|
+
when 'Time'
|
220
259
|
# parse date time (expecting ISO 8601 format)
|
221
|
-
|
260
|
+
Time.parse data
|
222
261
|
when 'Date'
|
223
262
|
# parse date time (expecting ISO 8601 format)
|
224
263
|
Date.parse data
|
@@ -236,46 +275,9 @@ module Patch
|
|
236
275
|
data.each { |k, v| hash[k] = convert_to_type(v, sub_type) }
|
237
276
|
end
|
238
277
|
else
|
239
|
-
# models
|
240
|
-
Patch.const_get(return_type)
|
241
|
-
|
242
|
-
end
|
243
|
-
|
244
|
-
# Save response body into a file in (the defined) temporary folder, using the filename
|
245
|
-
# from the "Content-Disposition" header if provided, otherwise a random filename.
|
246
|
-
# The response body is written to the file in chunks in order to handle files which
|
247
|
-
# size is larger than maximum Ruby String or even larger than the maximum memory a Ruby
|
248
|
-
# process can use.
|
249
|
-
#
|
250
|
-
# @see Configuration#temp_folder_path
|
251
|
-
def download_file(request)
|
252
|
-
tempfile = nil
|
253
|
-
encoding = nil
|
254
|
-
request.on_headers do |response|
|
255
|
-
content_disposition = response.headers['Content-Disposition']
|
256
|
-
if content_disposition && content_disposition =~ /filename=/i
|
257
|
-
filename = content_disposition[/filename=['"]?([^'"\s]+)['"]?/, 1]
|
258
|
-
prefix = sanitize_filename(filename)
|
259
|
-
else
|
260
|
-
prefix = 'download-'
|
261
|
-
end
|
262
|
-
prefix = prefix + '-' unless prefix.end_with?('-')
|
263
|
-
encoding = response.body.encoding
|
264
|
-
tempfile = Tempfile.open(prefix, @config.temp_folder_path, encoding: encoding)
|
265
|
-
@tempfile = tempfile
|
266
|
-
end
|
267
|
-
request.on_body do |chunk|
|
268
|
-
chunk.force_encoding(encoding)
|
269
|
-
tempfile.write(chunk)
|
270
|
-
end
|
271
|
-
request.on_complete do |response|
|
272
|
-
if tempfile
|
273
|
-
tempfile.close
|
274
|
-
@config.logger.info "Temp file written to #{tempfile.path}, please copy the file to a proper folder "\
|
275
|
-
"with e.g. `FileUtils.cp(tempfile.path, '/new/file/path')` otherwise the temp file "\
|
276
|
-
"will be deleted automatically with GC. It's also recommended to delete the temp file "\
|
277
|
-
"explicitly with `tempfile.delete`"
|
278
|
-
end
|
278
|
+
# models (e.g. Pet) or oneOf
|
279
|
+
klass = Patch.const_get(return_type)
|
280
|
+
klass.respond_to?(:openapi_one_of) ? klass.build(data) : klass.build_from_hash(data)
|
279
281
|
end
|
280
282
|
end
|
281
283
|
|
@@ -288,10 +290,10 @@ module Patch
|
|
288
290
|
filename.gsub(/.*[\/\\]/, '')
|
289
291
|
end
|
290
292
|
|
291
|
-
def build_request_url(path)
|
293
|
+
def build_request_url(path, opts = {})
|
292
294
|
# Add leading and trailing slashes to path
|
293
295
|
path = "/#{path}".gsub(/\/+/, '/')
|
294
|
-
@config.base_url + path
|
296
|
+
@config.base_url(opts[:operation]) + path
|
295
297
|
end
|
296
298
|
|
297
299
|
# Update hearder and query params based on authentication settings.
|
@@ -306,7 +308,7 @@ module Patch
|
|
306
308
|
case auth_setting[:in]
|
307
309
|
when 'header' then header_params[auth_setting[:key]] = auth_setting[:value]
|
308
310
|
when 'query' then query_params[auth_setting[:key]] = auth_setting[:value]
|
309
|
-
else fail ArgumentError, 'Authentication token must be in `query`
|
311
|
+
else fail ArgumentError, 'Authentication token must be in `query` or `header`'
|
310
312
|
end
|
311
313
|
end
|
312
314
|
end
|
data/lib/patch_ruby/api_error.rb
CHANGED
@@ -6,7 +6,7 @@
|
|
6
6
|
The version of the OpenAPI document: v1
|
7
7
|
Contact: developers@usepatch.com
|
8
8
|
Generated by: https://openapi-generator.tech
|
9
|
-
OpenAPI Generator version:
|
9
|
+
OpenAPI Generator version: 5.2.1
|
10
10
|
|
11
11
|
=end
|
12
12
|
|
@@ -21,6 +21,18 @@ module Patch
|
|
21
21
|
# Defines url base path
|
22
22
|
attr_accessor :base_path
|
23
23
|
|
24
|
+
# Define server configuration index
|
25
|
+
attr_accessor :server_index
|
26
|
+
|
27
|
+
# Define server operation configuration index
|
28
|
+
attr_accessor :server_operation_index
|
29
|
+
|
30
|
+
# Default server variables
|
31
|
+
attr_accessor :server_variables
|
32
|
+
|
33
|
+
# Default server operation variables
|
34
|
+
attr_accessor :server_operation_variables
|
35
|
+
|
24
36
|
# Defines API keys used with API Key authentications.
|
25
37
|
#
|
26
38
|
# @return [Hash] key: parameter name, value: parameter value (API key)
|
@@ -129,6 +141,10 @@ module Patch
|
|
129
141
|
@scheme = 'https'
|
130
142
|
@host = 'api.patch.io'
|
131
143
|
@base_path = ''
|
144
|
+
@server_index = 0
|
145
|
+
@server_operation_index = {}
|
146
|
+
@server_variables = {}
|
147
|
+
@server_operation_variables = {}
|
132
148
|
@api_key = {}
|
133
149
|
@api_key_prefix = {}
|
134
150
|
@timeout = 0
|
@@ -171,17 +187,23 @@ module Patch
|
|
171
187
|
@base_path = '' if @base_path == '/'
|
172
188
|
end
|
173
189
|
|
174
|
-
|
175
|
-
|
190
|
+
# Returns base URL for specified operation based on server settings
|
191
|
+
def base_url(operation = nil)
|
192
|
+
index = server_operation_index.fetch(operation, server_index)
|
193
|
+
return "#{scheme}://#{[host, base_path].join('/').gsub(/\/+/, '/')}".sub(/\/+\z/, '') if index == nil
|
194
|
+
|
195
|
+
server_url(index, server_operation_variables.fetch(operation, server_variables), operation_server_settings[operation])
|
176
196
|
end
|
177
197
|
|
178
198
|
# Gets API key (with prefix if set).
|
179
199
|
# @param [String] param_name the parameter name of API key auth
|
180
|
-
def api_key_with_prefix(param_name)
|
200
|
+
def api_key_with_prefix(param_name, param_alias = nil)
|
201
|
+
key = @api_key[param_name]
|
202
|
+
key = @api_key.fetch(param_alias, key) unless param_alias.nil?
|
181
203
|
if @api_key_prefix[param_name]
|
182
|
-
"#{@api_key_prefix[param_name]} #{
|
204
|
+
"#{@api_key_prefix[param_name]} #{key}"
|
183
205
|
else
|
184
|
-
|
206
|
+
key
|
185
207
|
end
|
186
208
|
end
|
187
209
|
|
@@ -219,12 +241,17 @@ module Patch
|
|
219
241
|
]
|
220
242
|
end
|
221
243
|
|
244
|
+
def operation_server_settings
|
245
|
+
{
|
246
|
+
}
|
247
|
+
end
|
248
|
+
|
222
249
|
# Returns URL based on server settings
|
223
250
|
#
|
224
251
|
# @param index array index of the server settings
|
225
252
|
# @param variables hash of variable and the corresponding value
|
226
|
-
def server_url(index, variables = {})
|
227
|
-
servers = server_settings
|
253
|
+
def server_url(index, variables = {}, servers = nil)
|
254
|
+
servers = server_settings if servers == nil
|
228
255
|
|
229
256
|
# check array index out of bound
|
230
257
|
if (index < 0 || index >= servers.size)
|
@@ -234,10 +261,12 @@ module Patch
|
|
234
261
|
server = servers[index]
|
235
262
|
url = server[:url]
|
236
263
|
|
264
|
+
return url unless server.key? :variables
|
265
|
+
|
237
266
|
# go through variable and assign a value
|
238
267
|
server[:variables].each do |name, variable|
|
239
268
|
if variables.key?(name)
|
240
|
-
if (server[:variables][name][:enum_values].include?
|
269
|
+
if (!server[:variables][name].key?(:enum_values) || server[:variables][name][:enum_values].include?(variables[name]))
|
241
270
|
url.gsub! "{" + name.to_s + "}", variables[name]
|
242
271
|
else
|
243
272
|
fail ArgumentError, "The variable `#{name}` in the server URL has invalid value #{variables[name]}. Must be #{server[:variables][name][:enum_values]}."
|
@@ -6,11 +6,12 @@
|
|
6
6
|
The version of the OpenAPI document: v1
|
7
7
|
Contact: developers@usepatch.com
|
8
8
|
Generated by: https://openapi-generator.tech
|
9
|
-
OpenAPI Generator version:
|
9
|
+
OpenAPI Generator version: 5.2.1
|
10
10
|
|
11
11
|
=end
|
12
12
|
|
13
13
|
require 'date'
|
14
|
+
require 'time'
|
14
15
|
|
15
16
|
module Patch
|
16
17
|
class Allocation
|
@@ -32,6 +33,11 @@ module Patch
|
|
32
33
|
}
|
33
34
|
end
|
34
35
|
|
36
|
+
# Returns all the JSON keys this model knows about
|
37
|
+
def self.acceptable_attributes
|
38
|
+
attribute_map.values
|
39
|
+
end
|
40
|
+
|
35
41
|
# Attribute type mapping.
|
36
42
|
def self.openapi_types
|
37
43
|
{
|
@@ -41,13 +47,13 @@ module Patch
|
|
41
47
|
}
|
42
48
|
end
|
43
49
|
|
44
|
-
#
|
50
|
+
# List of attributes with nullable: true
|
45
51
|
def self.openapi_nullable
|
46
|
-
|
47
|
-
|
48
|
-
nullable_properties
|
52
|
+
Set.new([
|
53
|
+
])
|
49
54
|
end
|
50
55
|
|
56
|
+
|
51
57
|
# Allows models with corresponding API classes to delegate API operations to those API classes
|
52
58
|
# Exposes Model.operation_id which delegates to ModelsApi.new.operation_id
|
53
59
|
# Eg. Order.create_order delegates to OrdersApi.new.create_order
|
@@ -150,7 +156,9 @@ module Patch
|
|
150
156
|
def build_from_hash(attributes)
|
151
157
|
return nil unless attributes.is_a?(Hash)
|
152
158
|
self.class.openapi_types.each_pair do |key, type|
|
153
|
-
if
|
159
|
+
if attributes[self.class.attribute_map[key]].nil? && self.class.openapi_nullable.include?(key)
|
160
|
+
self.send("#{key}=", nil)
|
161
|
+
elsif type =~ /\AArray<(.*)>/i
|
154
162
|
# check to ensure the input is an array given that the attribute
|
155
163
|
# is documented as an array but the input is not
|
156
164
|
if attributes[self.class.attribute_map[key]].is_a?(Array)
|
@@ -158,7 +166,7 @@ module Patch
|
|
158
166
|
end
|
159
167
|
elsif !attributes[self.class.attribute_map[key]].nil?
|
160
168
|
self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
|
161
|
-
end
|
169
|
+
end
|
162
170
|
end
|
163
171
|
|
164
172
|
self
|
@@ -170,8 +178,8 @@ module Patch
|
|
170
178
|
# @return [Object] Deserialized data
|
171
179
|
def _deserialize(type, value)
|
172
180
|
case type.to_sym
|
173
|
-
when :
|
174
|
-
|
181
|
+
when :Time
|
182
|
+
Time.parse(value)
|
175
183
|
when :Date
|
176
184
|
Date.parse(value)
|
177
185
|
when :String
|
@@ -201,7 +209,9 @@ module Patch
|
|
201
209
|
end
|
202
210
|
end
|
203
211
|
else # model
|
204
|
-
|
212
|
+
# models (e.g. Pet) or oneOf
|
213
|
+
klass = Patch.const_get(type)
|
214
|
+
klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass.build_from_hash(value)
|
205
215
|
end
|
206
216
|
end
|
207
217
|
|
@@ -227,7 +237,7 @@ module Patch
|
|
227
237
|
is_nullable = self.class.openapi_nullable.include?(attr)
|
228
238
|
next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
|
229
239
|
end
|
230
|
-
|
240
|
+
|
231
241
|
hash[param] = _to_hash(value)
|
232
242
|
end
|
233
243
|
hash
|