manticore-client 1.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 (113) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +39 -0
  3. data/.openapi-generator/FILES +149 -0
  4. data/.openapi-generator/VERSION +1 -0
  5. data/.openapi-generator-ignore +5 -0
  6. data/.rspec +2 -0
  7. data/.rubocop.yml +160 -0
  8. data/Gemfile +12 -0
  9. data/Gemfile.lock +103 -0
  10. data/LICENSE.txt +21 -0
  11. data/README.md +136 -0
  12. data/Rakefile +10 -0
  13. data/docs/AggComposite.md +20 -0
  14. data/docs/AggCompositeSource.md +18 -0
  15. data/docs/AggCompositeTerm.md +18 -0
  16. data/docs/AggTerms.md +20 -0
  17. data/docs/Aggregation.md +22 -0
  18. data/docs/AutocompleteRequest.md +22 -0
  19. data/docs/BoolFilter.md +22 -0
  20. data/docs/BulkResponse.md +26 -0
  21. data/docs/DeleteDocumentRequest.md +24 -0
  22. data/docs/DeleteResponse.md +26 -0
  23. data/docs/ErrorResponse.md +20 -0
  24. data/docs/FulltextFilter.md +24 -0
  25. data/docs/GeoDistance.md +24 -0
  26. data/docs/GeoDistanceLocationAnchor.md +20 -0
  27. data/docs/Highlight.md +62 -0
  28. data/docs/HighlightAllOfFields.md +15 -0
  29. data/docs/HighlightFieldOption.md +26 -0
  30. data/docs/HitsHits.md +22 -0
  31. data/docs/IndexApi.md +401 -0
  32. data/docs/InsertDocumentRequest.md +24 -0
  33. data/docs/Join.md +24 -0
  34. data/docs/JoinCond.md +22 -0
  35. data/docs/JoinOn.md +22 -0
  36. data/docs/KnnQuery.md +28 -0
  37. data/docs/Match.md +22 -0
  38. data/docs/MatchAll.md +18 -0
  39. data/docs/PercolateRequest.md +18 -0
  40. data/docs/PercolateRequestQuery.md +18 -0
  41. data/docs/QueryFilter.md +34 -0
  42. data/docs/Range.md +24 -0
  43. data/docs/ReplaceDocumentRequest.md +18 -0
  44. data/docs/ResponseError.md +49 -0
  45. data/docs/ResponseErrorDetails.md +22 -0
  46. data/docs/SearchApi.md +204 -0
  47. data/docs/SearchQuery.md +36 -0
  48. data/docs/SearchRequest.md +46 -0
  49. data/docs/SearchResponse.md +30 -0
  50. data/docs/SearchResponseHits.md +24 -0
  51. data/docs/SourceRules.md +20 -0
  52. data/docs/SqlResponse.md +49 -0
  53. data/docs/SuccessResponse.md +28 -0
  54. data/docs/UpdateDocumentRequest.md +26 -0
  55. data/docs/UpdateResponse.md +24 -0
  56. data/docs/UtilsApi.md +76 -0
  57. data/lib/manticore/client/api/index_api.rb +442 -0
  58. data/lib/manticore/client/api/search_api.rb +232 -0
  59. data/lib/manticore/client/api/utils_api.rb +93 -0
  60. data/lib/manticore/client/api_client.rb +437 -0
  61. data/lib/manticore/client/api_error.rb +58 -0
  62. data/lib/manticore/client/configuration.rb +385 -0
  63. data/lib/manticore/client/models/agg_composite.rb +233 -0
  64. data/lib/manticore/client/models/agg_composite_source.rb +238 -0
  65. data/lib/manticore/client/models/agg_composite_term.rb +239 -0
  66. data/lib/manticore/client/models/agg_terms.rb +249 -0
  67. data/lib/manticore/client/models/aggregation.rb +240 -0
  68. data/lib/manticore/client/models/autocomplete_request.rb +276 -0
  69. data/lib/manticore/client/models/bool_filter.rb +247 -0
  70. data/lib/manticore/client/models/bulk_response.rb +264 -0
  71. data/lib/manticore/client/models/delete_document_request.rb +269 -0
  72. data/lib/manticore/client/models/delete_response.rb +262 -0
  73. data/lib/manticore/client/models/error_response.rb +250 -0
  74. data/lib/manticore/client/models/fulltext_filter.rb +252 -0
  75. data/lib/manticore/client/models/geo_distance.rb +306 -0
  76. data/lib/manticore/client/models/geo_distance_location_anchor.rb +232 -0
  77. data/lib/manticore/client/models/highlight.rb +525 -0
  78. data/lib/manticore/client/models/highlight_all_of_fields.rb +105 -0
  79. data/lib/manticore/client/models/highlight_field_option.rb +262 -0
  80. data/lib/manticore/client/models/hits_hits.rb +242 -0
  81. data/lib/manticore/client/models/insert_document_request.rb +286 -0
  82. data/lib/manticore/client/models/join.rb +327 -0
  83. data/lib/manticore/client/models/join_cond.rb +276 -0
  84. data/lib/manticore/client/models/join_on.rb +272 -0
  85. data/lib/manticore/client/models/knn_query.rb +307 -0
  86. data/lib/manticore/client/models/match.rb +290 -0
  87. data/lib/manticore/client/models/match_all.rb +262 -0
  88. data/lib/manticore/client/models/percolate_request.rb +238 -0
  89. data/lib/manticore/client/models/percolate_request_query.rb +238 -0
  90. data/lib/manticore/client/models/query_filter.rb +307 -0
  91. data/lib/manticore/client/models/range.rb +252 -0
  92. data/lib/manticore/client/models/replace_document_request.rb +239 -0
  93. data/lib/manticore/client/models/response_error.rb +105 -0
  94. data/lib/manticore/client/models/response_error_details.rb +261 -0
  95. data/lib/manticore/client/models/search_query.rb +316 -0
  96. data/lib/manticore/client/models/search_request.rb +382 -0
  97. data/lib/manticore/client/models/search_response.rb +281 -0
  98. data/lib/manticore/client/models/search_response_hits.rb +254 -0
  99. data/lib/manticore/client/models/source_rules.rb +236 -0
  100. data/lib/manticore/client/models/sql_response.rb +106 -0
  101. data/lib/manticore/client/models/success_response.rb +272 -0
  102. data/lib/manticore/client/models/update_document_request.rb +296 -0
  103. data/lib/manticore/client/models/update_response.rb +252 -0
  104. data/lib/manticore/client/version.rb +7 -0
  105. data/lib/manticore/client.rb +32 -0
  106. data/lib/manticore-client.rb +3 -0
  107. data/manticore-client.gemspec +34 -0
  108. data/spec/api/index_api_spec.rb +179 -0
  109. data/spec/api/search_api_spec.rb +94 -0
  110. data/spec/api/utils_api_spec.rb +100 -0
  111. data/spec/spec_helper.rb +92 -0
  112. data/spec/support/manticore_sql_helper.rb +33 -0
  113. metadata +218 -0
