docraptor 2.0.0 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (64) hide show
  1. checksums.yaml +4 -4
  2. data/.docker_env.list +3 -0
  3. data/.generator-language-identifier +1 -0
  4. data/.generator-revision +1 -0
  5. data/.github/pull_request_template.txt +17 -0
  6. data/.gitignore +20 -14
  7. data/.gitlab-ci.yml +26 -0
  8. data/.openapi-generator/FILES +27 -0
  9. data/.openapi-generator/VERSION +1 -0
  10. data/{.swagger-codegen-ignore → .openapi-generator-ignore} +23 -7
  11. data/.review/README.md +16 -0
  12. data/.review/generated_files/.gitignore +39 -0
  13. data/.review/generated_files/README.md +107 -0
  14. data/.rubocop.yml +148 -0
  15. data/.runtime-environments +10 -0
  16. data/.travis.yml +12 -7
  17. data/CHANGELOG.md +5 -0
  18. data/Gemfile +3 -1
  19. data/README.md +8 -8
  20. data/Rakefile +1 -2
  21. data/docraptor.gemspec +5 -19
  22. data/docraptor.yaml +5 -4
  23. data/examples/async.rb +24 -30
  24. data/examples/hosted_async.rb +21 -33
  25. data/examples/hosted_sync.rb +19 -32
  26. data/examples/sync.rb +20 -26
  27. data/gemfiles/Gemfile.2.5.lock +70 -0
  28. data/gemfiles/Gemfile.2.6.lock +70 -0
  29. data/gemfiles/Gemfile.2.7.lock +70 -0
  30. data/gemfiles/Gemfile.3.0.lock +70 -0
  31. data/{swagger-config.json → generator-config.json} +3 -2
  32. data/lib/docraptor/api/doc_api.rb +154 -79
  33. data/lib/docraptor/api_client.rb +91 -90
  34. data/lib/docraptor/api_error.rb +22 -3
  35. data/lib/docraptor/configuration.rb +85 -15
  36. data/lib/docraptor/models/async_doc.rb +53 -18
  37. data/lib/docraptor/models/doc.rb +80 -45
  38. data/lib/docraptor/models/doc_status.rb +58 -23
  39. data/lib/docraptor/models/prince_options.rb +101 -66
  40. data/lib/docraptor/version.rb +4 -4
  41. data/lib/docraptor.rb +3 -3
  42. data/script/clean +2 -2
  43. data/script/console +5 -0
  44. data/script/docker +39 -0
  45. data/script/fix_gemspec.rb +3 -18
  46. data/script/generate_language +21 -4
  47. data/script/inside_container/README.md +6 -0
  48. data/script/inside_container/test +38 -0
  49. data/script/post_generate_language +10 -2
  50. data/script/setup +25 -14
  51. data/script/swagger +6 -33
  52. data/script/test +30 -27
  53. data/test/async.rb +2 -2
  54. data/test/expire_hosted.rb +2 -2
  55. data/test/hosted_async.rb +7 -1
  56. data/test/hosted_sync.rb +2 -2
  57. data/test/sync.rb +2 -2
  58. data/test/xlsx.rb +6 -3
  59. metadata +29 -217
  60. data/.swagger-codegen/VERSION +0 -1
  61. data/.swagger-revision +0 -1
  62. data/spec/api_client_spec.rb +0 -243
  63. data/spec/configuration_spec.rb +0 -42
  64. data/spec/spec_helper.rb +0 -111
@@ -3,10 +3,10 @@
3
3
 
4
4
  #A native client library for the DocRaptor HTML to PDF/XLS service.
5
5
 
6
- OpenAPI spec version: 1.4.0
6
+ The version of the OpenAPI document: 2.0.0
7
7
 
8
- Generated by: https://github.com/swagger-api/swagger-codegen.git
9
- Swagger Codegen version: 2.4.19
8
+ Generated by: https://openapi-generator.tech
9
+ OpenAPI Generator version: 6.1.0-SNAPSHOT
10
10
 
11
11
  =end
12
12
 
@@ -14,8 +14,8 @@ require 'date'
14
14
  require 'json'
15
15
  require 'logger'
16
16
  require 'tempfile'
