swagger_aem 3.8.0 → 4.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (110) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +107 -34
  3. data/README.md +8 -12
  4. data/bin/byebug +16 -0
  5. data/bin/coderay +16 -0
  6. data/bin/htmldiff +16 -0
  7. data/bin/ldiff +16 -0
  8. data/bin/pry +16 -0
  9. data/bin/racc +16 -0
  10. data/bin/rake +16 -0
  11. data/bin/rspec +16 -0
  12. data/bin/rubocop +16 -0
  13. data/bin/ruby-parse +16 -0
  14. data/bin/ruby-rewrite +16 -0
  15. data/docs/BundleData.md +24 -23
  16. data/docs/BundleDataProp.md +10 -9
  17. data/docs/BundleInfo.md +12 -11
  18. data/docs/ConsoleApi.md +188 -79
  19. data/docs/CqApi.md +52 -16
  20. data/docs/CrxApi.md +192 -64
  21. data/docs/CustomApi.md +85 -32
  22. data/docs/GraniteApi.md +37 -20
  23. data/docs/InstallStatus.md +8 -7
  24. data/docs/InstallStatusStatus.md +10 -9
  25. data/docs/KeystoreChainItems.md +16 -15
  26. data/docs/KeystoreInfo.md +10 -9
  27. data/docs/KeystoreItems.md +16 -15
  28. data/docs/SamlConfigurationInfo.md +18 -17
  29. data/docs/SamlConfigurationProperties.md +54 -53
  30. data/docs/SamlConfigurationPropertyItemsArray.md +18 -17
  31. data/docs/SamlConfigurationPropertyItemsBoolean.md +18 -17
  32. data/docs/SamlConfigurationPropertyItemsLong.md +18 -17
  33. data/docs/SamlConfigurationPropertyItemsString.md +18 -17
  34. data/docs/SlingApi.md +1021 -496
  35. data/docs/TruststoreInfo.md +10 -9
  36. data/docs/TruststoreItems.md +20 -19
  37. data/git_push.sh +3 -4
  38. data/lib/swagger_aem/api/console_api.rb +33 -27
  39. data/lib/swagger_aem/api/cq_api.rb +11 -9
  40. data/lib/swagger_aem/api/crx_api.rb +42 -32
  41. data/lib/swagger_aem/api/custom_api.rb +15 -12
  42. data/lib/swagger_aem/api/granite_api.rb +11 -7
  43. data/lib/swagger_aem/api/sling_api.rb +342 -298
  44. data/lib/swagger_aem/api_client.rb +73 -64
  45. data/lib/swagger_aem/api_error.rb +3 -2
  46. data/lib/swagger_aem/api_model_base.rb +88 -0
  47. data/lib/swagger_aem/configuration.rb +75 -15
  48. data/lib/swagger_aem/models/bundle_data.rb +32 -91
  49. data/lib/swagger_aem/models/bundle_data_prop.rb +32 -91
  50. data/lib/swagger_aem/models/bundle_info.rb +32 -91
  51. data/lib/swagger_aem/models/install_status.rb +32 -91
  52. data/lib/swagger_aem/models/install_status_status.rb +32 -91
  53. data/lib/swagger_aem/models/keystore_chain_items.rb +32 -91
  54. data/lib/swagger_aem/models/keystore_info.rb +32 -91
  55. data/lib/swagger_aem/models/keystore_items.rb +32 -91
  56. data/lib/swagger_aem/models/saml_configuration_info.rb +32 -91
  57. data/lib/swagger_aem/models/saml_configuration_properties.rb +32 -91
  58. data/lib/swagger_aem/models/saml_configuration_property_items_array.rb +32 -91
  59. data/lib/swagger_aem/models/saml_configuration_property_items_boolean.rb +32 -91
  60. data/lib/swagger_aem/models/saml_configuration_property_items_long.rb +32 -91
  61. data/lib/swagger_aem/models/saml_configuration_property_items_string.rb +32 -91
  62. data/lib/swagger_aem/models/truststore_info.rb +32 -91
  63. data/lib/swagger_aem/models/truststore_items.rb +32 -91
  64. data/lib/swagger_aem/version.rb +3 -3
  65. data/lib/swagger_aem.rb +3 -8
  66. data/spec/api/console_api_spec.rb +8 -8
  67. data/spec/api/cq_api_spec.rb +4 -4
  68. data/spec/api/crx_api_spec.rb +9 -9
  69. data/spec/api/custom_api_spec.rb +5 -5
  70. data/spec/api/granite_api_spec.rb +3 -3
  71. data/spec/api/sling_api_spec.rb +89 -87
  72. data/spec/models/bundle_data_prop_spec.rb +8 -6
  73. data/spec/models/bundle_data_spec.rb +15 -13
  74. data/spec/models/bundle_info_spec.rb +9 -7
  75. data/spec/models/install_status_spec.rb +7 -5
  76. data/spec/models/install_status_status_spec.rb +8 -6
  77. data/spec/models/keystore_chain_items_spec.rb +11 -9
  78. data/spec/models/keystore_info_spec.rb +8 -6
  79. data/spec/models/keystore_items_spec.rb +11 -9
  80. data/spec/models/saml_configuration_info_spec.rb +12 -10
  81. data/spec/models/saml_configuration_properties_spec.rb +30 -28
  82. data/spec/models/saml_configuration_property_items_array_spec.rb +12 -10
  83. data/spec/models/saml_configuration_property_items_boolean_spec.rb +12 -10
  84. data/spec/models/saml_configuration_property_items_long_spec.rb +12 -10
  85. data/spec/models/saml_configuration_property_items_string_spec.rb +12 -10
  86. data/spec/models/truststore_info_spec.rb +8 -6
  87. data/spec/models/truststore_items_spec.rb +13 -11
  88. data/spec/spec_helper.rb +2 -2
  89. data/swagger_aem.gemspec +4 -4
  90. metadata +15 -54
  91. data/docs/InlineObject.md +0 -17
  92. data/docs/InlineObject1.md +0 -17
  93. data/docs/InlineObject2.md +0 -17
  94. data/docs/InlineObject3.md +0 -17
  95. data/docs/InlineObject4.md +0 -21
  96. data/docs/InlineObject5.md +0 -19
  97. data/lib/swagger_aem/models/inline_object.rb +0 -206
  98. data/lib/swagger_aem/models/inline_object1.rb +0 -206
  99. data/lib/swagger_aem/models/inline_object2.rb +0 -206
  100. data/lib/swagger_aem/models/inline_object3.rb +0 -206
  101. data/lib/swagger_aem/models/inline_object4.rb +0 -224
  102. data/lib/swagger_aem/models/inline_object5.rb +0 -215
  103. data/spec/api_client_spec.rb +0 -226
  104. data/spec/configuration_spec.rb +0 -42
  105. data/spec/models/inline_object1_spec.rb +0 -41
  106. data/spec/models/inline_object2_spec.rb +0 -41
  107. data/spec/models/inline_object3_spec.rb +0 -41
  108. data/spec/models/inline_object4_spec.rb +0 -53
  109. data/spec/models/inline_object5_spec.rb +0 -47
  110. data/spec/models/inline_object_spec.rb +0 -41
