docraptor 2.0.0 → 3.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (83) hide show
  1. checksums.yaml +4 -4
  2. data/.docker_env.list +5 -0
  3. data/.docker_mounts.list +4 -0
  4. data/.generator-language-identifier +1 -0
  5. data/.generator-revision +1 -0
  6. data/.github/pull_request_template.txt +17 -0
  7. data/.gitignore +20 -14
  8. data/.gitlab-ci.yml +26 -0
  9. data/.openapi-generator/FILES +32 -0
  10. data/.openapi-generator/VERSION +1 -0
  11. data/{.swagger-codegen-ignore → .openapi-generator-ignore} +13 -7
  12. data/.review/README.md +16 -0
  13. data/.review/generated_files/.gitignore +39 -0
  14. data/.review/generated_files/README.md +108 -0
  15. data/.review/generated_files/docs/AsyncDoc.md +18 -0
  16. data/.review/generated_files/docs/Doc.md +50 -0
  17. data/.review/generated_files/docs/DocApi.md +503 -0
  18. data/.review/generated_files/docs/DocStatus.md +28 -0
  19. data/.review/generated_files/docs/PrinceOptions.md +82 -0
  20. data/.review/generated_files/spec/api/doc_api_spec.rb +112 -0
  21. data/{spec → .review/generated_files/spec}/api_client_spec.rb +6 -21
  22. data/{spec → .review/generated_files/spec}/configuration_spec.rb +6 -6
  23. data/.review/generated_files/spec/models/async_doc_spec.rb +34 -0
  24. data/.review/generated_files/spec/models/doc_spec.rb +138 -0
  25. data/.review/generated_files/spec/models/doc_status_spec.rb +64 -0
  26. data/.review/generated_files/spec/models/prince_options_spec.rb +234 -0
  27. data/{spec → .review/generated_files/spec}/spec_helper.rb +3 -3
  28. data/.rubocop.yml +148 -0
  29. data/.runtime-environments +13 -0
  30. data/.travis.yml +9 -7
  31. data/CHANGELOG.md +8 -0
  32. data/Gemfile +3 -1
  33. data/README.md +8 -8
  34. data/Rakefile +1 -2
  35. data/docraptor.gemspec +5 -19
  36. data/docraptor.yaml +283 -284
  37. data/examples/async.rb +24 -30
  38. data/examples/hosted_async.rb +21 -33
  39. data/examples/hosted_sync.rb +19 -32
  40. data/examples/sync.rb +20 -26
  41. data/gemfiles/Gemfile.2.5.lock +70 -0
  42. data/gemfiles/Gemfile.2.6.lock +70 -0
  43. data/gemfiles/Gemfile.2.7.lock +70 -0
  44. data/gemfiles/Gemfile.3.0.lock +70 -0
  45. data/gemfiles/Gemfile.3.1.lock +72 -0
  46. data/gemfiles/Gemfile.3.2.lock +72 -0
  47. data/gemfiles/Gemfile.3.3.lock +72 -0
  48. data/{swagger-config.json → generator-config.json} +3 -2
  49. data/lib/docraptor/api/doc_api.rb +180 -85
  50. data/lib/docraptor/api_client.rb +91 -90
  51. data/lib/docraptor/api_error.rb +23 -3
  52. data/lib/docraptor/configuration.rb +101 -15
  53. data/lib/docraptor/models/async_doc.rb +53 -18
  54. data/lib/docraptor/models/doc.rb +80 -50
  55. data/lib/docraptor/models/doc_status.rb +58 -23
  56. data/lib/docraptor/models/prince_options.rb +149 -75
  57. data/lib/docraptor/version.rb +4 -4
  58. data/lib/docraptor.rb +3 -3
  59. data/script/clean +2 -2
  60. data/script/console +5 -0
  61. data/script/docker +56 -0
  62. data/script/fix_gemspec.rb +3 -18
  63. data/script/generate_language +43 -4
  64. data/script/inside_container/README.md +6 -0
  65. data/script/inside_container/test +87 -0
  66. data/script/post_generate_language +8 -2
  67. data/script/release +13 -0
  68. data/script/setup +25 -14
  69. data/script/swagger +6 -33
  70. data/script/test +30 -27
  71. data/test/async.rb +2 -2
  72. data/test/expire_hosted.rb +2 -2
  73. data/test/hosted_async.rb +7 -1
  74. data/test/hosted_sync.rb +2 -2
  75. data/test/iframes_default.rb +40 -0
  76. data/test/iframes_false.rb +40 -0
  77. data/test/iframes_true.rb +40 -0
  78. data/test/prince_options.rb +45 -0
  79. data/test/sync.rb +2 -2
  80. data/test/xlsx.rb +10 -3
  81. metadata +52 -214
  82. data/.swagger-codegen/VERSION +0 -1
  83. data/.swagger-revision +0 -1
@@ -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.6.0
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.6.0
10
10
 
11
11
  =end
12
12
 
@@ -32,7 +32,27 @@ module DocRaptor
32
32
  end
33
33
  else
34
34
  super arg
35
+ @message = arg
35
36
  end
36
37
  end
38
+
39
+ # Override to_s to display a friendly error message
40
+ def to_s
41
+ message
42
+ end
43
+
44
+ def message
45
+ if @message.nil?
46
+ msg = "Error message: the server returns an error"
47
+ else
48
+ msg = @message
49
+ end
50
+
51
+ msg += "\nHTTP status code: #{code}" if code
52
+ msg += "\nResponse headers: #{response_headers}" if response_headers
53
+ msg += "\nResponse body: #{response_body}" if response_body
54
+
55
+ msg
56
+ end
37
57
  end