17
+ require 'time'
17
18
  require 'typhoeus'
18
- require 'addressable/uri'
19
19
 
20
20
  module DocRaptor
21
21
  class ApiClient
@@ -44,7 +44,7 @@ module DocRaptor
44
44
 
45
45
  # Call an API with given options.
46
46
  #
47
- # @return [Array<(Object, Fixnum, Hash)>] an array of 3 elements:
47
+ # @return [Array<(Object, Integer, Hash)>] an array of 3 elements:
48
48
  # the data deserialized from response body (could be nil), response status code and response headers.
49
49
  def call_api(http_method, path, opts = {})
50
50
  request = build_request(http_method, path, opts)
@@ -63,7 +63,7 @@ module DocRaptor
63
63
  :message => response.return_message)
64
64
  else
65
65
  fail ApiError.new(:code => response.code,
66
- :response_headers => response.headers.to_h,
66
+ :response_headers => response.headers,
67
67
  :response_body => response.body),
68
68
  response.status_message
69
69
  end
@@ -87,12 +87,13 @@ module DocRaptor
87
87
  # @option opts [Object] :body HTTP body (JSON/XML)
88
88
  # @return [Typhoeus::Request] A Typhoeus Request
89
89
  def build_request(http_method, path, opts = {})
90
- url = build_request_url(path)
90
+ url = build_request_url(path, opts)
91
91
  http_method = http_method.to_sym.downcase
92
92
 
93
93
  header_params = @default_headers.merge(opts[:header_params] || {})
94
94
  query_params = opts[:query_params] || {}
95
95
  form_params = opts[:form_params] || {}
96
+ follow_location = opts[:follow_location] || true
96
97
 
97
98
  update_params_for_auth! header_params, query_params, opts[:auth_names]
98
99
 
@@ -109,11 +110,10 @@ module DocRaptor
109
110
  :ssl_verifyhost => _verify_ssl_host,
110
111
  :sslcert => @config.cert_file,
111
112
  :sslkey => @config.key_file,
112
- :verbose => @config.debugging
113
+ :verbose => @config.debugging,
114
+ :followlocation => follow_location
113
115
  }
114
116
 
115
- req_opts.merge!(multipart: true) if header_params['Content-Type'].start_with? "multipart/"
116
-
117
117
  # set custom cert, if provided
118
118
  req_opts[:cainfo] = @config.ssl_ca_cert if @config.ssl_ca_cert
119
119
 
@@ -130,6 +130,72 @@ module DocRaptor
130
130
  request
131
131
  end
132
132
 
133
+ # Builds the HTTP request body
134
+ #
135
+ # @param [Hash] header_params Header parameters
136
+ # @param [Hash] form_params Query parameters
137
+ # @param [Object] body HTTP body (JSON/XML)
138
+ # @return [String] HTTP body data in the form of string
139
+ def build_request_body(header_params, form_params, body)
140
+ # http form
141
+ if header_params['Content-Type'] == 'application/x-www-form-urlencoded' ||
142
+ header_params['Content-Type'] == 'multipart/form-data'
143
+ data = {}
144
+ form_params.each do |key, value|
145
+ case value
146
+ when ::File, ::Array, nil
147
+ # let typhoeus handle File, Array and nil parameters
148
+ data[key] = value
149
+ else
150
+ data[key] = value.to_s
151
+ end
152
+ end
153
+ elsif body
154
+ data = body.is_a?(String) ? body : body.to_json
155
+ else
156
+ data = nil
157
+ end
158
+ data
159
+ end
160
+
161
+ # Save response body into a file in (the defined) temporary folder, using the filename
162
+ # from the "Content-Disposition" header if provided, otherwise a random filename.
163
+ # The response body is written to the file in chunks in order to handle files which
164
+ # size is larger than maximum Ruby String or even larger than the maximum memory a Ruby
165
+ # process can use.
166
+ #
167
+ # @see Configuration#temp_folder_path
168
+ def download_file(request)
169
+ tempfile = nil
170
+ encoding = nil
171
+ request.on_headers do |response|
172
+ content_disposition = response.headers['Content-Disposition']
173
+ if content_disposition && content_disposition =~ /filename=/i
174
+ filename = content_disposition[/filename=['"]?([^'"\s]+)['"]?/, 1]
175
+ prefix = sanitize_filename(filename)
176
+ else
177
+ prefix = 'download-'
178
+ end
179
+ prefix = prefix + '-' unless prefix.end_with?('-')
180
+ encoding = response.body.encoding
181
+ tempfile = Tempfile.open(prefix, @config.temp_folder_path, encoding: encoding)
182
+ @tempfile = tempfile
183
+ end
184
+ request.on_body do |chunk|
185
+ chunk.force_encoding(encoding)
186
+ tempfile.write(chunk)
187
+ end
188
+ request.on_complete do |response|
189
+ if tempfile
190
+ tempfile.close
191
+ @config.logger.info "Temp file written to #{tempfile.path}, please copy the file to a proper folder "\
192
+ "with e.g. `FileUtils.cp(tempfile.path, '/new/file/path')` otherwise the temp file "\
193
+ "will be deleted automatically with GC. It's also recommended to delete the temp file "\
194
+ "explicitly with `tempfile.delete`"
195
+ end
196
+ end
197
+ end
198
+
133
199
  # Check if the given MIME is a JSON MIME.