@@ -3,10 +3,10 @@
3
3
 
4
4
  #Swagger AEM is an OpenAPI specification for Adobe Experience Manager (AEM) API
5
5
 
6
- The version of the OpenAPI document: 3.7.1-pre.0
6
+ The version of the OpenAPI document: 4.0.0
7
7
  Contact: opensource@shinesolutions.com
8
8
  Generated by: https://openapi-generator.tech
9
- OpenAPI Generator version: 4.3.1
9
+ Generator version: 7.24.0
10
10
 
11
11
  =end
12
12
 
@@ -14,8 +14,10 @@ require 'date'
14
14
  require 'json'
15
15
  require 'logger'
16
16
  require 'tempfile'
17
+ require 'time'
17
18
  require 'typhoeus'
18
19
 
20
+
19
21
  module SwaggerAemClient
20
22
  class ApiClient
21
23
  # The Configuration object holding settings to be used in the API client.
@@ -44,9 +46,11 @@ module SwaggerAemClient
44
46
  # Call an API with given options.
45
47
  #
46
48
  # @return [Array<(Object, Integer, Hash)>] an array of 3 elements:
47
- # the data deserialized from response body (could be nil), response status code and response headers.
49
+ # the data deserialized from response body (may be a Tempfile or nil), response status code and response headers.
48
50
  def call_api(http_method, path, opts = {})