38
58
  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.6.0
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)
@@ -52,6 +62,16 @@ module DocRaptor
52
62
  # Defines the access token (Bearer) used with OAuth2.
53
63
  attr_accessor :access_token
54
64
 
65
+ # Defines a Proc used to fetch or refresh access tokens (Bearer) used with OAuth2.
66
+ # Overrides the access_token if set
67
+ # @return [Proc]
68
+ attr_accessor :access_token_getter
69
+
70
+ # Set this to return data as binary instead of downloading a temp file. When enabled (set to true)
71
+ # HTTP responses with return type `File` will be returned as a stream of binary data.
72
+ # Default to false.
73
+ attr_accessor :return_binary_data
74
+
55
75
  # Set this to enable/disable debugging. When enabled (set to true), HTTP request/response
56
76
  # details will be logged with `logger.debug` (see the `logger` attribute).
57
77
  # Default to false.
@@ -123,23 +143,28 @@ module DocRaptor
123
143
  # https://github.com/typhoeus/ethon/blob/master/lib/ethon/easy/queryable.rb#L96
124
144
  attr_accessor :params_encoding
125
145
 
146
+
126
147
  attr_accessor :inject_format
127
148
 
128
149
  attr_accessor :force_ending_format
129
150
 
130
151
  def initialize
131
152
  @scheme = 'https'
132
- @host = 'docraptor.com'
133
- @base_path = '/'
153
+ @host = 'api.docraptor.com'
154
+ @base_path = ''
155
+ @server_index = 0
156
+ @server_operation_index = {}
157
+ @server_variables = {}
158
+ @server_operation_variables = {}
134
159
  @api_key = {}
135
160
  @api_key_prefix = {}
136
- @timeout = 0
137
161
  @client_side_validation = true
138
162
  @verify_ssl = true
139
163
  @verify_ssl_host = true
140
- @params_encoding = nil
141
164
  @cert_file = nil
142
165
  @key_file = nil
166
+ @timeout = 0
167
+ @params_encoding = nil
143
168
  @debugging = false
144
169
  @inject_format = false
145
170
  @force_ending_format = false
@@ -173,21 +198,32 @@ module DocRaptor
173
198
  @base_path = '' if @base_path == '/'
174
199
  end
175
200
 
176
- def base_url
177
- url = "#{scheme}://#{[host, base_path].join('/').gsub(/\/+/, '/')}".sub(/\/+\z/, '')
178
- Addressable::URI.encode(url)
201
+ # Returns base URL for specified operation based on server settings
202
+ def base_url(operation = nil)
203
+ index = server_operation_index[operation]
204
+ return "#{scheme}://#{[host, base_path].join('/').gsub(/\/+/, '/')}".sub(/\/+\z/, '') if index == nil
205
+
206
+ server_url(index, server_operation_variables.fetch(operation, server_variables), operation_server_settings[operation])
179
207
  end
180
208
 
181
209
  # Gets API key (with prefix if set).
182
210
  # @param [String] param_name the parameter name of API key auth
183
- def api_key_with_prefix(param_name)
211
+ def api_key_with_prefix(param_name, param_alias = nil)
212
+ key = @api_key[param_name]
213
+ key = @api_key.fetch(param_alias, key) unless param_alias.nil?
184
214
  if @api_key_prefix[param_name]
185
- "#{@api_key_prefix[param_name]} #{@api_key[param_name]}"
215
+ "#{@api_key_prefix[param_name]} #{key}"
186
216
  else
187
- @api_key[param_name]
217
+ key
188
218
  end
189
219
  end
190
220
 
221
+ # Gets access_token using access_token_getter or uses the static access_token
222
+ def access_token_with_refresh
223
+ return access_token if access_token_getter.nil?
224
+ access_token_getter.call
225
+ end
226
+
191
227
  # Gets Basic Auth token string
192
228
  def basic_auth_token
193
229
  'Basic ' + ["#{username}:#{password}"].pack('m').delete("\r\n")
@@ -205,5 +241,55 @@ module DocRaptor
205
241
  },
206
242
  }
207
243
  end
244
+
245
+ # Returns an array of Server setting
246
+ def server_settings
247
+ [
248
+ {
249
+ url: "https://api.docraptor.com",
250
+ description: "DocRaptor API endpoint",
251
+ }
252
+ ]
253
+ end
254
+
255
+ def operation_server_settings
256
+ {
257
+ }
258
+ end
259
+
260
+ # Returns URL based on server settings
261
+ #
262
+ # @param index array index of the server settings
263
+ # @param variables hash of variable and the corresponding value
264
+ def server_url(index, variables = {}, servers = nil)
265
+ servers = server_settings if servers == nil
266
+
267
+ # check array index out of bound
268
+ if (index < 0 || index >= servers.size)
269
+ fail ArgumentError, "Invalid index #{index} when selecting the server. Must be less than #{servers.size}"
270
+ end
271
+
272
+ server = servers[index]
273
+ url = server[:url]
274
+
275
+ return url unless server.key? :variables
276
+
277
+ # go through variable and assign a value
278
+ server[:variables].each do |name, variable|
279
+ if variables.key?(name)
280
+ if (!server[:variables][name].key?(:enum_values) || server[:variables][name][:enum_values].include?(variables[name]))
281
+ url.gsub! "{" + name.to_s + "}", variables[name]
282
+ else
283
+ fail ArgumentError, "The variable `#{name}` in the server URL has invalid value #{variables[name]}. Must be #{server[:variables][name][:enum_values]}."
284
+ end
285
+ else
286
+ # use default value
287
+ url.gsub! "{" + name.to_s + "}", server[:variables][name][:default_value]
288
+ end
289
+ end
290
+
291
+ url
292
+ end
293
+
208
294
  end
209
295
  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.6.0
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