134
200
  # JSON MIME examples:
135
201
  # application/json
@@ -145,7 +211,7 @@ module DocRaptor
145
211
  # Deserialize the response to the given return type.
146
212
  #
147
213
  # @param [Response] response HTTP response
148
- # @param [String] return_type some examples: "User", "Array[User]", "Hash[String,Integer]"
214
+ # @param [String] return_type some examples: "User", "Array<User>", "Hash<String, Integer>"
149
215
  def deserialize(response, return_type)
150
216
  body = response.body
151
217
 
@@ -166,7 +232,7 @@ module DocRaptor
166
232
  begin
167
233
  data = JSON.parse("[#{body}]", :symbolize_names => true)[0]
168
234
  rescue JSON::ParserError => e
169
- if %w(String Date DateTime).include?(return_type)
235
+ if %w(String Date Time).include?(return_type)
170
236
  data = body
171
237
  else
172
238
  raise e
@@ -189,11 +255,11 @@ module DocRaptor
189
255
  data.to_i
190
256
  when 'Float'
191
257
  data.to_f
192
- when 'BOOLEAN'
258
+ when 'Boolean'
193
259
  data == true
194
- when 'DateTime'
260
+ when 'Time'
195
261
  # parse date time (expecting ISO 8601 format)
196
- DateTime.parse data
262
+ Time.parse data
197
263
  when 'Date'
198
264
  # parse date time (expecting ISO 8601 format)
199
265
  Date.parse data
@@ -211,46 +277,9 @@ module DocRaptor
211
277
  data.each { |k, v| hash[k] = convert_to_type(v, sub_type) }
212
278
  end
213
279
  else
214
- # models, e.g. Pet
215
- DocRaptor.const_get(return_type).new.tap do |model|
216
- model.build_from_hash data
217
- end
218
- end
219
- end
220
-
221
- # Save response body into a file in (the defined) temporary folder, using the filename
222
- # from the "Content-Disposition" header if provided, otherwise a random filename.
223
- # The response body is written to the file in chunks in order to handle files which
224
- # size is larger than maximum Ruby String or even larger than the maximum memory a Ruby
225
- # process can use.
226
- #
227
- # @see Configuration#temp_folder_path
228
- def download_file(request)
229
- tempfile = nil
230
- encoding = nil
231
- request.on_headers do |response|
232
- content_disposition = response.headers['Content-Disposition']
233
- if content_disposition && content_disposition =~ /filename=/i
234
- filename = content_disposition[/filename=['"]?([^'"\s]+)['"]?/, 1]
235
- prefix = sanitize_filename(filename)
236
- else
237
- prefix = 'download-'
238
- end
239
- prefix = prefix + '-' unless prefix.end_with?('-')
240
- encoding = response.body.encoding
241
- tempfile = Tempfile.open(prefix, @config.temp_folder_path, encoding: encoding)
242
- @tempfile = tempfile
243
- end
244
- request.on_body do |chunk|
245
- chunk.force_encoding(encoding)
246
- tempfile.write(chunk)
247
- end
248
- request.on_complete do |response|
249
- tempfile.close
250
- @config.logger.info "Temp file written to #{tempfile.path}, please copy the file to a proper folder "\
251
- "with e.g. `FileUtils.cp(tempfile.path, '/new/file/path')` otherwise the temp file "\
252
- "will be deleted automatically with GC. It's also recommended to delete the temp file "\
253
- "explicitly with `tempfile.delete`"
280
+ # models (e.g. Pet) or oneOf
281
+ klass = DocRaptor.const_get(return_type)
282
+ klass.respond_to?(:openapi_one_of) ? klass.build(data) : klass.build_from_hash(data)
254
283
  end