49
51
  request = build_request(http_method, path, opts)
52
+ tempfile = nil
53
+ (download_file(request) { tempfile = _1 }) if opts[:return_type] == 'File'
50
54
  response = request.run
51
55
 
52
56
  if @config.debugging
@@ -68,7 +72,9 @@ module SwaggerAemClient
68
72
  end
69
73
  end
70
74
 
71
- if opts[:return_type]
75
+ if opts[:return_type] == 'File'
76
+ data = tempfile
77
+ elsif opts[:return_type]
72
78
  data = deserialize(response, opts[:return_type])
73
79
  else
74
80
  data = nil
@@ -86,12 +92,13 @@ module SwaggerAemClient
86
92
  # @option opts [Object] :body HTTP body (JSON/XML)
87
93
  # @return [Typhoeus::Request] A Typhoeus Request
88
94
  def build_request(http_method, path, opts = {})
89
- url = build_request_url(path)
95
+ url = build_request_url(path, opts)
90
96
  http_method = http_method.to_sym.downcase
91
97
 
92
98
  header_params = @default_headers.merge(opts[:header_params] || {})
93
99
  query_params = opts[:query_params] || {}
94
100
  form_params = opts[:form_params] || {}
101
+ follow_location = opts[:follow_location] || true
95
102
 
96
103
  update_params_for_auth! header_params, query_params, opts[:auth_names]
97
104
 
@@ -108,7 +115,8 @@ module SwaggerAemClient
108
115
  :ssl_verifyhost => _verify_ssl_host,
109
116
  :sslcert => @config.cert_file,
110
117
  :sslkey => @config.key_file,
111
- :verbose => @config.debugging
118
+ :verbose => @config.debugging,
119
+ :followlocation => follow_location
112
120
  }
113
121
 
114
122
  # set custom cert, if provided
@@ -122,9 +130,7 @@ module SwaggerAemClient
122
130
  end
123
131
  end
124
132
 
125
- request = Typhoeus::Request.new(url, req_opts)
126
- download_file(request) if opts[:return_type] == 'File'
127
- request
133
+ Typhoeus::Request.new(url, req_opts)
128
134
  end
129
135
 
130
136
  # Builds the HTTP request body
@@ -155,6 +161,47 @@ module SwaggerAemClient
155
161
  data
156
162
  end
157
163
 
164
+ # Save response body into a file in (the defined) temporary folder, using the filename
165
+ # from the "Content-Disposition" header if provided, otherwise a random filename.
166
+ # The response body is written to the file in chunks in order to handle files which
167
+ # size is larger than maximum Ruby String or even larger than the maximum memory a Ruby
168
+ # process can use.
169
+ #
170
+ # @see Configuration#temp_folder_path
171
+ #
172
+ # @return [Tempfile] the tempfile generated
173
+ def download_file(request)
174
+ tempfile = nil
175
+ encoding = nil
176
+ request.on_headers do |response|
177
+ content_disposition = response.headers['Content-Disposition']
178
+ if content_disposition && content_disposition =~ /filename=/i
179
+ filename = content_disposition[/filename=['"]?([^'"\s]+)['"]?/, 1]
180
+ prefix = sanitize_filename(filename)
181
+ else
182
+ prefix = 'download-'
183
+ end
184
+ prefix = prefix + '-' unless prefix.end_with?('-')
185
+ encoding = response.body.encoding
186
+ tempfile = Tempfile.open(prefix, @config.temp_folder_path, encoding: encoding)
187
+ end
188
+ request.on_body do |chunk|
189
+ chunk.force_encoding(encoding)
190
+ tempfile.write(chunk)
191
+ end
192
+ request.on_complete do
193
+ if !tempfile
194
+ fail ApiError.new("Failed to create the tempfile based on the HTTP response from the server: #{request.inspect}")
195
+ end
196
+ tempfile.close
197
+ @config.logger.info "Temp file written to #{tempfile.path}, please copy the file to a proper folder "\
198
+ "with e.g. `FileUtils.cp(tempfile.path, '/new/file/path')` otherwise the temp file "\
199
+ "will be deleted automatically with GC. It's also recommended to delete the temp file "\
200
+ "explicitly with `tempfile.delete`"
201
+ yield tempfile if block_given?
202
+ end
203
+ end
204
+
158
205
  # Check if the given MIME is a JSON MIME.
