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,525 @@
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
+ class Highlight
18
+ # Maximum size of the text fragments in highlighted snippets per field
19
+ attr_accessor :fragment_size
20
+
21
+ # Maximum size of snippets per field
22
+ attr_accessor :limit
23
+
24
+ # Maximum number of snippets per field
25
+ attr_accessor :limit_snippets
26
+
27
+ # Maximum number of words per field
28
+ attr_accessor :limit_words
29
+
30
+ # Total number of highlighted fragments per field
31
+ attr_accessor :number_of_fragments
32
+
33
+ # Text inserted after the matched term, typically used for HTML formatting
34
+ attr_accessor :after_match
35
+
36
+ # Permits an empty string to be returned as the highlighting result. Otherwise, the beginning of the original text would be returned
37
+ attr_accessor :allow_empty
38
+
39
+ # Number of words around the match to include in the highlight
40
+ attr_accessor :around
41
+
42
+ # Text inserted before the match, typically used for HTML formatting
43
+ attr_accessor :before_match
44
+
45
+ # Emits an HTML tag with the enclosing zone name before each highlighted snippet
46
+ attr_accessor :emit_zones
47
+
48
+ # If set to 'html', retains HTML markup when highlighting
49
+ attr_accessor :encoder
50
+
51
+ attr_accessor :fields
52
+
53
+ # Ignores the length limit until the result includes all keywords
54
+ attr_accessor :force_all_words
55
+
56
+ # Forces snippet generation even if limits allow highlighting the entire text
57
+ attr_accessor :force_snippets
58
+
59
+ attr_accessor :highlight_query
60
+
61
+ # Defines the mode for handling HTML markup in the highlight
62
+ attr_accessor :html_strip_mode
63
+
64
+ # Determines whether the 'limit', 'limit_words', and 'limit_snippets' options operate as individual limits in each field of the document
65
+ attr_accessor :limits_per_field
66
+
67
+ # If set to 1, allows an empty string to be returned as a highlighting result
68
+ attr_accessor :no_match_size
69
+
70
+ # Sets the sorting order of highlighted snippets
71
+ attr_accessor :order
72
+
73
+ # Text inserted before each highlighted snippet
74
+ attr_accessor :pre_tags
75
+
76
+ # Text inserted after each highlighted snippet
77
+ attr_accessor :post_tags
78
+
79
+ # Sets the starting value of the %SNIPPET_ID% macro
80
+ attr_accessor :start_snippet_id
81
+
82
+ # Defines whether to additionally break snippets by phrase boundary characters
83
+ attr_accessor :use_boundaries
84
+
85
+ class EnumAttributeValidator
86
+ attr_reader :datatype
87
+ attr_reader :allowable_values
88
+
89
+ def initialize(datatype, allowable_values)
90
+ @allowable_values = allowable_values.map do |value|
91
+ case datatype.to_s
92
+ when /Integer/i
93
+ value.to_i
94
+ when /Float/i
95
+ value.to_f
96
+ else
97
+ value
98
+ end
99
+ end
100
+ end
101
+
102
+ def valid?(value)
103
+ !value || allowable_values.include?(value)
104
+ end
105
+ end
106
+
107
+ # Attribute mapping from ruby-style variable name to JSON key.
108
+ def self.attribute_map
109
+ {
110
+ :'fragment_size' => :'fragment_size',
111
+ :'limit' => :'limit',
112
+ :'limit_snippets' => :'limit_snippets',
113
+ :'limit_words' => :'limit_words',
114
+ :'number_of_fragments' => :'number_of_fragments',
115
+ :'after_match' => :'after_match',
116
+ :'allow_empty' => :'allow_empty',
117
+ :'around' => :'around',
118
+ :'before_match' => :'before_match',
119
+ :'emit_zones' => :'emit_zones',
120
+ :'encoder' => :'encoder',
121
+ :'fields' => :'fields',
122
+ :'force_all_words' => :'force_all_words',
123
+ :'force_snippets' => :'force_snippets',
124
+ :'highlight_query' => :'highlight_query',
125
+ :'html_strip_mode' => :'html_strip_mode',
126
+ :'limits_per_field' => :'limits_per_field',
127
+ :'no_match_size' => :'no_match_size',
128
+ :'order' => :'order',
129
+ :'pre_tags' => :'pre_tags',
130
+ :'post_tags' => :'post_tags',
131
+ :'start_snippet_id' => :'start_snippet_id',
132
+ :'use_boundaries' => :'use_boundaries'
133
+ }
134
+ end
135
+
136
+ # Returns attribute mapping this model knows about
137
+ def self.acceptable_attribute_map
138
+ attribute_map
139
+ end
140
+
141
+ # Returns all the JSON keys this model knows about
142
+ def self.acceptable_attributes
143
+ acceptable_attribute_map.values
144
+ end
145
+
146
+ # Attribute type mapping.
147
+ def self.openapi_types
148
+ {
149
+ :'fragment_size' => :'Integer',
150
+ :'limit' => :'Integer',
151
+ :'limit_snippets' => :'Integer',
152
+ :'limit_words' => :'Integer',
153
+ :'number_of_fragments' => :'Integer',
154
+ :'after_match' => :'String',
155
+ :'allow_empty' => :'Boolean',
156
+ :'around' => :'Integer',
157
+ :'before_match' => :'String',
158
+ :'emit_zones' => :'Boolean',
159
+ :'encoder' => :'String',
160
+ :'fields' => :'HighlightAllOfFields',
161
+ :'force_all_words' => :'Boolean',
162
+ :'force_snippets' => :'Boolean',
163
+ :'highlight_query' => :'QueryFilter',
164
+ :'html_strip_mode' => :'String',
165
+ :'limits_per_field' => :'Boolean',
166
+ :'no_match_size' => :'Integer',
167
+ :'order' => :'String',
168
+ :'pre_tags' => :'String',
169
+ :'post_tags' => :'String',
170
+ :'start_snippet_id' => :'Integer',
171
+ :'use_boundaries' => :'Boolean'
172
+ }
173
+ end
174
+
175
+ # List of attributes with nullable: true
176
+ def self.openapi_nullable
177
+ Set.new([
178
+ :'highlight_query',
179
+ ])
180
+ end
181
+
182
+ # List of class defined in allOf (OpenAPI v3)
183
+ def self.openapi_all_of
184
+ [
185
+ :'HighlightFieldOption'
186
+ ]
187
+ end
188
+
189
+ # Initializes the object
190
+ # @param [Hash] attributes Model attributes in the form of hash
191
+ def initialize(attributes = {})
192
+ if (!attributes.is_a?(Hash))
193
+ fail ArgumentError, "The input argument (attributes) must be a hash in `Manticore::Client::Highlight` initialize method"
194
+ end
195
+
196
+ # check to see if the attribute exists and convert string to symbol for hash key
197
+ acceptable_attribute_map = self.class.acceptable_attribute_map
198
+ attributes = attributes.each_with_object({}) { |(k, v), h|
199
+ if (!acceptable_attribute_map.key?(k.to_sym))
200
+ fail ArgumentError, "`#{k}` is not a valid attribute in `Manticore::Client::Highlight`. Please check the name to make sure it's valid. List of attributes: " + acceptable_attribute_map.keys.inspect
201
+ end
202
+ h[k.to_sym] = v
203
+ }
204
+
205
+ if attributes.key?(:'fragment_size')
206
+ self.fragment_size = attributes[:'fragment_size']
207
+ end
208
+
209
+ if attributes.key?(:'limit')
210
+ self.limit = attributes[:'limit']
211
+ end
212
+
213
+ if attributes.key?(:'limit_snippets')
214
+ self.limit_snippets = attributes[:'limit_snippets']
215
+ end
216
+
217
+ if attributes.key?(:'limit_words')
218
+ self.limit_words = attributes[:'limit_words']
219
+ end
220
+
221
+ if attributes.key?(:'number_of_fragments')
222
+ self.number_of_fragments = attributes[:'number_of_fragments']
223
+ end
224
+
225
+ if attributes.key?(:'after_match')
226
+ self.after_match = attributes[:'after_match']
227
+ else
228
+ self.after_match = '</strong>'
229
+ end
230
+
231
+ if attributes.key?(:'allow_empty')
232
+ self.allow_empty = attributes[:'allow_empty']
233
+ end
234
+
235
+ if attributes.key?(:'around')
236
+ self.around = attributes[:'around']
237
+ end
238
+
239
+ if attributes.key?(:'before_match')
240
+ self.before_match = attributes[:'before_match']
241
+ else
242
+ self.before_match = '<strong>'
243
+ end
244
+
245
+ if attributes.key?(:'emit_zones')
246
+ self.emit_zones = attributes[:'emit_zones']
247
+ end
248
+
249
+ if attributes.key?(:'encoder')
250
+ self.encoder = attributes[:'encoder']
251
+ end
252
+
253
+ if attributes.key?(:'fields')
254
+ self.fields = attributes[:'fields']
255
+ end
256
+
257
+ if attributes.key?(:'force_all_words')
258
+ self.force_all_words = attributes[:'force_all_words']
259
+ end
260
+
261
+ if attributes.key?(:'force_snippets')
262
+ self.force_snippets = attributes[:'force_snippets']
263
+ end
264
+
265
+ if attributes.key?(:'highlight_query')
266
+ self.highlight_query = attributes[:'highlight_query']
267
+ end
268
+
269
+ if attributes.key?(:'html_strip_mode')
270
+ self.html_strip_mode = attributes[:'html_strip_mode']
271
+ end
272
+
273
+ if attributes.key?(:'limits_per_field')
274
+ self.limits_per_field = attributes[:'limits_per_field']
275
+ end
276
+
277
+ if attributes.key?(:'no_match_size')
278
+ self.no_match_size = attributes[:'no_match_size']
279
+ end
280
+
281
+ if attributes.key?(:'order')
282
+ self.order = attributes[:'order']
283
+ end
284
+
285
+ if attributes.key?(:'pre_tags')
286
+ self.pre_tags = attributes[:'pre_tags']
287
+ else
288
+ self.pre_tags = '<strong>'
289
+ end
290
+
291
+ if attributes.key?(:'post_tags')
292
+ self.post_tags = attributes[:'post_tags']
293
+ else
294
+ self.post_tags = '</strong>'
295
+ end
296
+
297
+ if attributes.key?(:'start_snippet_id')
298
+ self.start_snippet_id = attributes[:'start_snippet_id']
299
+ end
300
+
301
+ if attributes.key?(:'use_boundaries')
302
+ self.use_boundaries = attributes[:'use_boundaries']
303
+ end
304
+ end
305
+
306
+ # Show invalid properties with the reasons. Usually used together with valid?
307
+ # @return Array for valid properties with the reasons
308
+ def list_invalid_properties
309
+ warn '[DEPRECATED] the `list_invalid_properties` method is obsolete'
310
+ invalid_properties = Array.new
311
+ invalid_properties
312
+ end
313
+
314
+ # Check to see if the all the properties in the model are valid
315
+ # @return true if the model is valid
316
+ def valid?
317
+ warn '[DEPRECATED] the `valid?` method is obsolete'
318
+ encoder_validator = EnumAttributeValidator.new('String', ["default", "html"])
319
+ return false unless encoder_validator.valid?(@encoder)
320
+ html_strip_mode_validator = EnumAttributeValidator.new('String', ["none", "strip", "index", "retain"])
321
+ return false unless html_strip_mode_validator.valid?(@html_strip_mode)
322
+ no_match_size_validator = EnumAttributeValidator.new('Integer', [0, 1])
323
+ return false unless no_match_size_validator.valid?(@no_match_size)
324
+ order_validator = EnumAttributeValidator.new('String', ["asc", "desc", "score"])
325
+ return false unless order_validator.valid?(@order)
326
+ true
327
+ end
328
+
329
+ # Custom attribute writer method checking allowed values (enum).
330
+ # @param [Object] encoder Object to be assigned
331
+ def encoder=(encoder)
332
+ validator = EnumAttributeValidator.new('String', ["default", "html"])
333
+ unless validator.valid?(encoder)
334
+ fail ArgumentError, "invalid value for \"encoder\", must be one of #{validator.allowable_values}."
335
+ end
336
+ @encoder = encoder
337
+ end
338
+
339
+ # Custom attribute writer method checking allowed values (enum).
340
+ # @param [Object] html_strip_mode Object to be assigned
341
+ def html_strip_mode=(html_strip_mode)
342
+ validator = EnumAttributeValidator.new('String', ["none", "strip", "index", "retain"])
343
+ unless validator.valid?(html_strip_mode)
344
+ fail ArgumentError, "invalid value for \"html_strip_mode\", must be one of #{validator.allowable_values}."
345
+ end
346
+ @html_strip_mode = html_strip_mode
347
+ end
348
+
349
+ # Custom attribute writer method checking allowed values (enum).
350
+ # @param [Object] no_match_size Object to be assigned
351
+ def no_match_size=(no_match_size)
352
+ validator = EnumAttributeValidator.new('Integer', [0, 1])
353
+ unless validator.valid?(no_match_size)
354
+ fail ArgumentError, "invalid value for \"no_match_size\", must be one of #{validator.allowable_values}."
355
+ end
356
+ @no_match_size = no_match_size
357
+ end
358
+
359
+ # Custom attribute writer method checking allowed values (enum).
360
+ # @param [Object] order Object to be assigned
361
+ def order=(order)
362
+ validator = EnumAttributeValidator.new('String', ["asc", "desc", "score"])
363
+ unless validator.valid?(order)
364
+ fail ArgumentError, "invalid value for \"order\", must be one of #{validator.allowable_values}."
365
+ end
366
+ @order = order
367
+ end
368
+
369
+ # Checks equality by comparing each attribute.
370
+ # @param [Object] Object to be compared
371
+ def ==(o)
372
+ return true if self.equal?(o)
373
+ self.class == o.class &&
374
+ fragment_size == o.fragment_size &&
375
+ limit == o.limit &&
376
+ limit_snippets == o.limit_snippets &&
377
+ limit_words == o.limit_words &&
378
+ number_of_fragments == o.number_of_fragments &&
379
+ after_match == o.after_match &&
380
+ allow_empty == o.allow_empty &&
381
+ around == o.around &&
382
+ before_match == o.before_match &&
383
+ emit_zones == o.emit_zones &&
384
+ encoder == o.encoder &&
385
+ fields == o.fields &&
386
+ force_all_words == o.force_all_words &&
387
+ force_snippets == o.force_snippets &&
388
+ highlight_query == o.highlight_query &&
389
+ html_strip_mode == o.html_strip_mode &&
390
+ limits_per_field == o.limits_per_field &&
391
+ no_match_size == o.no_match_size &&
392
+ order == o.order &&
393
+ pre_tags == o.pre_tags &&
394
+ post_tags == o.post_tags &&
395
+ start_snippet_id == o.start_snippet_id &&
396
+ use_boundaries == o.use_boundaries
397
+ end
398
+
399
+ # @see the `==` method
400
+ # @param [Object] Object to be compared
401
+ def eql?(o)
402
+ self == o
403
+ end
404
+
405
+ # Calculates hash code according to all attributes.
406
+ # @return [Integer] Hash code
407
+ def hash
408
+ [fragment_size, limit, limit_snippets, limit_words, number_of_fragments, after_match, allow_empty, around, before_match, emit_zones, encoder, fields, force_all_words, force_snippets, highlight_query, html_strip_mode, limits_per_field, no_match_size, order, pre_tags, post_tags, start_snippet_id, use_boundaries].hash
409
+ end
410
+
411
+ # Builds the object from hash
412
+ # @param [Hash] attributes Model attributes in the form of hash
413
+ # @return [Object] Returns the model itself
414
+ def self.build_from_hash(attributes)
415
+ return nil unless attributes.is_a?(Hash)
416
+ attributes = attributes.transform_keys(&:to_sym)
417
+ transformed_hash = {}
418
+ openapi_types.each_pair do |key, type|
419
+ if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil?
420
+ transformed_hash["#{key}"] = nil
421
+ elsif type =~ /\AArray<(.*)>/i
422
+ # check to ensure the input is an array given that the attribute
423
+ # is documented as an array but the input is not
424
+ if attributes[attribute_map[key]].is_a?(Array)
425
+ transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) }
426
+ end
427
+ elsif !attributes[attribute_map[key]].nil?
428
+ transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]])
429
+ end
430
+ end
431
+ new(transformed_hash)
432
+ end
433
+
434
+ # Deserializes the data based on type
435
+ # @param string type Data type
436
+ # @param string value Value to be deserialized
437
+ # @return [Object] Deserialized data
438
+ def self._deserialize(type, value)
439
+ case type.to_sym
440
+ when :Time
441
+ Time.parse(value)
442
+ when :Date
443
+ Date.parse(value)
444
+ when :String
445
+ value.to_s
446
+ when :Integer
447
+ value.to_i
448
+ when :Float
449
+ value.to_f
450
+ when :Boolean
451
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
452
+ true
453
+ else
454
+ false
455
+ end
456
+ when :Object
457
+ # generic object (usually a Hash), return directly
458
+ value
459
+ when /\AArray<(?<inner_type>.+)>\z/
460
+ inner_type = Regexp.last_match[:inner_type]
461
+ value.map { |v| _deserialize(inner_type, v) }
462
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
463
+ k_type = Regexp.last_match[:k_type]
464
+ v_type = Regexp.last_match[:v_type]
465
+ {}.tap do |hash|
466
+ value.each do |k, v|
467
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
468
+ end
469
+ end
470
+ else # model
471
+ # models (e.g. Pet) or oneOf
472
+ klass = Manticore::Client.const_get(type)
473
+ klass.respond_to?(:openapi_any_of) || klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass.build_from_hash(value)
474
+ end
475
+ end
476
+
477
+ # Returns the string representation of the object
478
+ # @return [String] String presentation of the object
479
+ def to_s
480
+ to_hash.to_s
481
+ end
482
+
483
+ # to_body is an alias to to_hash (backward compatibility)
484
+ # @return [Hash] Returns the object in the form of hash
485
+ def to_body
486
+ to_hash
487
+ end
488
+
489
+ # Returns the object in the form of hash
490
+ # @return [Hash] Returns the object in the form of hash
491
+ def to_hash
492
+ hash = {}
493
+ self.class.attribute_map.each_pair do |attr, param|
494
+ value = self.send(attr)
495
+ if value.nil?
496
+ is_nullable = self.class.openapi_nullable.include?(attr)
497
+ next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
498
+ end
499
+
500
+ hash[param] = _to_hash(value)
501
+ end
502
+ hash
503
+ end
504
+
505
+ # Outputs non-array value in the form of hash
506
+ # For object, use to_hash. Otherwise, just return the value
507
+ # @param [Object] value Any valid value
508
+ # @return [Hash] Returns the value in the form of hash
509
+ def _to_hash(value)
510
+ if value.is_a?(Array)
511
+ value.compact.map { |v| _to_hash(v) }
512
+ elsif value.is_a?(Hash)
513
+ {}.tap do |hash|
514
+ value.each { |k, v| hash[k] = _to_hash(v) }
515
+ end
516
+ elsif value.respond_to? :to_hash
517
+ value.to_hash
518
+ else
519
+ value
520
+ end
521
+ end
522
+
523
+ end
524
+
525
+ end
@@ -0,0 +1,105 @@
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
+ # List of fields available for highlighting
18
+ module HighlightAllOfFields
19
+ class << self
20
+ # List of class defined in anyOf (OpenAPI v3)
21
+ def openapi_any_of
22
+ [
23
+ :'Array<String>',
24
+ :'Object'
25
+ ]
26
+ end
27
+
28
+ # Builds the object
29
+ # @param [Mixed] Data to be matched against the list of anyOf items
30
+ # @return [Object] Returns the model or the data itself
31
+ def build(data)
32
+ # Go through the list of anyOf items and attempt to identify the appropriate one.
33
+ # Note:
34
+ # - No advanced validation of types in some cases (e.g. "x: { type: string }" will happily match { x: 123 })
35
+ # due to the way the deserialization is made in the base_object template (it just casts without verifying).
36
+ # - TODO: scalar values are de facto behaving as if they were nullable.
37
+ # - TODO: logging when debugging is set.
38
+ openapi_any_of.each do |klass|
39
+ begin
40
+ next if klass == :AnyType # "nullable: true"
41
+ typed_data = find_and_cast_into_type(klass, data)
42
+ return typed_data if typed_data
43
+ rescue # rescue all errors so we keep iterating even if the current item lookup raises
44
+ end
45
+ end
46
+
47
+ openapi_any_of.include?(:AnyType) ? data : nil
48
+ end
49
+
50
+ private
51
+
52
+ SchemaMismatchError = Class.new(StandardError)
53
+
54
+ # Note: 'File' is missing here because in the regular case we get the data _after_ a call to JSON.parse.
55
+ def find_and_cast_into_type(klass, data)
56
+ return if data.nil?
57
+
58
+ case klass.to_s
59
+ when 'Boolean'
60
+ return data if data.instance_of?(TrueClass) || data.instance_of?(FalseClass)
61
+ when 'Float'
62
+ return data if data.instance_of?(Float)
63
+ when 'Integer'
64
+ return data if data.instance_of?(Integer)
65
+ when 'Time'
66
+ return Time.parse(data)
67
+ when 'Date'
68
+ return Date.parse(data)
69
+ when 'String'
70
+ return data if data.instance_of?(String)
71
+ when 'Object' # "type: object"
72
+ return data if data.instance_of?(Hash)
73
+ when /\AArray<(?<sub_type>.+)>\z/ # "type: array"
74
+ if data.instance_of?(Array)
75
+ sub_type = Regexp.last_match[:sub_type]
76
+ return data.map { |item| find_and_cast_into_type(sub_type, item) }
77
+ end
78
+ when /\AHash<String, (?<sub_type>.+)>\z/ # "type: object" with "additionalProperties: { ... }"
79
+ if data.instance_of?(Hash) && data.keys.all? { |k| k.instance_of?(Symbol) || k.instance_of?(String) }
80
+ sub_type = Regexp.last_match[:sub_type]
81
+ return data.each_with_object({}) { |(k, v), hsh| hsh[k] = find_and_cast_into_type(sub_type, v) }
82
+ end
83
+ else # model
84
+ const = Manticore::Client.const_get(klass)
85
+ if const
86
+ if const.respond_to?(:openapi_any_of) # nested anyOf model
87
+ model = const.build(data)
88
+ return model if model
89
+ else
90
+ # raise if data contains keys that are not known to the model
91
+ raise if const.respond_to?(:acceptable_attributes) && !(data.keys - const.acceptable_attributes).empty?
92
+ model = const.build_from_hash(data)
93
+ return model if model
94
+ end
95
+ end
96
+ end
97
+
98
+ raise # if no match by now, raise
99
+ rescue
100
+ raise SchemaMismatchError, "#{data} doesn't match the #{klass} type"
101
+ end
102
+ end
103
+ end
104
+
105
+ end