255
284
  end
256
285
 
@@ -263,41 +292,13 @@ module DocRaptor
263
292
  filename.gsub(/.*[\/\\]/, '')
264
293
  end
265
294
 
266
- def build_request_url(path)
295
+ def build_request_url(path, opts = {})
267
296
  # Add leading and trailing slashes to path
268
297
  path = "/#{path}".gsub(/\/+/, '/')
269
- Addressable::URI.encode(@config.base_url + path)
270
- end
271
-
272
- # Builds the HTTP request body
273
- #
274
- # @param [Hash] header_params Header parameters
275
- # @param [Hash] form_params Query parameters
276
- # @param [Object] body HTTP body (JSON/XML)
277
- # @return [String] HTTP body data in the form of string
278
- def build_request_body(header_params, form_params, body)
279
- # http form
280
- if header_params['Content-Type'] == 'application/x-www-form-urlencoded' ||
281
- header_params['Content-Type'] == 'multipart/form-data'
282
- data = {}
283
- form_params.each do |key, value|
284
- case value
285
- when ::File, ::Array, nil
286
- # let typhoeus handle File, Array and nil parameters
287
- data[key] = value
288
- else
289
- data[key] = value.to_s
290
- end
291
- end
292
- elsif body
293
- data = body.is_a?(String) ? body : body.to_json
294
- else
295
- data = nil
296
- end
297
- data
298
+ @config.base_url(opts[:operation]) + path
298
299
  end
299
300
 
300
- # Update hearder and query params based on authentication settings.
301
+ # Update header and query params based on authentication settings.
301
302
  #
302
303
  # @param [Hash] header_params Header parameters
303
304
  # @param [Hash] query_params Query parameters
@@ -309,14 +310,14 @@ module DocRaptor
309
310
  case auth_setting[:in]
310
311
  when 'header' then header_params[auth_setting[:key]] = auth_setting[:value]
311
312
  when 'query' then query_params[auth_setting[:key]] = auth_setting[:value]
312
- else fail ArgumentError, 'Authentication token must be in `query` of `header`'
313
+ else fail ArgumentError, 'Authentication token must be in `query` or `header`'
313
314
  end
314
315
  end
315
316
  end
316
317
 
317
318
  # Sets user agent in HTTP header
318
319
  #
319
- # @param [String] user_agent User agent (e.g. swagger-codegen/ruby/1.0.0)
320
+ # @param [String] user_agent User agent (e.g. openapi-generator/ruby/1.0.0)
320
321
  def user_agent=(user_agent)
321
322
  @user_agent = user_agent
322
323
  @default_headers['User-Agent'] = @user_agent
@@ -336,8 +337,8 @@ module DocRaptor
336
337
  # @param [Array] content_types array for Content-Type
337
338
  # @return [String] the Content-Type header (e.g. application/json)
338
339
  def select_header_content_type(content_types)
339
- # use application/json by default
340
- return 'application/json' if content_types.nil? || content_types.empty?
340
+ # return nil by default
341
+ return if content_types.nil? || content_types.empty?
341
342
  # use JSON when present, otherwise use the first one
342
343
  json_content_type = content_types.find { |s| json_mime?(s) }
343
344
  json_content_type || content_types.first
@@ -3,10 +3,10 @@
3
3
 
4
4
  #A native client library for the DocRaptor HTML to PDF/XLS service.
5
5
 
6
- OpenAPI spec version: 1.4.0
6
+ The version of the OpenAPI document: 2.0.0
7
7
 