159
206
  # JSON MIME examples:
160
207
  # application/json
@@ -164,7 +211,7 @@ module SwaggerAemClient
164
211
  # @param [String] mime MIME
165
212
  # @return [Boolean] True if the MIME is application/json
166
213
  def json_mime?(mime)
167
- (mime == '*/*') || !(mime =~ /Application\/.*json(?!p)(;.*)?/i).nil?
214
+ (mime == '*/*') || !(mime =~ /^Application\/.*json(?!p)(;.*)?/i).nil?
168
215
  end
169
216
 
170
217
  # Deserialize the response to the given return type.
@@ -173,15 +220,10 @@ module SwaggerAemClient
173
220
  # @param [String] return_type some examples: "User", "Array<User>", "Hash<String, Integer>"
174
221
  def deserialize(response, return_type)
175
222
  body = response.body
176
-
177
- # handle file downloading - return the File instance processed in request callbacks
178
- # note that response body is empty when the file is written in chunks in request on_body callback
179
- return @tempfile if return_type == 'File'
180
-
181
223
  return nil if body.nil? || body.empty?
182
224
 
183
225
  # return response body directly for String return type
184
- return body if return_type == 'String'
226
+ return body.to_s if return_type == 'String'
185
227
 
186
228
  # ensuring a default content type
187
229
  content_type = response.headers['Content-Type'] || 'application/json'
@@ -191,7 +233,7 @@ module SwaggerAemClient
191
233
  begin
192
234
  data = JSON.parse("[#{body}]", :symbolize_names => true)[0]
193
235
  rescue JSON::ParserError => e
194
- if %w(String Date DateTime).include?(return_type)
236
+ if %w(String Date Time).include?(return_type)
195
237
  data = body
196
238
  else
197
239
  raise e
@@ -216,9 +258,9 @@ module SwaggerAemClient
216
258
  data.to_f
217
259
  when 'Boolean'
218
260
  data == true
219
- when 'DateTime'
261
+ when 'Time'
220
262
  # parse date time (expecting ISO 8601 format)
221
- DateTime.parse data
263
+ Time.parse data
222
264
  when 'Date'
223
265
  # parse date time (expecting ISO 8601 format)
224
266
  Date.parse data
@@ -236,45 +278,12 @@ module SwaggerAemClient
236
278
  data.each { |k, v| hash[k] = convert_to_type(v, sub_type) }
237
279
  end
238
280
  else