@@ -0,0 +1,385 @@
1
+ =begin
2
+ #Manticore Search Client
3
+
4
+ #Сlient for Manticore Search.
5
+
6
+ The version of the OpenAPI document: 5.0.0
7
+ Contact: info@manticoresearch.com
8
+ Generated by: https://openapi-generator.tech
9
+ Generator version: 7.13.0
10
+
11
+ =end
12
+
13
+ module Manticore::Client
14
+ class Configuration
15
+ # Defines url scheme
16
+ attr_accessor :scheme
17
+
18
+ # Defines url host
19
+ attr_accessor :host
20
+
21
+ # Defines url base path
22
+ attr_accessor :base_path
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
+
36
+ # Defines API keys used with API Key authentications.
37
+ #
38
+ # @return [Hash] key: parameter name, value: parameter value (API key)
39
+ #
40
+ # @example parameter name is "api_key", API key is "xxx" (e.g. "api_key=xxx" in query string)
41
+ # config.api_key['api_key'] = 'xxx'
42
+ attr_accessor :api_key
43
+
44
+ # Defines API key prefixes used with API Key authentications.
45
+ #
46
+ # @return [Hash] key: parameter name, value: API key prefix
47
+ #
48
+ # @example parameter name is "Authorization", API key prefix is "Token" (e.g. "Authorization: Token xxx" in headers)
49
+ # config.api_key_prefix['api_key'] = 'Token'
50
+ attr_accessor :api_key_prefix
51
+
52
+ # Defines the username used with HTTP basic authentication.
53
+ #
54
+ # @return [String]
55
+ attr_accessor :username
56
+
57
+ # Defines the password used with HTTP basic authentication.
58
+ #
59
+ # @return [String]
60
+ attr_accessor :password
61
+
62
+ # Defines the access token (Bearer) used with OAuth2.
63
+ attr_accessor :access_token
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
+
75
+ # Set this to enable/disable debugging. When enabled (set to true), HTTP request/response
76
+ # details will be logged with `logger.debug` (see the `logger` attribute).
77
+ # Default to false.
78
+ #
79
+ # @return [true, false]
80
+ attr_accessor :debugging
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
+
90
+ # Defines the logger used for debugging.
91
+ # Default to `Rails.logger` (when in Rails) or logging to STDOUT.
92
+ #
93
+ # @return [#debug]
94
+ attr_accessor :logger
95
+
96
+ # Defines the temporary folder to store downloaded files
97
+ # (for API endpoints that have file response).
98
+ # Default to use `Tempfile`.
99
+ #
100
+ # @return [String]
101
+ attr_accessor :temp_folder_path
102
+
103
+ # The time limit for HTTP request in seconds.
104
+ # Default to 0 (never times out).
105
+ attr_accessor :timeout
106
+
107
+ # Set this to false to skip client side validation in the operation.
108
+ # Default to true.
109
+ # @return [true, false]
110
+ attr_accessor :client_side_validation
111
+
112
+ ### TLS/SSL setting
113
+ # Set this to false to skip verifying SSL certificate when calling API from https server.
114
+ # Default to true.
115
+ #
116
+ # @note Do NOT set it to false in production code, otherwise you would face multiple types of cryptographic attacks.
117
+ #
118
+ # @return [true, false]
119
+ attr_accessor :ssl_verify
120
+
121
+ ### TLS/SSL setting
122
+ # Any `OpenSSL::SSL::` constant (see https://ruby-doc.org/stdlib-2.5.1/libdoc/openssl/rdoc/OpenSSL/SSL.html)
123
+ #
124
+ # @note Do NOT set it to false in production code, otherwise you would face multiple types of cryptographic attacks.
125
+ #
126
+ attr_accessor :ssl_verify_mode
127
+
128
+ ### TLS/SSL setting
129
+ # Set this to customize the certificate file to verify the peer.
130
+ #
131
+ # @return [String] the path to the certificate file
132
+ attr_accessor :ssl_ca_file
133
+
134
+ ### TLS/SSL setting
135
+ # Client certificate file (for client certificate)
136
+ attr_accessor :ssl_client_cert
137
+
138
+ ### TLS/SSL setting
139
+ # Client private key file (for client certificate)
140
+ attr_accessor :ssl_client_key
141
+
142
+ ### Proxy setting
143
+ # HTTP Proxy settings
144
+ attr_accessor :proxy
145
+
146
+ # Set this to customize parameters encoder of array parameter.
147
+ # Default to nil. Faraday uses NestedParamsEncoder when nil.
148
+ #
149
+ # @see The params_encoder option of Faraday. Related source code:
150
+ # https://github.com/lostisland/faraday/tree/main/lib/faraday/encoders
151
+ attr_accessor :params_encoder
152
+
153
+
154
+ attr_accessor :inject_format
155
+
156
+ attr_accessor :force_ending_format
157
+
158
+ def initialize
159
+ @scheme = 'http'
160
+ @host = '127.0.0.1:9308'
161
+ @base_path = ''
162
+ @server_index = nil
163
+ @server_operation_index = {}
164
+ @server_variables = {}
165
+ @server_operation_variables = {}
166
+ @api_key = {}
167
+ @api_key_prefix = {}
168
+ @client_side_validation = true
169
+ @ssl_verify = true
170
+ @ssl_verify_mode = nil
171
+ @ssl_ca_file = nil
172
+ @ssl_client_cert = nil
173
+ @ssl_client_key = nil
174
+ @middlewares = Hash.new { |h, k| h[k] = [] }
175
+ @configure_connection_blocks = []
176
+ @timeout = 60
177
+ # return data as binary instead of file
178
+ @return_binary_data = false
179
+ @params_encoder = nil
180
+ @debugging = false
181
+ @ignore_operation_servers = false
182
+ @inject_format = false
183
+ @force_ending_format = false
184
+ @logger = defined?(Rails) ? Rails.logger : Logger.new(STDOUT)
185
+
186
+ yield(self) if block_given?
187
+ end
188
+
189
+ # The default Configuration object.
190
+ def self.default
191
+ @@default ||= Configuration.new
192
+ end
193
+
194
+ def configure
195
+ yield(self) if block_given?
196
+ end
197
+
198
+ def scheme=(scheme)
199
+ # remove :// from scheme
200
+ @scheme = scheme.sub(/:\/\//, '')
201
+ end
202
+
203
+ def host=(host)
204
+ # remove http(s):// and anything after a slash
205
+ @host = host.sub(/https?:\/\//, '').split('/').first
206
+ end
207
+
208
+ def base_path=(base_path)
209
+ # Add leading and trailing slashes to base_path
210
+ @base_path = "/#{base_path}".gsub(/\/+/, '/')
211
+ @base_path = '' if @base_path == '/'
212
+ end
213
+
214
+ # Returns base URL for specified operation based on server settings
215
+ def base_url(operation = nil)
216
+ return "#{scheme}://#{[host, base_path].join('/').gsub(/\/+/, '/')}".sub(/\/+\z/, '') if ignore_operation_servers
217
+ if operation_server_settings.key?(operation) then
218
+ index = server_operation_index.fetch(operation, server_index)
219
+ server_url(index.nil? ? 0 : index, server_operation_variables.fetch(operation, server_variables), operation_server_settings[operation])
220
+ else
221
+ server_index.nil? ? "#{scheme}://#{[host, base_path].join('/').gsub(/\/+/, '/')}".sub(/\/+\z/, '') : server_url(server_index, server_variables, nil)
222
+ end
223
+ end
224
+
225
+ # Gets API key (with prefix if set).
226
+ # @param [String] param_name the parameter name of API key auth
227
+ def api_key_with_prefix(param_name, param_alias = nil)
228
+ key = @api_key[param_name]
229
+ key = @api_key.fetch(param_alias, key) unless param_alias.nil?
230
+ if @api_key_prefix[param_name]
231
+ "#{@api_key_prefix[param_name]} #{key}"
232
+ else
233
+ key
234
+ end
235
+ end
236
+
237
+ # Gets access_token using access_token_getter or uses the static access_token
238
+ def access_token_with_refresh
239
+ return access_token if access_token_getter.nil?
240
+ access_token_getter.call
241
+ end
242
+
243
+ # Gets Basic Auth token string
244
+ def basic_auth_token
245
+ 'Basic ' + ["#{username}:#{password}"].pack('m').delete("\r\n")
246
+ end
247
+
248
+ # Returns Auth Settings hash for api client.
249
+ def auth_settings
250
+ {
251
+ }
252
+ end
253
+
254
+ # Returns an array of Server setting
255
+ def server_settings
256
+ [
257
+ {
258
+ url: "http://127.0.0.1:9308",
259
+ description: "Default Manticore Search HTTP",
260
+ }
261
+ ]
262
+ end
263
+
264
+ def operation_server_settings
265
+ {
266
+ }
267
+ end
268
+
269
+ # Returns URL based on server settings
270
+ #
271
+ # @param index array index of the server settings
272
+ # @param variables hash of variable and the corresponding value
273
+ def server_url(index, variables = {}, servers = nil)
274
+ servers = server_settings if servers == nil
275
+
276
+ # check array index out of bound
277
+ if (index.nil? || index < 0 || index >= servers.size)
278
+ fail ArgumentError, "Invalid index #{index} when selecting the server. Must not be nil and must be less than #{servers.size}"
279
+ end
280
+
281
+ server = servers[index]
282
+ url = server[:url]
283
+
284
+ return url unless server.key? :variables
285
+
286
+ # go through variable and assign a value
287
+ server[:variables].each do |name, variable|
288
+ if variables.key?(name)
289
+ if (!server[:variables][name].key?(:enum_values) || server[:variables][name][:enum_values].include?(variables[name]))
290
+ url.gsub! "{" + name.to_s + "}", variables[name]
291
+ else
292
+ fail ArgumentError, "The variable `#{name}` in the server URL has invalid value #{variables[name]}. Must be #{server[:variables][name][:enum_values]}."
293
+ end
294
+ else
295
+ # use default value
296
+ url.gsub! "{" + name.to_s + "}", server[:variables][name][:default_value]
297
+ end
298
+ end
299
+
300
+ url
301
+ end
302
+
303
+ # Configure Faraday connection directly.
304
+ #
305
+ # ```
306
+ # c.configure_faraday_connection do |conn|
307
+ # conn.use Faraday::HttpCache, shared_cache: false, logger: logger
308
+ # conn.response :logger, nil, headers: true, bodies: true, log_level: :debug do |logger|
309
+ # logger.filter(/(Authorization: )(.*)/, '\1[REDACTED]')
310
+ # end
311
+ # end
312
+ #
313
+ # c.configure_faraday_connection do |conn|
314
+ # conn.adapter :typhoeus
315
+ # end
316
+ # ```
317
+ #
318
+ # @param block [Proc] `#call`able object that takes one arg, the connection
319
+ def configure_faraday_connection(&block)
320
+ @configure_connection_blocks << block
321
+ end
322
+
323
+ def configure_connection(conn)
324
+ @configure_connection_blocks.each do |block|
325
+ block.call(conn)
326
+ end
327
+ end
328
+
329
+ # Adds middleware to the stack
330
+ def use(*middleware)
331
+ set_faraday_middleware(:use, *middleware)
332
+ end
333
+
334
+ # Adds request middleware to the stack
335
+ def request(*middleware)
336
+ set_faraday_middleware(:request, *middleware)
337
+ end
338
+
339
+ # Adds response middleware to the stack
340
+ def response(*middleware)
341
+ set_faraday_middleware(:response, *middleware)
342
+ end
343
+
344
+ # Adds Faraday middleware setting information to the stack
345
+ #
346
+ # @example Use the `set_faraday_middleware` method to set middleware information
347
+ # config.set_faraday_middleware(:request, :retry, max: 3, methods: [:get, :post], retry_statuses: [503])
348
+ # config.set_faraday_middleware(:response, :logger, nil, { bodies: true, log_level: :debug })
349
+ # config.set_faraday_middleware(:use, Faraday::HttpCache, store: Rails.cache, shared_cache: false)
350
+ # config.set_faraday_middleware(:insert, 0, FaradayMiddleware::FollowRedirects, { standards_compliant: true, limit: 1 })
351
+ # config.set_faraday_middleware(:swap, 0, Faraday::Response::Logger)
352
+ # config.set_faraday_middleware(:delete, Faraday::Multipart::Middleware)
353
+ #
354
+ # @see https://github.com/lostisland/faraday/blob/v2.3.0/lib/faraday/rack_builder.rb#L92-L143
355
+ def set_faraday_middleware(operation, key, *args, &block)
356
+ unless [:request, :response, :use, :insert, :insert_before, :insert_after, :swap, :delete].include?(operation)
357
+ fail ArgumentError, "Invalid faraday middleware operation #{operation}. Must be" \
358
+ " :request, :response, :use, :insert, :insert_before, :insert_after, :swap or :delete."
359
+ end
360
+
361
+ @middlewares[operation] << [key, args, block]
362
+ end
363
+ ruby2_keywords(:set_faraday_middleware) if respond_to?(:ruby2_keywords, true)
364
+
365
+ # Set up middleware on the connection
366
+ def configure_middleware(connection)
367
+ return if @middlewares.empty?
368
+
369
+ [:request, :response, :use, :insert, :insert_before, :insert_after, :swap].each do |operation|
370
+ next unless @middlewares.key?(operation)
371
+
372
+ @middlewares[operation].each do |key, args, block|
373
+ connection.builder.send(operation, key, *args, &block)
374
+ end
375
+ end
376
+
377
+ if @middlewares.key?(:delete)
378
+ @middlewares[:delete].each do |key, _args, _block|
379
+ connection.builder.delete(key)
380
+ end
381
+ end
382
+ end
383
+
384
+ end
385
+ end
@@ -0,0 +1,233 @@
1
+ =begin
2
+ #Manticore Search Client
3
+
4
+ #Сlient for Manticore Search.
5
+
6
+ The version of the OpenAPI document: 5.0.0
7
+ Contact: info@manticoresearch.com
8
+ Generated by: https://openapi-generator.tech
9
+ Generator version: 7.13.0
10
+
11
+ =end
12
+
13
+ require 'date'
14
+ require 'time'
15
+
16
+ module Manticore::Client
17
+ # Object to perform composite aggregation, i.e., grouping search results by multiple fields
18
+ class AggComposite
19
+ # Maximum number of composite buckets in the result
20
+ attr_accessor :size
21
+
22
+ attr_accessor :sources
23
+
24
+ # Attribute mapping from ruby-style variable name to JSON key.
25
+ def self.attribute_map
26
+ {
27
+ :'size' => :'size',
28
+ :'sources' => :'sources'
29
+ }
30
+ end
31
+
32
+ # Returns attribute mapping this model knows about
33
+ def self.acceptable_attribute_map
34
+ attribute_map
35
+ end
36
+
37
+ # Returns all the JSON keys this model knows about
38
+ def self.acceptable_attributes
39
+ acceptable_attribute_map.values
40
+ end
41
+
42
+ # Attribute type mapping.
43
+ def self.openapi_types
44
+ {
45
+ :'size' => :'Integer',
46
+ :'sources' => :'Array<Hash<String, AggCompositeSource>>'
47
+ }
48
+ end
49
+
50
+ # List of attributes with nullable: true
51
+ def self.openapi_nullable
52
+ Set.new([
53
+ ])
54
+ end
55
+
56
+ # Initializes the object
57
+ # @param [Hash] attributes Model attributes in the form of hash
58
+ def initialize(attributes = {})
59
+ if (!attributes.is_a?(Hash))
60
+ fail ArgumentError, "The input argument (attributes) must be a hash in `Manticore::Client::AggComposite` initialize method"
61
+ end
62
+
63
+ # check to see if the attribute exists and convert string to symbol for hash key
64
+ acceptable_attribute_map = self.class.acceptable_attribute_map
65
+ attributes = attributes.each_with_object({}) { |(k, v), h|
66
+ if (!acceptable_attribute_map.key?(k.to_sym))
67
+ fail ArgumentError, "`#{k}` is not a valid attribute in `Manticore::Client::AggComposite`. Please check the name to make sure it's valid. List of attributes: " + acceptable_attribute_map.keys.inspect
68
+ end
69
+ h[k.to_sym] = v
70
+ }
71
+
72
+ if attributes.key?(:'size')
73
+ self.size = attributes[:'size']
74
+ end
75
+
76
+ if attributes.key?(:'sources')
77
+ if (value = attributes[:'sources']).is_a?(Array)
78
+ self.sources = value
79
+ end
80
+ end
81
+ end
82
+
83
+ # Show invalid properties with the reasons. Usually used together with valid?
84
+ # @return Array for valid properties with the reasons
85
+ def list_invalid_properties
86
+ warn '[DEPRECATED] the `list_invalid_properties` method is obsolete'
87
+ invalid_properties = Array.new
88
+ invalid_properties
89
+ end
90
+
91
+ # Check to see if the all the properties in the model are valid
92
+ # @return true if the model is valid
93
+ def valid?
94
+ warn '[DEPRECATED] the `valid?` method is obsolete'
95
+ true
96
+ end
97
+
98
+ # Checks equality by comparing each attribute.
99
+ # @param [Object] Object to be compared
100
+ def ==(o)
101
+ return true if self.equal?(o)
102
+ self.class == o.class &&
103
+ size == o.size &&
104
+ sources == o.sources
105
+ end
106
+
107
+ # @see the `==` method
108
+ # @param [Object] Object to be compared
109
+ def eql?(o)
110
+ self == o
111
+ end
112
+
113
+ # Calculates hash code according to all attributes.
114
+ # @return [Integer] Hash code
115
+ def hash
116
+ [size, sources].hash
117
+ end
118
+
119
+ # Builds the object from hash
120
+ # @param [Hash] attributes Model attributes in the form of hash
121
+ # @return [Object] Returns the model itself
122
+ def self.build_from_hash(attributes)
123
+ return nil unless attributes.is_a?(Hash)
124
+ attributes = attributes.transform_keys(&:to_sym)
125
+ transformed_hash = {}
126
+ openapi_types.each_pair do |key, type|
127
+ if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil?
128
+ transformed_hash["#{key}"] = nil
129
+ elsif type =~ /\AArray<(.*)>/i
130
+ # check to ensure the input is an array given that the attribute
131
+ # is documented as an array but the input is not
132
+ if attributes[attribute_map[key]].is_a?(Array)
133
+ transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) }
134
+ end
135
+ elsif !attributes[attribute_map[key]].nil?
136
+ transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]])
137
+ end
138
+ end
139
+ new(transformed_hash)
140
+ end
141
+
142
+ # Deserializes the data based on type
143
+ # @param string type Data type
144
+ # @param string value Value to be deserialized
145
+ # @return [Object] Deserialized data
146
+ def self._deserialize(type, value)
147
+ case type.to_sym
148
+ when :Time
149
+ Time.parse(value)
150
+ when :Date
151
+ Date.parse(value)
152
+ when :String
153
+ value.to_s
154
+ when :Integer
155
+ value.to_i
156
+ when :Float
157
+ value.to_f
158
+ when :Boolean
159
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
160
+ true
161
+ else
162
+ false
163
+ end
164
+ when :Object
165
+ # generic object (usually a Hash), return directly
166
+ value
167
+ when /\AArray<(?<inner_type>.+)>\z/
168
+ inner_type = Regexp.last_match[:inner_type]
169
+ value.map { |v| _deserialize(inner_type, v) }
170
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
171
+ k_type = Regexp.last_match[:k_type]
172
+ v_type = Regexp.last_match[:v_type]
173
+ {}.tap do |hash|
174
+ value.each do |k, v|
175
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
176
+ end
177
+ end
178
+ else # model
179
+ # models (e.g. Pet) or oneOf
180
+ klass = Manticore::Client.const_get(type)
181
+ klass.respond_to?(:openapi_any_of) || klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass.build_from_hash(value)
182
+ end
183
+ end
184
+
185
+ # Returns the string representation of the object
186
+ # @return [String] String presentation of the object
187
+ def to_s
188
+ to_hash.to_s
189
+ end
190
+
191
+ # to_body is an alias to to_hash (backward compatibility)
192
+ # @return [Hash] Returns the object in the form of hash
193
+ def to_body
194
+ to_hash
195
+ end
196
+
197
+ # Returns the object in the form of hash
198
+ # @return [Hash] Returns the object in the form of hash
199
+ def to_hash
200
+ hash = {}
201
+ self.class.attribute_map.each_pair do |attr, param|
202
+ value = self.send(attr)
203
+ if value.nil?
204
+ is_nullable = self.class.openapi_nullable.include?(attr)
205
+ next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
206
+ end
207
+
208
+ hash[param] = _to_hash(value)
209
+ end
210
+ hash
211
+ end
212
+
213
+ # Outputs non-array value in the form of hash
214
+ # For object, use to_hash. Otherwise, just return the value
215
+ # @param [Object] value Any valid value
216
+ # @return [Hash] Returns the value in the form of hash
217
+ def _to_hash(value)
218
+ if value.is_a?(Array)
219
+ value.compact.map { |v| _to_hash(v) }
220
+ elsif value.is_a?(Hash)
221
+ {}.tap do |hash|
222
+ value.each { |k, v| hash[k] = _to_hash(v) }
223
+ end
224
+ elsif value.respond_to? :to_hash
225
+ value.to_hash
226
+ else
227
+ value
228
+ end
229
+ end
230
+
231
+ end
232
+
233
+ end