8
- Generated by: https://github.com/swagger-api/swagger-codegen.git
9
- Swagger Codegen version: 2.4.19
8
+ Generated by: https://openapi-generator.tech
9
+ OpenAPI Generator version: 6.1.0-SNAPSHOT
10
10
 
11
11
  =end
12
12
 
@@ -34,5 +34,24 @@ module DocRaptor
34
34
  super arg
35
35
  end
36
36
  end
37
+
38
+ # Override to_s to display a friendly error message
39
+ def to_s
40
+ message
41
+ end
42
+
43
+ def message
44
+ if @message.nil?
45
+ msg = "Error message: the server returns an error"
46
+ else
47
+ msg = @message
48
+ end
49
+
50
+ msg += "\nHTTP status code: #{code}" if code
51
+ msg += "\nResponse headers: #{response_headers}" if response_headers
52
+ msg += "\nResponse body: #{response_body}" if response_body
53
+
54
+ msg
55
+ end
37
56
  end
38
57
  end
@@ -3,15 +3,13 @@
3
3
 
4
4
  #A native client library for the DocRaptor HTML to PDF/XLS service.
5
5
 
6
- OpenAPI spec version: 1.4.0
6
+ The version of the OpenAPI document: 2.0.0
7
7
 
8
- Generated by: https://github.com/swagger-api/swagger-codegen.git
9
- Swagger Codegen version: 2.4.19
8
+ Generated by: https://openapi-generator.tech
9
+ OpenAPI Generator version: 6.1.0-SNAPSHOT
10
10
 
11
11
  =end
12
12
 
13
- require 'addressable/uri'
14
-
15
13
  module DocRaptor
16
14
  class Configuration
17
15
  # Defines url scheme
@@ -23,6 +21,18 @@ module DocRaptor
23
21
  # Defines url base path
24
22
  attr_accessor :base_path
25
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
+
26
36
  # Defines API keys used with API Key authentications.
27
37
  #
28
38
  # @return [Hash] key: parameter name, value: parameter value (API key)
@@ -123,23 +133,28 @@ module DocRaptor
123
133
  # https://github.com/typhoeus/ethon/blob/master/lib/ethon/easy/queryable.rb#L96
124
134
  attr_accessor :params_encoding
125
135
 
136
+
126
137
  attr_accessor :inject_format
127
138
 
128
139
  attr_accessor :force_ending_format
129
140
 
130
141
  def initialize
131
142
  @scheme = 'https'
132
- @host = 'docraptor.com'
133
- @base_path = '/'
143
+ @host = 'api.docraptor.com'
144
+ @base_path = ''
145
+ @server_index = 0
146
+ @server_operation_index = {}
147
+ @server_variables = {}
148
+ @server_operation_variables = {}
134
149
  @api_key = {}
135
150
  @api_key_prefix = {}
136
- @timeout = 0
137
151
  @client_side_validation = true
138
152
  @verify_ssl = true
139
153
  @verify_ssl_host = true
140
- @params_encoding = nil
141
154
  @cert_file = nil
142
155
  @key_file = nil
156
+ @timeout = 0
157
+ @params_encoding = nil
143
158
  @debugging = false
144
159
  @inject_format = false
145
160
  @force_ending_format = false
@@ -173,18 +188,23 @@ module DocRaptor
173
188
  @base_path = '' if @base_path == '/'
174
189
  end
175
190
 
176
- def base_url
177
- url = "#{scheme}://#{[host, base_path].join('/').gsub(/\/+/, '/')}".sub(/\/+\z/, '')
178
- Addressable::URI.encode(url)
191
+ # Returns base URL for specified operation based on server settings
192
+ def base_url(operation = nil)
193
+ index = server_operation_index.fetch(operation, server_index)
194
+ return "#{scheme}://#{[host, base_path].join('/').gsub(/\/+/, '/')}".sub(/\/+\z/, '') if index == nil
195
+
196
+ server_url(index, server_operation_variables.fetch(operation, server_variables), operation_server_settings[operation])
179
197
  end
180
198
 
181
199
  # Gets API key (with prefix if set).
182
200
  # @param [String] param_name the parameter name of API key auth