239
- # models, e.g. Pet
240
- SwaggerAemClient.const_get(return_type).build_from_hash(data)
241
- end
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)
281
+ # models (e.g. Pet) or oneOf/anyOf
282
+ klass = SwaggerAemClient.const_get(return_type)
283
+ if klass.respond_to?(:openapi_one_of) || klass.respond_to?(:openapi_any_of)
284
+ klass.build(data)
259
285
  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`"
286
+ klass.build_from_hash(data)
278
287
  end
279
288
  end
280
289
  end
@@ -285,16 +294,16 @@ module SwaggerAemClient
285
294
  # @param [String] filename the filename to be sanitized
286
295
  # @return [String] the sanitized filename
287
296
  def sanitize_filename(filename)
288
- filename.gsub(/.*[\/\\]/, '')
297
+ filename.split(/[\/\\]/).last
289
298
  end
290
299
 
291
- def build_request_url(path)
300
+ def build_request_url(path, opts = {})
292
301
  # Add leading and trailing slashes to path
293
302
  path = "/#{path}".gsub(/\/+/, '/')
294
- @config.base_url + path
303
+ @config.base_url(opts[:operation]) + path
295
304
  end
296
305
 
297
- # Update hearder and query params based on authentication settings.
306
+ # Update header and query params based on authentication settings.
298
307
  #
299
308
  # @param [Hash] header_params Header parameters
300
309
  # @param [Hash] query_params Query parameters
@@ -306,7 +315,7 @@ module SwaggerAemClient
306
315
  case auth_setting[:in]
307
316
  when 'header' then header_params[auth_setting[:key]] = auth_setting[:value]
308
317
  when 'query' then query_params[auth_setting[:key]] = auth_setting[:value]
309
- else fail ArgumentError, 'Authentication token must be in `query` of `header`'
318
+ else fail ArgumentError, 'Authentication token must be in `query` or `header`'
310
319
  end
311
320
  end
312
321
  end
@@ -333,8 +342,8 @@ module SwaggerAemClient
333
342
  # @param [Array] content_types array for Content-Type
334
343
  # @return [String] the Content-Type header (e.g. application/json)
335
344
  def select_header_content_type(content_types)
336
- # use application/json by default
337
- return 'application/json' if content_types.nil? || content_types.empty?
345
+ # return nil by default
346
+ return if content_types.nil? || content_types.empty?
338
347
  # use JSON when present, otherwise use the first one
339
348
  json_content_type = content_types.find { |s| json_mime?(s) }
340
349
  json_content_type || content_types.first
@@ -3,10 +3,10 @@
3
3
 
4
4
  #Swagger AEM is an OpenAPI specification for Adobe Experience Manager (AEM) API
5
5
 
6
- The version of the OpenAPI document: 3.7.1-pre.0
6
+ The version of the OpenAPI document: 4.0.0
7
7
  Contact: opensource@shinesolutions.com
8
8
  Generated by: https://openapi-generator.tech
9
- OpenAPI Generator version: 4.3.1
9
+ Generator version: 7.24.0
10
10
 
11
11
  =end
12
12
 
@@ -32,6 +32,7 @@ module SwaggerAemClient
32
32
  end
33
33
  else
34
34
  super arg
35
+ @message = arg
35
36
  end
36
37
  end
37
38
 
@@ -0,0 +1,88 @@
1
+ =begin
2
+ #Adobe Experience Manager (AEM) API
3
+
4
+ #Swagger AEM is an OpenAPI specification for Adobe Experience Manager (AEM) API
5
+
6
+ The version of the OpenAPI document: 4.0.0
7
+ Contact: opensource@shinesolutions.com
8
+ Generated by: https://openapi-generator.tech
9
+ Generator version: 7.24.0
10
+
11
+ =end
12
+
13
+ module SwaggerAemClient
14
+ class ApiModelBase
15
+ # Deserializes the data based on type
16
+ # @param string type Data type
17
+ # @param string value Value to be deserialized
18
+ # @return [Object] Deserialized data
19
+ def self._deserialize(type, value)
20
+ case type.to_sym
21
+ when :Time
22
+ Time.parse(value)
23
+ when :Date
24
+ Date.parse(value)
25
+ when :String
26
+ value.to_s
27
+ when :Integer
28
+ value.to_i
29
+ when :Float
30
+ value.to_f
31
+ when :Boolean
32
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
33
+ true
34
+ else
35
+ false
36
+ end
37
+ when :Object
38
+ # generic object (usually a Hash), return directly
39
+ value
40
+ when /\AArray<(?<inner_type>.+)>\z/
41
+ inner_type = Regexp.last_match[:inner_type]
42
+ value.map { |v| _deserialize(inner_type, v) }
43
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
44
+ k_type = Regexp.last_match[:k_type]
45
+ v_type = Regexp.last_match[:v_type]
46
+ {}.tap do |hash|
47
+ value.each do |k, v|
48
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
49
+ end
50
+ end
51
+ else # model
52
+ # models (e.g. Pet) or oneOf
53
+ klass = SwaggerAemClient.const_get(type)
54
+ klass.respond_to?(:openapi_any_of) || klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass.build_from_hash(value)
55
+ end
56
+ end
57
+
58
+ # Returns the string representation of the object
59
+ # @return [String] String presentation of the object
60
+ def to_s
61
+ to_hash.to_s
62
+ end
63
+
64
+ # to_body is an alias to to_hash (backward compatibility)
65
+ # @return [Hash] Returns the object in the form of hash
66
+ def to_body
67
+ to_hash
68
+ end
69
+
70
+ # Outputs non-array value in the form of hash
71
+ # For object, use to_hash. Otherwise, just return the value
72
+ # @param [Object] value Any valid value
73
+ # @return [Hash] Returns the value in the form of hash
74
+ def _to_hash(value)
75
+ if value.is_a?(Array)
76
+ value.compact.map { |v| _to_hash(v) }
77
+ elsif value.is_a?(Hash)
78
+ {}.tap do |hash|
79
+ value.each { |k, v| hash[k] = _to_hash(v) }
80
+ end
81
+ elsif value.respond_to? :to_hash
82
+ value.to_hash
83
+ else
84
+ value
85
+ end
86
+ end
87
+ end
88
+ end
@@ -3,10 +3,10 @@
3
3
 
4
4
  #Swagger AEM is an OpenAPI specification for Adobe Experience Manager (AEM) API
5
5
 
6
- The version of the OpenAPI document: 3.7.1-pre.0
6
+ The version of the OpenAPI document: 4.0.0
7
7
  Contact: opensource@shinesolutions.com
8
8
  Generated by: https://openapi-generator.tech
9
- OpenAPI Generator version: 4.3.1
9
+ Generator version: 7.24.0
10
10
 
11
11
  =end
12
12
 
@@ -21,6 +21,18 @@ module SwaggerAemClient
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)
@@ -50,6 +62,16 @@ module SwaggerAemClient
50
62
  # Defines the access token (Bearer) used with OAuth2.
51
63
  attr_accessor :access_token
52
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
+
53
75
  # Set this to enable/disable debugging. When enabled (set to true), HTTP request/response
54
76
  # details will be logged with `logger.debug` (see the `logger` attribute).
55
77
  # Default to false.
@@ -57,6 +79,14 @@ module SwaggerAemClient
57
79
  # @return [true, false]
58
80
  attr_accessor :debugging
59
81
 
82
+ # Set this to ignore operation servers for the API client. This is useful when you need to
83
+ # send requests to a different server than the one specified in the OpenAPI document.
84
+ # Will default to the base url defined in the spec but can be overridden by setting
85
+ # `scheme`, `host`, `base_path` directly.
86
+ # Default to false.
87
+ # @return [true, false]
88
+ attr_accessor :ignore_operation_servers
89
+
60
90
  # Defines the logger used for debugging.
61
91
  # Default to `Rails.logger` (when in Rails) or logging to STDOUT.
62
92
  #
@@ -121,6 +151,7 @@ module SwaggerAemClient
121
151
  # https://github.com/typhoeus/ethon/blob/master/lib/ethon/easy/queryable.rb#L96
122
152
  attr_accessor :params_encoding
123
153
 
154
+
124
155
  attr_accessor :inject_format
125
156
 
126
157
  attr_accessor :force_ending_format
@@ -129,16 +160,21 @@ module SwaggerAemClient
129
160
  @scheme = 'http'
130
161
  @host = 'localhost'
131
162
  @base_path = ''
163
+ @server_index = nil
164
+ @server_operation_index = {}
165
+ @server_variables = {}
166
+ @server_operation_variables = {}
132
167
  @api_key = {}
133
168
  @api_key_prefix = {}
134
- @timeout = 0
135
169
  @client_side_validation = true
136
170
  @verify_ssl = true
137
171
  @verify_ssl_host = true
138
- @params_encoding = nil
139
172
  @cert_file = nil
140
173
  @key_file = nil
174
+ @timeout = 0
175
+ @params_encoding = nil
141
176
  @debugging = false
177
+ @ignore_operation_servers = false
142
178
  @inject_format = false
143
179
  @force_ending_format = false
144
180
  @logger = defined?(Rails) ? Rails.logger : Logger.new(STDOUT)
@@ -171,20 +207,35 @@ module SwaggerAemClient
171
207
  @base_path = '' if @base_path == '/'
172
208
  end
173
209
 
174
- def base_url
175
- "#{scheme}://#{[host, base_path].join('/').gsub(/\/+/, '/')}".sub(/\/+\z/, '')
210
+ # Returns base URL for specified operation based on server settings
211
+ def base_url(operation = nil)
212
+ return "#{scheme}://#{[host, base_path].join('/').gsub(/\/+/, '/')}".sub(/\/+\z/, '') if ignore_operation_servers
213
+ if operation_server_settings.key?(operation) then
214
+ index = server_operation_index.fetch(operation, server_index)
215
+ server_url(index.nil? ? 0 : index, server_operation_variables.fetch(operation, server_variables), operation_server_settings[operation])
216
+ else
217
+ server_index.nil? ? "#{scheme}://#{[host, base_path].join('/').gsub(/\/+/, '/')}".sub(/\/+\z/, '') : server_url(server_index, server_variables, nil)
218
+ end
176
219
  end
177
220
 
178
221
  # Gets API key (with prefix if set).
179
222
  # @param [String] param_name the parameter name of API key auth
180
- def api_key_with_prefix(param_name)
223
+ def api_key_with_prefix(param_name, param_alias = nil)
224
+ key = @api_key[param_name]
225
+ key = @api_key.fetch(param_alias, key) unless param_alias.nil?
181
226
  if @api_key_prefix[param_name]
182
- "#{@api_key_prefix[param_name]} #{@api_key[param_name]}"
227
+ "#{@api_key_prefix[param_name]} #{key}"
183
228
  else
184
- @api_key[param_name]
229
+ key
185
230
  end
186
231
  end
187
232
 
233
+ # Gets access_token using access_token_getter or uses the static access_token
234
+ def access_token_with_refresh
235
+ return access_token if access_token_getter.nil?
236
+ access_token_getter.call
237
+ end
238
+
188
239
  # Gets Basic Auth token string
189
240
  def basic_auth_token
190
241
  'Basic ' + ["#{username}:#{password}"].pack('m').delete("\r\n")
@@ -207,31 +258,38 @@ module SwaggerAemClient
207
258
  def server_settings
208
259
  [
209
260
  {
210
- url: "/",
261
+ url: "",
211
262
  description: "No description provided",
212
263
  }
213
264
  ]
214
265
  end
215
266
 
267
+ def operation_server_settings
268
+ {
269
+ }
270
+ end
271
+
216
272
  # Returns URL based on server settings
217
273
  #
218
274
  # @param index array index of the server settings
219
275
  # @param variables hash of variable and the corresponding value
220
- def server_url(index, variables = {})
221
- servers = server_settings
276
+ def server_url(index, variables = {}, servers = nil)
277
+ servers = server_settings if servers == nil
222
278
 
223
279
  # check array index out of bound
224
- if (index < 0 || index >= servers.size)
225
- fail ArgumentError, "Invalid index #{index} when selecting the server. Must be less than #{servers.size}"
280
+ if (index.nil? || index < 0 || index >= servers.size)
281
+ fail ArgumentError, "Invalid index #{index} when selecting the server. Must not be nil and must be less than #{servers.size}"
226
282
  end
227
283
 
228
284
  server = servers[index]
229
285
  url = server[:url]
230
286
 
287
+ return url unless server.key? :variables
288
+
231
289
  # go through variable and assign a value
232
290
  server[:variables].each do |name, variable|
233
291
  if variables.key?(name)
234
- if (server[:variables][name][:enum_values].include? variables[name])
292
+ if (!server[:variables][name].key?(:enum_values) || server[:variables][name][:enum_values].include?(variables[name]))
235
293
  url.gsub! "{" + name.to_s + "}", variables[name]
236
294
  else
237
295
  fail ArgumentError, "The variable `#{name}` in the server URL has invalid value #{variables[name]}. Must be #{server[:variables][name][:enum_values]}."
@@ -244,5 +302,7 @@ module SwaggerAemClient
244
302
 
245
303
  url
246
304
  end
305
+
306
+
247
307
  end
248
308
  end