183
- def api_key_with_prefix(param_name)
201
+ def api_key_with_prefix(param_name, param_alias = nil)
202
+ key = @api_key[param_name]
203
+ key = @api_key.fetch(param_alias, key) unless param_alias.nil?
184
204
  if @api_key_prefix[param_name]
185
- "#{@api_key_prefix[param_name]} #{@api_key[param_name]}"
205
+ "#{@api_key_prefix[param_name]} #{key}"
186
206
  else
187
- @api_key[param_name]
207
+ key
188
208
  end
189
209
  end
190
210
 
@@ -205,5 +225,55 @@ module DocRaptor
205
225
  },
206
226
  }
207
227
  end
228
+
229
+ # Returns an array of Server setting
230
+ def server_settings
231
+ [
232
+ {
233
+ url: "https://api.docraptor.com",
234
+ description: "No description provided",
235
+ }
236
+ ]
237
+ end
238
+
239
+ def operation_server_settings
240
+ {
241
+ }
242
+ end
243
+
244
+ # Returns URL based on server settings
245
+ #
246
+ # @param index array index of the server settings
247
+ # @param variables hash of variable and the corresponding value
248
+ def server_url(index, variables = {}, servers = nil)
249
+ servers = server_settings if servers == nil
250
+
251
+ # check array index out of bound
252
+ if (index < 0 || index >= servers.size)
253
+ fail ArgumentError, "Invalid index #{index} when selecting the server. Must be less than #{servers.size}"
254
+ end
255
+
256
+ server = servers[index]
257
+ url = server[:url]
258
+
259
+ return url unless server.key? :variables
260
+
261
+ # go through variable and assign a value
262
+ server[:variables].each do |name, variable|
263
+ if variables.key?(name)
264
+ if (!server[:variables][name].key?(:enum_values) || server[:variables][name][:enum_values].include?(variables[name]))
265
+ url.gsub! "{" + name.to_s + "}", variables[name]
266
+ else
267
+ fail ArgumentError, "The variable `#{name}` in the server URL has invalid value #{variables[name]}. Must be #{server[:variables][name][:enum_values]}."
268
+ end
269
+ else
270
+ # use default value
271
+ url.gsub! "{" + name.to_s + "}", server[:variables][name][:default_value]
272
+ end
273
+ end
274
+
275
+ url
276
+ end
277
+
208
278
  end
209
279
  end
@@ -3,14 +3,15 @@
3
3
 
4
4
  #A native client library for the DocRaptor HTML to PDF/XLS service.
5
5
 
6
- OpenAPI spec version: 1.4.0
6
+ The version of the OpenAPI document: 2.0.0
7
7
 
8
- Generated by: https://github.com/swagger-api/swagger-codegen.git
9
- Swagger Codegen version: 2.4.19
8
+ Generated by: https://openapi-generator.tech
9
+ OpenAPI Generator version: 6.1.0-SNAPSHOT
10
10
 
11
11
  =end
12
12
 
13
13
  require 'date'
14
+ require 'time'
14
15
 
15
16
  module DocRaptor
16
17
  class AsyncDoc
@@ -24,22 +25,40 @@ module DocRaptor
24
25
  }
25
26
  end
26
27
 
28
+ # Returns all the JSON keys this model knows about
29
+ def self.acceptable_attributes
30
+ attribute_map.values
31
+ end
32
+
27
33
  # Attribute type mapping.
28
- def self.swagger_types
34
+ def self.openapi_types
29
35
  {
30
36
  :'status_id' => :'String'
31
37
  }
32
38
  end
33
39
 
40
+ # List of attributes with nullable: true
41
+ def self.openapi_nullable
42
+ Set.new([
43
+ ])
44
+ end
45
+
34
46
  # Initializes the object
35
47
  # @param [Hash] attributes Model attributes in the form of hash
36
48
  def initialize(attributes = {})
37
- return unless attributes.is_a?(Hash)
49
+ if (!attributes.is_a?(Hash))
50
+ fail ArgumentError, "The input argument (attributes) must be a hash in `DocRaptor::AsyncDoc` initialize method"
51
+ end
38
52
 
39
- # convert string to symbol for hash key
40
- attributes = attributes.each_with_object({}) { |(k, v), h| h[k.to_sym] = v }
53
+ # check to see if the attribute exists and convert string to symbol for hash key
54
+ attributes = attributes.each_with_object({}) { |(k, v), h|
55
+ if (!self.class.attribute_map.key?(k.to_sym))
56
+ fail ArgumentError, "`#{k}` is not a valid attribute in `DocRaptor::AsyncDoc`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
57
+ end
58
+ h[k.to_sym] = v
59
+ }
41
60
 
42
- if attributes.has_key?(:'status_id')
61
+ if attributes.key?(:'status_id')
43
62
  self.status_id = attributes[:'status_id']
44
63
  end
45
64
  end
@@ -72,18 +91,28 @@ module DocRaptor
72
91
  end
73
92
 
74
93
  # Calculates hash code according to all attributes.
75
- # @return [Fixnum] Hash code
94
+ # @return [Integer] Hash code
76
95
  def hash
77
96
  [status_id].hash
78
97
  end
79
98
 
99
+ # Builds the object from hash
100
+ # @param [Hash] attributes Model attributes in the form of hash
101
+ # @return [Object] Returns the model itself
102
+ def self.build_from_hash(attributes)
103
+ new.build_from_hash(attributes)
104
+ end
105
+
80
106
  # Builds the object from hash
81
107
  # @param [Hash] attributes Model attributes in the form of hash
82
108
  # @return [Object] Returns the model itself
83
109
  def build_from_hash(attributes)
84
110
  return nil unless attributes.is_a?(Hash)
85
- self.class.swagger_types.each_pair do |key, type|
86
- if type =~ /\AArray<(.*)>/i
111
+ attributes = attributes.transform_keys(&:to_sym)
112
+ self.class.openapi_types.each_pair do |key, type|
113
+ if attributes[self.class.attribute_map[key]].nil? && self.class.openapi_nullable.include?(key)
114
+ self.send("#{key}=", nil)
115
+ elsif type =~ /\AArray<(.*)>/i
87
116
  # check to ensure the input is an array given that the attribute
88
117
  # is documented as an array but the input is not
89
118
  if attributes[self.class.attribute_map[key]].is_a?(Array)
@@ -91,7 +120,7 @@ module DocRaptor
91
120
  end
92
121
  elsif !attributes[self.class.attribute_map[key]].nil?
93
122
  self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
94
- end # or else data not found in attributes(hash), not an issue as the data can be optional
123
+ end
95
124
  end
96
125
 
97
126
  self
@@ -103,8 +132,8 @@ module DocRaptor
103
132
  # @return [Object] Deserialized data
104
133
  def _deserialize(type, value)
105
134
  case type.to_sym
106
- when :DateTime
107
- DateTime.parse(value)
135
+ when :Time
136
+ Time.parse(value)
108
137
  when :Date
109
138
  Date.parse(value)
110
139
  when :String
@@ -113,7 +142,7 @@ module DocRaptor
113
142
  value.to_i
114
143
  when :Float
115
144
  value.to_f
116
- when :BOOLEAN
145
+ when :Boolean
117
146
  if value.to_s =~ /\A(true|t|yes|y|1)\z/i
118
147
  true
119
148
  else
@@ -134,8 +163,9 @@ module DocRaptor
134
163
  end
135
164
  end
136
165
  else # model
137
- temp_model = DocRaptor.const_get(type).new
138
- temp_model.build_from_hash(value)
166
+ # models (e.g. Pet) or oneOf
167
+ klass = DocRaptor.const_get(type)
168
+ klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass.build_from_hash(value)
139
169
  end
140
170
  end
141
171
 
@@ -157,7 +187,11 @@ module DocRaptor
157
187
  hash = {}
158
188
  self.class.attribute_map.each_pair do |attr, param|
159
189
  value = self.send(attr)
160
- next if value.nil?
190
+ if value.nil?
191
+ is_nullable = self.class.openapi_nullable.include?(attr)
192
+ next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
193
+ end
194
+
161
195
  hash[param] = _to_hash(value)
162
196
  end
163
197
  hash
@@ -182,4 +216,5 @@ module DocRaptor
182
216
  end
183
217
 
184
218
  end
219
+
185
220
  end