From b23c8228e6495ad7c42c4f6174523e5f30d645d0 Mon Sep 17 00:00:00 2001 From: algolia-bot Date: Wed, 22 Jan 2025 08:32:46 +0000 Subject: [PATCH] feat(specs): rename composition to composition-full (private) and add composition (public) (generated) https://github.com/algolia/api-clients-automation/pull/4357 Co-authored-by: algolia-bot Co-authored-by: Emmanuel Krebs Co-authored-by: shortcuts Co-authored-by: Pierre Millot --- lib/algolia/api/composition_client.rb | 174 +++++ .../models/composition/around_precision.rb | 110 ++++ .../models/composition/around_radius.rb | 110 ++++ .../models/composition/around_radius_all.rb | 33 + lib/algolia/models/composition/banner.rb | 215 +++++++ .../models/composition/banner_image.rb | 220 +++++++ .../models/composition/banner_image_url.rb | 209 ++++++ lib/algolia/models/composition/banner_link.rb | 209 ++++++ .../composition_id_ranking_info.rb | 221 +++++++ .../composition_run_applied_rules.rb | 211 ++++++ .../composition_run_search_response.rb | 222 +++++++ .../compositions_search_response.rb | 212 ++++++ lib/algolia/models/composition/error_base.rb | 209 ++++++ lib/algolia/models/composition/exhaustive.rb | 250 +++++++ .../models/composition/facet_filters.rb | 110 ++++ lib/algolia/models/composition/facet_hits.rb | 235 +++++++ .../models/composition/facet_ordering.rb | 221 +++++++ lib/algolia/models/composition/facet_stats.rb | 239 +++++++ lib/algolia/models/composition/facets.rb | 209 ++++++ .../models/composition/highlight_result.rb | 110 ++++ .../composition/highlight_result_option.rb | 255 ++++++++ lib/algolia/models/composition/hit.rb | 251 ++++++++ .../models/composition/hit_ranking_info.rb | 371 +++++++++++ .../models/composition/inside_bounding_box.rb | 109 ++++ lib/algolia/models/composition/match_level.rb | 35 + .../composition/matched_geo_location.rb | 229 +++++++ .../models/composition/numeric_filters.rb | 110 ++++ .../models/composition/optional_filters.rb | 110 ++++ lib/algolia/models/composition/params.rb | 488 ++++++++++++++ .../models/composition/personalization.rb | 229 +++++++ lib/algolia/models/composition/range.rb | 217 +++++++ lib/algolia/models/composition/redirect.rb | 208 ++++++ .../composition/redirect_rule_index_data.rb | 211 ++++++ .../redirect_rule_index_metadata.rb | 258 ++++++++ .../models/composition/redirect_url.rb | 209 ++++++ .../models/composition/rendering_content.rb | 227 +++++++ .../models/composition/request_body.rb | 208 ++++++ .../results_composition_info_response.rb | 212 ++++++ ...jected_item_applied_rules_info_response.rb | 211 ++++++ .../results_injected_item_info_response.rb | 221 +++++++ .../search_for_facet_values_params.rb | 228 +++++++ .../search_for_facet_values_request.rb | 208 ++++++ .../search_for_facet_values_response.rb | 211 ++++++ .../search_for_facet_values_results.rb | 253 ++++++++ .../models/composition/search_response.rb | 230 +++++++ .../models/composition/search_results_item.rb | 608 ++++++++++++++++++ .../models/composition/snippet_result.rb | 110 ++++ .../composition/snippet_result_option.rb | 230 +++++++ .../models/composition/sort_remaining_by.rb | 35 + .../models/composition/supported_language.rb | 169 +++++ lib/algolia/models/composition/value.rb | 229 +++++++ lib/algolia/models/composition/widgets.rb | 209 ++++++ 52 files changed, 10818 insertions(+) create mode 100644 lib/algolia/api/composition_client.rb create mode 100644 lib/algolia/models/composition/around_precision.rb create mode 100644 lib/algolia/models/composition/around_radius.rb create mode 100644 lib/algolia/models/composition/around_radius_all.rb create mode 100644 lib/algolia/models/composition/banner.rb create mode 100644 lib/algolia/models/composition/banner_image.rb create mode 100644 lib/algolia/models/composition/banner_image_url.rb create mode 100644 lib/algolia/models/composition/banner_link.rb create mode 100644 lib/algolia/models/composition/composition_id_ranking_info.rb create mode 100644 lib/algolia/models/composition/composition_run_applied_rules.rb create mode 100644 lib/algolia/models/composition/composition_run_search_response.rb create mode 100644 lib/algolia/models/composition/compositions_search_response.rb create mode 100644 lib/algolia/models/composition/error_base.rb create mode 100644 lib/algolia/models/composition/exhaustive.rb create mode 100644 lib/algolia/models/composition/facet_filters.rb create mode 100644 lib/algolia/models/composition/facet_hits.rb create mode 100644 lib/algolia/models/composition/facet_ordering.rb create mode 100644 lib/algolia/models/composition/facet_stats.rb create mode 100644 lib/algolia/models/composition/facets.rb create mode 100644 lib/algolia/models/composition/highlight_result.rb create mode 100644 lib/algolia/models/composition/highlight_result_option.rb create mode 100644 lib/algolia/models/composition/hit.rb create mode 100644 lib/algolia/models/composition/hit_ranking_info.rb create mode 100644 lib/algolia/models/composition/inside_bounding_box.rb create mode 100644 lib/algolia/models/composition/match_level.rb create mode 100644 lib/algolia/models/composition/matched_geo_location.rb create mode 100644 lib/algolia/models/composition/numeric_filters.rb create mode 100644 lib/algolia/models/composition/optional_filters.rb create mode 100644 lib/algolia/models/composition/params.rb create mode 100644 lib/algolia/models/composition/personalization.rb create mode 100644 lib/algolia/models/composition/range.rb create mode 100644 lib/algolia/models/composition/redirect.rb create mode 100644 lib/algolia/models/composition/redirect_rule_index_data.rb create mode 100644 lib/algolia/models/composition/redirect_rule_index_metadata.rb create mode 100644 lib/algolia/models/composition/redirect_url.rb create mode 100644 lib/algolia/models/composition/rendering_content.rb create mode 100644 lib/algolia/models/composition/request_body.rb create mode 100644 lib/algolia/models/composition/results_composition_info_response.rb create mode 100644 lib/algolia/models/composition/results_injected_item_applied_rules_info_response.rb create mode 100644 lib/algolia/models/composition/results_injected_item_info_response.rb create mode 100644 lib/algolia/models/composition/search_for_facet_values_params.rb create mode 100644 lib/algolia/models/composition/search_for_facet_values_request.rb create mode 100644 lib/algolia/models/composition/search_for_facet_values_response.rb create mode 100644 lib/algolia/models/composition/search_for_facet_values_results.rb create mode 100644 lib/algolia/models/composition/search_response.rb create mode 100644 lib/algolia/models/composition/search_results_item.rb create mode 100644 lib/algolia/models/composition/snippet_result.rb create mode 100644 lib/algolia/models/composition/snippet_result_option.rb create mode 100644 lib/algolia/models/composition/sort_remaining_by.rb create mode 100644 lib/algolia/models/composition/supported_language.rb create mode 100644 lib/algolia/models/composition/value.rb create mode 100644 lib/algolia/models/composition/widgets.rb diff --git a/lib/algolia/api/composition_client.rb b/lib/algolia/api/composition_client.rb new file mode 100644 index 00000000..244cb8a8 --- /dev/null +++ b/lib/algolia/api/composition_client.rb @@ -0,0 +1,174 @@ +# frozen_string_literal: true + +# Code generated by OpenAPI Generator (https://openapi-generator.tech), manual changes will be lost - read more on https://github.com/algolia/api-clients-automation. DO NOT EDIT. + +module Algolia + class CompositionClient + attr_accessor :api_client + + def initialize(config = nil) + raise "`config` is missing." if config.nil? + raise "`app_id` is missing." if config.app_id.nil? || config.app_id == "" + raise "`api_key` is missing." if config.api_key.nil? || config.api_key == "" + + @api_client = Algolia::ApiClient.new(config) + end + + def self.create(app_id, api_key, opts = {}) + hosts = [] + hosts << Transport::StatefulHost.new("#{app_id}-dsn.algolia.net", accept: CallType::READ) + hosts << Transport::StatefulHost.new("#{app_id}.algolia.net", accept: CallType::WRITE) + + hosts += 1 + .upto(3) + .map do |i| + Transport::StatefulHost.new("#{app_id}-#{i}.algolianet.com", accept: CallType::READ | CallType::WRITE) + end + .shuffle + + config = Algolia::Configuration.new(app_id, api_key, hosts, "Composition", opts) + create_with_config(config) + end + + def self.create_with_config(config) + new(config) + end + + # Helper method to switch the API key used to authenticate the requests. + # + # @param api_key [String] the new API key to use. + # @return [void] + def set_client_api_key(api_key) + @api_client.set_client_api_key(api_key) + + self + end + + def add_user_agent_segment(segment, version = nil) + @api_client.config.add_user_agent_segment(segment, version) + + self + end + + # Runs a query on a single composition and returns matching results. + # + # Required API Key ACLs: + # - search + # @param composition_id [String] Unique Composition ObjectID. (required) + # @param request_body [RequestBody] (required) + # @param request_options: The request options to send along with the query, they will be merged with the transporter base parameters (headers, query params, timeouts, etc.). (optional) + # @return [Http::Response] the response + def search_with_http_info(composition_id, request_body, request_options = {}) + # verify the required parameter 'composition_id' is set + if @api_client.config.client_side_validation && composition_id.nil? + raise ArgumentError, "Parameter `composition_id` is required when calling `search`." + end + # verify the required parameter 'request_body' is set + if @api_client.config.client_side_validation && request_body.nil? + raise ArgumentError, "Parameter `request_body` is required when calling `search`." + end + + path = "/1/compositions/{compositionID}/run".sub( + "{" + "compositionID" + "}", + Transport.encode_uri(composition_id.to_s) + ) + query_params = {} + query_params = query_params.merge(request_options[:query_params]) unless request_options[:query_params].nil? + header_params = {} + header_params = header_params.merge(request_options[:header_params]) unless request_options[:header_params].nil? + + post_body = request_options[:debug_body] || @api_client.object_to_http_body(request_body) + + new_options = request_options.merge( + :operation => :"CompositionClient.search", + :header_params => header_params, + :query_params => query_params, + :body => post_body, + :use_read_transporter => true + ) + + @api_client.call_api(:POST, path, new_options) + end + + # Runs a query on a single composition and returns matching results. + # + # Required API Key ACLs: + # - search + # @param composition_id [String] Unique Composition ObjectID. (required) + # @param request_body [RequestBody] (required) + # @param request_options: The request options to send along with the query, they will be merged with the transporter base parameters (headers, query params, timeouts, etc.). (optional) + # @return [SearchResponse] + def search(composition_id, request_body, request_options = {}) + response = search_with_http_info(composition_id, request_body, request_options) + @api_client.deserialize(response.body, request_options[:debug_return_type] || "Composition::SearchResponse") + end + + # Searches for values of a specified facet attribute on the composition's main source's index. - By default, facet values are sorted by decreasing count. You can adjust this with the `sortFacetValueBy` parameter. - Searching for facet values doesn't work if you have **more than 65 searchable facets and searchable attributes combined**. + # + # Required API Key ACLs: + # - search + # @param composition_id [String] Unique Composition ObjectID. (required) + # @param facet_name [String] Facet attribute in which to search for values. This attribute must be included in the `attributesForFaceting` index setting with the `searchable()` modifier. (required) + # @param search_for_facet_values_request [SearchForFacetValuesRequest] + # @param request_options: The request options to send along with the query, they will be merged with the transporter base parameters (headers, query params, timeouts, etc.). (optional) + # @return [Http::Response] the response + def search_for_facet_values_with_http_info( + composition_id, + facet_name, + search_for_facet_values_request = nil, + request_options = {} + ) + # verify the required parameter 'composition_id' is set + if @api_client.config.client_side_validation && composition_id.nil? + raise ArgumentError, "Parameter `composition_id` is required when calling `search_for_facet_values`." + end + # verify the required parameter 'facet_name' is set + if @api_client.config.client_side_validation && facet_name.nil? + raise ArgumentError, "Parameter `facet_name` is required when calling `search_for_facet_values`." + end + + path = "/1/compositions/{compositionID}/facets/{facetName}/query" + .sub("{" + "compositionID" + "}", Transport.encode_uri(composition_id.to_s)) + .sub("{" + "facetName" + "}", Transport.encode_uri(facet_name.to_s)) + query_params = {} + query_params = query_params.merge(request_options[:query_params]) unless request_options[:query_params].nil? + header_params = {} + header_params = header_params.merge(request_options[:header_params]) unless request_options[:header_params].nil? + + post_body = request_options[:debug_body] || @api_client.object_to_http_body(search_for_facet_values_request) + + new_options = request_options.merge( + :operation => :"CompositionClient.search_for_facet_values", + :header_params => header_params, + :query_params => query_params, + :body => post_body, + :use_read_transporter => true + ) + + @api_client.call_api(:POST, path, new_options) + end + + # Searches for values of a specified facet attribute on the composition's main source's index. - By default, facet values are sorted by decreasing count. You can adjust this with the `sortFacetValueBy` parameter. - Searching for facet values doesn't work if you have **more than 65 searchable facets and searchable attributes combined**. + # + # Required API Key ACLs: + # - search + # @param composition_id [String] Unique Composition ObjectID. (required) + # @param facet_name [String] Facet attribute in which to search for values. This attribute must be included in the `attributesForFaceting` index setting with the `searchable()` modifier. (required) + # @param search_for_facet_values_request [SearchForFacetValuesRequest] + # @param request_options: The request options to send along with the query, they will be merged with the transporter base parameters (headers, query params, timeouts, etc.). (optional) + # @return [SearchForFacetValuesResponse] + def search_for_facet_values(composition_id, facet_name, search_for_facet_values_request = nil, request_options = {}) + response = search_for_facet_values_with_http_info( + composition_id, + facet_name, + search_for_facet_values_request, + request_options + ) + @api_client.deserialize( + response.body, + request_options[:debug_return_type] || "Composition::SearchForFacetValuesResponse" + ) + end + + end +end diff --git a/lib/algolia/models/composition/around_precision.rb b/lib/algolia/models/composition/around_precision.rb new file mode 100644 index 00000000..c010376f --- /dev/null +++ b/lib/algolia/models/composition/around_precision.rb @@ -0,0 +1,110 @@ +# frozen_string_literal: true + +# Code generated by OpenAPI Generator (https://openapi-generator.tech), manual changes will be lost - read more on https://github.com/algolia/api-clients-automation. DO NOT EDIT. + +require "date" +require "time" + +module Algolia + module Composition + # Precision of a coordinate-based search in meters to group results with similar distances. The Geo ranking criterion considers all matches within the same range of distances to be equal. + module AroundPrecision + class << self + # List of class defined in oneOf (OpenAPI v3) + def openapi_one_of + [ + :"Array", + :"Integer" + ] + end + + # Builds the object + # @param [Mixed] Data to be matched against the list of oneOf items + # @return [Object] Returns the model or the data itself + def build(data) + # Go through the list of oneOf items and attempt to identify the appropriate one. + # Note: + # - We do not attempt to check whether exactly one item matches. + # - No advanced validation of types in some cases (e.g. "x: { type: string }" will happily match { x: 123 }) + # due to the way the deserialization is made in the base_object template (it just casts without verifying). + # - TODO: scalar values are de facto behaving as if they were nullable. + # - TODO: logging when debugging is set. + openapi_one_of.each do |klass| + begin + # "nullable: true" + next if klass == :AnyType + typed_data = find_and_cast_into_type(klass, data) + return typed_data if typed_data + # rescue all errors so we keep iterating even if the current item lookup raises + rescue + end + end + + openapi_one_of.include?(:AnyType) ? data : nil + end + + private + + SchemaMismatchError = Class.new(StandardError) + + def find_and_cast_into_type(klass, data) + return if data.nil? + + case klass.to_s + when "Boolean" + return data if data.instance_of?(TrueClass) || data.instance_of?(FalseClass) + when "Float" + return data if data.instance_of?(Float) + when "Integer" + return data if data.instance_of?(Integer) + when "Time" + return Time.parse(data) + when "Date" + return Date.parse(data) + when "String" + return data if data.instance_of?(String) + # "type: object" + when "Object" + return data if data.instance_of?(Hash) + # "type: array" + when /\AArray<(?.+)>\z/ + if data.instance_of?(Array) + sub_type = Regexp.last_match[:sub_type] + return data.map { |item| find_and_cast_into_type(sub_type, item) } + end + # "type: object" with "additionalProperties: { ... }" + when /\AHash.+)>\z/ + if data.instance_of?(Hash) && data.keys.all? { |k| k.instance_of?(Symbol) || k.instance_of?(String) } + sub_type = Regexp.last_match[:sub_type] + return data.each_with_object({}) { |(k, v), hsh| hsh[k] = find_and_cast_into_type(sub_type, v) } + end + # model + else + const = Algolia::Composition.const_get(klass) + if const + if const.respond_to?(:openapi_one_of) + # nested oneOf model + model = const.build(data) + elsif const.respond_to?(:discriminator_attributes) + if const.discriminator_attributes.all? { |attr| data.key?(attr) } + model = const.build_from_hash(data) + end + else + # maybe it's an enum, or doens't have discriminators + model = const.build_from_hash(data) + end + + return model if model + end + end + + # if no match by now, raise + raise + rescue + raise SchemaMismatchError, "#{data} doesn't match the #{klass} type" + end + end + end + + end +end diff --git a/lib/algolia/models/composition/around_radius.rb b/lib/algolia/models/composition/around_radius.rb new file mode 100644 index 00000000..7c776de5 --- /dev/null +++ b/lib/algolia/models/composition/around_radius.rb @@ -0,0 +1,110 @@ +# frozen_string_literal: true + +# Code generated by OpenAPI Generator (https://openapi-generator.tech), manual changes will be lost - read more on https://github.com/algolia/api-clients-automation. DO NOT EDIT. + +require "date" +require "time" + +module Algolia + module Composition + # Maximum radius for a search around a central location. This parameter works in combination with the `aroundLatLng` and `aroundLatLngViaIP` parameters. By default, the search radius is determined automatically from the density of hits around the central location. The search radius is small if there are many hits close to the central coordinates. + module AroundRadius + class << self + # List of class defined in oneOf (OpenAPI v3) + def openapi_one_of + [ + :"AroundRadiusAll", + :"Integer" + ] + end + + # Builds the object + # @param [Mixed] Data to be matched against the list of oneOf items + # @return [Object] Returns the model or the data itself + def build(data) + # Go through the list of oneOf items and attempt to identify the appropriate one. + # Note: + # - We do not attempt to check whether exactly one item matches. + # - No advanced validation of types in some cases (e.g. "x: { type: string }" will happily match { x: 123 }) + # due to the way the deserialization is made in the base_object template (it just casts without verifying). + # - TODO: scalar values are de facto behaving as if they were nullable. + # - TODO: logging when debugging is set. + openapi_one_of.each do |klass| + begin + # "nullable: true" + next if klass == :AnyType + typed_data = find_and_cast_into_type(klass, data) + return typed_data if typed_data + # rescue all errors so we keep iterating even if the current item lookup raises + rescue + end + end + + openapi_one_of.include?(:AnyType) ? data : nil + end + + private + + SchemaMismatchError = Class.new(StandardError) + + def find_and_cast_into_type(klass, data) + return if data.nil? + + case klass.to_s + when "Boolean" + return data if data.instance_of?(TrueClass) || data.instance_of?(FalseClass) + when "Float" + return data if data.instance_of?(Float) + when "Integer" + return data if data.instance_of?(Integer) + when "Time" + return Time.parse(data) + when "Date" + return Date.parse(data) + when "String" + return data if data.instance_of?(String) + # "type: object" + when "Object" + return data if data.instance_of?(Hash) + # "type: array" + when /\AArray<(?.+)>\z/ + if data.instance_of?(Array) + sub_type = Regexp.last_match[:sub_type] + return data.map { |item| find_and_cast_into_type(sub_type, item) } + end + # "type: object" with "additionalProperties: { ... }" + when /\AHash.+)>\z/ + if data.instance_of?(Hash) && data.keys.all? { |k| k.instance_of?(Symbol) || k.instance_of?(String) } + sub_type = Regexp.last_match[:sub_type] + return data.each_with_object({}) { |(k, v), hsh| hsh[k] = find_and_cast_into_type(sub_type, v) } + end + # model + else + const = Algolia::Composition.const_get(klass) + if const + if const.respond_to?(:openapi_one_of) + # nested oneOf model + model = const.build(data) + elsif const.respond_to?(:discriminator_attributes) + if const.discriminator_attributes.all? { |attr| data.key?(attr) } + model = const.build_from_hash(data) + end + else + # maybe it's an enum, or doens't have discriminators + model = const.build_from_hash(data) + end + + return model if model + end + end + + # if no match by now, raise + raise + rescue + raise SchemaMismatchError, "#{data} doesn't match the #{klass} type" + end + end + end + + end +end diff --git a/lib/algolia/models/composition/around_radius_all.rb b/lib/algolia/models/composition/around_radius_all.rb new file mode 100644 index 00000000..013aaf65 --- /dev/null +++ b/lib/algolia/models/composition/around_radius_all.rb @@ -0,0 +1,33 @@ +# frozen_string_literal: true + +# Code generated by OpenAPI Generator (https://openapi-generator.tech), manual changes will be lost - read more on https://github.com/algolia/api-clients-automation. DO NOT EDIT. + +require "date" +require "time" + +module Algolia + module Composition + class AroundRadiusAll + ALL = "all".freeze + + def self.all_vars + @all_vars ||= [ALL].freeze + end + + # Builds the enum from string + # @param [String] The enum value in the form of the string + # @return [String] The enum value + def self.build_from_hash(value) + new.build_from_hash(value) + end + + # Builds the enum from string + # @param [String] The enum value in the form of the string + # @return [String] The enum value + def build_from_hash(value) + return value if AroundRadiusAll.all_vars.include?(value) + raise "Invalid ENUM value #{value} for class #AroundRadiusAll" + end + end + end +end diff --git a/lib/algolia/models/composition/banner.rb b/lib/algolia/models/composition/banner.rb new file mode 100644 index 00000000..413db4f2 --- /dev/null +++ b/lib/algolia/models/composition/banner.rb @@ -0,0 +1,215 @@ +# frozen_string_literal: true + +# Code generated by OpenAPI Generator (https://openapi-generator.tech), manual changes will be lost - read more on https://github.com/algolia/api-clients-automation. DO NOT EDIT. + +require "date" +require "time" + +module Algolia + module Composition + # Banner with image and link to redirect users. + class Banner + attr_accessor :image + + attr_accessor :link + + # Attribute mapping from ruby-style variable name to JSON key. + def self.attribute_map + { + :image => :image, + :link => :link + } + end + + # Attribute type mapping. + def self.types_mapping + { + :image => :"BannerImage", + :link => :"BannerLink" + } + end + + # List of attributes with nullable: true + def self.openapi_nullable + Set.new( + [] + ) + end + + # Initializes the object + # @param [Hash] attributes Model attributes in the form of hash + def initialize(attributes = {}) + if (!attributes.is_a?(Hash)) + raise ArgumentError, "The input argument (attributes) must be a hash in `Algolia::Banner` initialize method" + end + + # check to see if the attribute exists and convert string to symbol for hash key + attributes = attributes.each_with_object({}) { |(k, v), h| + if (!self.class.attribute_map.key?(k.to_sym)) + raise( + ArgumentError, + "`#{k}` is not a valid attribute in `Algolia::Banner`. Please check the name to make sure it's valid. List of attributes: " + + self.class.attribute_map.keys.inspect + ) + end + + h[k.to_sym] = v + } + + if attributes.key?(:image) + self.image = attributes[:image] + end + + if attributes.key?(:link) + self.link = attributes[:link] + end + end + + # Checks equality by comparing each attribute. + # @param [Object] Object to be compared + def ==(other) + return true if self.equal?(other) + self.class == other.class && + image == other.image && + link == other.link + end + + # @see the `==` method + # @param [Object] Object to be compared + def eql?(other) + self == other + end + + # Calculates hash code according to all attributes. + # @return [Integer] Hash code + def hash + [image, link].hash + end + + # Builds the object from hash + # @param [Hash] attributes Model attributes in the form of hash + # @return [Object] Returns the model itself + def self.build_from_hash(attributes) + return nil unless attributes.is_a?(Hash) + attributes = attributes.transform_keys(&:to_sym) + transformed_hash = {} + types_mapping.each_pair do |key, type| + if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + transformed_hash[key.to_sym] = nil + elsif type =~ /\AArray<(.*)>/i + # check to ensure the input is an array given that the attribute + # is documented as an array but the input is not + if attributes[attribute_map[key]].is_a?(Array) + transformed_hash[key.to_sym] = attributes[attribute_map[key]].map { |v| + _deserialize(::Regexp.last_match(1), v) + } + end + elsif !attributes[attribute_map[key]].nil? + transformed_hash[key.to_sym] = _deserialize(type, attributes[attribute_map[key]]) + end + end + + new(transformed_hash) + end + + # Deserializes the data based on type + # @param string type Data type + # @param string value Value to be deserialized + # @return [Object] Deserialized data + def self._deserialize(type, value) + case type.to_sym + when :Time + Time.parse(value) + when :Date + Date.parse(value) + when :String + value.to_s + when :Integer + value.to_i + when :Float + value.to_f + when :Boolean + if value.to_s =~ /\A(true|t|yes|y|1)\z/i + true + else + false + end + + when :Object + # generic object (usually a Hash), return directly + value + when /\AArray<(?.+)>\z/ + inner_type = Regexp.last_match[:inner_type] + value.map { |v| _deserialize(inner_type, v) } + when /\AHash<(?.+?), (?.+)>\z/ + k_type = Regexp.last_match[:k_type] + v_type = Regexp.last_match[:v_type] + {}.tap do |hash| + value.each do |k, v| + hash[_deserialize(k_type, k)] = _deserialize(v_type, v) + end + end + # model + else + # models (e.g. Pet) or oneOf + klass = Algolia::Composition.const_get(type) + klass.respond_to?(:openapi_any_of) || klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass + .build_from_hash(value) + end + end + + # Returns the string representation of the object + # @return [String] String presentation of the object + def to_s + to_hash.to_s + end + + # to_body is an alias to to_hash (backward compatibility) + # @return [Hash] Returns the object in the form of hash + def to_body + to_hash + end + + def to_json(*_args) + to_hash.to_json + end + + # Returns the object in the form of hash + # @return [Hash] Returns the object in the form of hash + def to_hash + hash = {} + self.class.attribute_map.each_pair do |attr, param| + value = send(attr) + if value.nil? + is_nullable = self.class.openapi_nullable.include?(attr) + next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) + end + + hash[param] = _to_hash(value) + end + + hash + end + + # Outputs non-array value in the form of hash + # For object, use to_hash. Otherwise, just return the value + # @param [Object] value Any valid value + # @return [Hash] Returns the value in the form of hash + def _to_hash(value) + if value.is_a?(Array) + value.compact.map { |v| _to_hash(v) } + elsif value.is_a?(Hash) + {}.tap do |hash| + value.each { |k, v| hash[k] = _to_hash(v) } + end + elsif value.respond_to?(:to_hash) + value.to_hash + else + value + end + end + + end + + end +end diff --git a/lib/algolia/models/composition/banner_image.rb b/lib/algolia/models/composition/banner_image.rb new file mode 100644 index 00000000..aff25371 --- /dev/null +++ b/lib/algolia/models/composition/banner_image.rb @@ -0,0 +1,220 @@ +# frozen_string_literal: true + +# Code generated by OpenAPI Generator (https://openapi-generator.tech), manual changes will be lost - read more on https://github.com/algolia/api-clients-automation. DO NOT EDIT. + +require "date" +require "time" + +module Algolia + module Composition + # Image to show inside a banner. + class BannerImage + attr_accessor :urls + + attr_accessor :title + + # Attribute mapping from ruby-style variable name to JSON key. + def self.attribute_map + { + :urls => :urls, + :title => :title + } + end + + # Attribute type mapping. + def self.types_mapping + { + :urls => :"Array", + :title => :"String" + } + end + + # List of attributes with nullable: true + def self.openapi_nullable + Set.new( + [] + ) + end + + # Initializes the object + # @param [Hash] attributes Model attributes in the form of hash + def initialize(attributes = {}) + if (!attributes.is_a?(Hash)) + raise( + ArgumentError, + "The input argument (attributes) must be a hash in `Algolia::BannerImage` initialize method" + ) + end + + # check to see if the attribute exists and convert string to symbol for hash key + attributes = attributes.each_with_object({}) { |(k, v), h| + if (!self.class.attribute_map.key?(k.to_sym)) + raise( + ArgumentError, + "`#{k}` is not a valid attribute in `Algolia::BannerImage`. Please check the name to make sure it's valid. List of attributes: " + + self.class.attribute_map.keys.inspect + ) + end + + h[k.to_sym] = v + } + + if attributes.key?(:urls) + if (value = attributes[:urls]).is_a?(Array) + self.urls = value + end + end + + if attributes.key?(:title) + self.title = attributes[:title] + end + end + + # Checks equality by comparing each attribute. + # @param [Object] Object to be compared + def ==(other) + return true if self.equal?(other) + self.class == other.class && + urls == other.urls && + title == other.title + end + + # @see the `==` method + # @param [Object] Object to be compared + def eql?(other) + self == other + end + + # Calculates hash code according to all attributes. + # @return [Integer] Hash code + def hash + [urls, title].hash + end + + # Builds the object from hash + # @param [Hash] attributes Model attributes in the form of hash + # @return [Object] Returns the model itself + def self.build_from_hash(attributes) + return nil unless attributes.is_a?(Hash) + attributes = attributes.transform_keys(&:to_sym) + transformed_hash = {} + types_mapping.each_pair do |key, type| + if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + transformed_hash[key.to_sym] = nil + elsif type =~ /\AArray<(.*)>/i + # check to ensure the input is an array given that the attribute + # is documented as an array but the input is not + if attributes[attribute_map[key]].is_a?(Array) + transformed_hash[key.to_sym] = attributes[attribute_map[key]].map { |v| + _deserialize(::Regexp.last_match(1), v) + } + end + elsif !attributes[attribute_map[key]].nil? + transformed_hash[key.to_sym] = _deserialize(type, attributes[attribute_map[key]]) + end + end + + new(transformed_hash) + end + + # Deserializes the data based on type + # @param string type Data type + # @param string value Value to be deserialized + # @return [Object] Deserialized data + def self._deserialize(type, value) + case type.to_sym + when :Time + Time.parse(value) + when :Date + Date.parse(value) + when :String + value.to_s + when :Integer + value.to_i + when :Float + value.to_f + when :Boolean + if value.to_s =~ /\A(true|t|yes|y|1)\z/i + true + else + false + end + + when :Object + # generic object (usually a Hash), return directly + value + when /\AArray<(?.+)>\z/ + inner_type = Regexp.last_match[:inner_type] + value.map { |v| _deserialize(inner_type, v) } + when /\AHash<(?.+?), (?.+)>\z/ + k_type = Regexp.last_match[:k_type] + v_type = Regexp.last_match[:v_type] + {}.tap do |hash| + value.each do |k, v| + hash[_deserialize(k_type, k)] = _deserialize(v_type, v) + end + end + # model + else + # models (e.g. Pet) or oneOf + klass = Algolia::Composition.const_get(type) + klass.respond_to?(:openapi_any_of) || klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass + .build_from_hash(value) + end + end + + # Returns the string representation of the object + # @return [String] String presentation of the object + def to_s + to_hash.to_s + end + + # to_body is an alias to to_hash (backward compatibility) + # @return [Hash] Returns the object in the form of hash + def to_body + to_hash + end + + def to_json(*_args) + to_hash.to_json + end + + # Returns the object in the form of hash + # @return [Hash] Returns the object in the form of hash + def to_hash + hash = {} + self.class.attribute_map.each_pair do |attr, param| + value = send(attr) + if value.nil? + is_nullable = self.class.openapi_nullable.include?(attr) + next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) + end + + hash[param] = _to_hash(value) + end + + hash + end + + # Outputs non-array value in the form of hash + # For object, use to_hash. Otherwise, just return the value + # @param [Object] value Any valid value + # @return [Hash] Returns the value in the form of hash + def _to_hash(value) + if value.is_a?(Array) + value.compact.map { |v| _to_hash(v) } + elsif value.is_a?(Hash) + {}.tap do |hash| + value.each { |k, v| hash[k] = _to_hash(v) } + end + elsif value.respond_to?(:to_hash) + value.to_hash + else + value + end + end + + end + + end +end diff --git a/lib/algolia/models/composition/banner_image_url.rb b/lib/algolia/models/composition/banner_image_url.rb new file mode 100644 index 00000000..0f3fefdb --- /dev/null +++ b/lib/algolia/models/composition/banner_image_url.rb @@ -0,0 +1,209 @@ +# frozen_string_literal: true + +# Code generated by OpenAPI Generator (https://openapi-generator.tech), manual changes will be lost - read more on https://github.com/algolia/api-clients-automation. DO NOT EDIT. + +require "date" +require "time" + +module Algolia + module Composition + # URL for an image to show inside a banner. + class BannerImageUrl + attr_accessor :url + + # Attribute mapping from ruby-style variable name to JSON key. + def self.attribute_map + { + :url => :url + } + end + + # Attribute type mapping. + def self.types_mapping + { + :url => :"String" + } + end + + # List of attributes with nullable: true + def self.openapi_nullable + Set.new( + [] + ) + end + + # Initializes the object + # @param [Hash] attributes Model attributes in the form of hash + def initialize(attributes = {}) + if (!attributes.is_a?(Hash)) + raise( + ArgumentError, + "The input argument (attributes) must be a hash in `Algolia::BannerImageUrl` initialize method" + ) + end + + # check to see if the attribute exists and convert string to symbol for hash key + attributes = attributes.each_with_object({}) { |(k, v), h| + if (!self.class.attribute_map.key?(k.to_sym)) + raise( + ArgumentError, + "`#{k}` is not a valid attribute in `Algolia::BannerImageUrl`. Please check the name to make sure it's valid. List of attributes: " + + self.class.attribute_map.keys.inspect + ) + end + + h[k.to_sym] = v + } + + if attributes.key?(:url) + self.url = attributes[:url] + end + end + + # Checks equality by comparing each attribute. + # @param [Object] Object to be compared + def ==(other) + return true if self.equal?(other) + self.class == other.class && + url == other.url + end + + # @see the `==` method + # @param [Object] Object to be compared + def eql?(other) + self == other + end + + # Calculates hash code according to all attributes. + # @return [Integer] Hash code + def hash + [url].hash + end + + # Builds the object from hash + # @param [Hash] attributes Model attributes in the form of hash + # @return [Object] Returns the model itself + def self.build_from_hash(attributes) + return nil unless attributes.is_a?(Hash) + attributes = attributes.transform_keys(&:to_sym) + transformed_hash = {} + types_mapping.each_pair do |key, type| + if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + transformed_hash[key.to_sym] = nil + elsif type =~ /\AArray<(.*)>/i + # check to ensure the input is an array given that the attribute + # is documented as an array but the input is not + if attributes[attribute_map[key]].is_a?(Array) + transformed_hash[key.to_sym] = attributes[attribute_map[key]].map { |v| + _deserialize(::Regexp.last_match(1), v) + } + end + elsif !attributes[attribute_map[key]].nil? + transformed_hash[key.to_sym] = _deserialize(type, attributes[attribute_map[key]]) + end + end + + new(transformed_hash) + end + + # Deserializes the data based on type + # @param string type Data type + # @param string value Value to be deserialized + # @return [Object] Deserialized data + def self._deserialize(type, value) + case type.to_sym + when :Time + Time.parse(value) + when :Date + Date.parse(value) + when :String + value.to_s + when :Integer + value.to_i + when :Float + value.to_f + when :Boolean + if value.to_s =~ /\A(true|t|yes|y|1)\z/i + true + else + false + end + + when :Object + # generic object (usually a Hash), return directly + value + when /\AArray<(?.+)>\z/ + inner_type = Regexp.last_match[:inner_type] + value.map { |v| _deserialize(inner_type, v) } + when /\AHash<(?.+?), (?.+)>\z/ + k_type = Regexp.last_match[:k_type] + v_type = Regexp.last_match[:v_type] + {}.tap do |hash| + value.each do |k, v| + hash[_deserialize(k_type, k)] = _deserialize(v_type, v) + end + end + # model + else + # models (e.g. Pet) or oneOf + klass = Algolia::Composition.const_get(type) + klass.respond_to?(:openapi_any_of) || klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass + .build_from_hash(value) + end + end + + # Returns the string representation of the object + # @return [String] String presentation of the object + def to_s + to_hash.to_s + end + + # to_body is an alias to to_hash (backward compatibility) + # @return [Hash] Returns the object in the form of hash + def to_body + to_hash + end + + def to_json(*_args) + to_hash.to_json + end + + # Returns the object in the form of hash + # @return [Hash] Returns the object in the form of hash + def to_hash + hash = {} + self.class.attribute_map.each_pair do |attr, param| + value = send(attr) + if value.nil? + is_nullable = self.class.openapi_nullable.include?(attr) + next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) + end + + hash[param] = _to_hash(value) + end + + hash + end + + # Outputs non-array value in the form of hash + # For object, use to_hash. Otherwise, just return the value + # @param [Object] value Any valid value + # @return [Hash] Returns the value in the form of hash + def _to_hash(value) + if value.is_a?(Array) + value.compact.map { |v| _to_hash(v) } + elsif value.is_a?(Hash) + {}.tap do |hash| + value.each { |k, v| hash[k] = _to_hash(v) } + end + elsif value.respond_to?(:to_hash) + value.to_hash + else + value + end + end + + end + + end +end diff --git a/lib/algolia/models/composition/banner_link.rb b/lib/algolia/models/composition/banner_link.rb new file mode 100644 index 00000000..03489aff --- /dev/null +++ b/lib/algolia/models/composition/banner_link.rb @@ -0,0 +1,209 @@ +# frozen_string_literal: true + +# Code generated by OpenAPI Generator (https://openapi-generator.tech), manual changes will be lost - read more on https://github.com/algolia/api-clients-automation. DO NOT EDIT. + +require "date" +require "time" + +module Algolia + module Composition + # Link for a banner defined in the Merchandising Studio. + class BannerLink + attr_accessor :url + + # Attribute mapping from ruby-style variable name to JSON key. + def self.attribute_map + { + :url => :url + } + end + + # Attribute type mapping. + def self.types_mapping + { + :url => :"String" + } + end + + # List of attributes with nullable: true + def self.openapi_nullable + Set.new( + [] + ) + end + + # Initializes the object + # @param [Hash] attributes Model attributes in the form of hash + def initialize(attributes = {}) + if (!attributes.is_a?(Hash)) + raise( + ArgumentError, + "The input argument (attributes) must be a hash in `Algolia::BannerLink` initialize method" + ) + end + + # check to see if the attribute exists and convert string to symbol for hash key + attributes = attributes.each_with_object({}) { |(k, v), h| + if (!self.class.attribute_map.key?(k.to_sym)) + raise( + ArgumentError, + "`#{k}` is not a valid attribute in `Algolia::BannerLink`. Please check the name to make sure it's valid. List of attributes: " + + self.class.attribute_map.keys.inspect + ) + end + + h[k.to_sym] = v + } + + if attributes.key?(:url) + self.url = attributes[:url] + end + end + + # Checks equality by comparing each attribute. + # @param [Object] Object to be compared + def ==(other) + return true if self.equal?(other) + self.class == other.class && + url == other.url + end + + # @see the `==` method + # @param [Object] Object to be compared + def eql?(other) + self == other + end + + # Calculates hash code according to all attributes. + # @return [Integer] Hash code + def hash + [url].hash + end + + # Builds the object from hash + # @param [Hash] attributes Model attributes in the form of hash + # @return [Object] Returns the model itself + def self.build_from_hash(attributes) + return nil unless attributes.is_a?(Hash) + attributes = attributes.transform_keys(&:to_sym) + transformed_hash = {} + types_mapping.each_pair do |key, type| + if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + transformed_hash[key.to_sym] = nil + elsif type =~ /\AArray<(.*)>/i + # check to ensure the input is an array given that the attribute + # is documented as an array but the input is not + if attributes[attribute_map[key]].is_a?(Array) + transformed_hash[key.to_sym] = attributes[attribute_map[key]].map { |v| + _deserialize(::Regexp.last_match(1), v) + } + end + elsif !attributes[attribute_map[key]].nil? + transformed_hash[key.to_sym] = _deserialize(type, attributes[attribute_map[key]]) + end + end + + new(transformed_hash) + end + + # Deserializes the data based on type + # @param string type Data type + # @param string value Value to be deserialized + # @return [Object] Deserialized data + def self._deserialize(type, value) + case type.to_sym + when :Time + Time.parse(value) + when :Date + Date.parse(value) + when :String + value.to_s + when :Integer + value.to_i + when :Float + value.to_f + when :Boolean + if value.to_s =~ /\A(true|t|yes|y|1)\z/i + true + else + false + end + + when :Object + # generic object (usually a Hash), return directly + value + when /\AArray<(?.+)>\z/ + inner_type = Regexp.last_match[:inner_type] + value.map { |v| _deserialize(inner_type, v) } + when /\AHash<(?.+?), (?.+)>\z/ + k_type = Regexp.last_match[:k_type] + v_type = Regexp.last_match[:v_type] + {}.tap do |hash| + value.each do |k, v| + hash[_deserialize(k_type, k)] = _deserialize(v_type, v) + end + end + # model + else + # models (e.g. Pet) or oneOf + klass = Algolia::Composition.const_get(type) + klass.respond_to?(:openapi_any_of) || klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass + .build_from_hash(value) + end + end + + # Returns the string representation of the object + # @return [String] String presentation of the object + def to_s + to_hash.to_s + end + + # to_body is an alias to to_hash (backward compatibility) + # @return [Hash] Returns the object in the form of hash + def to_body + to_hash + end + + def to_json(*_args) + to_hash.to_json + end + + # Returns the object in the form of hash + # @return [Hash] Returns the object in the form of hash + def to_hash + hash = {} + self.class.attribute_map.each_pair do |attr, param| + value = send(attr) + if value.nil? + is_nullable = self.class.openapi_nullable.include?(attr) + next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) + end + + hash[param] = _to_hash(value) + end + + hash + end + + # Outputs non-array value in the form of hash + # For object, use to_hash. Otherwise, just return the value + # @param [Object] value Any valid value + # @return [Hash] Returns the value in the form of hash + def _to_hash(value) + if value.is_a?(Array) + value.compact.map { |v| _to_hash(v) } + elsif value.is_a?(Hash) + {}.tap do |hash| + value.each { |k, v| hash[k] = _to_hash(v) } + end + elsif value.respond_to?(:to_hash) + value.to_hash + else + value + end + end + + end + + end +end diff --git a/lib/algolia/models/composition/composition_id_ranking_info.rb b/lib/algolia/models/composition/composition_id_ranking_info.rb new file mode 100644 index 00000000..97c90318 --- /dev/null +++ b/lib/algolia/models/composition/composition_id_ranking_info.rb @@ -0,0 +1,221 @@ +# frozen_string_literal: true + +# Code generated by OpenAPI Generator (https://openapi-generator.tech), manual changes will be lost - read more on https://github.com/algolia/api-clients-automation. DO NOT EDIT. + +require "date" +require "time" + +module Algolia + module Composition + class CompositionIdRankingInfo + attr_accessor :index + + attr_accessor :injected_item_key + + # Attribute mapping from ruby-style variable name to JSON key. + def self.attribute_map + { + :index => :index, + :injected_item_key => :injectedItemKey + } + end + + # Attribute type mapping. + def self.types_mapping + { + :index => :"String", + :injected_item_key => :"String" + } + end + + # List of attributes with nullable: true + def self.openapi_nullable + Set.new( + [] + ) + end + + # Initializes the object + # @param [Hash] attributes Model attributes in the form of hash + def initialize(attributes = {}) + if (!attributes.is_a?(Hash)) + raise( + ArgumentError, + "The input argument (attributes) must be a hash in `Algolia::CompositionIdRankingInfo` initialize method" + ) + end + + # check to see if the attribute exists and convert string to symbol for hash key + attributes = attributes.each_with_object({}) { |(k, v), h| + if (!self.class.attribute_map.key?(k.to_sym)) + raise( + ArgumentError, + "`#{k}` is not a valid attribute in `Algolia::CompositionIdRankingInfo`. Please check the name to make sure it's valid. List of attributes: " + + self.class.attribute_map.keys.inspect + ) + end + + h[k.to_sym] = v + } + + if attributes.key?(:index) + self.index = attributes[:index] + else + self.index = nil + end + + if attributes.key?(:injected_item_key) + self.injected_item_key = attributes[:injected_item_key] + else + self.injected_item_key = nil + end + end + + # Checks equality by comparing each attribute. + # @param [Object] Object to be compared + def ==(other) + return true if self.equal?(other) + self.class == other.class && + index == other.index && + injected_item_key == other.injected_item_key + end + + # @see the `==` method + # @param [Object] Object to be compared + def eql?(other) + self == other + end + + # Calculates hash code according to all attributes. + # @return [Integer] Hash code + def hash + [index, injected_item_key].hash + end + + # Builds the object from hash + # @param [Hash] attributes Model attributes in the form of hash + # @return [Object] Returns the model itself + def self.build_from_hash(attributes) + return nil unless attributes.is_a?(Hash) + attributes = attributes.transform_keys(&:to_sym) + transformed_hash = {} + types_mapping.each_pair do |key, type| + if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + transformed_hash[key.to_sym] = nil + elsif type =~ /\AArray<(.*)>/i + # check to ensure the input is an array given that the attribute + # is documented as an array but the input is not + if attributes[attribute_map[key]].is_a?(Array) + transformed_hash[key.to_sym] = attributes[attribute_map[key]].map { |v| + _deserialize(::Regexp.last_match(1), v) + } + end + elsif !attributes[attribute_map[key]].nil? + transformed_hash[key.to_sym] = _deserialize(type, attributes[attribute_map[key]]) + end + end + + new(transformed_hash) + end + + # Deserializes the data based on type + # @param string type Data type + # @param string value Value to be deserialized + # @return [Object] Deserialized data + def self._deserialize(type, value) + case type.to_sym + when :Time + Time.parse(value) + when :Date + Date.parse(value) + when :String + value.to_s + when :Integer + value.to_i + when :Float + value.to_f + when :Boolean + if value.to_s =~ /\A(true|t|yes|y|1)\z/i + true + else + false + end + + when :Object + # generic object (usually a Hash), return directly + value + when /\AArray<(?.+)>\z/ + inner_type = Regexp.last_match[:inner_type] + value.map { |v| _deserialize(inner_type, v) } + when /\AHash<(?.+?), (?.+)>\z/ + k_type = Regexp.last_match[:k_type] + v_type = Regexp.last_match[:v_type] + {}.tap do |hash| + value.each do |k, v| + hash[_deserialize(k_type, k)] = _deserialize(v_type, v) + end + end + # model + else + # models (e.g. Pet) or oneOf + klass = Algolia::Composition.const_get(type) + klass.respond_to?(:openapi_any_of) || klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass + .build_from_hash(value) + end + end + + # Returns the string representation of the object + # @return [String] String presentation of the object + def to_s + to_hash.to_s + end + + # to_body is an alias to to_hash (backward compatibility) + # @return [Hash] Returns the object in the form of hash + def to_body + to_hash + end + + def to_json(*_args) + to_hash.to_json + end + + # Returns the object in the form of hash + # @return [Hash] Returns the object in the form of hash + def to_hash + hash = {} + self.class.attribute_map.each_pair do |attr, param| + value = send(attr) + if value.nil? + is_nullable = self.class.openapi_nullable.include?(attr) + next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) + end + + hash[param] = _to_hash(value) + end + + hash + end + + # Outputs non-array value in the form of hash + # For object, use to_hash. Otherwise, just return the value + # @param [Object] value Any valid value + # @return [Hash] Returns the value in the form of hash + def _to_hash(value) + if value.is_a?(Array) + value.compact.map { |v| _to_hash(v) } + elsif value.is_a?(Hash) + {}.tap do |hash| + value.each { |k, v| hash[k] = _to_hash(v) } + end + elsif value.respond_to?(:to_hash) + value.to_hash + else + value + end + end + + end + + end +end diff --git a/lib/algolia/models/composition/composition_run_applied_rules.rb b/lib/algolia/models/composition/composition_run_applied_rules.rb new file mode 100644 index 00000000..c67d6bd0 --- /dev/null +++ b/lib/algolia/models/composition/composition_run_applied_rules.rb @@ -0,0 +1,211 @@ +# frozen_string_literal: true + +# Code generated by OpenAPI Generator (https://openapi-generator.tech), manual changes will be lost - read more on https://github.com/algolia/api-clients-automation. DO NOT EDIT. + +require "date" +require "time" + +module Algolia + module Composition + class CompositionRunAppliedRules + # Unique record identifier. + attr_accessor :algolia_object_id + + # Attribute mapping from ruby-style variable name to JSON key. + def self.attribute_map + { + :algolia_object_id => :objectID + } + end + + # Attribute type mapping. + def self.types_mapping + { + :algolia_object_id => :"String" + } + end + + # List of attributes with nullable: true + def self.openapi_nullable + Set.new( + [] + ) + end + + # Initializes the object + # @param [Hash] attributes Model attributes in the form of hash + def initialize(attributes = {}) + if (!attributes.is_a?(Hash)) + raise( + ArgumentError, + "The input argument (attributes) must be a hash in `Algolia::CompositionRunAppliedRules` initialize method" + ) + end + + # check to see if the attribute exists and convert string to symbol for hash key + attributes = attributes.each_with_object({}) { |(k, v), h| + if (!self.class.attribute_map.key?(k.to_sym)) + raise( + ArgumentError, + "`#{k}` is not a valid attribute in `Algolia::CompositionRunAppliedRules`. Please check the name to make sure it's valid. List of attributes: " + + self.class.attribute_map.keys.inspect + ) + end + + h[k.to_sym] = v + } + + if attributes.key?(:algolia_object_id) + self.algolia_object_id = attributes[:algolia_object_id] + else + self.algolia_object_id = nil + end + end + + # Checks equality by comparing each attribute. + # @param [Object] Object to be compared + def ==(other) + return true if self.equal?(other) + self.class == other.class && + algolia_object_id == other.algolia_object_id + end + + # @see the `==` method + # @param [Object] Object to be compared + def eql?(other) + self == other + end + + # Calculates hash code according to all attributes. + # @return [Integer] Hash code + def hash + [algolia_object_id].hash + end + + # Builds the object from hash + # @param [Hash] attributes Model attributes in the form of hash + # @return [Object] Returns the model itself + def self.build_from_hash(attributes) + return nil unless attributes.is_a?(Hash) + attributes = attributes.transform_keys(&:to_sym) + transformed_hash = {} + types_mapping.each_pair do |key, type| + if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + transformed_hash[key.to_sym] = nil + elsif type =~ /\AArray<(.*)>/i + # check to ensure the input is an array given that the attribute + # is documented as an array but the input is not + if attributes[attribute_map[key]].is_a?(Array) + transformed_hash[key.to_sym] = attributes[attribute_map[key]].map { |v| + _deserialize(::Regexp.last_match(1), v) + } + end + elsif !attributes[attribute_map[key]].nil? + transformed_hash[key.to_sym] = _deserialize(type, attributes[attribute_map[key]]) + end + end + + new(transformed_hash) + end + + # Deserializes the data based on type + # @param string type Data type + # @param string value Value to be deserialized + # @return [Object] Deserialized data + def self._deserialize(type, value) + case type.to_sym + when :Time + Time.parse(value) + when :Date + Date.parse(value) + when :String + value.to_s + when :Integer + value.to_i + when :Float + value.to_f + when :Boolean + if value.to_s =~ /\A(true|t|yes|y|1)\z/i + true + else + false + end + + when :Object + # generic object (usually a Hash), return directly + value + when /\AArray<(?.+)>\z/ + inner_type = Regexp.last_match[:inner_type] + value.map { |v| _deserialize(inner_type, v) } + when /\AHash<(?.+?), (?.+)>\z/ + k_type = Regexp.last_match[:k_type] + v_type = Regexp.last_match[:v_type] + {}.tap do |hash| + value.each do |k, v| + hash[_deserialize(k_type, k)] = _deserialize(v_type, v) + end + end + # model + else + # models (e.g. Pet) or oneOf + klass = Algolia::Composition.const_get(type) + klass.respond_to?(:openapi_any_of) || klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass + .build_from_hash(value) + end + end + + # Returns the string representation of the object + # @return [String] String presentation of the object + def to_s + to_hash.to_s + end + + # to_body is an alias to to_hash (backward compatibility) + # @return [Hash] Returns the object in the form of hash + def to_body + to_hash + end + + def to_json(*_args) + to_hash.to_json + end + + # Returns the object in the form of hash + # @return [Hash] Returns the object in the form of hash + def to_hash + hash = {} + self.class.attribute_map.each_pair do |attr, param| + value = send(attr) + if value.nil? + is_nullable = self.class.openapi_nullable.include?(attr) + next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) + end + + hash[param] = _to_hash(value) + end + + hash + end + + # Outputs non-array value in the form of hash + # For object, use to_hash. Otherwise, just return the value + # @param [Object] value Any valid value + # @return [Hash] Returns the value in the form of hash + def _to_hash(value) + if value.is_a?(Array) + value.compact.map { |v| _to_hash(v) } + elsif value.is_a?(Hash) + {}.tap do |hash| + value.each { |k, v| hash[k] = _to_hash(v) } + end + elsif value.respond_to?(:to_hash) + value.to_hash + else + value + end + end + + end + + end +end diff --git a/lib/algolia/models/composition/composition_run_search_response.rb b/lib/algolia/models/composition/composition_run_search_response.rb new file mode 100644 index 00000000..4eb04562 --- /dev/null +++ b/lib/algolia/models/composition/composition_run_search_response.rb @@ -0,0 +1,222 @@ +# frozen_string_literal: true + +# Code generated by OpenAPI Generator (https://openapi-generator.tech), manual changes will be lost - read more on https://github.com/algolia/api-clients-automation. DO NOT EDIT. + +require "date" +require "time" + +module Algolia + module Composition + class CompositionRunSearchResponse + # Unique record identifier. + attr_accessor :algolia_object_id + + attr_accessor :applied_rules + + attr_accessor :additional_properties + + # Attribute mapping from ruby-style variable name to JSON key. + def self.attribute_map + { + :algolia_object_id => :objectID, + :applied_rules => :appliedRules + } + end + + # Attribute type mapping. + def self.types_mapping + { + :algolia_object_id => :"String", + :applied_rules => :"Array" + } + end + + # List of attributes with nullable: true + def self.openapi_nullable + Set.new( + [] + ) + end + + # Initializes the object + # @param [Hash] attributes Model attributes in the form of hash + def initialize(attributes = {}) + if (!attributes.is_a?(Hash)) + raise( + ArgumentError, + "The input argument (attributes) must be a hash in `Algolia::CompositionRunSearchResponse` initialize method" + ) + end + + if attributes.key?(:algolia_object_id) + self.algolia_object_id = attributes[:algolia_object_id] + else + self.algolia_object_id = nil + end + + if attributes.key?(:applied_rules) + if (value = attributes[:applied_rules]).is_a?(Array) + self.applied_rules = value + end + end + + # add extra attribute to additional_properties + self.additional_properties ||= {} + self.additional_properties.merge!(attributes.reject { |k, _| self.class.attribute_map.key?(k.to_sym) }) + end + + # Checks equality by comparing each attribute. + # @param [Object] Object to be compared + def ==(other) + return true if self.equal?(other) + self.class == other.class && + algolia_object_id == other.algolia_object_id && + applied_rules == other.applied_rules + end + + # @see the `==` method + # @param [Object] Object to be compared + def eql?(other) + self == other + end + + # Calculates hash code according to all attributes. + # @return [Integer] Hash code + def hash + [algolia_object_id, applied_rules].hash + end + + # Builds the object from hash + # @param [Hash] attributes Model attributes in the form of hash + # @return [Object] Returns the model itself + def self.build_from_hash(attributes) + return nil unless attributes.is_a?(Hash) + attributes = attributes.transform_keys(&:to_sym) + transformed_hash = {} + types_mapping.each_pair do |key, type| + if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + transformed_hash[key.to_sym] = nil + elsif type =~ /\AArray<(.*)>/i + # check to ensure the input is an array given that the attribute + # is documented as an array but the input is not + if attributes[attribute_map[key]].is_a?(Array) + transformed_hash[key.to_sym] = attributes[attribute_map[key]].map { |v| + _deserialize(::Regexp.last_match(1), v) + } + end + elsif !attributes[attribute_map[key]].nil? + transformed_hash[key.to_sym] = _deserialize(type, attributes[attribute_map[key]]) + end + end + + # add extra attribute to transformed_hash + transformed_hash.merge!(attributes.reject { |k, _| attribute_map.key?(k.to_sym) }) + new(transformed_hash) + end + + # Deserializes the data based on type + # @param string type Data type + # @param string value Value to be deserialized + # @return [Object] Deserialized data + def self._deserialize(type, value) + case type.to_sym + when :Time + Time.parse(value) + when :Date + Date.parse(value) + when :String + value.to_s + when :Integer + value.to_i + when :Float + value.to_f + when :Boolean + if value.to_s =~ /\A(true|t|yes|y|1)\z/i + true + else + false + end + + when :Object + # generic object (usually a Hash), return directly + value + when /\AArray<(?.+)>\z/ + inner_type = Regexp.last_match[:inner_type] + value.map { |v| _deserialize(inner_type, v) } + when /\AHash<(?.+?), (?.+)>\z/ + k_type = Regexp.last_match[:k_type] + v_type = Regexp.last_match[:v_type] + {}.tap do |hash| + value.each do |k, v| + hash[_deserialize(k_type, k)] = _deserialize(v_type, v) + end + end + # model + else + # models (e.g. Pet) or oneOf + klass = Algolia::Composition.const_get(type) + klass.respond_to?(:openapi_any_of) || klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass + .build_from_hash(value) + end + end + + # Returns the string representation of the object + # @return [String] String presentation of the object + def to_s + to_hash.to_s + end + + # to_body is an alias to to_hash (backward compatibility) + # @return [Hash] Returns the object in the form of hash + def to_body + to_hash + end + + def to_json(*_args) + to_hash.to_json + end + + # Returns the object in the form of hash + # @return [Hash] Returns the object in the form of hash + def to_hash + hash = {} + self.class.attribute_map.each_pair do |attr, param| + value = send(attr) + if value.nil? + is_nullable = self.class.openapi_nullable.include?(attr) + next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) + end + + hash[param] = _to_hash(value) + end + + # also add attributes from additional_properties to hash + self.additional_properties&.each_pair do |k, v| + hash[k.to_sym] = _to_hash(v) + end + + hash + end + + # Outputs non-array value in the form of hash + # For object, use to_hash. Otherwise, just return the value + # @param [Object] value Any valid value + # @return [Hash] Returns the value in the form of hash + def _to_hash(value) + if value.is_a?(Array) + value.compact.map { |v| _to_hash(v) } + elsif value.is_a?(Hash) + {}.tap do |hash| + value.each { |k, v| hash[k] = _to_hash(v) } + end + elsif value.respond_to?(:to_hash) + value.to_hash + else + value + end + end + + end + + end +end diff --git a/lib/algolia/models/composition/compositions_search_response.rb b/lib/algolia/models/composition/compositions_search_response.rb new file mode 100644 index 00000000..7f775551 --- /dev/null +++ b/lib/algolia/models/composition/compositions_search_response.rb @@ -0,0 +1,212 @@ +# frozen_string_literal: true + +# Code generated by OpenAPI Generator (https://openapi-generator.tech), manual changes will be lost - read more on https://github.com/algolia/api-clients-automation. DO NOT EDIT. + +require "date" +require "time" + +module Algolia + module Composition + class CompositionsSearchResponse + attr_accessor :run + + attr_accessor :additional_properties + + # Attribute mapping from ruby-style variable name to JSON key. + def self.attribute_map + { + :run => :run + } + end + + # Attribute type mapping. + def self.types_mapping + { + :run => :"Array" + } + end + + # List of attributes with nullable: true + def self.openapi_nullable + Set.new( + [] + ) + end + + # Initializes the object + # @param [Hash] attributes Model attributes in the form of hash + def initialize(attributes = {}) + if (!attributes.is_a?(Hash)) + raise( + ArgumentError, + "The input argument (attributes) must be a hash in `Algolia::CompositionsSearchResponse` initialize method" + ) + end + + if attributes.key?(:run) + if (value = attributes[:run]).is_a?(Array) + self.run = value + end + else + self.run = nil + end + + # add extra attribute to additional_properties + self.additional_properties ||= {} + self.additional_properties.merge!(attributes.reject { |k, _| self.class.attribute_map.key?(k.to_sym) }) + end + + # Checks equality by comparing each attribute. + # @param [Object] Object to be compared + def ==(other) + return true if self.equal?(other) + self.class == other.class && + run == other.run + end + + # @see the `==` method + # @param [Object] Object to be compared + def eql?(other) + self == other + end + + # Calculates hash code according to all attributes. + # @return [Integer] Hash code + def hash + [run].hash + end + + # Builds the object from hash + # @param [Hash] attributes Model attributes in the form of hash + # @return [Object] Returns the model itself + def self.build_from_hash(attributes) + return nil unless attributes.is_a?(Hash) + attributes = attributes.transform_keys(&:to_sym) + transformed_hash = {} + types_mapping.each_pair do |key, type| + if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + transformed_hash[key.to_sym] = nil + elsif type =~ /\AArray<(.*)>/i + # check to ensure the input is an array given that the attribute + # is documented as an array but the input is not + if attributes[attribute_map[key]].is_a?(Array) + transformed_hash[key.to_sym] = attributes[attribute_map[key]].map { |v| + _deserialize(::Regexp.last_match(1), v) + } + end + elsif !attributes[attribute_map[key]].nil? + transformed_hash[key.to_sym] = _deserialize(type, attributes[attribute_map[key]]) + end + end + + # add extra attribute to transformed_hash + transformed_hash.merge!(attributes.reject { |k, _| attribute_map.key?(k.to_sym) }) + new(transformed_hash) + end + + # Deserializes the data based on type + # @param string type Data type + # @param string value Value to be deserialized + # @return [Object] Deserialized data + def self._deserialize(type, value) + case type.to_sym + when :Time + Time.parse(value) + when :Date + Date.parse(value) + when :String + value.to_s + when :Integer + value.to_i + when :Float + value.to_f + when :Boolean + if value.to_s =~ /\A(true|t|yes|y|1)\z/i + true + else + false + end + + when :Object + # generic object (usually a Hash), return directly + value + when /\AArray<(?.+)>\z/ + inner_type = Regexp.last_match[:inner_type] + value.map { |v| _deserialize(inner_type, v) } + when /\AHash<(?.+?), (?.+)>\z/ + k_type = Regexp.last_match[:k_type] + v_type = Regexp.last_match[:v_type] + {}.tap do |hash| + value.each do |k, v| + hash[_deserialize(k_type, k)] = _deserialize(v_type, v) + end + end + # model + else + # models (e.g. Pet) or oneOf + klass = Algolia::Composition.const_get(type) + klass.respond_to?(:openapi_any_of) || klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass + .build_from_hash(value) + end + end + + # Returns the string representation of the object + # @return [String] String presentation of the object + def to_s + to_hash.to_s + end + + # to_body is an alias to to_hash (backward compatibility) + # @return [Hash] Returns the object in the form of hash + def to_body + to_hash + end + + def to_json(*_args) + to_hash.to_json + end + + # Returns the object in the form of hash + # @return [Hash] Returns the object in the form of hash + def to_hash + hash = {} + self.class.attribute_map.each_pair do |attr, param| + value = send(attr) + if value.nil? + is_nullable = self.class.openapi_nullable.include?(attr) + next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) + end + + hash[param] = _to_hash(value) + end + + # also add attributes from additional_properties to hash + self.additional_properties&.each_pair do |k, v| + hash[k.to_sym] = _to_hash(v) + end + + hash + end + + # Outputs non-array value in the form of hash + # For object, use to_hash. Otherwise, just return the value + # @param [Object] value Any valid value + # @return [Hash] Returns the value in the form of hash + def _to_hash(value) + if value.is_a?(Array) + value.compact.map { |v| _to_hash(v) } + elsif value.is_a?(Hash) + {}.tap do |hash| + value.each { |k, v| hash[k] = _to_hash(v) } + end + elsif value.respond_to?(:to_hash) + value.to_hash + else + value + end + end + + end + + end +end diff --git a/lib/algolia/models/composition/error_base.rb b/lib/algolia/models/composition/error_base.rb new file mode 100644 index 00000000..f57b3f97 --- /dev/null +++ b/lib/algolia/models/composition/error_base.rb @@ -0,0 +1,209 @@ +# frozen_string_literal: true + +# Code generated by OpenAPI Generator (https://openapi-generator.tech), manual changes will be lost - read more on https://github.com/algolia/api-clients-automation. DO NOT EDIT. + +require "date" +require "time" + +module Algolia + module Composition + # Error. + class ErrorBase + attr_accessor :message + + attr_accessor :additional_properties + + # Attribute mapping from ruby-style variable name to JSON key. + def self.attribute_map + { + :message => :message + } + end + + # Attribute type mapping. + def self.types_mapping + { + :message => :"String" + } + end + + # List of attributes with nullable: true + def self.openapi_nullable + Set.new( + [] + ) + end + + # Initializes the object + # @param [Hash] attributes Model attributes in the form of hash + def initialize(attributes = {}) + if (!attributes.is_a?(Hash)) + raise( + ArgumentError, + "The input argument (attributes) must be a hash in `Algolia::ErrorBase` initialize method" + ) + end + + if attributes.key?(:message) + self.message = attributes[:message] + end + + # add extra attribute to additional_properties + self.additional_properties ||= {} + self.additional_properties.merge!(attributes.reject { |k, _| self.class.attribute_map.key?(k.to_sym) }) + end + + # Checks equality by comparing each attribute. + # @param [Object] Object to be compared + def ==(other) + return true if self.equal?(other) + self.class == other.class && + message == other.message + end + + # @see the `==` method + # @param [Object] Object to be compared + def eql?(other) + self == other + end + + # Calculates hash code according to all attributes. + # @return [Integer] Hash code + def hash + [message].hash + end + + # Builds the object from hash + # @param [Hash] attributes Model attributes in the form of hash + # @return [Object] Returns the model itself + def self.build_from_hash(attributes) + return nil unless attributes.is_a?(Hash) + attributes = attributes.transform_keys(&:to_sym) + transformed_hash = {} + types_mapping.each_pair do |key, type| + if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + transformed_hash[key.to_sym] = nil + elsif type =~ /\AArray<(.*)>/i + # check to ensure the input is an array given that the attribute + # is documented as an array but the input is not + if attributes[attribute_map[key]].is_a?(Array) + transformed_hash[key.to_sym] = attributes[attribute_map[key]].map { |v| + _deserialize(::Regexp.last_match(1), v) + } + end + elsif !attributes[attribute_map[key]].nil? + transformed_hash[key.to_sym] = _deserialize(type, attributes[attribute_map[key]]) + end + end + + # add extra attribute to transformed_hash + transformed_hash.merge!(attributes.reject { |k, _| attribute_map.key?(k.to_sym) }) + new(transformed_hash) + end + + # Deserializes the data based on type + # @param string type Data type + # @param string value Value to be deserialized + # @return [Object] Deserialized data + def self._deserialize(type, value) + case type.to_sym + when :Time + Time.parse(value) + when :Date + Date.parse(value) + when :String + value.to_s + when :Integer + value.to_i + when :Float + value.to_f + when :Boolean + if value.to_s =~ /\A(true|t|yes|y|1)\z/i + true + else + false + end + + when :Object + # generic object (usually a Hash), return directly + value + when /\AArray<(?.+)>\z/ + inner_type = Regexp.last_match[:inner_type] + value.map { |v| _deserialize(inner_type, v) } + when /\AHash<(?.+?), (?.+)>\z/ + k_type = Regexp.last_match[:k_type] + v_type = Regexp.last_match[:v_type] + {}.tap do |hash| + value.each do |k, v| + hash[_deserialize(k_type, k)] = _deserialize(v_type, v) + end + end + # model + else + # models (e.g. Pet) or oneOf + klass = Algolia::Composition.const_get(type) + klass.respond_to?(:openapi_any_of) || klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass + .build_from_hash(value) + end + end + + # Returns the string representation of the object + # @return [String] String presentation of the object + def to_s + to_hash.to_s + end + + # to_body is an alias to to_hash (backward compatibility) + # @return [Hash] Returns the object in the form of hash + def to_body + to_hash + end + + def to_json(*_args) + to_hash.to_json + end + + # Returns the object in the form of hash + # @return [Hash] Returns the object in the form of hash + def to_hash + hash = {} + self.class.attribute_map.each_pair do |attr, param| + value = send(attr) + if value.nil? + is_nullable = self.class.openapi_nullable.include?(attr) + next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) + end + + hash[param] = _to_hash(value) + end + + # also add attributes from additional_properties to hash + self.additional_properties&.each_pair do |k, v| + hash[k.to_sym] = _to_hash(v) + end + + hash + end + + # Outputs non-array value in the form of hash + # For object, use to_hash. Otherwise, just return the value + # @param [Object] value Any valid value + # @return [Hash] Returns the value in the form of hash + def _to_hash(value) + if value.is_a?(Array) + value.compact.map { |v| _to_hash(v) } + elsif value.is_a?(Hash) + {}.tap do |hash| + value.each { |k, v| hash[k] = _to_hash(v) } + end + elsif value.respond_to?(:to_hash) + value.to_hash + else + value + end + end + + end + + end +end diff --git a/lib/algolia/models/composition/exhaustive.rb b/lib/algolia/models/composition/exhaustive.rb new file mode 100644 index 00000000..533b89db --- /dev/null +++ b/lib/algolia/models/composition/exhaustive.rb @@ -0,0 +1,250 @@ +# frozen_string_literal: true + +# Code generated by OpenAPI Generator (https://openapi-generator.tech), manual changes will be lost - read more on https://github.com/algolia/api-clients-automation. DO NOT EDIT. + +require "date" +require "time" + +module Algolia + module Composition + # Whether certain properties of the search response are calculated exhaustive (exact) or approximated. + class Exhaustive + # Whether the facet count is exhaustive (`true`) or approximate (`false`). See the [related discussion](https://support.algolia.com/hc/en-us/articles/4406975248145-Why-are-my-facet-and-hit-counts-not-accurate-). + attr_accessor :facets_count + + # The value is `false` if not all facet values are retrieved. + attr_accessor :facet_values + + # Whether the `nbHits` is exhaustive (`true`) or approximate (`false`). When the query takes more than 50ms to be processed, the engine makes an approximation. This can happen when using complex filters on millions of records, when typo-tolerance was not exhaustive, or when enough hits have been retrieved (for example, after the engine finds 10,000 exact matches). `nbHits` is reported as non-exhaustive whenever an approximation is made, even if the approximation didn’t, in the end, impact the exhaustivity of the query. + attr_accessor :nb_hits + + # Rules matching exhaustivity. The value is `false` if rules were enable for this query, and could not be fully processed due a timeout. This is generally caused by the number of alternatives (such as typos) which is too large. + attr_accessor :rules_match + + # Whether the typo search was exhaustive (`true`) or approximate (`false`). An approximation is done when the typo search query part takes more than 10% of the query budget (ie. 5ms by default) to be processed (this can happen when a lot of typo alternatives exist for the query). This field will not be included when typo-tolerance is entirely disabled. + attr_accessor :typo + + # Attribute mapping from ruby-style variable name to JSON key. + def self.attribute_map + { + :facets_count => :facetsCount, + :facet_values => :facetValues, + :nb_hits => :nbHits, + :rules_match => :rulesMatch, + :typo => :typo + } + end + + # Attribute type mapping. + def self.types_mapping + { + :facets_count => :"Boolean", + :facet_values => :"Boolean", + :nb_hits => :"Boolean", + :rules_match => :"Boolean", + :typo => :"Boolean" + } + end + + # List of attributes with nullable: true + def self.openapi_nullable + Set.new( + [] + ) + end + + # Initializes the object + # @param [Hash] attributes Model attributes in the form of hash + def initialize(attributes = {}) + if (!attributes.is_a?(Hash)) + raise( + ArgumentError, + "The input argument (attributes) must be a hash in `Algolia::Exhaustive` initialize method" + ) + end + + # check to see if the attribute exists and convert string to symbol for hash key + attributes = attributes.each_with_object({}) { |(k, v), h| + if (!self.class.attribute_map.key?(k.to_sym)) + raise( + ArgumentError, + "`#{k}` is not a valid attribute in `Algolia::Exhaustive`. Please check the name to make sure it's valid. List of attributes: " + + self.class.attribute_map.keys.inspect + ) + end + + h[k.to_sym] = v + } + + if attributes.key?(:facets_count) + self.facets_count = attributes[:facets_count] + end + + if attributes.key?(:facet_values) + self.facet_values = attributes[:facet_values] + end + + if attributes.key?(:nb_hits) + self.nb_hits = attributes[:nb_hits] + end + + if attributes.key?(:rules_match) + self.rules_match = attributes[:rules_match] + end + + if attributes.key?(:typo) + self.typo = attributes[:typo] + end + end + + # Checks equality by comparing each attribute. + # @param [Object] Object to be compared + def ==(other) + return true if self.equal?(other) + self.class == other.class && + facets_count == other.facets_count && + facet_values == other.facet_values && + nb_hits == other.nb_hits && + rules_match == other.rules_match && + typo == other.typo + end + + # @see the `==` method + # @param [Object] Object to be compared + def eql?(other) + self == other + end + + # Calculates hash code according to all attributes. + # @return [Integer] Hash code + def hash + [facets_count, facet_values, nb_hits, rules_match, typo].hash + end + + # Builds the object from hash + # @param [Hash] attributes Model attributes in the form of hash + # @return [Object] Returns the model itself + def self.build_from_hash(attributes) + return nil unless attributes.is_a?(Hash) + attributes = attributes.transform_keys(&:to_sym) + transformed_hash = {} + types_mapping.each_pair do |key, type| + if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + transformed_hash[key.to_sym] = nil + elsif type =~ /\AArray<(.*)>/i + # check to ensure the input is an array given that the attribute + # is documented as an array but the input is not + if attributes[attribute_map[key]].is_a?(Array) + transformed_hash[key.to_sym] = attributes[attribute_map[key]].map { |v| + _deserialize(::Regexp.last_match(1), v) + } + end + elsif !attributes[attribute_map[key]].nil? + transformed_hash[key.to_sym] = _deserialize(type, attributes[attribute_map[key]]) + end + end + + new(transformed_hash) + end + + # Deserializes the data based on type + # @param string type Data type + # @param string value Value to be deserialized + # @return [Object] Deserialized data + def self._deserialize(type, value) + case type.to_sym + when :Time + Time.parse(value) + when :Date + Date.parse(value) + when :String + value.to_s + when :Integer + value.to_i + when :Float + value.to_f + when :Boolean + if value.to_s =~ /\A(true|t|yes|y|1)\z/i + true + else + false + end + + when :Object + # generic object (usually a Hash), return directly + value + when /\AArray<(?.+)>\z/ + inner_type = Regexp.last_match[:inner_type] + value.map { |v| _deserialize(inner_type, v) } + when /\AHash<(?.+?), (?.+)>\z/ + k_type = Regexp.last_match[:k_type] + v_type = Regexp.last_match[:v_type] + {}.tap do |hash| + value.each do |k, v| + hash[_deserialize(k_type, k)] = _deserialize(v_type, v) + end + end + # model + else + # models (e.g. Pet) or oneOf + klass = Algolia::Composition.const_get(type) + klass.respond_to?(:openapi_any_of) || klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass + .build_from_hash(value) + end + end + + # Returns the string representation of the object + # @return [String] String presentation of the object + def to_s + to_hash.to_s + end + + # to_body is an alias to to_hash (backward compatibility) + # @return [Hash] Returns the object in the form of hash + def to_body + to_hash + end + + def to_json(*_args) + to_hash.to_json + end + + # Returns the object in the form of hash + # @return [Hash] Returns the object in the form of hash + def to_hash + hash = {} + self.class.attribute_map.each_pair do |attr, param| + value = send(attr) + if value.nil? + is_nullable = self.class.openapi_nullable.include?(attr) + next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) + end + + hash[param] = _to_hash(value) + end + + hash + end + + # Outputs non-array value in the form of hash + # For object, use to_hash. Otherwise, just return the value + # @param [Object] value Any valid value + # @return [Hash] Returns the value in the form of hash + def _to_hash(value) + if value.is_a?(Array) + value.compact.map { |v| _to_hash(v) } + elsif value.is_a?(Hash) + {}.tap do |hash| + value.each { |k, v| hash[k] = _to_hash(v) } + end + elsif value.respond_to?(:to_hash) + value.to_hash + else + value + end + end + + end + + end +end diff --git a/lib/algolia/models/composition/facet_filters.rb b/lib/algolia/models/composition/facet_filters.rb new file mode 100644 index 00000000..e6437c2e --- /dev/null +++ b/lib/algolia/models/composition/facet_filters.rb @@ -0,0 +1,110 @@ +# frozen_string_literal: true + +# Code generated by OpenAPI Generator (https://openapi-generator.tech), manual changes will be lost - read more on https://github.com/algolia/api-clients-automation. DO NOT EDIT. + +require "date" +require "time" + +module Algolia + module Composition + # Filter the search by facet values, so that only records with the same facet values are retrieved. **Prefer using the `filters` parameter, which supports all filter types and combinations with boolean operators.** - `[filter1, filter2]` is interpreted as `filter1 AND filter2`. - `[[filter1, filter2], filter3]` is interpreted as `filter1 OR filter2 AND filter3`. - `facet:-value` is interpreted as `NOT facet:value`. While it's best to avoid attributes that start with a `-`, you can still filter them by escaping with a backslash: `facet:\\-value`. + module FacetFilters + class << self + # List of class defined in oneOf (OpenAPI v3) + def openapi_one_of + [ + :"Array", + :"String" + ] + end + + # Builds the object + # @param [Mixed] Data to be matched against the list of oneOf items + # @return [Object] Returns the model or the data itself + def build(data) + # Go through the list of oneOf items and attempt to identify the appropriate one. + # Note: + # - We do not attempt to check whether exactly one item matches. + # - No advanced validation of types in some cases (e.g. "x: { type: string }" will happily match { x: 123 }) + # due to the way the deserialization is made in the base_object template (it just casts without verifying). + # - TODO: scalar values are de facto behaving as if they were nullable. + # - TODO: logging when debugging is set. + openapi_one_of.each do |klass| + begin + # "nullable: true" + next if klass == :AnyType + typed_data = find_and_cast_into_type(klass, data) + return typed_data if typed_data + # rescue all errors so we keep iterating even if the current item lookup raises + rescue + end + end + + openapi_one_of.include?(:AnyType) ? data : nil + end + + private + + SchemaMismatchError = Class.new(StandardError) + + def find_and_cast_into_type(klass, data) + return if data.nil? + + case klass.to_s + when "Boolean" + return data if data.instance_of?(TrueClass) || data.instance_of?(FalseClass) + when "Float" + return data if data.instance_of?(Float) + when "Integer" + return data if data.instance_of?(Integer) + when "Time" + return Time.parse(data) + when "Date" + return Date.parse(data) + when "String" + return data if data.instance_of?(String) + # "type: object" + when "Object" + return data if data.instance_of?(Hash) + # "type: array" + when /\AArray<(?.+)>\z/ + if data.instance_of?(Array) + sub_type = Regexp.last_match[:sub_type] + return data.map { |item| find_and_cast_into_type(sub_type, item) } + end + # "type: object" with "additionalProperties: { ... }" + when /\AHash.+)>\z/ + if data.instance_of?(Hash) && data.keys.all? { |k| k.instance_of?(Symbol) || k.instance_of?(String) } + sub_type = Regexp.last_match[:sub_type] + return data.each_with_object({}) { |(k, v), hsh| hsh[k] = find_and_cast_into_type(sub_type, v) } + end + # model + else + const = Algolia::Composition.const_get(klass) + if const + if const.respond_to?(:openapi_one_of) + # nested oneOf model + model = const.build(data) + elsif const.respond_to?(:discriminator_attributes) + if const.discriminator_attributes.all? { |attr| data.key?(attr) } + model = const.build_from_hash(data) + end + else + # maybe it's an enum, or doens't have discriminators + model = const.build_from_hash(data) + end + + return model if model + end + end + + # if no match by now, raise + raise + rescue + raise SchemaMismatchError, "#{data} doesn't match the #{klass} type" + end + end + end + + end +end diff --git a/lib/algolia/models/composition/facet_hits.rb b/lib/algolia/models/composition/facet_hits.rb new file mode 100644 index 00000000..7abd6a90 --- /dev/null +++ b/lib/algolia/models/composition/facet_hits.rb @@ -0,0 +1,235 @@ +# frozen_string_literal: true + +# Code generated by OpenAPI Generator (https://openapi-generator.tech), manual changes will be lost - read more on https://github.com/algolia/api-clients-automation. DO NOT EDIT. + +require "date" +require "time" + +module Algolia + module Composition + class FacetHits + # Facet value. + attr_accessor :value + + # Highlighted attribute value, including HTML tags. + attr_accessor :highlighted + + # Number of records with this facet value. [The count may be approximated](https://support.algolia.com/hc/en-us/articles/4406975248145-Why-are-my-facet-and-hit-counts-not-accurate-). + attr_accessor :count + + # Attribute mapping from ruby-style variable name to JSON key. + def self.attribute_map + { + :value => :value, + :highlighted => :highlighted, + :count => :count + } + end + + # Attribute type mapping. + def self.types_mapping + { + :value => :"String", + :highlighted => :"String", + :count => :"Integer" + } + end + + # List of attributes with nullable: true + def self.openapi_nullable + Set.new( + [] + ) + end + + # Initializes the object + # @param [Hash] attributes Model attributes in the form of hash + def initialize(attributes = {}) + if (!attributes.is_a?(Hash)) + raise( + ArgumentError, + "The input argument (attributes) must be a hash in `Algolia::FacetHits` initialize method" + ) + end + + # check to see if the attribute exists and convert string to symbol for hash key + attributes = attributes.each_with_object({}) { |(k, v), h| + if (!self.class.attribute_map.key?(k.to_sym)) + raise( + ArgumentError, + "`#{k}` is not a valid attribute in `Algolia::FacetHits`. Please check the name to make sure it's valid. List of attributes: " + + self.class.attribute_map.keys.inspect + ) + end + + h[k.to_sym] = v + } + + if attributes.key?(:value) + self.value = attributes[:value] + else + self.value = nil + end + + if attributes.key?(:highlighted) + self.highlighted = attributes[:highlighted] + else + self.highlighted = nil + end + + if attributes.key?(:count) + self.count = attributes[:count] + else + self.count = nil + end + end + + # Checks equality by comparing each attribute. + # @param [Object] Object to be compared + def ==(other) + return true if self.equal?(other) + self.class == other.class && + value == other.value && + highlighted == other.highlighted && + count == other.count + end + + # @see the `==` method + # @param [Object] Object to be compared + def eql?(other) + self == other + end + + # Calculates hash code according to all attributes. + # @return [Integer] Hash code + def hash + [value, highlighted, count].hash + end + + # Builds the object from hash + # @param [Hash] attributes Model attributes in the form of hash + # @return [Object] Returns the model itself + def self.build_from_hash(attributes) + return nil unless attributes.is_a?(Hash) + attributes = attributes.transform_keys(&:to_sym) + transformed_hash = {} + types_mapping.each_pair do |key, type| + if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + transformed_hash[key.to_sym] = nil + elsif type =~ /\AArray<(.*)>/i + # check to ensure the input is an array given that the attribute + # is documented as an array but the input is not + if attributes[attribute_map[key]].is_a?(Array) + transformed_hash[key.to_sym] = attributes[attribute_map[key]].map { |v| + _deserialize(::Regexp.last_match(1), v) + } + end + elsif !attributes[attribute_map[key]].nil? + transformed_hash[key.to_sym] = _deserialize(type, attributes[attribute_map[key]]) + end + end + + new(transformed_hash) + end + + # Deserializes the data based on type + # @param string type Data type + # @param string value Value to be deserialized + # @return [Object] Deserialized data + def self._deserialize(type, value) + case type.to_sym + when :Time + Time.parse(value) + when :Date + Date.parse(value) + when :String + value.to_s + when :Integer + value.to_i + when :Float + value.to_f + when :Boolean + if value.to_s =~ /\A(true|t|yes|y|1)\z/i + true + else + false + end + + when :Object + # generic object (usually a Hash), return directly + value + when /\AArray<(?.+)>\z/ + inner_type = Regexp.last_match[:inner_type] + value.map { |v| _deserialize(inner_type, v) } + when /\AHash<(?.+?), (?.+)>\z/ + k_type = Regexp.last_match[:k_type] + v_type = Regexp.last_match[:v_type] + {}.tap do |hash| + value.each do |k, v| + hash[_deserialize(k_type, k)] = _deserialize(v_type, v) + end + end + # model + else + # models (e.g. Pet) or oneOf + klass = Algolia::Composition.const_get(type) + klass.respond_to?(:openapi_any_of) || klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass + .build_from_hash(value) + end + end + + # Returns the string representation of the object + # @return [String] String presentation of the object + def to_s + to_hash.to_s + end + + # to_body is an alias to to_hash (backward compatibility) + # @return [Hash] Returns the object in the form of hash + def to_body + to_hash + end + + def to_json(*_args) + to_hash.to_json + end + + # Returns the object in the form of hash + # @return [Hash] Returns the object in the form of hash + def to_hash + hash = {} + self.class.attribute_map.each_pair do |attr, param| + value = send(attr) + if value.nil? + is_nullable = self.class.openapi_nullable.include?(attr) + next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) + end + + hash[param] = _to_hash(value) + end + + hash + end + + # Outputs non-array value in the form of hash + # For object, use to_hash. Otherwise, just return the value + # @param [Object] value Any valid value + # @return [Hash] Returns the value in the form of hash + def _to_hash(value) + if value.is_a?(Array) + value.compact.map { |v| _to_hash(v) } + elsif value.is_a?(Hash) + {}.tap do |hash| + value.each { |k, v| hash[k] = _to_hash(v) } + end + elsif value.respond_to?(:to_hash) + value.to_hash + else + value + end + end + + end + + end +end diff --git a/lib/algolia/models/composition/facet_ordering.rb b/lib/algolia/models/composition/facet_ordering.rb new file mode 100644 index 00000000..0698a84b --- /dev/null +++ b/lib/algolia/models/composition/facet_ordering.rb @@ -0,0 +1,221 @@ +# frozen_string_literal: true + +# Code generated by OpenAPI Generator (https://openapi-generator.tech), manual changes will be lost - read more on https://github.com/algolia/api-clients-automation. DO NOT EDIT. + +require "date" +require "time" + +module Algolia + module Composition + # Order of facet names and facet values in your UI. + class FacetOrdering + attr_accessor :facets + + # Order of facet values. One object for each facet. + attr_accessor :values + + # Attribute mapping from ruby-style variable name to JSON key. + def self.attribute_map + { + :facets => :facets, + :values => :values + } + end + + # Attribute type mapping. + def self.types_mapping + { + :facets => :"Facets", + :values => :"Hash" + } + end + + # List of attributes with nullable: true + def self.openapi_nullable + Set.new( + [] + ) + end + + # Initializes the object + # @param [Hash] attributes Model attributes in the form of hash + def initialize(attributes = {}) + if (!attributes.is_a?(Hash)) + raise( + ArgumentError, + "The input argument (attributes) must be a hash in `Algolia::FacetOrdering` initialize method" + ) + end + + # check to see if the attribute exists and convert string to symbol for hash key + attributes = attributes.each_with_object({}) { |(k, v), h| + if (!self.class.attribute_map.key?(k.to_sym)) + raise( + ArgumentError, + "`#{k}` is not a valid attribute in `Algolia::FacetOrdering`. Please check the name to make sure it's valid. List of attributes: " + + self.class.attribute_map.keys.inspect + ) + end + + h[k.to_sym] = v + } + + if attributes.key?(:facets) + self.facets = attributes[:facets] + end + + if attributes.key?(:values) + if (value = attributes[:values]).is_a?(Hash) + self.values = value + end + end + end + + # Checks equality by comparing each attribute. + # @param [Object] Object to be compared + def ==(other) + return true if self.equal?(other) + self.class == other.class && + facets == other.facets && + values == other.values + end + + # @see the `==` method + # @param [Object] Object to be compared + def eql?(other) + self == other + end + + # Calculates hash code according to all attributes. + # @return [Integer] Hash code + def hash + [facets, values].hash + end + + # Builds the object from hash + # @param [Hash] attributes Model attributes in the form of hash + # @return [Object] Returns the model itself + def self.build_from_hash(attributes) + return nil unless attributes.is_a?(Hash) + attributes = attributes.transform_keys(&:to_sym) + transformed_hash = {} + types_mapping.each_pair do |key, type| + if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + transformed_hash[key.to_sym] = nil + elsif type =~ /\AArray<(.*)>/i + # check to ensure the input is an array given that the attribute + # is documented as an array but the input is not + if attributes[attribute_map[key]].is_a?(Array) + transformed_hash[key.to_sym] = attributes[attribute_map[key]].map { |v| + _deserialize(::Regexp.last_match(1), v) + } + end + elsif !attributes[attribute_map[key]].nil? + transformed_hash[key.to_sym] = _deserialize(type, attributes[attribute_map[key]]) + end + end + + new(transformed_hash) + end + + # Deserializes the data based on type + # @param string type Data type + # @param string value Value to be deserialized + # @return [Object] Deserialized data + def self._deserialize(type, value) + case type.to_sym + when :Time + Time.parse(value) + when :Date + Date.parse(value) + when :String + value.to_s + when :Integer + value.to_i + when :Float + value.to_f + when :Boolean + if value.to_s =~ /\A(true|t|yes|y|1)\z/i + true + else + false + end + + when :Object + # generic object (usually a Hash), return directly + value + when /\AArray<(?.+)>\z/ + inner_type = Regexp.last_match[:inner_type] + value.map { |v| _deserialize(inner_type, v) } + when /\AHash<(?.+?), (?.+)>\z/ + k_type = Regexp.last_match[:k_type] + v_type = Regexp.last_match[:v_type] + {}.tap do |hash| + value.each do |k, v| + hash[_deserialize(k_type, k)] = _deserialize(v_type, v) + end + end + # model + else + # models (e.g. Pet) or oneOf + klass = Algolia::Composition.const_get(type) + klass.respond_to?(:openapi_any_of) || klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass + .build_from_hash(value) + end + end + + # Returns the string representation of the object + # @return [String] String presentation of the object + def to_s + to_hash.to_s + end + + # to_body is an alias to to_hash (backward compatibility) + # @return [Hash] Returns the object in the form of hash + def to_body + to_hash + end + + def to_json(*_args) + to_hash.to_json + end + + # Returns the object in the form of hash + # @return [Hash] Returns the object in the form of hash + def to_hash + hash = {} + self.class.attribute_map.each_pair do |attr, param| + value = send(attr) + if value.nil? + is_nullable = self.class.openapi_nullable.include?(attr) + next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) + end + + hash[param] = _to_hash(value) + end + + hash + end + + # Outputs non-array value in the form of hash + # For object, use to_hash. Otherwise, just return the value + # @param [Object] value Any valid value + # @return [Hash] Returns the value in the form of hash + def _to_hash(value) + if value.is_a?(Array) + value.compact.map { |v| _to_hash(v) } + elsif value.is_a?(Hash) + {}.tap do |hash| + value.each { |k, v| hash[k] = _to_hash(v) } + end + elsif value.respond_to?(:to_hash) + value.to_hash + else + value + end + end + + end + + end +end diff --git a/lib/algolia/models/composition/facet_stats.rb b/lib/algolia/models/composition/facet_stats.rb new file mode 100644 index 00000000..cb601284 --- /dev/null +++ b/lib/algolia/models/composition/facet_stats.rb @@ -0,0 +1,239 @@ +# frozen_string_literal: true + +# Code generated by OpenAPI Generator (https://openapi-generator.tech), manual changes will be lost - read more on https://github.com/algolia/api-clients-automation. DO NOT EDIT. + +require "date" +require "time" + +module Algolia + module Composition + class FacetStats + # Minimum value in the results. + attr_accessor :min + + # Maximum value in the results. + attr_accessor :max + + # Average facet value in the results. + attr_accessor :avg + + # Sum of all values in the results. + attr_accessor :sum + + # Attribute mapping from ruby-style variable name to JSON key. + def self.attribute_map + { + :min => :min, + :max => :max, + :avg => :avg, + :sum => :sum + } + end + + # Attribute type mapping. + def self.types_mapping + { + :min => :"Float", + :max => :"Float", + :avg => :"Float", + :sum => :"Float" + } + end + + # List of attributes with nullable: true + def self.openapi_nullable + Set.new( + [] + ) + end + + # Initializes the object + # @param [Hash] attributes Model attributes in the form of hash + def initialize(attributes = {}) + if (!attributes.is_a?(Hash)) + raise( + ArgumentError, + "The input argument (attributes) must be a hash in `Algolia::FacetStats` initialize method" + ) + end + + # check to see if the attribute exists and convert string to symbol for hash key + attributes = attributes.each_with_object({}) { |(k, v), h| + if (!self.class.attribute_map.key?(k.to_sym)) + raise( + ArgumentError, + "`#{k}` is not a valid attribute in `Algolia::FacetStats`. Please check the name to make sure it's valid. List of attributes: " + + self.class.attribute_map.keys.inspect + ) + end + + h[k.to_sym] = v + } + + if attributes.key?(:min) + self.min = attributes[:min] + end + + if attributes.key?(:max) + self.max = attributes[:max] + end + + if attributes.key?(:avg) + self.avg = attributes[:avg] + end + + if attributes.key?(:sum) + self.sum = attributes[:sum] + end + end + + # Checks equality by comparing each attribute. + # @param [Object] Object to be compared + def ==(other) + return true if self.equal?(other) + self.class == other.class && + min == other.min && + max == other.max && + avg == other.avg && + sum == other.sum + end + + # @see the `==` method + # @param [Object] Object to be compared + def eql?(other) + self == other + end + + # Calculates hash code according to all attributes. + # @return [Integer] Hash code + def hash + [min, max, avg, sum].hash + end + + # Builds the object from hash + # @param [Hash] attributes Model attributes in the form of hash + # @return [Object] Returns the model itself + def self.build_from_hash(attributes) + return nil unless attributes.is_a?(Hash) + attributes = attributes.transform_keys(&:to_sym) + transformed_hash = {} + types_mapping.each_pair do |key, type| + if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + transformed_hash[key.to_sym] = nil + elsif type =~ /\AArray<(.*)>/i + # check to ensure the input is an array given that the attribute + # is documented as an array but the input is not + if attributes[attribute_map[key]].is_a?(Array) + transformed_hash[key.to_sym] = attributes[attribute_map[key]].map { |v| + _deserialize(::Regexp.last_match(1), v) + } + end + elsif !attributes[attribute_map[key]].nil? + transformed_hash[key.to_sym] = _deserialize(type, attributes[attribute_map[key]]) + end + end + + new(transformed_hash) + end + + # Deserializes the data based on type + # @param string type Data type + # @param string value Value to be deserialized + # @return [Object] Deserialized data + def self._deserialize(type, value) + case type.to_sym + when :Time + Time.parse(value) + when :Date + Date.parse(value) + when :String + value.to_s + when :Integer + value.to_i + when :Float + value.to_f + when :Boolean + if value.to_s =~ /\A(true|t|yes|y|1)\z/i + true + else + false + end + + when :Object + # generic object (usually a Hash), return directly + value + when /\AArray<(?.+)>\z/ + inner_type = Regexp.last_match[:inner_type] + value.map { |v| _deserialize(inner_type, v) } + when /\AHash<(?.+?), (?.+)>\z/ + k_type = Regexp.last_match[:k_type] + v_type = Regexp.last_match[:v_type] + {}.tap do |hash| + value.each do |k, v| + hash[_deserialize(k_type, k)] = _deserialize(v_type, v) + end + end + # model + else + # models (e.g. Pet) or oneOf + klass = Algolia::Composition.const_get(type) + klass.respond_to?(:openapi_any_of) || klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass + .build_from_hash(value) + end + end + + # Returns the string representation of the object + # @return [String] String presentation of the object + def to_s + to_hash.to_s + end + + # to_body is an alias to to_hash (backward compatibility) + # @return [Hash] Returns the object in the form of hash + def to_body + to_hash + end + + def to_json(*_args) + to_hash.to_json + end + + # Returns the object in the form of hash + # @return [Hash] Returns the object in the form of hash + def to_hash + hash = {} + self.class.attribute_map.each_pair do |attr, param| + value = send(attr) + if value.nil? + is_nullable = self.class.openapi_nullable.include?(attr) + next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) + end + + hash[param] = _to_hash(value) + end + + hash + end + + # Outputs non-array value in the form of hash + # For object, use to_hash. Otherwise, just return the value + # @param [Object] value Any valid value + # @return [Hash] Returns the value in the form of hash + def _to_hash(value) + if value.is_a?(Array) + value.compact.map { |v| _to_hash(v) } + elsif value.is_a?(Hash) + {}.tap do |hash| + value.each { |k, v| hash[k] = _to_hash(v) } + end + elsif value.respond_to?(:to_hash) + value.to_hash + else + value + end + end + + end + + end +end diff --git a/lib/algolia/models/composition/facets.rb b/lib/algolia/models/composition/facets.rb new file mode 100644 index 00000000..f519b65b --- /dev/null +++ b/lib/algolia/models/composition/facets.rb @@ -0,0 +1,209 @@ +# frozen_string_literal: true + +# Code generated by OpenAPI Generator (https://openapi-generator.tech), manual changes will be lost - read more on https://github.com/algolia/api-clients-automation. DO NOT EDIT. + +require "date" +require "time" + +module Algolia + module Composition + # Order of facet names. + class Facets + # Explicit order of facets or facet values. This setting lets you always show specific facets or facet values at the top of the list. + attr_accessor :order + + # Attribute mapping from ruby-style variable name to JSON key. + def self.attribute_map + { + :order => :order + } + end + + # Attribute type mapping. + def self.types_mapping + { + :order => :"Array" + } + end + + # List of attributes with nullable: true + def self.openapi_nullable + Set.new( + [] + ) + end + + # Initializes the object + # @param [Hash] attributes Model attributes in the form of hash + def initialize(attributes = {}) + if (!attributes.is_a?(Hash)) + raise ArgumentError, "The input argument (attributes) must be a hash in `Algolia::Facets` initialize method" + end + + # check to see if the attribute exists and convert string to symbol for hash key + attributes = attributes.each_with_object({}) { |(k, v), h| + if (!self.class.attribute_map.key?(k.to_sym)) + raise( + ArgumentError, + "`#{k}` is not a valid attribute in `Algolia::Facets`. Please check the name to make sure it's valid. List of attributes: " + + self.class.attribute_map.keys.inspect + ) + end + + h[k.to_sym] = v + } + + if attributes.key?(:order) + if (value = attributes[:order]).is_a?(Array) + self.order = value + end + end + end + + # Checks equality by comparing each attribute. + # @param [Object] Object to be compared + def ==(other) + return true if self.equal?(other) + self.class == other.class && + order == other.order + end + + # @see the `==` method + # @param [Object] Object to be compared + def eql?(other) + self == other + end + + # Calculates hash code according to all attributes. + # @return [Integer] Hash code + def hash + [order].hash + end + + # Builds the object from hash + # @param [Hash] attributes Model attributes in the form of hash + # @return [Object] Returns the model itself + def self.build_from_hash(attributes) + return nil unless attributes.is_a?(Hash) + attributes = attributes.transform_keys(&:to_sym) + transformed_hash = {} + types_mapping.each_pair do |key, type| + if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + transformed_hash[key.to_sym] = nil + elsif type =~ /\AArray<(.*)>/i + # check to ensure the input is an array given that the attribute + # is documented as an array but the input is not + if attributes[attribute_map[key]].is_a?(Array) + transformed_hash[key.to_sym] = attributes[attribute_map[key]].map { |v| + _deserialize(::Regexp.last_match(1), v) + } + end + elsif !attributes[attribute_map[key]].nil? + transformed_hash[key.to_sym] = _deserialize(type, attributes[attribute_map[key]]) + end + end + + new(transformed_hash) + end + + # Deserializes the data based on type + # @param string type Data type + # @param string value Value to be deserialized + # @return [Object] Deserialized data + def self._deserialize(type, value) + case type.to_sym + when :Time + Time.parse(value) + when :Date + Date.parse(value) + when :String + value.to_s + when :Integer + value.to_i + when :Float + value.to_f + when :Boolean + if value.to_s =~ /\A(true|t|yes|y|1)\z/i + true + else + false + end + + when :Object + # generic object (usually a Hash), return directly + value + when /\AArray<(?.+)>\z/ + inner_type = Regexp.last_match[:inner_type] + value.map { |v| _deserialize(inner_type, v) } + when /\AHash<(?.+?), (?.+)>\z/ + k_type = Regexp.last_match[:k_type] + v_type = Regexp.last_match[:v_type] + {}.tap do |hash| + value.each do |k, v| + hash[_deserialize(k_type, k)] = _deserialize(v_type, v) + end + end + # model + else + # models (e.g. Pet) or oneOf + klass = Algolia::Composition.const_get(type) + klass.respond_to?(:openapi_any_of) || klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass + .build_from_hash(value) + end + end + + # Returns the string representation of the object + # @return [String] String presentation of the object + def to_s + to_hash.to_s + end + + # to_body is an alias to to_hash (backward compatibility) + # @return [Hash] Returns the object in the form of hash + def to_body + to_hash + end + + def to_json(*_args) + to_hash.to_json + end + + # Returns the object in the form of hash + # @return [Hash] Returns the object in the form of hash + def to_hash + hash = {} + self.class.attribute_map.each_pair do |attr, param| + value = send(attr) + if value.nil? + is_nullable = self.class.openapi_nullable.include?(attr) + next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) + end + + hash[param] = _to_hash(value) + end + + hash + end + + # Outputs non-array value in the form of hash + # For object, use to_hash. Otherwise, just return the value + # @param [Object] value Any valid value + # @return [Hash] Returns the value in the form of hash + def _to_hash(value) + if value.is_a?(Array) + value.compact.map { |v| _to_hash(v) } + elsif value.is_a?(Hash) + {}.tap do |hash| + value.each { |k, v| hash[k] = _to_hash(v) } + end + elsif value.respond_to?(:to_hash) + value.to_hash + else + value + end + end + + end + + end +end diff --git a/lib/algolia/models/composition/highlight_result.rb b/lib/algolia/models/composition/highlight_result.rb new file mode 100644 index 00000000..4667df66 --- /dev/null +++ b/lib/algolia/models/composition/highlight_result.rb @@ -0,0 +1,110 @@ +# frozen_string_literal: true + +# Code generated by OpenAPI Generator (https://openapi-generator.tech), manual changes will be lost - read more on https://github.com/algolia/api-clients-automation. DO NOT EDIT. + +require "date" +require "time" + +module Algolia + module Composition + module HighlightResult + class << self + # List of class defined in oneOf (OpenAPI v3) + def openapi_one_of + [ + :"Array", + :"Hash", + :"HighlightResultOption" + ] + end + + # Builds the object + # @param [Mixed] Data to be matched against the list of oneOf items + # @return [Object] Returns the model or the data itself + def build(data) + # Go through the list of oneOf items and attempt to identify the appropriate one. + # Note: + # - We do not attempt to check whether exactly one item matches. + # - No advanced validation of types in some cases (e.g. "x: { type: string }" will happily match { x: 123 }) + # due to the way the deserialization is made in the base_object template (it just casts without verifying). + # - TODO: scalar values are de facto behaving as if they were nullable. + # - TODO: logging when debugging is set. + openapi_one_of.each do |klass| + begin + # "nullable: true" + next if klass == :AnyType + typed_data = find_and_cast_into_type(klass, data) + return typed_data if typed_data + # rescue all errors so we keep iterating even if the current item lookup raises + rescue + end + end + + openapi_one_of.include?(:AnyType) ? data : nil + end + + private + + SchemaMismatchError = Class.new(StandardError) + + def find_and_cast_into_type(klass, data) + return if data.nil? + + case klass.to_s + when "Boolean" + return data if data.instance_of?(TrueClass) || data.instance_of?(FalseClass) + when "Float" + return data if data.instance_of?(Float) + when "Integer" + return data if data.instance_of?(Integer) + when "Time" + return Time.parse(data) + when "Date" + return Date.parse(data) + when "String" + return data if data.instance_of?(String) + # "type: object" + when "Object" + return data if data.instance_of?(Hash) + # "type: array" + when /\AArray<(?.+)>\z/ + if data.instance_of?(Array) + sub_type = Regexp.last_match[:sub_type] + return data.map { |item| find_and_cast_into_type(sub_type, item) } + end + # "type: object" with "additionalProperties: { ... }" + when /\AHash.+)>\z/ + if data.instance_of?(Hash) && data.keys.all? { |k| k.instance_of?(Symbol) || k.instance_of?(String) } + sub_type = Regexp.last_match[:sub_type] + return data.each_with_object({}) { |(k, v), hsh| hsh[k] = find_and_cast_into_type(sub_type, v) } + end + # model + else + const = Algolia::Composition.const_get(klass) + if const + if const.respond_to?(:openapi_one_of) + # nested oneOf model + model = const.build(data) + elsif const.respond_to?(:discriminator_attributes) + if const.discriminator_attributes.all? { |attr| data.key?(attr) } + model = const.build_from_hash(data) + end + else + # maybe it's an enum, or doens't have discriminators + model = const.build_from_hash(data) + end + + return model if model + end + end + + # if no match by now, raise + raise + rescue + raise SchemaMismatchError, "#{data} doesn't match the #{klass} type" + end + end + end + + end +end diff --git a/lib/algolia/models/composition/highlight_result_option.rb b/lib/algolia/models/composition/highlight_result_option.rb new file mode 100644 index 00000000..1f58198e --- /dev/null +++ b/lib/algolia/models/composition/highlight_result_option.rb @@ -0,0 +1,255 @@ +# frozen_string_literal: true + +# Code generated by OpenAPI Generator (https://openapi-generator.tech), manual changes will be lost - read more on https://github.com/algolia/api-clients-automation. DO NOT EDIT. + +require "date" +require "time" + +module Algolia + module Composition + # Surround words that match the query with HTML tags for highlighting. + class HighlightResultOption + # Highlighted attribute value, including HTML tags. + attr_accessor :value + + attr_accessor :match_level + + # List of matched words from the search query. + attr_accessor :matched_words + + # Whether the entire attribute value is highlighted. + attr_accessor :fully_highlighted + + # Attribute mapping from ruby-style variable name to JSON key. + def self.attribute_map + { + :value => :value, + :match_level => :matchLevel, + :matched_words => :matchedWords, + :fully_highlighted => :fullyHighlighted + } + end + + # Returns the keys that uniquely identify this oneOf variant when present + def self.discriminator_attributes + [ + :matchLevel, + :matchedWords + ] + end + + # Attribute type mapping. + def self.types_mapping + { + :value => :"String", + :match_level => :"MatchLevel", + :matched_words => :"Array", + :fully_highlighted => :"Boolean" + } + end + + # List of attributes with nullable: true + def self.openapi_nullable + Set.new( + [] + ) + end + + # Initializes the object + # @param [Hash] attributes Model attributes in the form of hash + def initialize(attributes = {}) + if (!attributes.is_a?(Hash)) + raise( + ArgumentError, + "The input argument (attributes) must be a hash in `Algolia::HighlightResultOption` initialize method" + ) + end + + # check to see if the attribute exists and convert string to symbol for hash key + attributes = attributes.each_with_object({}) { |(k, v), h| + if (!self.class.attribute_map.key?(k.to_sym)) + raise( + ArgumentError, + "`#{k}` is not a valid attribute in `Algolia::HighlightResultOption`. Please check the name to make sure it's valid. List of attributes: " + + self.class.attribute_map.keys.inspect + ) + end + + h[k.to_sym] = v + } + + if attributes.key?(:value) + self.value = attributes[:value] + else + self.value = nil + end + + if attributes.key?(:match_level) + self.match_level = attributes[:match_level] + else + self.match_level = nil + end + + if attributes.key?(:matched_words) + if (value = attributes[:matched_words]).is_a?(Array) + self.matched_words = value + end + else + self.matched_words = nil + end + + if attributes.key?(:fully_highlighted) + self.fully_highlighted = attributes[:fully_highlighted] + end + end + + # Checks equality by comparing each attribute. + # @param [Object] Object to be compared + def ==(other) + return true if self.equal?(other) + self.class == other.class && + value == other.value && + match_level == other.match_level && + matched_words == other.matched_words && + fully_highlighted == other.fully_highlighted + end + + # @see the `==` method + # @param [Object] Object to be compared + def eql?(other) + self == other + end + + # Calculates hash code according to all attributes. + # @return [Integer] Hash code + def hash + [value, match_level, matched_words, fully_highlighted].hash + end + + # Builds the object from hash + # @param [Hash] attributes Model attributes in the form of hash + # @return [Object] Returns the model itself + def self.build_from_hash(attributes) + return nil unless attributes.is_a?(Hash) + attributes = attributes.transform_keys(&:to_sym) + transformed_hash = {} + types_mapping.each_pair do |key, type| + if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + transformed_hash[key.to_sym] = nil + elsif type =~ /\AArray<(.*)>/i + # check to ensure the input is an array given that the attribute + # is documented as an array but the input is not + if attributes[attribute_map[key]].is_a?(Array) + transformed_hash[key.to_sym] = attributes[attribute_map[key]].map { |v| + _deserialize(::Regexp.last_match(1), v) + } + end + elsif !attributes[attribute_map[key]].nil? + transformed_hash[key.to_sym] = _deserialize(type, attributes[attribute_map[key]]) + end + end + + new(transformed_hash) + end + + # Deserializes the data based on type + # @param string type Data type + # @param string value Value to be deserialized + # @return [Object] Deserialized data + def self._deserialize(type, value) + case type.to_sym + when :Time + Time.parse(value) + when :Date + Date.parse(value) + when :String + value.to_s + when :Integer + value.to_i + when :Float + value.to_f + when :Boolean + if value.to_s =~ /\A(true|t|yes|y|1)\z/i + true + else + false + end + + when :Object + # generic object (usually a Hash), return directly + value + when /\AArray<(?.+)>\z/ + inner_type = Regexp.last_match[:inner_type] + value.map { |v| _deserialize(inner_type, v) } + when /\AHash<(?.+?), (?.+)>\z/ + k_type = Regexp.last_match[:k_type] + v_type = Regexp.last_match[:v_type] + {}.tap do |hash| + value.each do |k, v| + hash[_deserialize(k_type, k)] = _deserialize(v_type, v) + end + end + # model + else + # models (e.g. Pet) or oneOf + klass = Algolia::Composition.const_get(type) + klass.respond_to?(:openapi_any_of) || klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass + .build_from_hash(value) + end + end + + # Returns the string representation of the object + # @return [String] String presentation of the object + def to_s + to_hash.to_s + end + + # to_body is an alias to to_hash (backward compatibility) + # @return [Hash] Returns the object in the form of hash + def to_body + to_hash + end + + def to_json(*_args) + to_hash.to_json + end + + # Returns the object in the form of hash + # @return [Hash] Returns the object in the form of hash + def to_hash + hash = {} + self.class.attribute_map.each_pair do |attr, param| + value = send(attr) + if value.nil? + is_nullable = self.class.openapi_nullable.include?(attr) + next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) + end + + hash[param] = _to_hash(value) + end + + hash + end + + # Outputs non-array value in the form of hash + # For object, use to_hash. Otherwise, just return the value + # @param [Object] value Any valid value + # @return [Hash] Returns the value in the form of hash + def _to_hash(value) + if value.is_a?(Array) + value.compact.map { |v| _to_hash(v) } + elsif value.is_a?(Hash) + {}.tap do |hash| + value.each { |k, v| hash[k] = _to_hash(v) } + end + elsif value.respond_to?(:to_hash) + value.to_hash + else + value + end + end + + end + + end +end diff --git a/lib/algolia/models/composition/hit.rb b/lib/algolia/models/composition/hit.rb new file mode 100644 index 00000000..6e777f92 --- /dev/null +++ b/lib/algolia/models/composition/hit.rb @@ -0,0 +1,251 @@ +# frozen_string_literal: true + +# Code generated by OpenAPI Generator (https://openapi-generator.tech), manual changes will be lost - read more on https://github.com/algolia/api-clients-automation. DO NOT EDIT. + +require "date" +require "time" + +module Algolia + module Composition + # Search result. A hit is a record from your index, augmented with special attributes for highlighting, snippeting, and ranking. + class Hit + # Unique record identifier. + attr_accessor :algolia_object_id + + # Surround words that match the query with HTML tags for highlighting. + attr_accessor :_highlight_result + + # Snippets that show the context around a matching search query. + attr_accessor :_snippet_result + + attr_accessor :_ranking_info + + attr_accessor :_distinct_seq_id + + attr_accessor :additional_properties + + # Attribute mapping from ruby-style variable name to JSON key. + def self.attribute_map + { + :algolia_object_id => :objectID, + :_highlight_result => :_highlightResult, + :_snippet_result => :_snippetResult, + :_ranking_info => :_rankingInfo, + :_distinct_seq_id => :_distinctSeqID + } + end + + # Attribute type mapping. + def self.types_mapping + { + :algolia_object_id => :"String", + :_highlight_result => :"Hash", + :_snippet_result => :"Hash", + :_ranking_info => :"HitRankingInfo", + :_distinct_seq_id => :"Integer" + } + end + + # List of attributes with nullable: true + def self.openapi_nullable + Set.new( + [] + ) + end + + # Initializes the object + # @param [Hash] attributes Model attributes in the form of hash + def initialize(attributes = {}) + if (!attributes.is_a?(Hash)) + raise ArgumentError, "The input argument (attributes) must be a hash in `Algolia::Hit` initialize method" + end + + if attributes.key?(:algolia_object_id) + self.algolia_object_id = attributes[:algolia_object_id] + else + self.algolia_object_id = nil + end + + if attributes.key?(:_highlight_result) + if (value = attributes[:_highlight_result]).is_a?(Hash) + self._highlight_result = value + end + end + + if attributes.key?(:_snippet_result) + if (value = attributes[:_snippet_result]).is_a?(Hash) + self._snippet_result = value + end + end + + if attributes.key?(:_ranking_info) + self._ranking_info = attributes[:_ranking_info] + end + + if attributes.key?(:_distinct_seq_id) + self._distinct_seq_id = attributes[:_distinct_seq_id] + end + + # add extra attribute to additional_properties + self.additional_properties ||= {} + self.additional_properties.merge!(attributes.reject { |k, _| self.class.attribute_map.key?(k.to_sym) }) + end + + # Checks equality by comparing each attribute. + # @param [Object] Object to be compared + def ==(other) + return true if self.equal?(other) + self.class == other.class && + algolia_object_id == other.algolia_object_id && + _highlight_result == other._highlight_result && + _snippet_result == other._snippet_result && + _ranking_info == other._ranking_info && + _distinct_seq_id == other._distinct_seq_id + end + + # @see the `==` method + # @param [Object] Object to be compared + def eql?(other) + self == other + end + + # Calculates hash code according to all attributes. + # @return [Integer] Hash code + def hash + [algolia_object_id, _highlight_result, _snippet_result, _ranking_info, _distinct_seq_id].hash + end + + # Builds the object from hash + # @param [Hash] attributes Model attributes in the form of hash + # @return [Object] Returns the model itself + def self.build_from_hash(attributes) + return nil unless attributes.is_a?(Hash) + attributes = attributes.transform_keys(&:to_sym) + transformed_hash = {} + types_mapping.each_pair do |key, type| + if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + transformed_hash[key.to_sym] = nil + elsif type =~ /\AArray<(.*)>/i + # check to ensure the input is an array given that the attribute + # is documented as an array but the input is not + if attributes[attribute_map[key]].is_a?(Array) + transformed_hash[key.to_sym] = attributes[attribute_map[key]].map { |v| + _deserialize(::Regexp.last_match(1), v) + } + end + elsif !attributes[attribute_map[key]].nil? + transformed_hash[key.to_sym] = _deserialize(type, attributes[attribute_map[key]]) + end + end + + # add extra attribute to transformed_hash + transformed_hash.merge!(attributes.reject { |k, _| attribute_map.key?(k.to_sym) }) + new(transformed_hash) + end + + # Deserializes the data based on type + # @param string type Data type + # @param string value Value to be deserialized + # @return [Object] Deserialized data + def self._deserialize(type, value) + case type.to_sym + when :Time + Time.parse(value) + when :Date + Date.parse(value) + when :String + value.to_s + when :Integer + value.to_i + when :Float + value.to_f + when :Boolean + if value.to_s =~ /\A(true|t|yes|y|1)\z/i + true + else + false + end + + when :Object + # generic object (usually a Hash), return directly + value + when /\AArray<(?.+)>\z/ + inner_type = Regexp.last_match[:inner_type] + value.map { |v| _deserialize(inner_type, v) } + when /\AHash<(?.+?), (?.+)>\z/ + k_type = Regexp.last_match[:k_type] + v_type = Regexp.last_match[:v_type] + {}.tap do |hash| + value.each do |k, v| + hash[_deserialize(k_type, k)] = _deserialize(v_type, v) + end + end + # model + else + # models (e.g. Pet) or oneOf + klass = Algolia::Composition.const_get(type) + klass.respond_to?(:openapi_any_of) || klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass + .build_from_hash(value) + end + end + + # Returns the string representation of the object + # @return [String] String presentation of the object + def to_s + to_hash.to_s + end + + # to_body is an alias to to_hash (backward compatibility) + # @return [Hash] Returns the object in the form of hash + def to_body + to_hash + end + + def to_json(*_args) + to_hash.to_json + end + + # Returns the object in the form of hash + # @return [Hash] Returns the object in the form of hash + def to_hash + hash = {} + self.class.attribute_map.each_pair do |attr, param| + value = send(attr) + if value.nil? + is_nullable = self.class.openapi_nullable.include?(attr) + next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) + end + + hash[param] = _to_hash(value) + end + + # also add attributes from additional_properties to hash + self.additional_properties&.each_pair do |k, v| + hash[k.to_sym] = _to_hash(v) + end + + hash + end + + # Outputs non-array value in the form of hash + # For object, use to_hash. Otherwise, just return the value + # @param [Object] value Any valid value + # @return [Hash] Returns the value in the form of hash + def _to_hash(value) + if value.is_a?(Array) + value.compact.map { |v| _to_hash(v) } + elsif value.is_a?(Hash) + {}.tap do |hash| + value.each { |k, v| hash[k] = _to_hash(v) } + end + elsif value.respond_to?(:to_hash) + value.to_hash + else + value + end + end + + end + + end +end diff --git a/lib/algolia/models/composition/hit_ranking_info.rb b/lib/algolia/models/composition/hit_ranking_info.rb new file mode 100644 index 00000000..2f57e774 --- /dev/null +++ b/lib/algolia/models/composition/hit_ranking_info.rb @@ -0,0 +1,371 @@ +# frozen_string_literal: true + +# Code generated by OpenAPI Generator (https://openapi-generator.tech), manual changes will be lost - read more on https://github.com/algolia/api-clients-automation. DO NOT EDIT. + +require "date" +require "time" + +module Algolia + module Composition + class HitRankingInfo + # Whether a filter matched the query. + attr_accessor :filters + + # Position of the first matched word in the best matching attribute of the record. + attr_accessor :first_matched_word + + # Distance between the geo location in the search query and the best matching geo location in the record, divided by the geo precision (in meters). + attr_accessor :geo_distance + + # Precision used when computing the geo distance, in meters. + attr_accessor :geo_precision + + attr_accessor :matched_geo_location + + attr_accessor :personalization + + # Number of exactly matched words. + attr_accessor :nb_exact_words + + # Number of typos encountered when matching the record. + attr_accessor :nb_typos + + # Whether the record was promoted by a rule. + attr_accessor :promoted + + # Number of words between multiple matches in the query plus 1. For single word queries, `proximityDistance` is 0. + attr_accessor :proximity_distance + + # Overall ranking of the record, expressed as a single integer. This attribute is internal. + attr_accessor :user_score + + # Number of matched words. + attr_accessor :words + + # Whether the record is re-ranked. + attr_accessor :promoted_by_re_ranking + + attr_accessor :composed + + # Attribute mapping from ruby-style variable name to JSON key. + def self.attribute_map + { + :filters => :filters, + :first_matched_word => :firstMatchedWord, + :geo_distance => :geoDistance, + :geo_precision => :geoPrecision, + :matched_geo_location => :matchedGeoLocation, + :personalization => :personalization, + :nb_exact_words => :nbExactWords, + :nb_typos => :nbTypos, + :promoted => :promoted, + :proximity_distance => :proximityDistance, + :user_score => :userScore, + :words => :words, + :promoted_by_re_ranking => :promotedByReRanking, + :composed => :composed + } + end + + # Attribute type mapping. + def self.types_mapping + { + :filters => :"Integer", + :first_matched_word => :"Integer", + :geo_distance => :"Integer", + :geo_precision => :"Integer", + :matched_geo_location => :"MatchedGeoLocation", + :personalization => :"Personalization", + :nb_exact_words => :"Integer", + :nb_typos => :"Integer", + :promoted => :"Boolean", + :proximity_distance => :"Integer", + :user_score => :"Integer", + :words => :"Integer", + :promoted_by_re_ranking => :"Boolean", + :composed => :"Hash" + } + end + + # List of attributes with nullable: true + def self.openapi_nullable + Set.new( + [] + ) + end + + # List of class defined in allOf (OpenAPI v3) + def self.openapi_all_of + [ + :"CompositionRankingInfo", + :"RankingInfo" + ] + end + + # Initializes the object + # @param [Hash] attributes Model attributes in the form of hash + def initialize(attributes = {}) + if (!attributes.is_a?(Hash)) + raise( + ArgumentError, + "The input argument (attributes) must be a hash in `Algolia::HitRankingInfo` initialize method" + ) + end + + # check to see if the attribute exists and convert string to symbol for hash key + attributes = attributes.each_with_object({}) { |(k, v), h| + if (!self.class.attribute_map.key?(k.to_sym)) + raise( + ArgumentError, + "`#{k}` is not a valid attribute in `Algolia::HitRankingInfo`. Please check the name to make sure it's valid. List of attributes: " + + self.class.attribute_map.keys.inspect + ) + end + + h[k.to_sym] = v + } + + if attributes.key?(:filters) + self.filters = attributes[:filters] + end + + if attributes.key?(:first_matched_word) + self.first_matched_word = attributes[:first_matched_word] + else + self.first_matched_word = nil + end + + if attributes.key?(:geo_distance) + self.geo_distance = attributes[:geo_distance] + else + self.geo_distance = nil + end + + if attributes.key?(:geo_precision) + self.geo_precision = attributes[:geo_precision] + end + + if attributes.key?(:matched_geo_location) + self.matched_geo_location = attributes[:matched_geo_location] + end + + if attributes.key?(:personalization) + self.personalization = attributes[:personalization] + end + + if attributes.key?(:nb_exact_words) + self.nb_exact_words = attributes[:nb_exact_words] + else + self.nb_exact_words = nil + end + + if attributes.key?(:nb_typos) + self.nb_typos = attributes[:nb_typos] + else + self.nb_typos = nil + end + + if attributes.key?(:promoted) + self.promoted = attributes[:promoted] + end + + if attributes.key?(:proximity_distance) + self.proximity_distance = attributes[:proximity_distance] + end + + if attributes.key?(:user_score) + self.user_score = attributes[:user_score] + else + self.user_score = nil + end + + if attributes.key?(:words) + self.words = attributes[:words] + end + + if attributes.key?(:promoted_by_re_ranking) + self.promoted_by_re_ranking = attributes[:promoted_by_re_ranking] + end + + if attributes.key?(:composed) + if (value = attributes[:composed]).is_a?(Hash) + self.composed = value + end + end + end + + # Checks equality by comparing each attribute. + # @param [Object] Object to be compared + def ==(other) + return true if self.equal?(other) + self.class == other.class && + filters == other.filters && + first_matched_word == other.first_matched_word && + geo_distance == other.geo_distance && + geo_precision == other.geo_precision && + matched_geo_location == other.matched_geo_location && + personalization == other.personalization && + nb_exact_words == other.nb_exact_words && + nb_typos == other.nb_typos && + promoted == other.promoted && + proximity_distance == other.proximity_distance && + user_score == other.user_score && + words == other.words && + promoted_by_re_ranking == other.promoted_by_re_ranking && + composed == other.composed + end + + # @see the `==` method + # @param [Object] Object to be compared + def eql?(other) + self == other + end + + # Calculates hash code according to all attributes. + # @return [Integer] Hash code + def hash + [ + filters, + first_matched_word, + geo_distance, + geo_precision, + matched_geo_location, + personalization, + nb_exact_words, + nb_typos, + promoted, + proximity_distance, + user_score, + words, + promoted_by_re_ranking, + composed + ].hash + end + + # Builds the object from hash + # @param [Hash] attributes Model attributes in the form of hash + # @return [Object] Returns the model itself + def self.build_from_hash(attributes) + return nil unless attributes.is_a?(Hash) + attributes = attributes.transform_keys(&:to_sym) + transformed_hash = {} + types_mapping.each_pair do |key, type| + if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + transformed_hash[key.to_sym] = nil + elsif type =~ /\AArray<(.*)>/i + # check to ensure the input is an array given that the attribute + # is documented as an array but the input is not + if attributes[attribute_map[key]].is_a?(Array) + transformed_hash[key.to_sym] = attributes[attribute_map[key]].map { |v| + _deserialize(::Regexp.last_match(1), v) + } + end + elsif !attributes[attribute_map[key]].nil? + transformed_hash[key.to_sym] = _deserialize(type, attributes[attribute_map[key]]) + end + end + + new(transformed_hash) + end + + # Deserializes the data based on type + # @param string type Data type + # @param string value Value to be deserialized + # @return [Object] Deserialized data + def self._deserialize(type, value) + case type.to_sym + when :Time + Time.parse(value) + when :Date + Date.parse(value) + when :String + value.to_s + when :Integer + value.to_i + when :Float + value.to_f + when :Boolean + if value.to_s =~ /\A(true|t|yes|y|1)\z/i + true + else + false + end + + when :Object + # generic object (usually a Hash), return directly + value + when /\AArray<(?.+)>\z/ + inner_type = Regexp.last_match[:inner_type] + value.map { |v| _deserialize(inner_type, v) } + when /\AHash<(?.+?), (?.+)>\z/ + k_type = Regexp.last_match[:k_type] + v_type = Regexp.last_match[:v_type] + {}.tap do |hash| + value.each do |k, v| + hash[_deserialize(k_type, k)] = _deserialize(v_type, v) + end + end + # model + else + # models (e.g. Pet) or oneOf + klass = Algolia::Composition.const_get(type) + klass.respond_to?(:openapi_any_of) || klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass + .build_from_hash(value) + end + end + + # Returns the string representation of the object + # @return [String] String presentation of the object + def to_s + to_hash.to_s + end + + # to_body is an alias to to_hash (backward compatibility) + # @return [Hash] Returns the object in the form of hash + def to_body + to_hash + end + + def to_json(*_args) + to_hash.to_json + end + + # Returns the object in the form of hash + # @return [Hash] Returns the object in the form of hash + def to_hash + hash = {} + self.class.attribute_map.each_pair do |attr, param| + value = send(attr) + if value.nil? + is_nullable = self.class.openapi_nullable.include?(attr) + next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) + end + + hash[param] = _to_hash(value) + end + + hash + end + + # Outputs non-array value in the form of hash + # For object, use to_hash. Otherwise, just return the value + # @param [Object] value Any valid value + # @return [Hash] Returns the value in the form of hash + def _to_hash(value) + if value.is_a?(Array) + value.compact.map { |v| _to_hash(v) } + elsif value.is_a?(Hash) + {}.tap do |hash| + value.each { |k, v| hash[k] = _to_hash(v) } + end + elsif value.respond_to?(:to_hash) + value.to_hash + else + value + end + end + + end + + end +end diff --git a/lib/algolia/models/composition/inside_bounding_box.rb b/lib/algolia/models/composition/inside_bounding_box.rb new file mode 100644 index 00000000..3016a123 --- /dev/null +++ b/lib/algolia/models/composition/inside_bounding_box.rb @@ -0,0 +1,109 @@ +# frozen_string_literal: true + +# Code generated by OpenAPI Generator (https://openapi-generator.tech), manual changes will be lost - read more on https://github.com/algolia/api-clients-automation. DO NOT EDIT. + +require "date" +require "time" + +module Algolia + module Composition + module InsideBoundingBox + class << self + # List of class defined in oneOf (OpenAPI v3) + def openapi_one_of + [ + :"Array>", + :"String" + ] + end + + # Builds the object + # @param [Mixed] Data to be matched against the list of oneOf items + # @return [Object] Returns the model or the data itself + def build(data) + # Go through the list of oneOf items and attempt to identify the appropriate one. + # Note: + # - We do not attempt to check whether exactly one item matches. + # - No advanced validation of types in some cases (e.g. "x: { type: string }" will happily match { x: 123 }) + # due to the way the deserialization is made in the base_object template (it just casts without verifying). + # - TODO: scalar values are de facto behaving as if they were nullable. + # - TODO: logging when debugging is set. + openapi_one_of.each do |klass| + begin + # "nullable: true" + next if klass == :AnyType + typed_data = find_and_cast_into_type(klass, data) + return typed_data if typed_data + # rescue all errors so we keep iterating even if the current item lookup raises + rescue + end + end + + openapi_one_of.include?(:AnyType) ? data : nil + end + + private + + SchemaMismatchError = Class.new(StandardError) + + def find_and_cast_into_type(klass, data) + return if data.nil? + + case klass.to_s + when "Boolean" + return data if data.instance_of?(TrueClass) || data.instance_of?(FalseClass) + when "Float" + return data if data.instance_of?(Float) + when "Integer" + return data if data.instance_of?(Integer) + when "Time" + return Time.parse(data) + when "Date" + return Date.parse(data) + when "String" + return data if data.instance_of?(String) + # "type: object" + when "Object" + return data if data.instance_of?(Hash) + # "type: array" + when /\AArray<(?.+)>\z/ + if data.instance_of?(Array) + sub_type = Regexp.last_match[:sub_type] + return data.map { |item| find_and_cast_into_type(sub_type, item) } + end + # "type: object" with "additionalProperties: { ... }" + when /\AHash.+)>\z/ + if data.instance_of?(Hash) && data.keys.all? { |k| k.instance_of?(Symbol) || k.instance_of?(String) } + sub_type = Regexp.last_match[:sub_type] + return data.each_with_object({}) { |(k, v), hsh| hsh[k] = find_and_cast_into_type(sub_type, v) } + end + # model + else + const = Algolia::Composition.const_get(klass) + if const + if const.respond_to?(:openapi_one_of) + # nested oneOf model + model = const.build(data) + elsif const.respond_to?(:discriminator_attributes) + if const.discriminator_attributes.all? { |attr| data.key?(attr) } + model = const.build_from_hash(data) + end + else + # maybe it's an enum, or doens't have discriminators + model = const.build_from_hash(data) + end + + return model if model + end + end + + # if no match by now, raise + raise + rescue + raise SchemaMismatchError, "#{data} doesn't match the #{klass} type" + end + end + end + + end +end diff --git a/lib/algolia/models/composition/match_level.rb b/lib/algolia/models/composition/match_level.rb new file mode 100644 index 00000000..ef496905 --- /dev/null +++ b/lib/algolia/models/composition/match_level.rb @@ -0,0 +1,35 @@ +# frozen_string_literal: true + +# Code generated by OpenAPI Generator (https://openapi-generator.tech), manual changes will be lost - read more on https://github.com/algolia/api-clients-automation. DO NOT EDIT. + +require "date" +require "time" + +module Algolia + module Composition + class MatchLevel + NONE = "none".freeze + PARTIAL = "partial".freeze + FULL = "full".freeze + + def self.all_vars + @all_vars ||= [NONE, PARTIAL, FULL].freeze + end + + # Builds the enum from string + # @param [String] The enum value in the form of the string + # @return [String] The enum value + def self.build_from_hash(value) + new.build_from_hash(value) + end + + # Builds the enum from string + # @param [String] The enum value in the form of the string + # @return [String] The enum value + def build_from_hash(value) + return value if MatchLevel.all_vars.include?(value) + raise "Invalid ENUM value #{value} for class #MatchLevel" + end + end + end +end diff --git a/lib/algolia/models/composition/matched_geo_location.rb b/lib/algolia/models/composition/matched_geo_location.rb new file mode 100644 index 00000000..604492f2 --- /dev/null +++ b/lib/algolia/models/composition/matched_geo_location.rb @@ -0,0 +1,229 @@ +# frozen_string_literal: true + +# Code generated by OpenAPI Generator (https://openapi-generator.tech), manual changes will be lost - read more on https://github.com/algolia/api-clients-automation. DO NOT EDIT. + +require "date" +require "time" + +module Algolia + module Composition + class MatchedGeoLocation + # Latitude of the matched location. + attr_accessor :lat + + # Longitude of the matched location. + attr_accessor :lng + + # Distance between the matched location and the search location (in meters). + attr_accessor :distance + + # Attribute mapping from ruby-style variable name to JSON key. + def self.attribute_map + { + :lat => :lat, + :lng => :lng, + :distance => :distance + } + end + + # Attribute type mapping. + def self.types_mapping + { + :lat => :"Float", + :lng => :"Float", + :distance => :"Integer" + } + end + + # List of attributes with nullable: true + def self.openapi_nullable + Set.new( + [] + ) + end + + # Initializes the object + # @param [Hash] attributes Model attributes in the form of hash + def initialize(attributes = {}) + if (!attributes.is_a?(Hash)) + raise( + ArgumentError, + "The input argument (attributes) must be a hash in `Algolia::MatchedGeoLocation` initialize method" + ) + end + + # check to see if the attribute exists and convert string to symbol for hash key + attributes = attributes.each_with_object({}) { |(k, v), h| + if (!self.class.attribute_map.key?(k.to_sym)) + raise( + ArgumentError, + "`#{k}` is not a valid attribute in `Algolia::MatchedGeoLocation`. Please check the name to make sure it's valid. List of attributes: " + + self.class.attribute_map.keys.inspect + ) + end + + h[k.to_sym] = v + } + + if attributes.key?(:lat) + self.lat = attributes[:lat] + end + + if attributes.key?(:lng) + self.lng = attributes[:lng] + end + + if attributes.key?(:distance) + self.distance = attributes[:distance] + end + end + + # Checks equality by comparing each attribute. + # @param [Object] Object to be compared + def ==(other) + return true if self.equal?(other) + self.class == other.class && + lat == other.lat && + lng == other.lng && + distance == other.distance + end + + # @see the `==` method + # @param [Object] Object to be compared + def eql?(other) + self == other + end + + # Calculates hash code according to all attributes. + # @return [Integer] Hash code + def hash + [lat, lng, distance].hash + end + + # Builds the object from hash + # @param [Hash] attributes Model attributes in the form of hash + # @return [Object] Returns the model itself + def self.build_from_hash(attributes) + return nil unless attributes.is_a?(Hash) + attributes = attributes.transform_keys(&:to_sym) + transformed_hash = {} + types_mapping.each_pair do |key, type| + if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + transformed_hash[key.to_sym] = nil + elsif type =~ /\AArray<(.*)>/i + # check to ensure the input is an array given that the attribute + # is documented as an array but the input is not + if attributes[attribute_map[key]].is_a?(Array) + transformed_hash[key.to_sym] = attributes[attribute_map[key]].map { |v| + _deserialize(::Regexp.last_match(1), v) + } + end + elsif !attributes[attribute_map[key]].nil? + transformed_hash[key.to_sym] = _deserialize(type, attributes[attribute_map[key]]) + end + end + + new(transformed_hash) + end + + # Deserializes the data based on type + # @param string type Data type + # @param string value Value to be deserialized + # @return [Object] Deserialized data + def self._deserialize(type, value) + case type.to_sym + when :Time + Time.parse(value) + when :Date + Date.parse(value) + when :String + value.to_s + when :Integer + value.to_i + when :Float + value.to_f + when :Boolean + if value.to_s =~ /\A(true|t|yes|y|1)\z/i + true + else + false + end + + when :Object + # generic object (usually a Hash), return directly + value + when /\AArray<(?.+)>\z/ + inner_type = Regexp.last_match[:inner_type] + value.map { |v| _deserialize(inner_type, v) } + when /\AHash<(?.+?), (?.+)>\z/ + k_type = Regexp.last_match[:k_type] + v_type = Regexp.last_match[:v_type] + {}.tap do |hash| + value.each do |k, v| + hash[_deserialize(k_type, k)] = _deserialize(v_type, v) + end + end + # model + else + # models (e.g. Pet) or oneOf + klass = Algolia::Composition.const_get(type) + klass.respond_to?(:openapi_any_of) || klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass + .build_from_hash(value) + end + end + + # Returns the string representation of the object + # @return [String] String presentation of the object + def to_s + to_hash.to_s + end + + # to_body is an alias to to_hash (backward compatibility) + # @return [Hash] Returns the object in the form of hash + def to_body + to_hash + end + + def to_json(*_args) + to_hash.to_json + end + + # Returns the object in the form of hash + # @return [Hash] Returns the object in the form of hash + def to_hash + hash = {} + self.class.attribute_map.each_pair do |attr, param| + value = send(attr) + if value.nil? + is_nullable = self.class.openapi_nullable.include?(attr) + next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) + end + + hash[param] = _to_hash(value) + end + + hash + end + + # Outputs non-array value in the form of hash + # For object, use to_hash. Otherwise, just return the value + # @param [Object] value Any valid value + # @return [Hash] Returns the value in the form of hash + def _to_hash(value) + if value.is_a?(Array) + value.compact.map { |v| _to_hash(v) } + elsif value.is_a?(Hash) + {}.tap do |hash| + value.each { |k, v| hash[k] = _to_hash(v) } + end + elsif value.respond_to?(:to_hash) + value.to_hash + else + value + end + end + + end + + end +end diff --git a/lib/algolia/models/composition/numeric_filters.rb b/lib/algolia/models/composition/numeric_filters.rb new file mode 100644 index 00000000..1ba9a2e9 --- /dev/null +++ b/lib/algolia/models/composition/numeric_filters.rb @@ -0,0 +1,110 @@ +# frozen_string_literal: true + +# Code generated by OpenAPI Generator (https://openapi-generator.tech), manual changes will be lost - read more on https://github.com/algolia/api-clients-automation. DO NOT EDIT. + +require "date" +require "time" + +module Algolia + module Composition + # Filter by numeric facets. **Prefer using the `filters` parameter, which supports all filter types and combinations with boolean operators.** You can use numeric comparison operators: `<`, `<=`, `=`, `!=`, `>`, `>=`. Comparisons are precise up to 3 decimals. You can also provide ranges: `facet: TO `. The range includes the lower and upper boundaries. The same combination rules apply as for `facetFilters`. + module NumericFilters + class << self + # List of class defined in oneOf (OpenAPI v3) + def openapi_one_of + [ + :"Array", + :"String" + ] + end + + # Builds the object + # @param [Mixed] Data to be matched against the list of oneOf items + # @return [Object] Returns the model or the data itself + def build(data) + # Go through the list of oneOf items and attempt to identify the appropriate one. + # Note: + # - We do not attempt to check whether exactly one item matches. + # - No advanced validation of types in some cases (e.g. "x: { type: string }" will happily match { x: 123 }) + # due to the way the deserialization is made in the base_object template (it just casts without verifying). + # - TODO: scalar values are de facto behaving as if they were nullable. + # - TODO: logging when debugging is set. + openapi_one_of.each do |klass| + begin + # "nullable: true" + next if klass == :AnyType + typed_data = find_and_cast_into_type(klass, data) + return typed_data if typed_data + # rescue all errors so we keep iterating even if the current item lookup raises + rescue + end + end + + openapi_one_of.include?(:AnyType) ? data : nil + end + + private + + SchemaMismatchError = Class.new(StandardError) + + def find_and_cast_into_type(klass, data) + return if data.nil? + + case klass.to_s + when "Boolean" + return data if data.instance_of?(TrueClass) || data.instance_of?(FalseClass) + when "Float" + return data if data.instance_of?(Float) + when "Integer" + return data if data.instance_of?(Integer) + when "Time" + return Time.parse(data) + when "Date" + return Date.parse(data) + when "String" + return data if data.instance_of?(String) + # "type: object" + when "Object" + return data if data.instance_of?(Hash) + # "type: array" + when /\AArray<(?.+)>\z/ + if data.instance_of?(Array) + sub_type = Regexp.last_match[:sub_type] + return data.map { |item| find_and_cast_into_type(sub_type, item) } + end + # "type: object" with "additionalProperties: { ... }" + when /\AHash.+)>\z/ + if data.instance_of?(Hash) && data.keys.all? { |k| k.instance_of?(Symbol) || k.instance_of?(String) } + sub_type = Regexp.last_match[:sub_type] + return data.each_with_object({}) { |(k, v), hsh| hsh[k] = find_and_cast_into_type(sub_type, v) } + end + # model + else + const = Algolia::Composition.const_get(klass) + if const + if const.respond_to?(:openapi_one_of) + # nested oneOf model + model = const.build(data) + elsif const.respond_to?(:discriminator_attributes) + if const.discriminator_attributes.all? { |attr| data.key?(attr) } + model = const.build_from_hash(data) + end + else + # maybe it's an enum, or doens't have discriminators + model = const.build_from_hash(data) + end + + return model if model + end + end + + # if no match by now, raise + raise + rescue + raise SchemaMismatchError, "#{data} doesn't match the #{klass} type" + end + end + end + + end +end diff --git a/lib/algolia/models/composition/optional_filters.rb b/lib/algolia/models/composition/optional_filters.rb new file mode 100644 index 00000000..46492d47 --- /dev/null +++ b/lib/algolia/models/composition/optional_filters.rb @@ -0,0 +1,110 @@ +# frozen_string_literal: true + +# Code generated by OpenAPI Generator (https://openapi-generator.tech), manual changes will be lost - read more on https://github.com/algolia/api-clients-automation. DO NOT EDIT. + +require "date" +require "time" + +module Algolia + module Composition + # Filters to promote or demote records in the search results. Optional filters work like facet filters, but they don't exclude records from the search results. Records that match the optional filter rank before records that don't match. If you're using a negative filter `facet:-value`, matching records rank after records that don't match. - Optional filters don't work on virtual replicas. - Optional filters are applied _after_ sort-by attributes. - Optional filters are applied _before_ custom ranking attributes (in the default [ranking](https://www.algolia.com/doc/guides/managing-results/relevance-overview/in-depth/ranking-criteria/)). - Optional filters don't work with numeric attributes. + module OptionalFilters + class << self + # List of class defined in oneOf (OpenAPI v3) + def openapi_one_of + [ + :"Array", + :"String" + ] + end + + # Builds the object + # @param [Mixed] Data to be matched against the list of oneOf items + # @return [Object] Returns the model or the data itself + def build(data) + # Go through the list of oneOf items and attempt to identify the appropriate one. + # Note: + # - We do not attempt to check whether exactly one item matches. + # - No advanced validation of types in some cases (e.g. "x: { type: string }" will happily match { x: 123 }) + # due to the way the deserialization is made in the base_object template (it just casts without verifying). + # - TODO: scalar values are de facto behaving as if they were nullable. + # - TODO: logging when debugging is set. + openapi_one_of.each do |klass| + begin + # "nullable: true" + next if klass == :AnyType + typed_data = find_and_cast_into_type(klass, data) + return typed_data if typed_data + # rescue all errors so we keep iterating even if the current item lookup raises + rescue + end + end + + openapi_one_of.include?(:AnyType) ? data : nil + end + + private + + SchemaMismatchError = Class.new(StandardError) + + def find_and_cast_into_type(klass, data) + return if data.nil? + + case klass.to_s + when "Boolean" + return data if data.instance_of?(TrueClass) || data.instance_of?(FalseClass) + when "Float" + return data if data.instance_of?(Float) + when "Integer" + return data if data.instance_of?(Integer) + when "Time" + return Time.parse(data) + when "Date" + return Date.parse(data) + when "String" + return data if data.instance_of?(String) + # "type: object" + when "Object" + return data if data.instance_of?(Hash) + # "type: array" + when /\AArray<(?.+)>\z/ + if data.instance_of?(Array) + sub_type = Regexp.last_match[:sub_type] + return data.map { |item| find_and_cast_into_type(sub_type, item) } + end + # "type: object" with "additionalProperties: { ... }" + when /\AHash.+)>\z/ + if data.instance_of?(Hash) && data.keys.all? { |k| k.instance_of?(Symbol) || k.instance_of?(String) } + sub_type = Regexp.last_match[:sub_type] + return data.each_with_object({}) { |(k, v), hsh| hsh[k] = find_and_cast_into_type(sub_type, v) } + end + # model + else + const = Algolia::Composition.const_get(klass) + if const + if const.respond_to?(:openapi_one_of) + # nested oneOf model + model = const.build(data) + elsif const.respond_to?(:discriminator_attributes) + if const.discriminator_attributes.all? { |attr| data.key?(attr) } + model = const.build_from_hash(data) + end + else + # maybe it's an enum, or doens't have discriminators + model = const.build_from_hash(data) + end + + return model if model + end + end + + # if no match by now, raise + raise + rescue + raise SchemaMismatchError, "#{data} doesn't match the #{klass} type" + end + end + end + + end +end diff --git a/lib/algolia/models/composition/params.rb b/lib/algolia/models/composition/params.rb new file mode 100644 index 00000000..6b9191b2 --- /dev/null +++ b/lib/algolia/models/composition/params.rb @@ -0,0 +1,488 @@ +# frozen_string_literal: true + +# Code generated by OpenAPI Generator (https://openapi-generator.tech), manual changes will be lost - read more on https://github.com/algolia/api-clients-automation. DO NOT EDIT. + +require "date" +require "time" + +module Algolia + module Composition + class Params + # Search query. + attr_accessor :query + + # Filter expression to only include items that match the filter criteria in the response. You can use these filter expressions: - **Numeric filters.** ` `, where `` is one of `<`, `<=`, `=`, `!=`, `>`, `>=`. - **Ranges.** `: TO ` where `` and `` are the lower and upper limits of the range (inclusive). - **Facet filters.** `:` where `` is a facet attribute (case-sensitive) and `` a facet value. - **Tag filters.** `_tags:` or just `` (case-sensitive). - **Boolean filters.** `: true | false`. You can combine filters with `AND`, `OR`, and `NOT` operators with the following restrictions: - You can only combine filters of the same type with `OR`. **Not supported:** `facet:value OR num > 3`. - You can't use `NOT` with combinations of filters. **Not supported:** `NOT(facet:value OR facet:value)` - You can't combine conjunctions (`AND`) with `OR`. **Not supported:** `facet:value OR (facet:value AND facet:value)` Use quotes around your filters, if the facet attribute name or facet value has spaces, keywords (`OR`, `AND`, `NOT`), or quotes. If a facet attribute is an array, the filter matches if it matches at least one element of the array. For more information, see [Filters](https://www.algolia.com/doc/guides/managing-results/refine-results/filtering/). + attr_accessor :filters + + # Page of search results to retrieve. + attr_accessor :page + + # Whether the search response should include detailed ranking information. + attr_accessor :get_ranking_info + + attr_accessor :relevancy_strictness + + attr_accessor :facet_filters + + attr_accessor :optional_filters + + attr_accessor :numeric_filters + + # Number of hits per page. + attr_accessor :hits_per_page + + # Coordinates for the center of a circle, expressed as a comma-separated string of latitude and longitude. Only records included within a circle around this central location are included in the results. The radius of the circle is determined by the `aroundRadius` and `minimumAroundRadius` settings. This parameter is ignored if you also specify `insidePolygon` or `insideBoundingBox`. + attr_accessor :around_lat_lng + + # Whether to obtain the coordinates from the request's IP address. + attr_accessor :around_lat_lng_via_ip + + attr_accessor :around_radius + + attr_accessor :around_precision + + # Minimum radius (in meters) for a search around a location when `aroundRadius` isn't set. + attr_accessor :minimum_around_radius + + attr_accessor :inside_bounding_box + + # Coordinates of a polygon in which to search. Polygons are defined by 3 to 10,000 points. Each point is represented by its latitude and longitude. Provide multiple polygons as nested arrays. For more information, see [filtering inside polygons](https://www.algolia.com/doc/guides/managing-results/refine-results/geolocation/#filtering-inside-rectangular-or-polygonal-areas). This parameter is ignored if you also specify `insideBoundingBox`. + attr_accessor :inside_polygon + + # Languages for language-specific query processing steps such as plurals, stop-word removal, and word-detection dictionaries. This setting sets a default list of languages used by the `removeStopWords` and `ignorePlurals` settings. This setting also sets a dictionary for word detection in the logogram-based [CJK](https://www.algolia.com/doc/guides/managing-results/optimize-search-results/handling-natural-languages-nlp/in-depth/normalization/#normalization-for-logogram-based-languages-cjk) languages. To support this, you must place the CJK language **first**. **You should always specify a query language.** If you don't specify an indexing language, the search engine uses all [supported languages](https://www.algolia.com/doc/guides/managing-results/optimize-search-results/handling-natural-languages-nlp/in-depth/supported-languages/), or the languages you specified with the `ignorePlurals` or `removeStopWords` parameters. This can lead to unexpected search results. For more information, see [Language-specific configuration](https://www.algolia.com/doc/guides/managing-results/optimize-search-results/handling-natural-languages-nlp/in-depth/language-specific-configurations/). + attr_accessor :query_languages + + # ISO language codes that adjust settings that are useful for processing natural language queries (as opposed to keyword searches): - Sets `removeStopWords` and `ignorePlurals` to the list of provided languages. - Sets `removeWordsIfNoResults` to `allOptional`. - Adds a `natural_language` attribute to `ruleContexts` and `analyticsTags`. + attr_accessor :natural_languages + + # Whether to enable rules. + attr_accessor :enable_rules + + # Assigns a rule context to the search query. [Rule contexts](https://www.algolia.com/doc/guides/managing-results/rules/rules-overview/how-to/customize-search-results-by-platform/#whats-a-context) are strings that you can use to trigger matching rules. + attr_accessor :rule_contexts + + # Unique pseudonymous or anonymous user identifier. This helps with analytics and click and conversion events. For more information, see [user token](https://www.algolia.com/doc/guides/sending-events/concepts/usertoken/). + attr_accessor :user_token + + # Whether to include a `queryID` attribute in the response. The query ID is a unique identifier for a search query and is required for tracking [click and conversion events](https://www.algolia.com/guides/sending-events/getting-started/). + attr_accessor :click_analytics + + # Whether this search will be included in Analytics. + attr_accessor :analytics + + # Tags to apply to the query for [segmenting analytics data](https://www.algolia.com/doc/guides/search-analytics/guides/segments/). + attr_accessor :analytics_tags + + # Whether to enable A/B testing for this search. + attr_accessor :enable_ab_test + + # Whether this search will use [Dynamic Re-Ranking](https://www.algolia.com/doc/guides/algolia-ai/re-ranking/). This setting only has an effect if you activated Dynamic Re-Ranking for this index in the Algolia dashboard. + attr_accessor :enable_re_ranking + + # Attribute mapping from ruby-style variable name to JSON key. + def self.attribute_map + { + :query => :query, + :filters => :filters, + :page => :page, + :get_ranking_info => :getRankingInfo, + :relevancy_strictness => :relevancyStrictness, + :facet_filters => :facetFilters, + :optional_filters => :optionalFilters, + :numeric_filters => :numericFilters, + :hits_per_page => :hitsPerPage, + :around_lat_lng => :aroundLatLng, + :around_lat_lng_via_ip => :aroundLatLngViaIP, + :around_radius => :aroundRadius, + :around_precision => :aroundPrecision, + :minimum_around_radius => :minimumAroundRadius, + :inside_bounding_box => :insideBoundingBox, + :inside_polygon => :insidePolygon, + :query_languages => :queryLanguages, + :natural_languages => :naturalLanguages, + :enable_rules => :enableRules, + :rule_contexts => :ruleContexts, + :user_token => :userToken, + :click_analytics => :clickAnalytics, + :analytics => :analytics, + :analytics_tags => :analyticsTags, + :enable_ab_test => :enableABTest, + :enable_re_ranking => :enableReRanking + } + end + + # Attribute type mapping. + def self.types_mapping + { + :query => :"String", + :filters => :"String", + :page => :"Integer", + :get_ranking_info => :"Boolean", + :relevancy_strictness => :"Integer", + :facet_filters => :"FacetFilters", + :optional_filters => :"OptionalFilters", + :numeric_filters => :"NumericFilters", + :hits_per_page => :"Integer", + :around_lat_lng => :"String", + :around_lat_lng_via_ip => :"Boolean", + :around_radius => :"AroundRadius", + :around_precision => :"AroundPrecision", + :minimum_around_radius => :"Integer", + :inside_bounding_box => :"InsideBoundingBox", + :inside_polygon => :"Array>", + :query_languages => :"Array", + :natural_languages => :"Array", + :enable_rules => :"Boolean", + :rule_contexts => :"Array", + :user_token => :"String", + :click_analytics => :"Boolean", + :analytics => :"Boolean", + :analytics_tags => :"Array", + :enable_ab_test => :"Boolean", + :enable_re_ranking => :"Boolean" + } + end + + # List of attributes with nullable: true + def self.openapi_nullable + Set.new( + [ + :inside_bounding_box + ] + ) + end + + # Initializes the object + # @param [Hash] attributes Model attributes in the form of hash + def initialize(attributes = {}) + if (!attributes.is_a?(Hash)) + raise ArgumentError, "The input argument (attributes) must be a hash in `Algolia::Params` initialize method" + end + + # check to see if the attribute exists and convert string to symbol for hash key + attributes = attributes.each_with_object({}) { |(k, v), h| + if (!self.class.attribute_map.key?(k.to_sym)) + raise( + ArgumentError, + "`#{k}` is not a valid attribute in `Algolia::Params`. Please check the name to make sure it's valid. List of attributes: " + + self.class.attribute_map.keys.inspect + ) + end + + h[k.to_sym] = v + } + + if attributes.key?(:query) + self.query = attributes[:query] + end + + if attributes.key?(:filters) + self.filters = attributes[:filters] + end + + if attributes.key?(:page) + self.page = attributes[:page] + end + + if attributes.key?(:get_ranking_info) + self.get_ranking_info = attributes[:get_ranking_info] + end + + if attributes.key?(:relevancy_strictness) + self.relevancy_strictness = attributes[:relevancy_strictness] + end + + if attributes.key?(:facet_filters) + self.facet_filters = attributes[:facet_filters] + end + + if attributes.key?(:optional_filters) + self.optional_filters = attributes[:optional_filters] + end + + if attributes.key?(:numeric_filters) + self.numeric_filters = attributes[:numeric_filters] + end + + if attributes.key?(:hits_per_page) + self.hits_per_page = attributes[:hits_per_page] + end + + if attributes.key?(:around_lat_lng) + self.around_lat_lng = attributes[:around_lat_lng] + end + + if attributes.key?(:around_lat_lng_via_ip) + self.around_lat_lng_via_ip = attributes[:around_lat_lng_via_ip] + end + + if attributes.key?(:around_radius) + self.around_radius = attributes[:around_radius] + end + + if attributes.key?(:around_precision) + self.around_precision = attributes[:around_precision] + end + + if attributes.key?(:minimum_around_radius) + self.minimum_around_radius = attributes[:minimum_around_radius] + end + + if attributes.key?(:inside_bounding_box) + self.inside_bounding_box = attributes[:inside_bounding_box] + end + + if attributes.key?(:inside_polygon) + if (value = attributes[:inside_polygon]).is_a?(Array) + self.inside_polygon = value + end + end + + if attributes.key?(:query_languages) + if (value = attributes[:query_languages]).is_a?(Array) + self.query_languages = value + end + end + + if attributes.key?(:natural_languages) + if (value = attributes[:natural_languages]).is_a?(Array) + self.natural_languages = value + end + end + + if attributes.key?(:enable_rules) + self.enable_rules = attributes[:enable_rules] + end + + if attributes.key?(:rule_contexts) + if (value = attributes[:rule_contexts]).is_a?(Array) + self.rule_contexts = value + end + end + + if attributes.key?(:user_token) + self.user_token = attributes[:user_token] + end + + if attributes.key?(:click_analytics) + self.click_analytics = attributes[:click_analytics] + end + + if attributes.key?(:analytics) + self.analytics = attributes[:analytics] + end + + if attributes.key?(:analytics_tags) + if (value = attributes[:analytics_tags]).is_a?(Array) + self.analytics_tags = value + end + end + + if attributes.key?(:enable_ab_test) + self.enable_ab_test = attributes[:enable_ab_test] + end + + if attributes.key?(:enable_re_ranking) + self.enable_re_ranking = attributes[:enable_re_ranking] + end + end + + # Checks equality by comparing each attribute. + # @param [Object] Object to be compared + def ==(other) + return true if self.equal?(other) + self.class == other.class && + query == other.query && + filters == other.filters && + page == other.page && + get_ranking_info == other.get_ranking_info && + relevancy_strictness == other.relevancy_strictness && + facet_filters == other.facet_filters && + optional_filters == other.optional_filters && + numeric_filters == other.numeric_filters && + hits_per_page == other.hits_per_page && + around_lat_lng == other.around_lat_lng && + around_lat_lng_via_ip == other.around_lat_lng_via_ip && + around_radius == other.around_radius && + around_precision == other.around_precision && + minimum_around_radius == other.minimum_around_radius && + inside_bounding_box == other.inside_bounding_box && + inside_polygon == other.inside_polygon && + query_languages == other.query_languages && + natural_languages == other.natural_languages && + enable_rules == other.enable_rules && + rule_contexts == other.rule_contexts && + user_token == other.user_token && + click_analytics == other.click_analytics && + analytics == other.analytics && + analytics_tags == other.analytics_tags && + enable_ab_test == other.enable_ab_test && + enable_re_ranking == other.enable_re_ranking + end + + # @see the `==` method + # @param [Object] Object to be compared + def eql?(other) + self == other + end + + # Calculates hash code according to all attributes. + # @return [Integer] Hash code + def hash + [ + query, + filters, + page, + get_ranking_info, + relevancy_strictness, + facet_filters, + optional_filters, + numeric_filters, + hits_per_page, + around_lat_lng, + around_lat_lng_via_ip, + around_radius, + around_precision, + minimum_around_radius, + inside_bounding_box, + inside_polygon, + query_languages, + natural_languages, + enable_rules, + rule_contexts, + user_token, + click_analytics, + analytics, + analytics_tags, + enable_ab_test, + enable_re_ranking + ].hash + end + + # Builds the object from hash + # @param [Hash] attributes Model attributes in the form of hash + # @return [Object] Returns the model itself + def self.build_from_hash(attributes) + return nil unless attributes.is_a?(Hash) + attributes = attributes.transform_keys(&:to_sym) + transformed_hash = {} + types_mapping.each_pair do |key, type| + if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + transformed_hash[key.to_sym] = nil + elsif type =~ /\AArray<(.*)>/i + # check to ensure the input is an array given that the attribute + # is documented as an array but the input is not + if attributes[attribute_map[key]].is_a?(Array) + transformed_hash[key.to_sym] = attributes[attribute_map[key]].map { |v| + _deserialize(::Regexp.last_match(1), v) + } + end + elsif !attributes[attribute_map[key]].nil? + transformed_hash[key.to_sym] = _deserialize(type, attributes[attribute_map[key]]) + end + end + + new(transformed_hash) + end + + # Deserializes the data based on type + # @param string type Data type + # @param string value Value to be deserialized + # @return [Object] Deserialized data + def self._deserialize(type, value) + case type.to_sym + when :Time + Time.parse(value) + when :Date + Date.parse(value) + when :String + value.to_s + when :Integer + value.to_i + when :Float + value.to_f + when :Boolean + if value.to_s =~ /\A(true|t|yes|y|1)\z/i + true + else + false + end + + when :Object + # generic object (usually a Hash), return directly + value + when /\AArray<(?.+)>\z/ + inner_type = Regexp.last_match[:inner_type] + value.map { |v| _deserialize(inner_type, v) } + when /\AHash<(?.+?), (?.+)>\z/ + k_type = Regexp.last_match[:k_type] + v_type = Regexp.last_match[:v_type] + {}.tap do |hash| + value.each do |k, v| + hash[_deserialize(k_type, k)] = _deserialize(v_type, v) + end + end + # model + else + # models (e.g. Pet) or oneOf + klass = Algolia::Composition.const_get(type) + klass.respond_to?(:openapi_any_of) || klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass + .build_from_hash(value) + end + end + + # Returns the string representation of the object + # @return [String] String presentation of the object + def to_s + to_hash.to_s + end + + # to_body is an alias to to_hash (backward compatibility) + # @return [Hash] Returns the object in the form of hash + def to_body + to_hash + end + + def to_json(*_args) + to_hash.to_json + end + + # Returns the object in the form of hash + # @return [Hash] Returns the object in the form of hash + def to_hash + hash = {} + self.class.attribute_map.each_pair do |attr, param| + value = send(attr) + if value.nil? + is_nullable = self.class.openapi_nullable.include?(attr) + next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) + end + + hash[param] = _to_hash(value) + end + + hash + end + + # Outputs non-array value in the form of hash + # For object, use to_hash. Otherwise, just return the value + # @param [Object] value Any valid value + # @return [Hash] Returns the value in the form of hash + def _to_hash(value) + if value.is_a?(Array) + value.compact.map { |v| _to_hash(v) } + elsif value.is_a?(Hash) + {}.tap do |hash| + value.each { |k, v| hash[k] = _to_hash(v) } + end + elsif value.respond_to?(:to_hash) + value.to_hash + else + value + end + end + + end + + end +end diff --git a/lib/algolia/models/composition/personalization.rb b/lib/algolia/models/composition/personalization.rb new file mode 100644 index 00000000..a0b865aa --- /dev/null +++ b/lib/algolia/models/composition/personalization.rb @@ -0,0 +1,229 @@ +# frozen_string_literal: true + +# Code generated by OpenAPI Generator (https://openapi-generator.tech), manual changes will be lost - read more on https://github.com/algolia/api-clients-automation. DO NOT EDIT. + +require "date" +require "time" + +module Algolia + module Composition + class Personalization + # The score of the filters. + attr_accessor :filters_score + + # The score of the ranking. + attr_accessor :ranking_score + + # The score of the event. + attr_accessor :score + + # Attribute mapping from ruby-style variable name to JSON key. + def self.attribute_map + { + :filters_score => :filtersScore, + :ranking_score => :rankingScore, + :score => :score + } + end + + # Attribute type mapping. + def self.types_mapping + { + :filters_score => :"Integer", + :ranking_score => :"Integer", + :score => :"Integer" + } + end + + # List of attributes with nullable: true + def self.openapi_nullable + Set.new( + [] + ) + end + + # Initializes the object + # @param [Hash] attributes Model attributes in the form of hash + def initialize(attributes = {}) + if (!attributes.is_a?(Hash)) + raise( + ArgumentError, + "The input argument (attributes) must be a hash in `Algolia::Personalization` initialize method" + ) + end + + # check to see if the attribute exists and convert string to symbol for hash key + attributes = attributes.each_with_object({}) { |(k, v), h| + if (!self.class.attribute_map.key?(k.to_sym)) + raise( + ArgumentError, + "`#{k}` is not a valid attribute in `Algolia::Personalization`. Please check the name to make sure it's valid. List of attributes: " + + self.class.attribute_map.keys.inspect + ) + end + + h[k.to_sym] = v + } + + if attributes.key?(:filters_score) + self.filters_score = attributes[:filters_score] + end + + if attributes.key?(:ranking_score) + self.ranking_score = attributes[:ranking_score] + end + + if attributes.key?(:score) + self.score = attributes[:score] + end + end + + # Checks equality by comparing each attribute. + # @param [Object] Object to be compared + def ==(other) + return true if self.equal?(other) + self.class == other.class && + filters_score == other.filters_score && + ranking_score == other.ranking_score && + score == other.score + end + + # @see the `==` method + # @param [Object] Object to be compared + def eql?(other) + self == other + end + + # Calculates hash code according to all attributes. + # @return [Integer] Hash code + def hash + [filters_score, ranking_score, score].hash + end + + # Builds the object from hash + # @param [Hash] attributes Model attributes in the form of hash + # @return [Object] Returns the model itself + def self.build_from_hash(attributes) + return nil unless attributes.is_a?(Hash) + attributes = attributes.transform_keys(&:to_sym) + transformed_hash = {} + types_mapping.each_pair do |key, type| + if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + transformed_hash[key.to_sym] = nil + elsif type =~ /\AArray<(.*)>/i + # check to ensure the input is an array given that the attribute + # is documented as an array but the input is not + if attributes[attribute_map[key]].is_a?(Array) + transformed_hash[key.to_sym] = attributes[attribute_map[key]].map { |v| + _deserialize(::Regexp.last_match(1), v) + } + end + elsif !attributes[attribute_map[key]].nil? + transformed_hash[key.to_sym] = _deserialize(type, attributes[attribute_map[key]]) + end + end + + new(transformed_hash) + end + + # Deserializes the data based on type + # @param string type Data type + # @param string value Value to be deserialized + # @return [Object] Deserialized data + def self._deserialize(type, value) + case type.to_sym + when :Time + Time.parse(value) + when :Date + Date.parse(value) + when :String + value.to_s + when :Integer + value.to_i + when :Float + value.to_f + when :Boolean + if value.to_s =~ /\A(true|t|yes|y|1)\z/i + true + else + false + end + + when :Object + # generic object (usually a Hash), return directly + value + when /\AArray<(?.+)>\z/ + inner_type = Regexp.last_match[:inner_type] + value.map { |v| _deserialize(inner_type, v) } + when /\AHash<(?.+?), (?.+)>\z/ + k_type = Regexp.last_match[:k_type] + v_type = Regexp.last_match[:v_type] + {}.tap do |hash| + value.each do |k, v| + hash[_deserialize(k_type, k)] = _deserialize(v_type, v) + end + end + # model + else + # models (e.g. Pet) or oneOf + klass = Algolia::Composition.const_get(type) + klass.respond_to?(:openapi_any_of) || klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass + .build_from_hash(value) + end + end + + # Returns the string representation of the object + # @return [String] String presentation of the object + def to_s + to_hash.to_s + end + + # to_body is an alias to to_hash (backward compatibility) + # @return [Hash] Returns the object in the form of hash + def to_body + to_hash + end + + def to_json(*_args) + to_hash.to_json + end + + # Returns the object in the form of hash + # @return [Hash] Returns the object in the form of hash + def to_hash + hash = {} + self.class.attribute_map.each_pair do |attr, param| + value = send(attr) + if value.nil? + is_nullable = self.class.openapi_nullable.include?(attr) + next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) + end + + hash[param] = _to_hash(value) + end + + hash + end + + # Outputs non-array value in the form of hash + # For object, use to_hash. Otherwise, just return the value + # @param [Object] value Any valid value + # @return [Hash] Returns the value in the form of hash + def _to_hash(value) + if value.is_a?(Array) + value.compact.map { |v| _to_hash(v) } + elsif value.is_a?(Hash) + {}.tap do |hash| + value.each { |k, v| hash[k] = _to_hash(v) } + end + elsif value.respond_to?(:to_hash) + value.to_hash + else + value + end + end + + end + + end +end diff --git a/lib/algolia/models/composition/range.rb b/lib/algolia/models/composition/range.rb new file mode 100644 index 00000000..a40b0d9f --- /dev/null +++ b/lib/algolia/models/composition/range.rb @@ -0,0 +1,217 @@ +# frozen_string_literal: true + +# Code generated by OpenAPI Generator (https://openapi-generator.tech), manual changes will be lost - read more on https://github.com/algolia/api-clients-automation. DO NOT EDIT. + +require "date" +require "time" + +module Algolia + module Composition + # Range object with lower and upper values in meters to define custom ranges. + class Range + # Lower boundary of a range in meters. The Geo ranking criterion considers all records within the range to be equal. + attr_accessor :from + + # Upper boundary of a range in meters. The Geo ranking criterion considers all records within the range to be equal. + attr_accessor :value + + # Attribute mapping from ruby-style variable name to JSON key. + def self.attribute_map + { + :from => :from, + :value => :value + } + end + + # Attribute type mapping. + def self.types_mapping + { + :from => :"Integer", + :value => :"Integer" + } + end + + # List of attributes with nullable: true + def self.openapi_nullable + Set.new( + [] + ) + end + + # Initializes the object + # @param [Hash] attributes Model attributes in the form of hash + def initialize(attributes = {}) + if (!attributes.is_a?(Hash)) + raise ArgumentError, "The input argument (attributes) must be a hash in `Algolia::Range` initialize method" + end + + # check to see if the attribute exists and convert string to symbol for hash key + attributes = attributes.each_with_object({}) { |(k, v), h| + if (!self.class.attribute_map.key?(k.to_sym)) + raise( + ArgumentError, + "`#{k}` is not a valid attribute in `Algolia::Range`. Please check the name to make sure it's valid. List of attributes: " + + self.class.attribute_map.keys.inspect + ) + end + + h[k.to_sym] = v + } + + if attributes.key?(:from) + self.from = attributes[:from] + end + + if attributes.key?(:value) + self.value = attributes[:value] + end + end + + # Checks equality by comparing each attribute. + # @param [Object] Object to be compared + def ==(other) + return true if self.equal?(other) + self.class == other.class && + from == other.from && + value == other.value + end + + # @see the `==` method + # @param [Object] Object to be compared + def eql?(other) + self == other + end + + # Calculates hash code according to all attributes. + # @return [Integer] Hash code + def hash + [from, value].hash + end + + # Builds the object from hash + # @param [Hash] attributes Model attributes in the form of hash + # @return [Object] Returns the model itself + def self.build_from_hash(attributes) + return nil unless attributes.is_a?(Hash) + attributes = attributes.transform_keys(&:to_sym) + transformed_hash = {} + types_mapping.each_pair do |key, type| + if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + transformed_hash[key.to_sym] = nil + elsif type =~ /\AArray<(.*)>/i + # check to ensure the input is an array given that the attribute + # is documented as an array but the input is not + if attributes[attribute_map[key]].is_a?(Array) + transformed_hash[key.to_sym] = attributes[attribute_map[key]].map { |v| + _deserialize(::Regexp.last_match(1), v) + } + end + elsif !attributes[attribute_map[key]].nil? + transformed_hash[key.to_sym] = _deserialize(type, attributes[attribute_map[key]]) + end + end + + new(transformed_hash) + end + + # Deserializes the data based on type + # @param string type Data type + # @param string value Value to be deserialized + # @return [Object] Deserialized data + def self._deserialize(type, value) + case type.to_sym + when :Time + Time.parse(value) + when :Date + Date.parse(value) + when :String + value.to_s + when :Integer + value.to_i + when :Float + value.to_f + when :Boolean + if value.to_s =~ /\A(true|t|yes|y|1)\z/i + true + else + false + end + + when :Object + # generic object (usually a Hash), return directly + value + when /\AArray<(?.+)>\z/ + inner_type = Regexp.last_match[:inner_type] + value.map { |v| _deserialize(inner_type, v) } + when /\AHash<(?.+?), (?.+)>\z/ + k_type = Regexp.last_match[:k_type] + v_type = Regexp.last_match[:v_type] + {}.tap do |hash| + value.each do |k, v| + hash[_deserialize(k_type, k)] = _deserialize(v_type, v) + end + end + # model + else + # models (e.g. Pet) or oneOf + klass = Algolia::Composition.const_get(type) + klass.respond_to?(:openapi_any_of) || klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass + .build_from_hash(value) + end + end + + # Returns the string representation of the object + # @return [String] String presentation of the object + def to_s + to_hash.to_s + end + + # to_body is an alias to to_hash (backward compatibility) + # @return [Hash] Returns the object in the form of hash + def to_body + to_hash + end + + def to_json(*_args) + to_hash.to_json + end + + # Returns the object in the form of hash + # @return [Hash] Returns the object in the form of hash + def to_hash + hash = {} + self.class.attribute_map.each_pair do |attr, param| + value = send(attr) + if value.nil? + is_nullable = self.class.openapi_nullable.include?(attr) + next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) + end + + hash[param] = _to_hash(value) + end + + hash + end + + # Outputs non-array value in the form of hash + # For object, use to_hash. Otherwise, just return the value + # @param [Object] value Any valid value + # @return [Hash] Returns the value in the form of hash + def _to_hash(value) + if value.is_a?(Array) + value.compact.map { |v| _to_hash(v) } + elsif value.is_a?(Hash) + {}.tap do |hash| + value.each { |k, v| hash[k] = _to_hash(v) } + end + elsif value.respond_to?(:to_hash) + value.to_hash + else + value + end + end + + end + + end +end diff --git a/lib/algolia/models/composition/redirect.rb b/lib/algolia/models/composition/redirect.rb new file mode 100644 index 00000000..15b58961 --- /dev/null +++ b/lib/algolia/models/composition/redirect.rb @@ -0,0 +1,208 @@ +# frozen_string_literal: true + +# Code generated by OpenAPI Generator (https://openapi-generator.tech), manual changes will be lost - read more on https://github.com/algolia/api-clients-automation. DO NOT EDIT. + +require "date" +require "time" + +module Algolia + module Composition + # [Redirect results to a URL](https://www.algolia.com/doc/guides/managing-results/rules/merchandising-and-promoting/how-to/redirects/), this this parameter is for internal use only. + class Redirect + attr_accessor :index + + # Attribute mapping from ruby-style variable name to JSON key. + def self.attribute_map + { + :index => :index + } + end + + # Attribute type mapping. + def self.types_mapping + { + :index => :"Array" + } + end + + # List of attributes with nullable: true + def self.openapi_nullable + Set.new( + [] + ) + end + + # Initializes the object + # @param [Hash] attributes Model attributes in the form of hash + def initialize(attributes = {}) + if (!attributes.is_a?(Hash)) + raise ArgumentError, "The input argument (attributes) must be a hash in `Algolia::Redirect` initialize method" + end + + # check to see if the attribute exists and convert string to symbol for hash key + attributes = attributes.each_with_object({}) { |(k, v), h| + if (!self.class.attribute_map.key?(k.to_sym)) + raise( + ArgumentError, + "`#{k}` is not a valid attribute in `Algolia::Redirect`. Please check the name to make sure it's valid. List of attributes: " + + self.class.attribute_map.keys.inspect + ) + end + + h[k.to_sym] = v + } + + if attributes.key?(:index) + if (value = attributes[:index]).is_a?(Array) + self.index = value + end + end + end + + # Checks equality by comparing each attribute. + # @param [Object] Object to be compared + def ==(other) + return true if self.equal?(other) + self.class == other.class && + index == other.index + end + + # @see the `==` method + # @param [Object] Object to be compared + def eql?(other) + self == other + end + + # Calculates hash code according to all attributes. + # @return [Integer] Hash code + def hash + [index].hash + end + + # Builds the object from hash + # @param [Hash] attributes Model attributes in the form of hash + # @return [Object] Returns the model itself + def self.build_from_hash(attributes) + return nil unless attributes.is_a?(Hash) + attributes = attributes.transform_keys(&:to_sym) + transformed_hash = {} + types_mapping.each_pair do |key, type| + if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + transformed_hash[key.to_sym] = nil + elsif type =~ /\AArray<(.*)>/i + # check to ensure the input is an array given that the attribute + # is documented as an array but the input is not + if attributes[attribute_map[key]].is_a?(Array) + transformed_hash[key.to_sym] = attributes[attribute_map[key]].map { |v| + _deserialize(::Regexp.last_match(1), v) + } + end + elsif !attributes[attribute_map[key]].nil? + transformed_hash[key.to_sym] = _deserialize(type, attributes[attribute_map[key]]) + end + end + + new(transformed_hash) + end + + # Deserializes the data based on type + # @param string type Data type + # @param string value Value to be deserialized + # @return [Object] Deserialized data + def self._deserialize(type, value) + case type.to_sym + when :Time + Time.parse(value) + when :Date + Date.parse(value) + when :String + value.to_s + when :Integer + value.to_i + when :Float + value.to_f + when :Boolean + if value.to_s =~ /\A(true|t|yes|y|1)\z/i + true + else + false + end + + when :Object + # generic object (usually a Hash), return directly + value + when /\AArray<(?.+)>\z/ + inner_type = Regexp.last_match[:inner_type] + value.map { |v| _deserialize(inner_type, v) } + when /\AHash<(?.+?), (?.+)>\z/ + k_type = Regexp.last_match[:k_type] + v_type = Regexp.last_match[:v_type] + {}.tap do |hash| + value.each do |k, v| + hash[_deserialize(k_type, k)] = _deserialize(v_type, v) + end + end + # model + else + # models (e.g. Pet) or oneOf + klass = Algolia::Composition.const_get(type) + klass.respond_to?(:openapi_any_of) || klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass + .build_from_hash(value) + end + end + + # Returns the string representation of the object + # @return [String] String presentation of the object + def to_s + to_hash.to_s + end + + # to_body is an alias to to_hash (backward compatibility) + # @return [Hash] Returns the object in the form of hash + def to_body + to_hash + end + + def to_json(*_args) + to_hash.to_json + end + + # Returns the object in the form of hash + # @return [Hash] Returns the object in the form of hash + def to_hash + hash = {} + self.class.attribute_map.each_pair do |attr, param| + value = send(attr) + if value.nil? + is_nullable = self.class.openapi_nullable.include?(attr) + next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) + end + + hash[param] = _to_hash(value) + end + + hash + end + + # Outputs non-array value in the form of hash + # For object, use to_hash. Otherwise, just return the value + # @param [Object] value Any valid value + # @return [Hash] Returns the value in the form of hash + def _to_hash(value) + if value.is_a?(Array) + value.compact.map { |v| _to_hash(v) } + elsif value.is_a?(Hash) + {}.tap do |hash| + value.each { |k, v| hash[k] = _to_hash(v) } + end + elsif value.respond_to?(:to_hash) + value.to_hash + else + value + end + end + + end + + end +end diff --git a/lib/algolia/models/composition/redirect_rule_index_data.rb b/lib/algolia/models/composition/redirect_rule_index_data.rb new file mode 100644 index 00000000..461cefa8 --- /dev/null +++ b/lib/algolia/models/composition/redirect_rule_index_data.rb @@ -0,0 +1,211 @@ +# frozen_string_literal: true + +# Code generated by OpenAPI Generator (https://openapi-generator.tech), manual changes will be lost - read more on https://github.com/algolia/api-clients-automation. DO NOT EDIT. + +require "date" +require "time" + +module Algolia + module Composition + # Redirect rule data. + class RedirectRuleIndexData + attr_accessor :rule_object_id + + # Attribute mapping from ruby-style variable name to JSON key. + def self.attribute_map + { + :rule_object_id => :ruleObjectID + } + end + + # Attribute type mapping. + def self.types_mapping + { + :rule_object_id => :"String" + } + end + + # List of attributes with nullable: true + def self.openapi_nullable + Set.new( + [] + ) + end + + # Initializes the object + # @param [Hash] attributes Model attributes in the form of hash + def initialize(attributes = {}) + if (!attributes.is_a?(Hash)) + raise( + ArgumentError, + "The input argument (attributes) must be a hash in `Algolia::RedirectRuleIndexData` initialize method" + ) + end + + # check to see if the attribute exists and convert string to symbol for hash key + attributes = attributes.each_with_object({}) { |(k, v), h| + if (!self.class.attribute_map.key?(k.to_sym)) + raise( + ArgumentError, + "`#{k}` is not a valid attribute in `Algolia::RedirectRuleIndexData`. Please check the name to make sure it's valid. List of attributes: " + + self.class.attribute_map.keys.inspect + ) + end + + h[k.to_sym] = v + } + + if attributes.key?(:rule_object_id) + self.rule_object_id = attributes[:rule_object_id] + else + self.rule_object_id = nil + end + end + + # Checks equality by comparing each attribute. + # @param [Object] Object to be compared + def ==(other) + return true if self.equal?(other) + self.class == other.class && + rule_object_id == other.rule_object_id + end + + # @see the `==` method + # @param [Object] Object to be compared + def eql?(other) + self == other + end + + # Calculates hash code according to all attributes. + # @return [Integer] Hash code + def hash + [rule_object_id].hash + end + + # Builds the object from hash + # @param [Hash] attributes Model attributes in the form of hash + # @return [Object] Returns the model itself + def self.build_from_hash(attributes) + return nil unless attributes.is_a?(Hash) + attributes = attributes.transform_keys(&:to_sym) + transformed_hash = {} + types_mapping.each_pair do |key, type| + if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + transformed_hash[key.to_sym] = nil + elsif type =~ /\AArray<(.*)>/i + # check to ensure the input is an array given that the attribute + # is documented as an array but the input is not + if attributes[attribute_map[key]].is_a?(Array) + transformed_hash[key.to_sym] = attributes[attribute_map[key]].map { |v| + _deserialize(::Regexp.last_match(1), v) + } + end + elsif !attributes[attribute_map[key]].nil? + transformed_hash[key.to_sym] = _deserialize(type, attributes[attribute_map[key]]) + end + end + + new(transformed_hash) + end + + # Deserializes the data based on type + # @param string type Data type + # @param string value Value to be deserialized + # @return [Object] Deserialized data + def self._deserialize(type, value) + case type.to_sym + when :Time + Time.parse(value) + when :Date + Date.parse(value) + when :String + value.to_s + when :Integer + value.to_i + when :Float + value.to_f + when :Boolean + if value.to_s =~ /\A(true|t|yes|y|1)\z/i + true + else + false + end + + when :Object + # generic object (usually a Hash), return directly + value + when /\AArray<(?.+)>\z/ + inner_type = Regexp.last_match[:inner_type] + value.map { |v| _deserialize(inner_type, v) } + when /\AHash<(?.+?), (?.+)>\z/ + k_type = Regexp.last_match[:k_type] + v_type = Regexp.last_match[:v_type] + {}.tap do |hash| + value.each do |k, v| + hash[_deserialize(k_type, k)] = _deserialize(v_type, v) + end + end + # model + else + # models (e.g. Pet) or oneOf + klass = Algolia::Composition.const_get(type) + klass.respond_to?(:openapi_any_of) || klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass + .build_from_hash(value) + end + end + + # Returns the string representation of the object + # @return [String] String presentation of the object + def to_s + to_hash.to_s + end + + # to_body is an alias to to_hash (backward compatibility) + # @return [Hash] Returns the object in the form of hash + def to_body + to_hash + end + + def to_json(*_args) + to_hash.to_json + end + + # Returns the object in the form of hash + # @return [Hash] Returns the object in the form of hash + def to_hash + hash = {} + self.class.attribute_map.each_pair do |attr, param| + value = send(attr) + if value.nil? + is_nullable = self.class.openapi_nullable.include?(attr) + next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) + end + + hash[param] = _to_hash(value) + end + + hash + end + + # Outputs non-array value in the form of hash + # For object, use to_hash. Otherwise, just return the value + # @param [Object] value Any valid value + # @return [Hash] Returns the value in the form of hash + def _to_hash(value) + if value.is_a?(Array) + value.compact.map { |v| _to_hash(v) } + elsif value.is_a?(Hash) + {}.tap do |hash| + value.each { |k, v| hash[k] = _to_hash(v) } + end + elsif value.respond_to?(:to_hash) + value.to_hash + else + value + end + end + + end + + end +end diff --git a/lib/algolia/models/composition/redirect_rule_index_metadata.rb b/lib/algolia/models/composition/redirect_rule_index_metadata.rb new file mode 100644 index 00000000..ea9183d8 --- /dev/null +++ b/lib/algolia/models/composition/redirect_rule_index_metadata.rb @@ -0,0 +1,258 @@ +# frozen_string_literal: true + +# Code generated by OpenAPI Generator (https://openapi-generator.tech), manual changes will be lost - read more on https://github.com/algolia/api-clients-automation. DO NOT EDIT. + +require "date" +require "time" + +module Algolia + module Composition + class RedirectRuleIndexMetadata + # Source index for the redirect rule. + attr_accessor :source + + # Destination index for the redirect rule. + attr_accessor :dest + + # Reason for the redirect rule. + attr_accessor :reason + + # Redirect rule status. + attr_accessor :succeed + + attr_accessor :data + + # Attribute mapping from ruby-style variable name to JSON key. + def self.attribute_map + { + :source => :source, + :dest => :dest, + :reason => :reason, + :succeed => :succeed, + :data => :data + } + end + + # Attribute type mapping. + def self.types_mapping + { + :source => :"String", + :dest => :"String", + :reason => :"String", + :succeed => :"Boolean", + :data => :"RedirectRuleIndexData" + } + end + + # List of attributes with nullable: true + def self.openapi_nullable + Set.new( + [] + ) + end + + # Initializes the object + # @param [Hash] attributes Model attributes in the form of hash + def initialize(attributes = {}) + if (!attributes.is_a?(Hash)) + raise( + ArgumentError, + "The input argument (attributes) must be a hash in `Algolia::RedirectRuleIndexMetadata` initialize method" + ) + end + + # check to see if the attribute exists and convert string to symbol for hash key + attributes = attributes.each_with_object({}) { |(k, v), h| + if (!self.class.attribute_map.key?(k.to_sym)) + raise( + ArgumentError, + "`#{k}` is not a valid attribute in `Algolia::RedirectRuleIndexMetadata`. Please check the name to make sure it's valid. List of attributes: " + + self.class.attribute_map.keys.inspect + ) + end + + h[k.to_sym] = v + } + + if attributes.key?(:source) + self.source = attributes[:source] + else + self.source = nil + end + + if attributes.key?(:dest) + self.dest = attributes[:dest] + else + self.dest = nil + end + + if attributes.key?(:reason) + self.reason = attributes[:reason] + else + self.reason = nil + end + + if attributes.key?(:succeed) + self.succeed = attributes[:succeed] + else + self.succeed = nil + end + + if attributes.key?(:data) + self.data = attributes[:data] + else + self.data = nil + end + end + + # Checks equality by comparing each attribute. + # @param [Object] Object to be compared + def ==(other) + return true if self.equal?(other) + self.class == other.class && + source == other.source && + dest == other.dest && + reason == other.reason && + succeed == other.succeed && + data == other.data + end + + # @see the `==` method + # @param [Object] Object to be compared + def eql?(other) + self == other + end + + # Calculates hash code according to all attributes. + # @return [Integer] Hash code + def hash + [source, dest, reason, succeed, data].hash + end + + # Builds the object from hash + # @param [Hash] attributes Model attributes in the form of hash + # @return [Object] Returns the model itself + def self.build_from_hash(attributes) + return nil unless attributes.is_a?(Hash) + attributes = attributes.transform_keys(&:to_sym) + transformed_hash = {} + types_mapping.each_pair do |key, type| + if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + transformed_hash[key.to_sym] = nil + elsif type =~ /\AArray<(.*)>/i + # check to ensure the input is an array given that the attribute + # is documented as an array but the input is not + if attributes[attribute_map[key]].is_a?(Array) + transformed_hash[key.to_sym] = attributes[attribute_map[key]].map { |v| + _deserialize(::Regexp.last_match(1), v) + } + end + elsif !attributes[attribute_map[key]].nil? + transformed_hash[key.to_sym] = _deserialize(type, attributes[attribute_map[key]]) + end + end + + new(transformed_hash) + end + + # Deserializes the data based on type + # @param string type Data type + # @param string value Value to be deserialized + # @return [Object] Deserialized data + def self._deserialize(type, value) + case type.to_sym + when :Time + Time.parse(value) + when :Date + Date.parse(value) + when :String + value.to_s + when :Integer + value.to_i + when :Float + value.to_f + when :Boolean + if value.to_s =~ /\A(true|t|yes|y|1)\z/i + true + else + false + end + + when :Object + # generic object (usually a Hash), return directly + value + when /\AArray<(?.+)>\z/ + inner_type = Regexp.last_match[:inner_type] + value.map { |v| _deserialize(inner_type, v) } + when /\AHash<(?.+?), (?.+)>\z/ + k_type = Regexp.last_match[:k_type] + v_type = Regexp.last_match[:v_type] + {}.tap do |hash| + value.each do |k, v| + hash[_deserialize(k_type, k)] = _deserialize(v_type, v) + end + end + # model + else + # models (e.g. Pet) or oneOf + klass = Algolia::Composition.const_get(type) + klass.respond_to?(:openapi_any_of) || klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass + .build_from_hash(value) + end + end + + # Returns the string representation of the object + # @return [String] String presentation of the object + def to_s + to_hash.to_s + end + + # to_body is an alias to to_hash (backward compatibility) + # @return [Hash] Returns the object in the form of hash + def to_body + to_hash + end + + def to_json(*_args) + to_hash.to_json + end + + # Returns the object in the form of hash + # @return [Hash] Returns the object in the form of hash + def to_hash + hash = {} + self.class.attribute_map.each_pair do |attr, param| + value = send(attr) + if value.nil? + is_nullable = self.class.openapi_nullable.include?(attr) + next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) + end + + hash[param] = _to_hash(value) + end + + hash + end + + # Outputs non-array value in the form of hash + # For object, use to_hash. Otherwise, just return the value + # @param [Object] value Any valid value + # @return [Hash] Returns the value in the form of hash + def _to_hash(value) + if value.is_a?(Array) + value.compact.map { |v| _to_hash(v) } + elsif value.is_a?(Hash) + {}.tap do |hash| + value.each { |k, v| hash[k] = _to_hash(v) } + end + elsif value.respond_to?(:to_hash) + value.to_hash + else + value + end + end + + end + + end +end diff --git a/lib/algolia/models/composition/redirect_url.rb b/lib/algolia/models/composition/redirect_url.rb new file mode 100644 index 00000000..ca0a54cc --- /dev/null +++ b/lib/algolia/models/composition/redirect_url.rb @@ -0,0 +1,209 @@ +# frozen_string_literal: true + +# Code generated by OpenAPI Generator (https://openapi-generator.tech), manual changes will be lost - read more on https://github.com/algolia/api-clients-automation. DO NOT EDIT. + +require "date" +require "time" + +module Algolia + module Composition + # The redirect rule container. + class RedirectURL + attr_accessor :url + + # Attribute mapping from ruby-style variable name to JSON key. + def self.attribute_map + { + :url => :url + } + end + + # Attribute type mapping. + def self.types_mapping + { + :url => :"String" + } + end + + # List of attributes with nullable: true + def self.openapi_nullable + Set.new( + [] + ) + end + + # Initializes the object + # @param [Hash] attributes Model attributes in the form of hash + def initialize(attributes = {}) + if (!attributes.is_a?(Hash)) + raise( + ArgumentError, + "The input argument (attributes) must be a hash in `Algolia::RedirectURL` initialize method" + ) + end + + # check to see if the attribute exists and convert string to symbol for hash key + attributes = attributes.each_with_object({}) { |(k, v), h| + if (!self.class.attribute_map.key?(k.to_sym)) + raise( + ArgumentError, + "`#{k}` is not a valid attribute in `Algolia::RedirectURL`. Please check the name to make sure it's valid. List of attributes: " + + self.class.attribute_map.keys.inspect + ) + end + + h[k.to_sym] = v + } + + if attributes.key?(:url) + self.url = attributes[:url] + end + end + + # Checks equality by comparing each attribute. + # @param [Object] Object to be compared + def ==(other) + return true if self.equal?(other) + self.class == other.class && + url == other.url + end + + # @see the `==` method + # @param [Object] Object to be compared + def eql?(other) + self == other + end + + # Calculates hash code according to all attributes. + # @return [Integer] Hash code + def hash + [url].hash + end + + # Builds the object from hash + # @param [Hash] attributes Model attributes in the form of hash + # @return [Object] Returns the model itself + def self.build_from_hash(attributes) + return nil unless attributes.is_a?(Hash) + attributes = attributes.transform_keys(&:to_sym) + transformed_hash = {} + types_mapping.each_pair do |key, type| + if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + transformed_hash[key.to_sym] = nil + elsif type =~ /\AArray<(.*)>/i + # check to ensure the input is an array given that the attribute + # is documented as an array but the input is not + if attributes[attribute_map[key]].is_a?(Array) + transformed_hash[key.to_sym] = attributes[attribute_map[key]].map { |v| + _deserialize(::Regexp.last_match(1), v) + } + end + elsif !attributes[attribute_map[key]].nil? + transformed_hash[key.to_sym] = _deserialize(type, attributes[attribute_map[key]]) + end + end + + new(transformed_hash) + end + + # Deserializes the data based on type + # @param string type Data type + # @param string value Value to be deserialized + # @return [Object] Deserialized data + def self._deserialize(type, value) + case type.to_sym + when :Time + Time.parse(value) + when :Date + Date.parse(value) + when :String + value.to_s + when :Integer + value.to_i + when :Float + value.to_f + when :Boolean + if value.to_s =~ /\A(true|t|yes|y|1)\z/i + true + else + false + end + + when :Object + # generic object (usually a Hash), return directly + value + when /\AArray<(?.+)>\z/ + inner_type = Regexp.last_match[:inner_type] + value.map { |v| _deserialize(inner_type, v) } + when /\AHash<(?.+?), (?.+)>\z/ + k_type = Regexp.last_match[:k_type] + v_type = Regexp.last_match[:v_type] + {}.tap do |hash| + value.each do |k, v| + hash[_deserialize(k_type, k)] = _deserialize(v_type, v) + end + end + # model + else + # models (e.g. Pet) or oneOf + klass = Algolia::Composition.const_get(type) + klass.respond_to?(:openapi_any_of) || klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass + .build_from_hash(value) + end + end + + # Returns the string representation of the object + # @return [String] String presentation of the object + def to_s + to_hash.to_s + end + + # to_body is an alias to to_hash (backward compatibility) + # @return [Hash] Returns the object in the form of hash + def to_body + to_hash + end + + def to_json(*_args) + to_hash.to_json + end + + # Returns the object in the form of hash + # @return [Hash] Returns the object in the form of hash + def to_hash + hash = {} + self.class.attribute_map.each_pair do |attr, param| + value = send(attr) + if value.nil? + is_nullable = self.class.openapi_nullable.include?(attr) + next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) + end + + hash[param] = _to_hash(value) + end + + hash + end + + # Outputs non-array value in the form of hash + # For object, use to_hash. Otherwise, just return the value + # @param [Object] value Any valid value + # @return [Hash] Returns the value in the form of hash + def _to_hash(value) + if value.is_a?(Array) + value.compact.map { |v| _to_hash(v) } + elsif value.is_a?(Hash) + {}.tap do |hash| + value.each { |k, v| hash[k] = _to_hash(v) } + end + elsif value.respond_to?(:to_hash) + value.to_hash + else + value + end + end + + end + + end +end diff --git a/lib/algolia/models/composition/rendering_content.rb b/lib/algolia/models/composition/rendering_content.rb new file mode 100644 index 00000000..5cca0663 --- /dev/null +++ b/lib/algolia/models/composition/rendering_content.rb @@ -0,0 +1,227 @@ +# frozen_string_literal: true + +# Code generated by OpenAPI Generator (https://openapi-generator.tech), manual changes will be lost - read more on https://github.com/algolia/api-clients-automation. DO NOT EDIT. + +require "date" +require "time" + +module Algolia + module Composition + # Extra data that can be used in the search UI. You can use this to control aspects of your search UI, such as the order of facet names and values without changing your frontend code. + class RenderingContent + attr_accessor :facet_ordering + + attr_accessor :redirect + + attr_accessor :widgets + + # Attribute mapping from ruby-style variable name to JSON key. + def self.attribute_map + { + :facet_ordering => :facetOrdering, + :redirect => :redirect, + :widgets => :widgets + } + end + + # Attribute type mapping. + def self.types_mapping + { + :facet_ordering => :"FacetOrdering", + :redirect => :"RedirectURL", + :widgets => :"Widgets" + } + end + + # List of attributes with nullable: true + def self.openapi_nullable + Set.new( + [] + ) + end + + # Initializes the object + # @param [Hash] attributes Model attributes in the form of hash + def initialize(attributes = {}) + if (!attributes.is_a?(Hash)) + raise( + ArgumentError, + "The input argument (attributes) must be a hash in `Algolia::RenderingContent` initialize method" + ) + end + + # check to see if the attribute exists and convert string to symbol for hash key + attributes = attributes.each_with_object({}) { |(k, v), h| + if (!self.class.attribute_map.key?(k.to_sym)) + raise( + ArgumentError, + "`#{k}` is not a valid attribute in `Algolia::RenderingContent`. Please check the name to make sure it's valid. List of attributes: " + + self.class.attribute_map.keys.inspect + ) + end + + h[k.to_sym] = v + } + + if attributes.key?(:facet_ordering) + self.facet_ordering = attributes[:facet_ordering] + end + + if attributes.key?(:redirect) + self.redirect = attributes[:redirect] + end + + if attributes.key?(:widgets) + self.widgets = attributes[:widgets] + end + end + + # Checks equality by comparing each attribute. + # @param [Object] Object to be compared + def ==(other) + return true if self.equal?(other) + self.class == other.class && + facet_ordering == other.facet_ordering && + redirect == other.redirect && + widgets == other.widgets + end + + # @see the `==` method + # @param [Object] Object to be compared + def eql?(other) + self == other + end + + # Calculates hash code according to all attributes. + # @return [Integer] Hash code + def hash + [facet_ordering, redirect, widgets].hash + end + + # Builds the object from hash + # @param [Hash] attributes Model attributes in the form of hash + # @return [Object] Returns the model itself + def self.build_from_hash(attributes) + return nil unless attributes.is_a?(Hash) + attributes = attributes.transform_keys(&:to_sym) + transformed_hash = {} + types_mapping.each_pair do |key, type| + if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + transformed_hash[key.to_sym] = nil + elsif type =~ /\AArray<(.*)>/i + # check to ensure the input is an array given that the attribute + # is documented as an array but the input is not + if attributes[attribute_map[key]].is_a?(Array) + transformed_hash[key.to_sym] = attributes[attribute_map[key]].map { |v| + _deserialize(::Regexp.last_match(1), v) + } + end + elsif !attributes[attribute_map[key]].nil? + transformed_hash[key.to_sym] = _deserialize(type, attributes[attribute_map[key]]) + end + end + + new(transformed_hash) + end + + # Deserializes the data based on type + # @param string type Data type + # @param string value Value to be deserialized + # @return [Object] Deserialized data + def self._deserialize(type, value) + case type.to_sym + when :Time + Time.parse(value) + when :Date + Date.parse(value) + when :String + value.to_s + when :Integer + value.to_i + when :Float + value.to_f + when :Boolean + if value.to_s =~ /\A(true|t|yes|y|1)\z/i + true + else + false + end + + when :Object + # generic object (usually a Hash), return directly + value + when /\AArray<(?.+)>\z/ + inner_type = Regexp.last_match[:inner_type] + value.map { |v| _deserialize(inner_type, v) } + when /\AHash<(?.+?), (?.+)>\z/ + k_type = Regexp.last_match[:k_type] + v_type = Regexp.last_match[:v_type] + {}.tap do |hash| + value.each do |k, v| + hash[_deserialize(k_type, k)] = _deserialize(v_type, v) + end + end + # model + else + # models (e.g. Pet) or oneOf + klass = Algolia::Composition.const_get(type) + klass.respond_to?(:openapi_any_of) || klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass + .build_from_hash(value) + end + end + + # Returns the string representation of the object + # @return [String] String presentation of the object + def to_s + to_hash.to_s + end + + # to_body is an alias to to_hash (backward compatibility) + # @return [Hash] Returns the object in the form of hash + def to_body + to_hash + end + + def to_json(*_args) + to_hash.to_json + end + + # Returns the object in the form of hash + # @return [Hash] Returns the object in the form of hash + def to_hash + hash = {} + self.class.attribute_map.each_pair do |attr, param| + value = send(attr) + if value.nil? + is_nullable = self.class.openapi_nullable.include?(attr) + next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) + end + + hash[param] = _to_hash(value) + end + + hash + end + + # Outputs non-array value in the form of hash + # For object, use to_hash. Otherwise, just return the value + # @param [Object] value Any valid value + # @return [Hash] Returns the value in the form of hash + def _to_hash(value) + if value.is_a?(Array) + value.compact.map { |v| _to_hash(v) } + elsif value.is_a?(Hash) + {}.tap do |hash| + value.each { |k, v| hash[k] = _to_hash(v) } + end + elsif value.respond_to?(:to_hash) + value.to_hash + else + value + end + end + + end + + end +end diff --git a/lib/algolia/models/composition/request_body.rb b/lib/algolia/models/composition/request_body.rb new file mode 100644 index 00000000..e614d38e --- /dev/null +++ b/lib/algolia/models/composition/request_body.rb @@ -0,0 +1,208 @@ +# frozen_string_literal: true + +# Code generated by OpenAPI Generator (https://openapi-generator.tech), manual changes will be lost - read more on https://github.com/algolia/api-clients-automation. DO NOT EDIT. + +require "date" +require "time" + +module Algolia + module Composition + class RequestBody + attr_accessor :params + + # Attribute mapping from ruby-style variable name to JSON key. + def self.attribute_map + { + :params => :params + } + end + + # Attribute type mapping. + def self.types_mapping + { + :params => :"Params" + } + end + + # List of attributes with nullable: true + def self.openapi_nullable + Set.new( + [] + ) + end + + # Initializes the object + # @param [Hash] attributes Model attributes in the form of hash + def initialize(attributes = {}) + if (!attributes.is_a?(Hash)) + raise( + ArgumentError, + "The input argument (attributes) must be a hash in `Algolia::RequestBody` initialize method" + ) + end + + # check to see if the attribute exists and convert string to symbol for hash key + attributes = attributes.each_with_object({}) { |(k, v), h| + if (!self.class.attribute_map.key?(k.to_sym)) + raise( + ArgumentError, + "`#{k}` is not a valid attribute in `Algolia::RequestBody`. Please check the name to make sure it's valid. List of attributes: " + + self.class.attribute_map.keys.inspect + ) + end + + h[k.to_sym] = v + } + + if attributes.key?(:params) + self.params = attributes[:params] + end + end + + # Checks equality by comparing each attribute. + # @param [Object] Object to be compared + def ==(other) + return true if self.equal?(other) + self.class == other.class && + params == other.params + end + + # @see the `==` method + # @param [Object] Object to be compared + def eql?(other) + self == other + end + + # Calculates hash code according to all attributes. + # @return [Integer] Hash code + def hash + [params].hash + end + + # Builds the object from hash + # @param [Hash] attributes Model attributes in the form of hash + # @return [Object] Returns the model itself + def self.build_from_hash(attributes) + return nil unless attributes.is_a?(Hash) + attributes = attributes.transform_keys(&:to_sym) + transformed_hash = {} + types_mapping.each_pair do |key, type| + if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + transformed_hash[key.to_sym] = nil + elsif type =~ /\AArray<(.*)>/i + # check to ensure the input is an array given that the attribute + # is documented as an array but the input is not + if attributes[attribute_map[key]].is_a?(Array) + transformed_hash[key.to_sym] = attributes[attribute_map[key]].map { |v| + _deserialize(::Regexp.last_match(1), v) + } + end + elsif !attributes[attribute_map[key]].nil? + transformed_hash[key.to_sym] = _deserialize(type, attributes[attribute_map[key]]) + end + end + + new(transformed_hash) + end + + # Deserializes the data based on type + # @param string type Data type + # @param string value Value to be deserialized + # @return [Object] Deserialized data + def self._deserialize(type, value) + case type.to_sym + when :Time + Time.parse(value) + when :Date + Date.parse(value) + when :String + value.to_s + when :Integer + value.to_i + when :Float + value.to_f + when :Boolean + if value.to_s =~ /\A(true|t|yes|y|1)\z/i + true + else + false + end + + when :Object + # generic object (usually a Hash), return directly + value + when /\AArray<(?.+)>\z/ + inner_type = Regexp.last_match[:inner_type] + value.map { |v| _deserialize(inner_type, v) } + when /\AHash<(?.+?), (?.+)>\z/ + k_type = Regexp.last_match[:k_type] + v_type = Regexp.last_match[:v_type] + {}.tap do |hash| + value.each do |k, v| + hash[_deserialize(k_type, k)] = _deserialize(v_type, v) + end + end + # model + else + # models (e.g. Pet) or oneOf + klass = Algolia::Composition.const_get(type) + klass.respond_to?(:openapi_any_of) || klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass + .build_from_hash(value) + end + end + + # Returns the string representation of the object + # @return [String] String presentation of the object + def to_s + to_hash.to_s + end + + # to_body is an alias to to_hash (backward compatibility) + # @return [Hash] Returns the object in the form of hash + def to_body + to_hash + end + + def to_json(*_args) + to_hash.to_json + end + + # Returns the object in the form of hash + # @return [Hash] Returns the object in the form of hash + def to_hash + hash = {} + self.class.attribute_map.each_pair do |attr, param| + value = send(attr) + if value.nil? + is_nullable = self.class.openapi_nullable.include?(attr) + next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) + end + + hash[param] = _to_hash(value) + end + + hash + end + + # Outputs non-array value in the form of hash + # For object, use to_hash. Otherwise, just return the value + # @param [Object] value Any valid value + # @return [Hash] Returns the value in the form of hash + def _to_hash(value) + if value.is_a?(Array) + value.compact.map { |v| _to_hash(v) } + elsif value.is_a?(Hash) + {}.tap do |hash| + value.each { |k, v| hash[k] = _to_hash(v) } + end + elsif value.respond_to?(:to_hash) + value.to_hash + else + value + end + end + + end + + end +end diff --git a/lib/algolia/models/composition/results_composition_info_response.rb b/lib/algolia/models/composition/results_composition_info_response.rb new file mode 100644 index 00000000..115c25a0 --- /dev/null +++ b/lib/algolia/models/composition/results_composition_info_response.rb @@ -0,0 +1,212 @@ +# frozen_string_literal: true + +# Code generated by OpenAPI Generator (https://openapi-generator.tech), manual changes will be lost - read more on https://github.com/algolia/api-clients-automation. DO NOT EDIT. + +require "date" +require "time" + +module Algolia + module Composition + class ResultsCompositionInfoResponse + attr_accessor :injected_items + + # Attribute mapping from ruby-style variable name to JSON key. + def self.attribute_map + { + :injected_items => :injectedItems + } + end + + # Attribute type mapping. + def self.types_mapping + { + :injected_items => :"Array" + } + end + + # List of attributes with nullable: true + def self.openapi_nullable + Set.new( + [] + ) + end + + # Initializes the object + # @param [Hash] attributes Model attributes in the form of hash + def initialize(attributes = {}) + if (!attributes.is_a?(Hash)) + raise( + ArgumentError, + "The input argument (attributes) must be a hash in `Algolia::ResultsCompositionInfoResponse` initialize method" + ) + end + + # check to see if the attribute exists and convert string to symbol for hash key + attributes = attributes.each_with_object({}) { |(k, v), h| + if (!self.class.attribute_map.key?(k.to_sym)) + raise( + ArgumentError, + "`#{k}` is not a valid attribute in `Algolia::ResultsCompositionInfoResponse`. Please check the name to make sure it's valid. List of attributes: " + + self.class.attribute_map.keys.inspect + ) + end + + h[k.to_sym] = v + } + + if attributes.key?(:injected_items) + if (value = attributes[:injected_items]).is_a?(Array) + self.injected_items = value + end + else + self.injected_items = nil + end + end + + # Checks equality by comparing each attribute. + # @param [Object] Object to be compared + def ==(other) + return true if self.equal?(other) + self.class == other.class && + injected_items == other.injected_items + end + + # @see the `==` method + # @param [Object] Object to be compared + def eql?(other) + self == other + end + + # Calculates hash code according to all attributes. + # @return [Integer] Hash code + def hash + [injected_items].hash + end + + # Builds the object from hash + # @param [Hash] attributes Model attributes in the form of hash + # @return [Object] Returns the model itself + def self.build_from_hash(attributes) + return nil unless attributes.is_a?(Hash) + attributes = attributes.transform_keys(&:to_sym) + transformed_hash = {} + types_mapping.each_pair do |key, type| + if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + transformed_hash[key.to_sym] = nil + elsif type =~ /\AArray<(.*)>/i + # check to ensure the input is an array given that the attribute + # is documented as an array but the input is not + if attributes[attribute_map[key]].is_a?(Array) + transformed_hash[key.to_sym] = attributes[attribute_map[key]].map { |v| + _deserialize(::Regexp.last_match(1), v) + } + end + elsif !attributes[attribute_map[key]].nil? + transformed_hash[key.to_sym] = _deserialize(type, attributes[attribute_map[key]]) + end + end + + new(transformed_hash) + end + + # Deserializes the data based on type + # @param string type Data type + # @param string value Value to be deserialized + # @return [Object] Deserialized data + def self._deserialize(type, value) + case type.to_sym + when :Time + Time.parse(value) + when :Date + Date.parse(value) + when :String + value.to_s + when :Integer + value.to_i + when :Float + value.to_f + when :Boolean + if value.to_s =~ /\A(true|t|yes|y|1)\z/i + true + else + false + end + + when :Object + # generic object (usually a Hash), return directly + value + when /\AArray<(?.+)>\z/ + inner_type = Regexp.last_match[:inner_type] + value.map { |v| _deserialize(inner_type, v) } + when /\AHash<(?.+?), (?.+)>\z/ + k_type = Regexp.last_match[:k_type] + v_type = Regexp.last_match[:v_type] + {}.tap do |hash| + value.each do |k, v| + hash[_deserialize(k_type, k)] = _deserialize(v_type, v) + end + end + # model + else + # models (e.g. Pet) or oneOf + klass = Algolia::Composition.const_get(type) + klass.respond_to?(:openapi_any_of) || klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass + .build_from_hash(value) + end + end + + # Returns the string representation of the object + # @return [String] String presentation of the object + def to_s + to_hash.to_s + end + + # to_body is an alias to to_hash (backward compatibility) + # @return [Hash] Returns the object in the form of hash + def to_body + to_hash + end + + def to_json(*_args) + to_hash.to_json + end + + # Returns the object in the form of hash + # @return [Hash] Returns the object in the form of hash + def to_hash + hash = {} + self.class.attribute_map.each_pair do |attr, param| + value = send(attr) + if value.nil? + is_nullable = self.class.openapi_nullable.include?(attr) + next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) + end + + hash[param] = _to_hash(value) + end + + hash + end + + # Outputs non-array value in the form of hash + # For object, use to_hash. Otherwise, just return the value + # @param [Object] value Any valid value + # @return [Hash] Returns the value in the form of hash + def _to_hash(value) + if value.is_a?(Array) + value.compact.map { |v| _to_hash(v) } + elsif value.is_a?(Hash) + {}.tap do |hash| + value.each { |k, v| hash[k] = _to_hash(v) } + end + elsif value.respond_to?(:to_hash) + value.to_hash + else + value + end + end + + end + + end +end diff --git a/lib/algolia/models/composition/results_injected_item_applied_rules_info_response.rb b/lib/algolia/models/composition/results_injected_item_applied_rules_info_response.rb new file mode 100644 index 00000000..42c2a71a --- /dev/null +++ b/lib/algolia/models/composition/results_injected_item_applied_rules_info_response.rb @@ -0,0 +1,211 @@ +# frozen_string_literal: true + +# Code generated by OpenAPI Generator (https://openapi-generator.tech), manual changes will be lost - read more on https://github.com/algolia/api-clients-automation. DO NOT EDIT. + +require "date" +require "time" + +module Algolia + module Composition + class ResultsInjectedItemAppliedRulesInfoResponse + # Unique record identifier. + attr_accessor :algolia_object_id + + # Attribute mapping from ruby-style variable name to JSON key. + def self.attribute_map + { + :algolia_object_id => :objectID + } + end + + # Attribute type mapping. + def self.types_mapping + { + :algolia_object_id => :"String" + } + end + + # List of attributes with nullable: true + def self.openapi_nullable + Set.new( + [] + ) + end + + # Initializes the object + # @param [Hash] attributes Model attributes in the form of hash + def initialize(attributes = {}) + if (!attributes.is_a?(Hash)) + raise( + ArgumentError, + "The input argument (attributes) must be a hash in `Algolia::ResultsInjectedItemAppliedRulesInfoResponse` initialize method" + ) + end + + # check to see if the attribute exists and convert string to symbol for hash key + attributes = attributes.each_with_object({}) { |(k, v), h| + if (!self.class.attribute_map.key?(k.to_sym)) + raise( + ArgumentError, + "`#{k}` is not a valid attribute in `Algolia::ResultsInjectedItemAppliedRulesInfoResponse`. Please check the name to make sure it's valid. List of attributes: " + + self.class.attribute_map.keys.inspect + ) + end + + h[k.to_sym] = v + } + + if attributes.key?(:algolia_object_id) + self.algolia_object_id = attributes[:algolia_object_id] + else + self.algolia_object_id = nil + end + end + + # Checks equality by comparing each attribute. + # @param [Object] Object to be compared + def ==(other) + return true if self.equal?(other) + self.class == other.class && + algolia_object_id == other.algolia_object_id + end + + # @see the `==` method + # @param [Object] Object to be compared + def eql?(other) + self == other + end + + # Calculates hash code according to all attributes. + # @return [Integer] Hash code + def hash + [algolia_object_id].hash + end + + # Builds the object from hash + # @param [Hash] attributes Model attributes in the form of hash + # @return [Object] Returns the model itself + def self.build_from_hash(attributes) + return nil unless attributes.is_a?(Hash) + attributes = attributes.transform_keys(&:to_sym) + transformed_hash = {} + types_mapping.each_pair do |key, type| + if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + transformed_hash[key.to_sym] = nil + elsif type =~ /\AArray<(.*)>/i + # check to ensure the input is an array given that the attribute + # is documented as an array but the input is not + if attributes[attribute_map[key]].is_a?(Array) + transformed_hash[key.to_sym] = attributes[attribute_map[key]].map { |v| + _deserialize(::Regexp.last_match(1), v) + } + end + elsif !attributes[attribute_map[key]].nil? + transformed_hash[key.to_sym] = _deserialize(type, attributes[attribute_map[key]]) + end + end + + new(transformed_hash) + end + + # Deserializes the data based on type + # @param string type Data type + # @param string value Value to be deserialized + # @return [Object] Deserialized data + def self._deserialize(type, value) + case type.to_sym + when :Time + Time.parse(value) + when :Date + Date.parse(value) + when :String + value.to_s + when :Integer + value.to_i + when :Float + value.to_f + when :Boolean + if value.to_s =~ /\A(true|t|yes|y|1)\z/i + true + else + false + end + + when :Object + # generic object (usually a Hash), return directly + value + when /\AArray<(?.+)>\z/ + inner_type = Regexp.last_match[:inner_type] + value.map { |v| _deserialize(inner_type, v) } + when /\AHash<(?.+?), (?.+)>\z/ + k_type = Regexp.last_match[:k_type] + v_type = Regexp.last_match[:v_type] + {}.tap do |hash| + value.each do |k, v| + hash[_deserialize(k_type, k)] = _deserialize(v_type, v) + end + end + # model + else + # models (e.g. Pet) or oneOf + klass = Algolia::Composition.const_get(type) + klass.respond_to?(:openapi_any_of) || klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass + .build_from_hash(value) + end + end + + # Returns the string representation of the object + # @return [String] String presentation of the object + def to_s + to_hash.to_s + end + + # to_body is an alias to to_hash (backward compatibility) + # @return [Hash] Returns the object in the form of hash + def to_body + to_hash + end + + def to_json(*_args) + to_hash.to_json + end + + # Returns the object in the form of hash + # @return [Hash] Returns the object in the form of hash + def to_hash + hash = {} + self.class.attribute_map.each_pair do |attr, param| + value = send(attr) + if value.nil? + is_nullable = self.class.openapi_nullable.include?(attr) + next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) + end + + hash[param] = _to_hash(value) + end + + hash + end + + # Outputs non-array value in the form of hash + # For object, use to_hash. Otherwise, just return the value + # @param [Object] value Any valid value + # @return [Hash] Returns the value in the form of hash + def _to_hash(value) + if value.is_a?(Array) + value.compact.map { |v| _to_hash(v) } + elsif value.is_a?(Hash) + {}.tap do |hash| + value.each { |k, v| hash[k] = _to_hash(v) } + end + elsif value.respond_to?(:to_hash) + value.to_hash + else + value + end + end + + end + + end +end diff --git a/lib/algolia/models/composition/results_injected_item_info_response.rb b/lib/algolia/models/composition/results_injected_item_info_response.rb new file mode 100644 index 00000000..b4fc0786 --- /dev/null +++ b/lib/algolia/models/composition/results_injected_item_info_response.rb @@ -0,0 +1,221 @@ +# frozen_string_literal: true + +# Code generated by OpenAPI Generator (https://openapi-generator.tech), manual changes will be lost - read more on https://github.com/algolia/api-clients-automation. DO NOT EDIT. + +require "date" +require "time" + +module Algolia + module Composition + class ResultsInjectedItemInfoResponse + attr_accessor :key + + attr_accessor :applied_rules + + attr_accessor :additional_properties + + # Attribute mapping from ruby-style variable name to JSON key. + def self.attribute_map + { + :key => :key, + :applied_rules => :appliedRules + } + end + + # Attribute type mapping. + def self.types_mapping + { + :key => :"String", + :applied_rules => :"Array" + } + end + + # List of attributes with nullable: true + def self.openapi_nullable + Set.new( + [] + ) + end + + # Initializes the object + # @param [Hash] attributes Model attributes in the form of hash + def initialize(attributes = {}) + if (!attributes.is_a?(Hash)) + raise( + ArgumentError, + "The input argument (attributes) must be a hash in `Algolia::ResultsInjectedItemInfoResponse` initialize method" + ) + end + + if attributes.key?(:key) + self.key = attributes[:key] + else + self.key = nil + end + + if attributes.key?(:applied_rules) + if (value = attributes[:applied_rules]).is_a?(Array) + self.applied_rules = value + end + end + + # add extra attribute to additional_properties + self.additional_properties ||= {} + self.additional_properties.merge!(attributes.reject { |k, _| self.class.attribute_map.key?(k.to_sym) }) + end + + # Checks equality by comparing each attribute. + # @param [Object] Object to be compared + def ==(other) + return true if self.equal?(other) + self.class == other.class && + key == other.key && + applied_rules == other.applied_rules + end + + # @see the `==` method + # @param [Object] Object to be compared + def eql?(other) + self == other + end + + # Calculates hash code according to all attributes. + # @return [Integer] Hash code + def hash + [key, applied_rules].hash + end + + # Builds the object from hash + # @param [Hash] attributes Model attributes in the form of hash + # @return [Object] Returns the model itself + def self.build_from_hash(attributes) + return nil unless attributes.is_a?(Hash) + attributes = attributes.transform_keys(&:to_sym) + transformed_hash = {} + types_mapping.each_pair do |key, type| + if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + transformed_hash[key.to_sym] = nil + elsif type =~ /\AArray<(.*)>/i + # check to ensure the input is an array given that the attribute + # is documented as an array but the input is not + if attributes[attribute_map[key]].is_a?(Array) + transformed_hash[key.to_sym] = attributes[attribute_map[key]].map { |v| + _deserialize(::Regexp.last_match(1), v) + } + end + elsif !attributes[attribute_map[key]].nil? + transformed_hash[key.to_sym] = _deserialize(type, attributes[attribute_map[key]]) + end + end + + # add extra attribute to transformed_hash + transformed_hash.merge!(attributes.reject { |k, _| attribute_map.key?(k.to_sym) }) + new(transformed_hash) + end + + # Deserializes the data based on type + # @param string type Data type + # @param string value Value to be deserialized + # @return [Object] Deserialized data + def self._deserialize(type, value) + case type.to_sym + when :Time + Time.parse(value) + when :Date + Date.parse(value) + when :String + value.to_s + when :Integer + value.to_i + when :Float + value.to_f + when :Boolean + if value.to_s =~ /\A(true|t|yes|y|1)\z/i + true + else + false + end + + when :Object + # generic object (usually a Hash), return directly + value + when /\AArray<(?.+)>\z/ + inner_type = Regexp.last_match[:inner_type] + value.map { |v| _deserialize(inner_type, v) } + when /\AHash<(?.+?), (?.+)>\z/ + k_type = Regexp.last_match[:k_type] + v_type = Regexp.last_match[:v_type] + {}.tap do |hash| + value.each do |k, v| + hash[_deserialize(k_type, k)] = _deserialize(v_type, v) + end + end + # model + else + # models (e.g. Pet) or oneOf + klass = Algolia::Composition.const_get(type) + klass.respond_to?(:openapi_any_of) || klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass + .build_from_hash(value) + end + end + + # Returns the string representation of the object + # @return [String] String presentation of the object + def to_s + to_hash.to_s + end + + # to_body is an alias to to_hash (backward compatibility) + # @return [Hash] Returns the object in the form of hash + def to_body + to_hash + end + + def to_json(*_args) + to_hash.to_json + end + + # Returns the object in the form of hash + # @return [Hash] Returns the object in the form of hash + def to_hash + hash = {} + self.class.attribute_map.each_pair do |attr, param| + value = send(attr) + if value.nil? + is_nullable = self.class.openapi_nullable.include?(attr) + next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) + end + + hash[param] = _to_hash(value) + end + + # also add attributes from additional_properties to hash + self.additional_properties&.each_pair do |k, v| + hash[k.to_sym] = _to_hash(v) + end + + hash + end + + # Outputs non-array value in the form of hash + # For object, use to_hash. Otherwise, just return the value + # @param [Object] value Any valid value + # @return [Hash] Returns the value in the form of hash + def _to_hash(value) + if value.is_a?(Array) + value.compact.map { |v| _to_hash(v) } + elsif value.is_a?(Hash) + {}.tap do |hash| + value.each { |k, v| hash[k] = _to_hash(v) } + end + elsif value.respond_to?(:to_hash) + value.to_hash + else + value + end + end + + end + + end +end diff --git a/lib/algolia/models/composition/search_for_facet_values_params.rb b/lib/algolia/models/composition/search_for_facet_values_params.rb new file mode 100644 index 00000000..c14ae03c --- /dev/null +++ b/lib/algolia/models/composition/search_for_facet_values_params.rb @@ -0,0 +1,228 @@ +# frozen_string_literal: true + +# Code generated by OpenAPI Generator (https://openapi-generator.tech), manual changes will be lost - read more on https://github.com/algolia/api-clients-automation. DO NOT EDIT. + +require "date" +require "time" + +module Algolia + module Composition + class SearchForFacetValuesParams + # Search query. + attr_accessor :query + + # Maximum number of facet values to return when [searching for facet values](https://www.algolia.com/doc/guides/managing-results/refine-results/faceting/#search-for-facet-values). + attr_accessor :max_facet_hits + + attr_accessor :search_query + + # Attribute mapping from ruby-style variable name to JSON key. + def self.attribute_map + { + :query => :query, + :max_facet_hits => :maxFacetHits, + :search_query => :searchQuery + } + end + + # Attribute type mapping. + def self.types_mapping + { + :query => :"String", + :max_facet_hits => :"Integer", + :search_query => :"Params" + } + end + + # List of attributes with nullable: true + def self.openapi_nullable + Set.new( + [] + ) + end + + # Initializes the object + # @param [Hash] attributes Model attributes in the form of hash + def initialize(attributes = {}) + if (!attributes.is_a?(Hash)) + raise( + ArgumentError, + "The input argument (attributes) must be a hash in `Algolia::SearchForFacetValuesParams` initialize method" + ) + end + + # check to see if the attribute exists and convert string to symbol for hash key + attributes = attributes.each_with_object({}) { |(k, v), h| + if (!self.class.attribute_map.key?(k.to_sym)) + raise( + ArgumentError, + "`#{k}` is not a valid attribute in `Algolia::SearchForFacetValuesParams`. Please check the name to make sure it's valid. List of attributes: " + + self.class.attribute_map.keys.inspect + ) + end + + h[k.to_sym] = v + } + + if attributes.key?(:query) + self.query = attributes[:query] + end + + if attributes.key?(:max_facet_hits) + self.max_facet_hits = attributes[:max_facet_hits] + end + + if attributes.key?(:search_query) + self.search_query = attributes[:search_query] + end + end + + # Checks equality by comparing each attribute. + # @param [Object] Object to be compared + def ==(other) + return true if self.equal?(other) + self.class == other.class && + query == other.query && + max_facet_hits == other.max_facet_hits && + search_query == other.search_query + end + + # @see the `==` method + # @param [Object] Object to be compared + def eql?(other) + self == other + end + + # Calculates hash code according to all attributes. + # @return [Integer] Hash code + def hash + [query, max_facet_hits, search_query].hash + end + + # Builds the object from hash + # @param [Hash] attributes Model attributes in the form of hash + # @return [Object] Returns the model itself + def self.build_from_hash(attributes) + return nil unless attributes.is_a?(Hash) + attributes = attributes.transform_keys(&:to_sym) + transformed_hash = {} + types_mapping.each_pair do |key, type| + if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + transformed_hash[key.to_sym] = nil + elsif type =~ /\AArray<(.*)>/i + # check to ensure the input is an array given that the attribute + # is documented as an array but the input is not + if attributes[attribute_map[key]].is_a?(Array) + transformed_hash[key.to_sym] = attributes[attribute_map[key]].map { |v| + _deserialize(::Regexp.last_match(1), v) + } + end + elsif !attributes[attribute_map[key]].nil? + transformed_hash[key.to_sym] = _deserialize(type, attributes[attribute_map[key]]) + end + end + + new(transformed_hash) + end + + # Deserializes the data based on type + # @param string type Data type + # @param string value Value to be deserialized + # @return [Object] Deserialized data + def self._deserialize(type, value) + case type.to_sym + when :Time + Time.parse(value) + when :Date + Date.parse(value) + when :String + value.to_s + when :Integer + value.to_i + when :Float + value.to_f + when :Boolean + if value.to_s =~ /\A(true|t|yes|y|1)\z/i + true + else + false + end + + when :Object + # generic object (usually a Hash), return directly + value + when /\AArray<(?.+)>\z/ + inner_type = Regexp.last_match[:inner_type] + value.map { |v| _deserialize(inner_type, v) } + when /\AHash<(?.+?), (?.+)>\z/ + k_type = Regexp.last_match[:k_type] + v_type = Regexp.last_match[:v_type] + {}.tap do |hash| + value.each do |k, v| + hash[_deserialize(k_type, k)] = _deserialize(v_type, v) + end + end + # model + else + # models (e.g. Pet) or oneOf + klass = Algolia::Composition.const_get(type) + klass.respond_to?(:openapi_any_of) || klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass + .build_from_hash(value) + end + end + + # Returns the string representation of the object + # @return [String] String presentation of the object + def to_s + to_hash.to_s + end + + # to_body is an alias to to_hash (backward compatibility) + # @return [Hash] Returns the object in the form of hash + def to_body + to_hash + end + + def to_json(*_args) + to_hash.to_json + end + + # Returns the object in the form of hash + # @return [Hash] Returns the object in the form of hash + def to_hash + hash = {} + self.class.attribute_map.each_pair do |attr, param| + value = send(attr) + if value.nil? + is_nullable = self.class.openapi_nullable.include?(attr) + next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) + end + + hash[param] = _to_hash(value) + end + + hash + end + + # Outputs non-array value in the form of hash + # For object, use to_hash. Otherwise, just return the value + # @param [Object] value Any valid value + # @return [Hash] Returns the value in the form of hash + def _to_hash(value) + if value.is_a?(Array) + value.compact.map { |v| _to_hash(v) } + elsif value.is_a?(Hash) + {}.tap do |hash| + value.each { |k, v| hash[k] = _to_hash(v) } + end + elsif value.respond_to?(:to_hash) + value.to_hash + else + value + end + end + + end + + end +end diff --git a/lib/algolia/models/composition/search_for_facet_values_request.rb b/lib/algolia/models/composition/search_for_facet_values_request.rb new file mode 100644 index 00000000..579ed07b --- /dev/null +++ b/lib/algolia/models/composition/search_for_facet_values_request.rb @@ -0,0 +1,208 @@ +# frozen_string_literal: true + +# Code generated by OpenAPI Generator (https://openapi-generator.tech), manual changes will be lost - read more on https://github.com/algolia/api-clients-automation. DO NOT EDIT. + +require "date" +require "time" + +module Algolia + module Composition + class SearchForFacetValuesRequest + attr_accessor :params + + # Attribute mapping from ruby-style variable name to JSON key. + def self.attribute_map + { + :params => :params + } + end + + # Attribute type mapping. + def self.types_mapping + { + :params => :"SearchForFacetValuesParams" + } + end + + # List of attributes with nullable: true + def self.openapi_nullable + Set.new( + [] + ) + end + + # Initializes the object + # @param [Hash] attributes Model attributes in the form of hash + def initialize(attributes = {}) + if (!attributes.is_a?(Hash)) + raise( + ArgumentError, + "The input argument (attributes) must be a hash in `Algolia::SearchForFacetValuesRequest` initialize method" + ) + end + + # check to see if the attribute exists and convert string to symbol for hash key + attributes = attributes.each_with_object({}) { |(k, v), h| + if (!self.class.attribute_map.key?(k.to_sym)) + raise( + ArgumentError, + "`#{k}` is not a valid attribute in `Algolia::SearchForFacetValuesRequest`. Please check the name to make sure it's valid. List of attributes: " + + self.class.attribute_map.keys.inspect + ) + end + + h[k.to_sym] = v + } + + if attributes.key?(:params) + self.params = attributes[:params] + end + end + + # Checks equality by comparing each attribute. + # @param [Object] Object to be compared + def ==(other) + return true if self.equal?(other) + self.class == other.class && + params == other.params + end + + # @see the `==` method + # @param [Object] Object to be compared + def eql?(other) + self == other + end + + # Calculates hash code according to all attributes. + # @return [Integer] Hash code + def hash + [params].hash + end + + # Builds the object from hash + # @param [Hash] attributes Model attributes in the form of hash + # @return [Object] Returns the model itself + def self.build_from_hash(attributes) + return nil unless attributes.is_a?(Hash) + attributes = attributes.transform_keys(&:to_sym) + transformed_hash = {} + types_mapping.each_pair do |key, type| + if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + transformed_hash[key.to_sym] = nil + elsif type =~ /\AArray<(.*)>/i + # check to ensure the input is an array given that the attribute + # is documented as an array but the input is not + if attributes[attribute_map[key]].is_a?(Array) + transformed_hash[key.to_sym] = attributes[attribute_map[key]].map { |v| + _deserialize(::Regexp.last_match(1), v) + } + end + elsif !attributes[attribute_map[key]].nil? + transformed_hash[key.to_sym] = _deserialize(type, attributes[attribute_map[key]]) + end + end + + new(transformed_hash) + end + + # Deserializes the data based on type + # @param string type Data type + # @param string value Value to be deserialized + # @return [Object] Deserialized data + def self._deserialize(type, value) + case type.to_sym + when :Time + Time.parse(value) + when :Date + Date.parse(value) + when :String + value.to_s + when :Integer + value.to_i + when :Float + value.to_f + when :Boolean + if value.to_s =~ /\A(true|t|yes|y|1)\z/i + true + else + false + end + + when :Object + # generic object (usually a Hash), return directly + value + when /\AArray<(?.+)>\z/ + inner_type = Regexp.last_match[:inner_type] + value.map { |v| _deserialize(inner_type, v) } + when /\AHash<(?.+?), (?.+)>\z/ + k_type = Regexp.last_match[:k_type] + v_type = Regexp.last_match[:v_type] + {}.tap do |hash| + value.each do |k, v| + hash[_deserialize(k_type, k)] = _deserialize(v_type, v) + end + end + # model + else + # models (e.g. Pet) or oneOf + klass = Algolia::Composition.const_get(type) + klass.respond_to?(:openapi_any_of) || klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass + .build_from_hash(value) + end + end + + # Returns the string representation of the object + # @return [String] String presentation of the object + def to_s + to_hash.to_s + end + + # to_body is an alias to to_hash (backward compatibility) + # @return [Hash] Returns the object in the form of hash + def to_body + to_hash + end + + def to_json(*_args) + to_hash.to_json + end + + # Returns the object in the form of hash + # @return [Hash] Returns the object in the form of hash + def to_hash + hash = {} + self.class.attribute_map.each_pair do |attr, param| + value = send(attr) + if value.nil? + is_nullable = self.class.openapi_nullable.include?(attr) + next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) + end + + hash[param] = _to_hash(value) + end + + hash + end + + # Outputs non-array value in the form of hash + # For object, use to_hash. Otherwise, just return the value + # @param [Object] value Any valid value + # @return [Hash] Returns the value in the form of hash + def _to_hash(value) + if value.is_a?(Array) + value.compact.map { |v| _to_hash(v) } + elsif value.is_a?(Hash) + {}.tap do |hash| + value.each { |k, v| hash[k] = _to_hash(v) } + end + elsif value.respond_to?(:to_hash) + value.to_hash + else + value + end + end + + end + + end +end diff --git a/lib/algolia/models/composition/search_for_facet_values_response.rb b/lib/algolia/models/composition/search_for_facet_values_response.rb new file mode 100644 index 00000000..75a2ae7e --- /dev/null +++ b/lib/algolia/models/composition/search_for_facet_values_response.rb @@ -0,0 +1,211 @@ +# frozen_string_literal: true + +# Code generated by OpenAPI Generator (https://openapi-generator.tech), manual changes will be lost - read more on https://github.com/algolia/api-clients-automation. DO NOT EDIT. + +require "date" +require "time" + +module Algolia + module Composition + class SearchForFacetValuesResponse + # Search for facet values results. + attr_accessor :results + + # Attribute mapping from ruby-style variable name to JSON key. + def self.attribute_map + { + :results => :results + } + end + + # Attribute type mapping. + def self.types_mapping + { + :results => :"Array" + } + end + + # List of attributes with nullable: true + def self.openapi_nullable + Set.new( + [] + ) + end + + # Initializes the object + # @param [Hash] attributes Model attributes in the form of hash + def initialize(attributes = {}) + if (!attributes.is_a?(Hash)) + raise( + ArgumentError, + "The input argument (attributes) must be a hash in `Algolia::SearchForFacetValuesResponse` initialize method" + ) + end + + # check to see if the attribute exists and convert string to symbol for hash key + attributes = attributes.each_with_object({}) { |(k, v), h| + if (!self.class.attribute_map.key?(k.to_sym)) + raise( + ArgumentError, + "`#{k}` is not a valid attribute in `Algolia::SearchForFacetValuesResponse`. Please check the name to make sure it's valid. List of attributes: " + + self.class.attribute_map.keys.inspect + ) + end + + h[k.to_sym] = v + } + + if attributes.key?(:results) + if (value = attributes[:results]).is_a?(Array) + self.results = value + end + end + end + + # Checks equality by comparing each attribute. + # @param [Object] Object to be compared + def ==(other) + return true if self.equal?(other) + self.class == other.class && + results == other.results + end + + # @see the `==` method + # @param [Object] Object to be compared + def eql?(other) + self == other + end + + # Calculates hash code according to all attributes. + # @return [Integer] Hash code + def hash + [results].hash + end + + # Builds the object from hash + # @param [Hash] attributes Model attributes in the form of hash + # @return [Object] Returns the model itself + def self.build_from_hash(attributes) + return nil unless attributes.is_a?(Hash) + attributes = attributes.transform_keys(&:to_sym) + transformed_hash = {} + types_mapping.each_pair do |key, type| + if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + transformed_hash[key.to_sym] = nil + elsif type =~ /\AArray<(.*)>/i + # check to ensure the input is an array given that the attribute + # is documented as an array but the input is not + if attributes[attribute_map[key]].is_a?(Array) + transformed_hash[key.to_sym] = attributes[attribute_map[key]].map { |v| + _deserialize(::Regexp.last_match(1), v) + } + end + elsif !attributes[attribute_map[key]].nil? + transformed_hash[key.to_sym] = _deserialize(type, attributes[attribute_map[key]]) + end + end + + new(transformed_hash) + end + + # Deserializes the data based on type + # @param string type Data type + # @param string value Value to be deserialized + # @return [Object] Deserialized data + def self._deserialize(type, value) + case type.to_sym + when :Time + Time.parse(value) + when :Date + Date.parse(value) + when :String + value.to_s + when :Integer + value.to_i + when :Float + value.to_f + when :Boolean + if value.to_s =~ /\A(true|t|yes|y|1)\z/i + true + else + false + end + + when :Object + # generic object (usually a Hash), return directly + value + when /\AArray<(?.+)>\z/ + inner_type = Regexp.last_match[:inner_type] + value.map { |v| _deserialize(inner_type, v) } + when /\AHash<(?.+?), (?.+)>\z/ + k_type = Regexp.last_match[:k_type] + v_type = Regexp.last_match[:v_type] + {}.tap do |hash| + value.each do |k, v| + hash[_deserialize(k_type, k)] = _deserialize(v_type, v) + end + end + # model + else + # models (e.g. Pet) or oneOf + klass = Algolia::Composition.const_get(type) + klass.respond_to?(:openapi_any_of) || klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass + .build_from_hash(value) + end + end + + # Returns the string representation of the object + # @return [String] String presentation of the object + def to_s + to_hash.to_s + end + + # to_body is an alias to to_hash (backward compatibility) + # @return [Hash] Returns the object in the form of hash + def to_body + to_hash + end + + def to_json(*_args) + to_hash.to_json + end + + # Returns the object in the form of hash + # @return [Hash] Returns the object in the form of hash + def to_hash + hash = {} + self.class.attribute_map.each_pair do |attr, param| + value = send(attr) + if value.nil? + is_nullable = self.class.openapi_nullable.include?(attr) + next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) + end + + hash[param] = _to_hash(value) + end + + hash + end + + # Outputs non-array value in the form of hash + # For object, use to_hash. Otherwise, just return the value + # @param [Object] value Any valid value + # @return [Hash] Returns the value in the form of hash + def _to_hash(value) + if value.is_a?(Array) + value.compact.map { |v| _to_hash(v) } + elsif value.is_a?(Hash) + {}.tap do |hash| + value.each { |k, v| hash[k] = _to_hash(v) } + end + elsif value.respond_to?(:to_hash) + value.to_hash + else + value + end + end + + end + + end +end diff --git a/lib/algolia/models/composition/search_for_facet_values_results.rb b/lib/algolia/models/composition/search_for_facet_values_results.rb new file mode 100644 index 00000000..c3be26e2 --- /dev/null +++ b/lib/algolia/models/composition/search_for_facet_values_results.rb @@ -0,0 +1,253 @@ +# frozen_string_literal: true + +# Code generated by OpenAPI Generator (https://openapi-generator.tech), manual changes will be lost - read more on https://github.com/algolia/api-clients-automation. DO NOT EDIT. + +require "date" +require "time" + +module Algolia + module Composition + class SearchForFacetValuesResults + attr_accessor :index_name + + # Matching facet values. + attr_accessor :facet_hits + + # Whether the facet count is exhaustive (true) or approximate (false). For more information, see [Why are my facet and hit counts not accurate](https://support.algolia.com/hc/en-us/articles/4406975248145-Why-are-my-facet-and-hit-counts-not-accurate-). + attr_accessor :exhaustive_facets_count + + # Time the server took to process the request, in milliseconds. + attr_accessor :processing_time_ms + + # Attribute mapping from ruby-style variable name to JSON key. + def self.attribute_map + { + :index_name => :indexName, + :facet_hits => :facetHits, + :exhaustive_facets_count => :exhaustiveFacetsCount, + :processing_time_ms => :processingTimeMS + } + end + + # Returns the keys that uniquely identify this oneOf variant when present + def self.discriminator_attributes + [ + :facetHits + ] + end + + # Attribute type mapping. + def self.types_mapping + { + :index_name => :"String", + :facet_hits => :"Array", + :exhaustive_facets_count => :"Boolean", + :processing_time_ms => :"Integer" + } + end + + # List of attributes with nullable: true + def self.openapi_nullable + Set.new( + [] + ) + end + + # Initializes the object + # @param [Hash] attributes Model attributes in the form of hash + def initialize(attributes = {}) + if (!attributes.is_a?(Hash)) + raise( + ArgumentError, + "The input argument (attributes) must be a hash in `Algolia::SearchForFacetValuesResults` initialize method" + ) + end + + # check to see if the attribute exists and convert string to symbol for hash key + attributes = attributes.each_with_object({}) { |(k, v), h| + if (!self.class.attribute_map.key?(k.to_sym)) + raise( + ArgumentError, + "`#{k}` is not a valid attribute in `Algolia::SearchForFacetValuesResults`. Please check the name to make sure it's valid. List of attributes: " + + self.class.attribute_map.keys.inspect + ) + end + + h[k.to_sym] = v + } + + if attributes.key?(:index_name) + self.index_name = attributes[:index_name] + else + self.index_name = nil + end + + if attributes.key?(:facet_hits) + if (value = attributes[:facet_hits]).is_a?(Array) + self.facet_hits = value + end + else + self.facet_hits = nil + end + + if attributes.key?(:exhaustive_facets_count) + self.exhaustive_facets_count = attributes[:exhaustive_facets_count] + else + self.exhaustive_facets_count = nil + end + + if attributes.key?(:processing_time_ms) + self.processing_time_ms = attributes[:processing_time_ms] + end + end + + # Checks equality by comparing each attribute. + # @param [Object] Object to be compared + def ==(other) + return true if self.equal?(other) + self.class == other.class && + index_name == other.index_name && + facet_hits == other.facet_hits && + exhaustive_facets_count == other.exhaustive_facets_count && + processing_time_ms == other.processing_time_ms + end + + # @see the `==` method + # @param [Object] Object to be compared + def eql?(other) + self == other + end + + # Calculates hash code according to all attributes. + # @return [Integer] Hash code + def hash + [index_name, facet_hits, exhaustive_facets_count, processing_time_ms].hash + end + + # Builds the object from hash + # @param [Hash] attributes Model attributes in the form of hash + # @return [Object] Returns the model itself + def self.build_from_hash(attributes) + return nil unless attributes.is_a?(Hash) + attributes = attributes.transform_keys(&:to_sym) + transformed_hash = {} + types_mapping.each_pair do |key, type| + if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + transformed_hash[key.to_sym] = nil + elsif type =~ /\AArray<(.*)>/i + # check to ensure the input is an array given that the attribute + # is documented as an array but the input is not + if attributes[attribute_map[key]].is_a?(Array) + transformed_hash[key.to_sym] = attributes[attribute_map[key]].map { |v| + _deserialize(::Regexp.last_match(1), v) + } + end + elsif !attributes[attribute_map[key]].nil? + transformed_hash[key.to_sym] = _deserialize(type, attributes[attribute_map[key]]) + end + end + + new(transformed_hash) + end + + # Deserializes the data based on type + # @param string type Data type + # @param string value Value to be deserialized + # @return [Object] Deserialized data + def self._deserialize(type, value) + case type.to_sym + when :Time + Time.parse(value) + when :Date + Date.parse(value) + when :String + value.to_s + when :Integer + value.to_i + when :Float + value.to_f + when :Boolean + if value.to_s =~ /\A(true|t|yes|y|1)\z/i + true + else + false + end + + when :Object + # generic object (usually a Hash), return directly + value + when /\AArray<(?.+)>\z/ + inner_type = Regexp.last_match[:inner_type] + value.map { |v| _deserialize(inner_type, v) } + when /\AHash<(?.+?), (?.+)>\z/ + k_type = Regexp.last_match[:k_type] + v_type = Regexp.last_match[:v_type] + {}.tap do |hash| + value.each do |k, v| + hash[_deserialize(k_type, k)] = _deserialize(v_type, v) + end + end + # model + else + # models (e.g. Pet) or oneOf + klass = Algolia::Composition.const_get(type) + klass.respond_to?(:openapi_any_of) || klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass + .build_from_hash(value) + end + end + + # Returns the string representation of the object + # @return [String] String presentation of the object + def to_s + to_hash.to_s + end + + # to_body is an alias to to_hash (backward compatibility) + # @return [Hash] Returns the object in the form of hash + def to_body + to_hash + end + + def to_json(*_args) + to_hash.to_json + end + + # Returns the object in the form of hash + # @return [Hash] Returns the object in the form of hash + def to_hash + hash = {} + self.class.attribute_map.each_pair do |attr, param| + value = send(attr) + if value.nil? + is_nullable = self.class.openapi_nullable.include?(attr) + next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) + end + + hash[param] = _to_hash(value) + end + + hash + end + + # Outputs non-array value in the form of hash + # For object, use to_hash. Otherwise, just return the value + # @param [Object] value Any valid value + # @return [Hash] Returns the value in the form of hash + def _to_hash(value) + if value.is_a?(Array) + value.compact.map { |v| _to_hash(v) } + elsif value.is_a?(Hash) + {}.tap do |hash| + value.each { |k, v| hash[k] = _to_hash(v) } + end + elsif value.respond_to?(:to_hash) + value.to_hash + else + value + end + end + + end + + end +end diff --git a/lib/algolia/models/composition/search_response.rb b/lib/algolia/models/composition/search_response.rb new file mode 100644 index 00000000..d05a89f3 --- /dev/null +++ b/lib/algolia/models/composition/search_response.rb @@ -0,0 +1,230 @@ +# frozen_string_literal: true + +# Code generated by OpenAPI Generator (https://openapi-generator.tech), manual changes will be lost - read more on https://github.com/algolia/api-clients-automation. DO NOT EDIT. + +require "date" +require "time" + +module Algolia + module Composition + class SearchResponse + attr_accessor :compositions + + # Search results. + attr_accessor :results + + attr_accessor :additional_properties + + # Attribute mapping from ruby-style variable name to JSON key. + def self.attribute_map + { + :compositions => :compositions, + :results => :results + } + end + + # Attribute type mapping. + def self.types_mapping + { + :compositions => :"CompositionsSearchResponse", + :results => :"Array" + } + end + + # List of attributes with nullable: true + def self.openapi_nullable + Set.new( + [] + ) + end + + # List of class defined in allOf (OpenAPI v3) + def self.openapi_all_of + [ + :"CompositionBaseSearchResponse", + :"SearchResults" + ] + end + + # Initializes the object + # @param [Hash] attributes Model attributes in the form of hash + def initialize(attributes = {}) + if (!attributes.is_a?(Hash)) + raise( + ArgumentError, + "The input argument (attributes) must be a hash in `Algolia::SearchResponse` initialize method" + ) + end + + if attributes.key?(:compositions) + self.compositions = attributes[:compositions] + end + + if attributes.key?(:results) + if (value = attributes[:results]).is_a?(Array) + self.results = value + end + else + self.results = nil + end + + # add extra attribute to additional_properties + self.additional_properties ||= {} + self.additional_properties.merge!(attributes.reject { |k, _| self.class.attribute_map.key?(k.to_sym) }) + end + + # Checks equality by comparing each attribute. + # @param [Object] Object to be compared + def ==(other) + return true if self.equal?(other) + self.class == other.class && + compositions == other.compositions && + results == other.results + end + + # @see the `==` method + # @param [Object] Object to be compared + def eql?(other) + self == other + end + + # Calculates hash code according to all attributes. + # @return [Integer] Hash code + def hash + [compositions, results].hash + end + + # Builds the object from hash + # @param [Hash] attributes Model attributes in the form of hash + # @return [Object] Returns the model itself + def self.build_from_hash(attributes) + return nil unless attributes.is_a?(Hash) + attributes = attributes.transform_keys(&:to_sym) + transformed_hash = {} + types_mapping.each_pair do |key, type| + if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + transformed_hash[key.to_sym] = nil + elsif type =~ /\AArray<(.*)>/i + # check to ensure the input is an array given that the attribute + # is documented as an array but the input is not + if attributes[attribute_map[key]].is_a?(Array) + transformed_hash[key.to_sym] = attributes[attribute_map[key]].map { |v| + _deserialize(::Regexp.last_match(1), v) + } + end + elsif !attributes[attribute_map[key]].nil? + transformed_hash[key.to_sym] = _deserialize(type, attributes[attribute_map[key]]) + end + end + + # add extra attribute to transformed_hash + transformed_hash.merge!(attributes.reject { |k, _| attribute_map.key?(k.to_sym) }) + new(transformed_hash) + end + + # Deserializes the data based on type + # @param string type Data type + # @param string value Value to be deserialized + # @return [Object] Deserialized data + def self._deserialize(type, value) + case type.to_sym + when :Time + Time.parse(value) + when :Date + Date.parse(value) + when :String + value.to_s + when :Integer + value.to_i + when :Float + value.to_f + when :Boolean + if value.to_s =~ /\A(true|t|yes|y|1)\z/i + true + else + false + end + + when :Object + # generic object (usually a Hash), return directly + value + when /\AArray<(?.+)>\z/ + inner_type = Regexp.last_match[:inner_type] + value.map { |v| _deserialize(inner_type, v) } + when /\AHash<(?.+?), (?.+)>\z/ + k_type = Regexp.last_match[:k_type] + v_type = Regexp.last_match[:v_type] + {}.tap do |hash| + value.each do |k, v| + hash[_deserialize(k_type, k)] = _deserialize(v_type, v) + end + end + # model + else + # models (e.g. Pet) or oneOf + klass = Algolia::Composition.const_get(type) + klass.respond_to?(:openapi_any_of) || klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass + .build_from_hash(value) + end + end + + # Returns the string representation of the object + # @return [String] String presentation of the object + def to_s + to_hash.to_s + end + + # to_body is an alias to to_hash (backward compatibility) + # @return [Hash] Returns the object in the form of hash + def to_body + to_hash + end + + def to_json(*_args) + to_hash.to_json + end + + # Returns the object in the form of hash + # @return [Hash] Returns the object in the form of hash + def to_hash + hash = {} + self.class.attribute_map.each_pair do |attr, param| + value = send(attr) + if value.nil? + is_nullable = self.class.openapi_nullable.include?(attr) + next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) + end + + hash[param] = _to_hash(value) + end + + # also add attributes from additional_properties to hash + self.additional_properties&.each_pair do |k, v| + hash[k.to_sym] = _to_hash(v) + end + + hash + end + + # Outputs non-array value in the form of hash + # For object, use to_hash. Otherwise, just return the value + # @param [Object] value Any valid value + # @return [Hash] Returns the value in the form of hash + def _to_hash(value) + if value.is_a?(Array) + value.compact.map { |v| _to_hash(v) } + elsif value.is_a?(Hash) + {}.tap do |hash| + value.each { |k, v| hash[k] = _to_hash(v) } + end + elsif value.respond_to?(:to_hash) + value.to_hash + else + value + end + end + + end + + end +end diff --git a/lib/algolia/models/composition/search_results_item.rb b/lib/algolia/models/composition/search_results_item.rb new file mode 100644 index 00000000..d3b3ce94 --- /dev/null +++ b/lib/algolia/models/composition/search_results_item.rb @@ -0,0 +1,608 @@ +# frozen_string_literal: true + +# Code generated by OpenAPI Generator (https://openapi-generator.tech), manual changes will be lost - read more on https://github.com/algolia/api-clients-automation. DO NOT EDIT. + +require "date" +require "time" + +module Algolia + module Composition + class SearchResultsItem + # A/B test ID. This is only included in the response for indices that are part of an A/B test. + attr_accessor :ab_test_id + + # Variant ID. This is only included in the response for indices that are part of an A/B test. + attr_accessor :ab_test_variant_id + + # Computed geographical location. + attr_accessor :around_lat_lng + + # Distance from a central coordinate provided by `aroundLatLng`. + attr_accessor :automatic_radius + + attr_accessor :exhaustive + + # Rules applied to the query. + attr_accessor :applied_rules + + # See the `facetsCount` field of the `exhaustive` object in the response. + attr_accessor :exhaustive_facets_count + + # See the `nbHits` field of the `exhaustive` object in the response. + attr_accessor :exhaustive_nb_hits + + # See the `typo` field of the `exhaustive` object in the response. + attr_accessor :exhaustive_typo + + # Facet counts. + attr_accessor :facets + + # Statistics for numerical facets. + attr_accessor :facets_stats + + # Index name used for the query. + attr_accessor :index + + # Index name used for the query. During A/B testing, the targeted index isn't always the index used by the query. + attr_accessor :index_used + + # Warnings about the query. + attr_accessor :message + + # Number of hits selected and sorted by the relevant sort algorithm. + attr_accessor :nb_sorted_hits + + # Post-[normalization](https://www.algolia.com/doc/guides/managing-results/optimize-search-results/handling-natural-languages-nlp/#what-does-normalization-mean) query string that will be searched. + attr_accessor :parsed_query + + # Time the server took to process the request, in milliseconds. + attr_accessor :processing_time_ms + + # Experimental. List of processing steps and their times, in milliseconds. You can use this list to investigate performance issues. + attr_accessor :processing_timings_ms + + # Markup text indicating which parts of the original query have been removed to retrieve a non-empty result set. + attr_accessor :query_after_removal + + attr_accessor :redirect + + attr_accessor :rendering_content + + # Time the server took to process the request, in milliseconds. + attr_accessor :server_time_ms + + # Host name of the server that processed the request. + attr_accessor :server_used + + # An object with custom data. You can store up to 32kB as custom data. + attr_accessor :user_data + + # Unique identifier for the query. This is used for [click analytics](https://www.algolia.com/doc/guides/analytics/click-analytics/). + attr_accessor :query_id + + # Whether automatic events collection is enabled for the application. + attr_accessor :_automatic_insights + + # Page of search results to retrieve. + attr_accessor :page + + # Number of results (hits). + attr_accessor :nb_hits + + # Number of pages of results. + attr_accessor :nb_pages + + # Number of hits per page. + attr_accessor :hits_per_page + + # Search results (hits). Hits are records from your index that match the search criteria, augmented with additional attributes, such as, for highlighting. + attr_accessor :hits + + # Search query. + attr_accessor :query + + # URL-encoded string of all search parameters. + attr_accessor :params + + attr_accessor :compositions + + # Attribute mapping from ruby-style variable name to JSON key. + def self.attribute_map + { + :ab_test_id => :abTestID, + :ab_test_variant_id => :abTestVariantID, + :around_lat_lng => :aroundLatLng, + :automatic_radius => :automaticRadius, + :exhaustive => :exhaustive, + :applied_rules => :appliedRules, + :exhaustive_facets_count => :exhaustiveFacetsCount, + :exhaustive_nb_hits => :exhaustiveNbHits, + :exhaustive_typo => :exhaustiveTypo, + :facets => :facets, + :facets_stats => :facets_stats, + :index => :index, + :index_used => :indexUsed, + :message => :message, + :nb_sorted_hits => :nbSortedHits, + :parsed_query => :parsedQuery, + :processing_time_ms => :processingTimeMS, + :processing_timings_ms => :processingTimingsMS, + :query_after_removal => :queryAfterRemoval, + :redirect => :redirect, + :rendering_content => :renderingContent, + :server_time_ms => :serverTimeMS, + :server_used => :serverUsed, + :user_data => :userData, + :query_id => :queryID, + :_automatic_insights => :_automaticInsights, + :page => :page, + :nb_hits => :nbHits, + :nb_pages => :nbPages, + :hits_per_page => :hitsPerPage, + :hits => :hits, + :query => :query, + :params => :params, + :compositions => :compositions + } + end + + # Attribute type mapping. + def self.types_mapping + { + :ab_test_id => :"Integer", + :ab_test_variant_id => :"Integer", + :around_lat_lng => :"String", + :automatic_radius => :"String", + :exhaustive => :"Exhaustive", + :applied_rules => :"Array", + :exhaustive_facets_count => :"Boolean", + :exhaustive_nb_hits => :"Boolean", + :exhaustive_typo => :"Boolean", + :facets => :"Hash>", + :facets_stats => :"Hash", + :index => :"String", + :index_used => :"String", + :message => :"String", + :nb_sorted_hits => :"Integer", + :parsed_query => :"String", + :processing_time_ms => :"Integer", + :processing_timings_ms => :"Object", + :query_after_removal => :"String", + :redirect => :"Redirect", + :rendering_content => :"RenderingContent", + :server_time_ms => :"Integer", + :server_used => :"String", + :user_data => :"Object", + :query_id => :"String", + :_automatic_insights => :"Boolean", + :page => :"Integer", + :nb_hits => :"Integer", + :nb_pages => :"Integer", + :hits_per_page => :"Integer", + :hits => :"Array", + :query => :"String", + :params => :"String", + :compositions => :"Hash" + } + end + + # List of attributes with nullable: true + def self.openapi_nullable + Set.new( + [] + ) + end + + # List of class defined in allOf (OpenAPI v3) + def self.openapi_all_of + [ + :"BaseSearchResponse", + :"ResultsCompositionsResponse", + :"SearchHits", + :"SearchPagination" + ] + end + + # Initializes the object + # @param [Hash] attributes Model attributes in the form of hash + def initialize(attributes = {}) + if (!attributes.is_a?(Hash)) + raise( + ArgumentError, + "The input argument (attributes) must be a hash in `Algolia::SearchResultsItem` initialize method" + ) + end + + # check to see if the attribute exists and convert string to symbol for hash key + attributes = attributes.each_with_object({}) { |(k, v), h| + if (!self.class.attribute_map.key?(k.to_sym)) + raise( + ArgumentError, + "`#{k}` is not a valid attribute in `Algolia::SearchResultsItem`. Please check the name to make sure it's valid. List of attributes: " + + self.class.attribute_map.keys.inspect + ) + end + + h[k.to_sym] = v + } + + if attributes.key?(:ab_test_id) + self.ab_test_id = attributes[:ab_test_id] + end + + if attributes.key?(:ab_test_variant_id) + self.ab_test_variant_id = attributes[:ab_test_variant_id] + end + + if attributes.key?(:around_lat_lng) + self.around_lat_lng = attributes[:around_lat_lng] + end + + if attributes.key?(:automatic_radius) + self.automatic_radius = attributes[:automatic_radius] + end + + if attributes.key?(:exhaustive) + self.exhaustive = attributes[:exhaustive] + end + + if attributes.key?(:applied_rules) + if (value = attributes[:applied_rules]).is_a?(Array) + self.applied_rules = value + end + end + + if attributes.key?(:exhaustive_facets_count) + self.exhaustive_facets_count = attributes[:exhaustive_facets_count] + end + + if attributes.key?(:exhaustive_nb_hits) + self.exhaustive_nb_hits = attributes[:exhaustive_nb_hits] + end + + if attributes.key?(:exhaustive_typo) + self.exhaustive_typo = attributes[:exhaustive_typo] + end + + if attributes.key?(:facets) + if (value = attributes[:facets]).is_a?(Hash) + self.facets = value + end + end + + if attributes.key?(:facets_stats) + if (value = attributes[:facets_stats]).is_a?(Hash) + self.facets_stats = value + end + end + + if attributes.key?(:index) + self.index = attributes[:index] + end + + if attributes.key?(:index_used) + self.index_used = attributes[:index_used] + end + + if attributes.key?(:message) + self.message = attributes[:message] + end + + if attributes.key?(:nb_sorted_hits) + self.nb_sorted_hits = attributes[:nb_sorted_hits] + end + + if attributes.key?(:parsed_query) + self.parsed_query = attributes[:parsed_query] + end + + if attributes.key?(:processing_time_ms) + self.processing_time_ms = attributes[:processing_time_ms] + else + self.processing_time_ms = nil + end + + if attributes.key?(:processing_timings_ms) + self.processing_timings_ms = attributes[:processing_timings_ms] + end + + if attributes.key?(:query_after_removal) + self.query_after_removal = attributes[:query_after_removal] + end + + if attributes.key?(:redirect) + self.redirect = attributes[:redirect] + end + + if attributes.key?(:rendering_content) + self.rendering_content = attributes[:rendering_content] + end + + if attributes.key?(:server_time_ms) + self.server_time_ms = attributes[:server_time_ms] + end + + if attributes.key?(:server_used) + self.server_used = attributes[:server_used] + end + + if attributes.key?(:user_data) + self.user_data = attributes[:user_data] + end + + if attributes.key?(:query_id) + self.query_id = attributes[:query_id] + end + + if attributes.key?(:_automatic_insights) + self._automatic_insights = attributes[:_automatic_insights] + end + + if attributes.key?(:page) + self.page = attributes[:page] + else + self.page = nil + end + + if attributes.key?(:nb_hits) + self.nb_hits = attributes[:nb_hits] + else + self.nb_hits = nil + end + + if attributes.key?(:nb_pages) + self.nb_pages = attributes[:nb_pages] + else + self.nb_pages = nil + end + + if attributes.key?(:hits_per_page) + self.hits_per_page = attributes[:hits_per_page] + else + self.hits_per_page = nil + end + + if attributes.key?(:hits) + if (value = attributes[:hits]).is_a?(Array) + self.hits = value + end + else + self.hits = nil + end + + if attributes.key?(:query) + self.query = attributes[:query] + else + self.query = nil + end + + if attributes.key?(:params) + self.params = attributes[:params] + else + self.params = nil + end + + if attributes.key?(:compositions) + if (value = attributes[:compositions]).is_a?(Hash) + self.compositions = value + end + else + self.compositions = nil + end + end + + # Checks equality by comparing each attribute. + # @param [Object] Object to be compared + def ==(other) + return true if self.equal?(other) + self.class == other.class && + ab_test_id == other.ab_test_id && + ab_test_variant_id == other.ab_test_variant_id && + around_lat_lng == other.around_lat_lng && + automatic_radius == other.automatic_radius && + exhaustive == other.exhaustive && + applied_rules == other.applied_rules && + exhaustive_facets_count == other.exhaustive_facets_count && + exhaustive_nb_hits == other.exhaustive_nb_hits && + exhaustive_typo == other.exhaustive_typo && + facets == other.facets && + facets_stats == other.facets_stats && + index == other.index && + index_used == other.index_used && + message == other.message && + nb_sorted_hits == other.nb_sorted_hits && + parsed_query == other.parsed_query && + processing_time_ms == other.processing_time_ms && + processing_timings_ms == other.processing_timings_ms && + query_after_removal == other.query_after_removal && + redirect == other.redirect && + rendering_content == other.rendering_content && + server_time_ms == other.server_time_ms && + server_used == other.server_used && + user_data == other.user_data && + query_id == other.query_id && + _automatic_insights == other._automatic_insights && + page == other.page && + nb_hits == other.nb_hits && + nb_pages == other.nb_pages && + hits_per_page == other.hits_per_page && + hits == other.hits && + query == other.query && + params == other.params && + compositions == other.compositions + end + + # @see the `==` method + # @param [Object] Object to be compared + def eql?(other) + self == other + end + + # Calculates hash code according to all attributes. + # @return [Integer] Hash code + def hash + [ + ab_test_id, + ab_test_variant_id, + around_lat_lng, + automatic_radius, + exhaustive, + applied_rules, + exhaustive_facets_count, + exhaustive_nb_hits, + exhaustive_typo, + facets, + facets_stats, + index, + index_used, + message, + nb_sorted_hits, + parsed_query, + processing_time_ms, + processing_timings_ms, + query_after_removal, + redirect, + rendering_content, + server_time_ms, + server_used, + user_data, + query_id, + _automatic_insights, + page, + nb_hits, + nb_pages, + hits_per_page, + hits, + query, + params, + compositions + ].hash + end + + # Builds the object from hash + # @param [Hash] attributes Model attributes in the form of hash + # @return [Object] Returns the model itself + def self.build_from_hash(attributes) + return nil unless attributes.is_a?(Hash) + attributes = attributes.transform_keys(&:to_sym) + transformed_hash = {} + types_mapping.each_pair do |key, type| + if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + transformed_hash[key.to_sym] = nil + elsif type =~ /\AArray<(.*)>/i + # check to ensure the input is an array given that the attribute + # is documented as an array but the input is not + if attributes[attribute_map[key]].is_a?(Array) + transformed_hash[key.to_sym] = attributes[attribute_map[key]].map { |v| + _deserialize(::Regexp.last_match(1), v) + } + end + elsif !attributes[attribute_map[key]].nil? + transformed_hash[key.to_sym] = _deserialize(type, attributes[attribute_map[key]]) + end + end + + new(transformed_hash) + end + + # Deserializes the data based on type + # @param string type Data type + # @param string value Value to be deserialized + # @return [Object] Deserialized data + def self._deserialize(type, value) + case type.to_sym + when :Time + Time.parse(value) + when :Date + Date.parse(value) + when :String + value.to_s + when :Integer + value.to_i + when :Float + value.to_f + when :Boolean + if value.to_s =~ /\A(true|t|yes|y|1)\z/i + true + else + false + end + + when :Object + # generic object (usually a Hash), return directly + value + when /\AArray<(?.+)>\z/ + inner_type = Regexp.last_match[:inner_type] + value.map { |v| _deserialize(inner_type, v) } + when /\AHash<(?.+?), (?.+)>\z/ + k_type = Regexp.last_match[:k_type] + v_type = Regexp.last_match[:v_type] + {}.tap do |hash| + value.each do |k, v| + hash[_deserialize(k_type, k)] = _deserialize(v_type, v) + end + end + # model + else + # models (e.g. Pet) or oneOf + klass = Algolia::Composition.const_get(type) + klass.respond_to?(:openapi_any_of) || klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass + .build_from_hash(value) + end + end + + # Returns the string representation of the object + # @return [String] String presentation of the object + def to_s + to_hash.to_s + end + + # to_body is an alias to to_hash (backward compatibility) + # @return [Hash] Returns the object in the form of hash + def to_body + to_hash + end + + def to_json(*_args) + to_hash.to_json + end + + # Returns the object in the form of hash + # @return [Hash] Returns the object in the form of hash + def to_hash + hash = {} + self.class.attribute_map.each_pair do |attr, param| + value = send(attr) + if value.nil? + is_nullable = self.class.openapi_nullable.include?(attr) + next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) + end + + hash[param] = _to_hash(value) + end + + hash + end + + # Outputs non-array value in the form of hash + # For object, use to_hash. Otherwise, just return the value + # @param [Object] value Any valid value + # @return [Hash] Returns the value in the form of hash + def _to_hash(value) + if value.is_a?(Array) + value.compact.map { |v| _to_hash(v) } + elsif value.is_a?(Hash) + {}.tap do |hash| + value.each { |k, v| hash[k] = _to_hash(v) } + end + elsif value.respond_to?(:to_hash) + value.to_hash + else + value + end + end + + end + + end +end diff --git a/lib/algolia/models/composition/snippet_result.rb b/lib/algolia/models/composition/snippet_result.rb new file mode 100644 index 00000000..6c175bfb --- /dev/null +++ b/lib/algolia/models/composition/snippet_result.rb @@ -0,0 +1,110 @@ +# frozen_string_literal: true + +# Code generated by OpenAPI Generator (https://openapi-generator.tech), manual changes will be lost - read more on https://github.com/algolia/api-clients-automation. DO NOT EDIT. + +require "date" +require "time" + +module Algolia + module Composition + module SnippetResult + class << self + # List of class defined in oneOf (OpenAPI v3) + def openapi_one_of + [ + :"Array", + :"Hash", + :"SnippetResultOption" + ] + end + + # Builds the object + # @param [Mixed] Data to be matched against the list of oneOf items + # @return [Object] Returns the model or the data itself + def build(data) + # Go through the list of oneOf items and attempt to identify the appropriate one. + # Note: + # - We do not attempt to check whether exactly one item matches. + # - No advanced validation of types in some cases (e.g. "x: { type: string }" will happily match { x: 123 }) + # due to the way the deserialization is made in the base_object template (it just casts without verifying). + # - TODO: scalar values are de facto behaving as if they were nullable. + # - TODO: logging when debugging is set. + openapi_one_of.each do |klass| + begin + # "nullable: true" + next if klass == :AnyType + typed_data = find_and_cast_into_type(klass, data) + return typed_data if typed_data + # rescue all errors so we keep iterating even if the current item lookup raises + rescue + end + end + + openapi_one_of.include?(:AnyType) ? data : nil + end + + private + + SchemaMismatchError = Class.new(StandardError) + + def find_and_cast_into_type(klass, data) + return if data.nil? + + case klass.to_s + when "Boolean" + return data if data.instance_of?(TrueClass) || data.instance_of?(FalseClass) + when "Float" + return data if data.instance_of?(Float) + when "Integer" + return data if data.instance_of?(Integer) + when "Time" + return Time.parse(data) + when "Date" + return Date.parse(data) + when "String" + return data if data.instance_of?(String) + # "type: object" + when "Object" + return data if data.instance_of?(Hash) + # "type: array" + when /\AArray<(?.+)>\z/ + if data.instance_of?(Array) + sub_type = Regexp.last_match[:sub_type] + return data.map { |item| find_and_cast_into_type(sub_type, item) } + end + # "type: object" with "additionalProperties: { ... }" + when /\AHash.+)>\z/ + if data.instance_of?(Hash) && data.keys.all? { |k| k.instance_of?(Symbol) || k.instance_of?(String) } + sub_type = Regexp.last_match[:sub_type] + return data.each_with_object({}) { |(k, v), hsh| hsh[k] = find_and_cast_into_type(sub_type, v) } + end + # model + else + const = Algolia::Composition.const_get(klass) + if const + if const.respond_to?(:openapi_one_of) + # nested oneOf model + model = const.build(data) + elsif const.respond_to?(:discriminator_attributes) + if const.discriminator_attributes.all? { |attr| data.key?(attr) } + model = const.build_from_hash(data) + end + else + # maybe it's an enum, or doens't have discriminators + model = const.build_from_hash(data) + end + + return model if model + end + end + + # if no match by now, raise + raise + rescue + raise SchemaMismatchError, "#{data} doesn't match the #{klass} type" + end + end + end + + end +end diff --git a/lib/algolia/models/composition/snippet_result_option.rb b/lib/algolia/models/composition/snippet_result_option.rb new file mode 100644 index 00000000..07af657a --- /dev/null +++ b/lib/algolia/models/composition/snippet_result_option.rb @@ -0,0 +1,230 @@ +# frozen_string_literal: true + +# Code generated by OpenAPI Generator (https://openapi-generator.tech), manual changes will be lost - read more on https://github.com/algolia/api-clients-automation. DO NOT EDIT. + +require "date" +require "time" + +module Algolia + module Composition + # Snippets that show the context around a matching search query. + class SnippetResultOption + # Highlighted attribute value, including HTML tags. + attr_accessor :value + + attr_accessor :match_level + + # Attribute mapping from ruby-style variable name to JSON key. + def self.attribute_map + { + :value => :value, + :match_level => :matchLevel + } + end + + # Returns the keys that uniquely identify this oneOf variant when present + def self.discriminator_attributes + [ + :matchLevel + ] + end + + # Attribute type mapping. + def self.types_mapping + { + :value => :"String", + :match_level => :"MatchLevel" + } + end + + # List of attributes with nullable: true + def self.openapi_nullable + Set.new( + [] + ) + end + + # Initializes the object + # @param [Hash] attributes Model attributes in the form of hash + def initialize(attributes = {}) + if (!attributes.is_a?(Hash)) + raise( + ArgumentError, + "The input argument (attributes) must be a hash in `Algolia::SnippetResultOption` initialize method" + ) + end + + # check to see if the attribute exists and convert string to symbol for hash key + attributes = attributes.each_with_object({}) { |(k, v), h| + if (!self.class.attribute_map.key?(k.to_sym)) + raise( + ArgumentError, + "`#{k}` is not a valid attribute in `Algolia::SnippetResultOption`. Please check the name to make sure it's valid. List of attributes: " + + self.class.attribute_map.keys.inspect + ) + end + + h[k.to_sym] = v + } + + if attributes.key?(:value) + self.value = attributes[:value] + else + self.value = nil + end + + if attributes.key?(:match_level) + self.match_level = attributes[:match_level] + else + self.match_level = nil + end + end + + # Checks equality by comparing each attribute. + # @param [Object] Object to be compared + def ==(other) + return true if self.equal?(other) + self.class == other.class && + value == other.value && + match_level == other.match_level + end + + # @see the `==` method + # @param [Object] Object to be compared + def eql?(other) + self == other + end + + # Calculates hash code according to all attributes. + # @return [Integer] Hash code + def hash + [value, match_level].hash + end + + # Builds the object from hash + # @param [Hash] attributes Model attributes in the form of hash + # @return [Object] Returns the model itself + def self.build_from_hash(attributes) + return nil unless attributes.is_a?(Hash) + attributes = attributes.transform_keys(&:to_sym) + transformed_hash = {} + types_mapping.each_pair do |key, type| + if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + transformed_hash[key.to_sym] = nil + elsif type =~ /\AArray<(.*)>/i + # check to ensure the input is an array given that the attribute + # is documented as an array but the input is not + if attributes[attribute_map[key]].is_a?(Array) + transformed_hash[key.to_sym] = attributes[attribute_map[key]].map { |v| + _deserialize(::Regexp.last_match(1), v) + } + end + elsif !attributes[attribute_map[key]].nil? + transformed_hash[key.to_sym] = _deserialize(type, attributes[attribute_map[key]]) + end + end + + new(transformed_hash) + end + + # Deserializes the data based on type + # @param string type Data type + # @param string value Value to be deserialized + # @return [Object] Deserialized data + def self._deserialize(type, value) + case type.to_sym + when :Time + Time.parse(value) + when :Date + Date.parse(value) + when :String + value.to_s + when :Integer + value.to_i + when :Float + value.to_f + when :Boolean + if value.to_s =~ /\A(true|t|yes|y|1)\z/i + true + else + false + end + + when :Object + # generic object (usually a Hash), return directly + value + when /\AArray<(?.+)>\z/ + inner_type = Regexp.last_match[:inner_type] + value.map { |v| _deserialize(inner_type, v) } + when /\AHash<(?.+?), (?.+)>\z/ + k_type = Regexp.last_match[:k_type] + v_type = Regexp.last_match[:v_type] + {}.tap do |hash| + value.each do |k, v| + hash[_deserialize(k_type, k)] = _deserialize(v_type, v) + end + end + # model + else + # models (e.g. Pet) or oneOf + klass = Algolia::Composition.const_get(type) + klass.respond_to?(:openapi_any_of) || klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass + .build_from_hash(value) + end + end + + # Returns the string representation of the object + # @return [String] String presentation of the object + def to_s + to_hash.to_s + end + + # to_body is an alias to to_hash (backward compatibility) + # @return [Hash] Returns the object in the form of hash + def to_body + to_hash + end + + def to_json(*_args) + to_hash.to_json + end + + # Returns the object in the form of hash + # @return [Hash] Returns the object in the form of hash + def to_hash + hash = {} + self.class.attribute_map.each_pair do |attr, param| + value = send(attr) + if value.nil? + is_nullable = self.class.openapi_nullable.include?(attr) + next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) + end + + hash[param] = _to_hash(value) + end + + hash + end + + # Outputs non-array value in the form of hash + # For object, use to_hash. Otherwise, just return the value + # @param [Object] value Any valid value + # @return [Hash] Returns the value in the form of hash + def _to_hash(value) + if value.is_a?(Array) + value.compact.map { |v| _to_hash(v) } + elsif value.is_a?(Hash) + {}.tap do |hash| + value.each { |k, v| hash[k] = _to_hash(v) } + end + elsif value.respond_to?(:to_hash) + value.to_hash + else + value + end + end + + end + + end +end diff --git a/lib/algolia/models/composition/sort_remaining_by.rb b/lib/algolia/models/composition/sort_remaining_by.rb new file mode 100644 index 00000000..233e69a9 --- /dev/null +++ b/lib/algolia/models/composition/sort_remaining_by.rb @@ -0,0 +1,35 @@ +# frozen_string_literal: true + +# Code generated by OpenAPI Generator (https://openapi-generator.tech), manual changes will be lost - read more on https://github.com/algolia/api-clients-automation. DO NOT EDIT. + +require "date" +require "time" + +module Algolia + module Composition + class SortRemainingBy + COUNT = "count".freeze + ALPHA = "alpha".freeze + HIDDEN = "hidden".freeze + + def self.all_vars + @all_vars ||= [COUNT, ALPHA, HIDDEN].freeze + end + + # Builds the enum from string + # @param [String] The enum value in the form of the string + # @return [String] The enum value + def self.build_from_hash(value) + new.build_from_hash(value) + end + + # Builds the enum from string + # @param [String] The enum value in the form of the string + # @return [String] The enum value + def build_from_hash(value) + return value if SortRemainingBy.all_vars.include?(value) + raise "Invalid ENUM value #{value} for class #SortRemainingBy" + end + end + end +end diff --git a/lib/algolia/models/composition/supported_language.rb b/lib/algolia/models/composition/supported_language.rb new file mode 100644 index 00000000..8592daeb --- /dev/null +++ b/lib/algolia/models/composition/supported_language.rb @@ -0,0 +1,169 @@ +# frozen_string_literal: true + +# Code generated by OpenAPI Generator (https://openapi-generator.tech), manual changes will be lost - read more on https://github.com/algolia/api-clients-automation. DO NOT EDIT. + +require "date" +require "time" + +module Algolia + module Composition + class SupportedLanguage + AF = "af".freeze + AR = "ar".freeze + AZ = "az".freeze + BG = "bg".freeze + BN = "bn".freeze + CA = "ca".freeze + CS = "cs".freeze + CY = "cy".freeze + DA = "da".freeze + DE = "de".freeze + EL = "el".freeze + EN = "en".freeze + EO = "eo".freeze + ES = "es".freeze + ET = "et".freeze + EU = "eu".freeze + FA = "fa".freeze + FI = "fi".freeze + FO = "fo".freeze + FR = "fr".freeze + GA = "ga".freeze + GL = "gl".freeze + HE = "he".freeze + HI = "hi".freeze + HU = "hu".freeze + HY = "hy".freeze + ID = "id".freeze + IS = "is".freeze + IT = "it".freeze + JA = "ja".freeze + KA = "ka".freeze + KK = "kk".freeze + KO = "ko".freeze + KU = "ku".freeze + KY = "ky".freeze + LT = "lt".freeze + LV = "lv".freeze + MI = "mi".freeze + MN = "mn".freeze + MR = "mr".freeze + MS = "ms".freeze + MT = "mt".freeze + NB = "nb".freeze + NL = "nl".freeze + NO = "no".freeze + NS = "ns".freeze + PL = "pl".freeze + PS = "ps".freeze + PT = "pt".freeze + PT_BR = "pt-br".freeze + QU = "qu".freeze + RO = "ro".freeze + RU = "ru".freeze + SK = "sk".freeze + SQ = "sq".freeze + SV = "sv".freeze + SW = "sw".freeze + TA = "ta".freeze + TE = "te".freeze + TH = "th".freeze + TL = "tl".freeze + TN = "tn".freeze + TR = "tr".freeze + TT = "tt".freeze + UK = "uk".freeze + UR = "ur".freeze + UZ = "uz".freeze + ZH = "zh".freeze + + def self.all_vars + @all_vars ||= [ + AF, + AR, + AZ, + BG, + BN, + CA, + CS, + CY, + DA, + DE, + EL, + EN, + EO, + ES, + ET, + EU, + FA, + FI, + FO, + FR, + GA, + GL, + HE, + HI, + HU, + HY, + ID, + IS, + IT, + JA, + KA, + KK, + KO, + KU, + KY, + LT, + LV, + MI, + MN, + MR, + MS, + MT, + NB, + NL, + NO, + NS, + PL, + PS, + PT, + PT_BR, + QU, + RO, + RU, + SK, + SQ, + SV, + SW, + TA, + TE, + TH, + TL, + TN, + TR, + TT, + UK, + UR, + UZ, + ZH + ].freeze + end + + # Builds the enum from string + # @param [String] The enum value in the form of the string + # @return [String] The enum value + def self.build_from_hash(value) + new.build_from_hash(value) + end + + # Builds the enum from string + # @param [String] The enum value in the form of the string + # @return [String] The enum value + def build_from_hash(value) + return value if SupportedLanguage.all_vars.include?(value) + raise "Invalid ENUM value #{value} for class #SupportedLanguage" + end + end + end +end diff --git a/lib/algolia/models/composition/value.rb b/lib/algolia/models/composition/value.rb new file mode 100644 index 00000000..9e68cb51 --- /dev/null +++ b/lib/algolia/models/composition/value.rb @@ -0,0 +1,229 @@ +# frozen_string_literal: true + +# Code generated by OpenAPI Generator (https://openapi-generator.tech), manual changes will be lost - read more on https://github.com/algolia/api-clients-automation. DO NOT EDIT. + +require "date" +require "time" + +module Algolia + module Composition + class Value + # Explicit order of facets or facet values. This setting lets you always show specific facets or facet values at the top of the list. + attr_accessor :order + + attr_accessor :sort_remaining_by + + # Hide facet values. + attr_accessor :hide + + # Attribute mapping from ruby-style variable name to JSON key. + def self.attribute_map + { + :order => :order, + :sort_remaining_by => :sortRemainingBy, + :hide => :hide + } + end + + # Attribute type mapping. + def self.types_mapping + { + :order => :"Array", + :sort_remaining_by => :"SortRemainingBy", + :hide => :"Array" + } + end + + # List of attributes with nullable: true + def self.openapi_nullable + Set.new( + [] + ) + end + + # Initializes the object + # @param [Hash] attributes Model attributes in the form of hash + def initialize(attributes = {}) + if (!attributes.is_a?(Hash)) + raise ArgumentError, "The input argument (attributes) must be a hash in `Algolia::Value` initialize method" + end + + # check to see if the attribute exists and convert string to symbol for hash key + attributes = attributes.each_with_object({}) { |(k, v), h| + if (!self.class.attribute_map.key?(k.to_sym)) + raise( + ArgumentError, + "`#{k}` is not a valid attribute in `Algolia::Value`. Please check the name to make sure it's valid. List of attributes: " + + self.class.attribute_map.keys.inspect + ) + end + + h[k.to_sym] = v + } + + if attributes.key?(:order) + if (value = attributes[:order]).is_a?(Array) + self.order = value + end + end + + if attributes.key?(:sort_remaining_by) + self.sort_remaining_by = attributes[:sort_remaining_by] + end + + if attributes.key?(:hide) + if (value = attributes[:hide]).is_a?(Array) + self.hide = value + end + end + end + + # Checks equality by comparing each attribute. + # @param [Object] Object to be compared + def ==(other) + return true if self.equal?(other) + self.class == other.class && + order == other.order && + sort_remaining_by == other.sort_remaining_by && + hide == other.hide + end + + # @see the `==` method + # @param [Object] Object to be compared + def eql?(other) + self == other + end + + # Calculates hash code according to all attributes. + # @return [Integer] Hash code + def hash + [order, sort_remaining_by, hide].hash + end + + # Builds the object from hash + # @param [Hash] attributes Model attributes in the form of hash + # @return [Object] Returns the model itself + def self.build_from_hash(attributes) + return nil unless attributes.is_a?(Hash) + attributes = attributes.transform_keys(&:to_sym) + transformed_hash = {} + types_mapping.each_pair do |key, type| + if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + transformed_hash[key.to_sym] = nil + elsif type =~ /\AArray<(.*)>/i + # check to ensure the input is an array given that the attribute + # is documented as an array but the input is not + if attributes[attribute_map[key]].is_a?(Array) + transformed_hash[key.to_sym] = attributes[attribute_map[key]].map { |v| + _deserialize(::Regexp.last_match(1), v) + } + end + elsif !attributes[attribute_map[key]].nil? + transformed_hash[key.to_sym] = _deserialize(type, attributes[attribute_map[key]]) + end + end + + new(transformed_hash) + end + + # Deserializes the data based on type + # @param string type Data type + # @param string value Value to be deserialized + # @return [Object] Deserialized data + def self._deserialize(type, value) + case type.to_sym + when :Time + Time.parse(value) + when :Date + Date.parse(value) + when :String + value.to_s + when :Integer + value.to_i + when :Float + value.to_f + when :Boolean + if value.to_s =~ /\A(true|t|yes|y|1)\z/i + true + else + false + end + + when :Object + # generic object (usually a Hash), return directly + value + when /\AArray<(?.+)>\z/ + inner_type = Regexp.last_match[:inner_type] + value.map { |v| _deserialize(inner_type, v) } + when /\AHash<(?.+?), (?.+)>\z/ + k_type = Regexp.last_match[:k_type] + v_type = Regexp.last_match[:v_type] + {}.tap do |hash| + value.each do |k, v| + hash[_deserialize(k_type, k)] = _deserialize(v_type, v) + end + end + # model + else + # models (e.g. Pet) or oneOf + klass = Algolia::Composition.const_get(type) + klass.respond_to?(:openapi_any_of) || klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass + .build_from_hash(value) + end + end + + # Returns the string representation of the object + # @return [String] String presentation of the object + def to_s + to_hash.to_s + end + + # to_body is an alias to to_hash (backward compatibility) + # @return [Hash] Returns the object in the form of hash + def to_body + to_hash + end + + def to_json(*_args) + to_hash.to_json + end + + # Returns the object in the form of hash + # @return [Hash] Returns the object in the form of hash + def to_hash + hash = {} + self.class.attribute_map.each_pair do |attr, param| + value = send(attr) + if value.nil? + is_nullable = self.class.openapi_nullable.include?(attr) + next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) + end + + hash[param] = _to_hash(value) + end + + hash + end + + # Outputs non-array value in the form of hash + # For object, use to_hash. Otherwise, just return the value + # @param [Object] value Any valid value + # @return [Hash] Returns the value in the form of hash + def _to_hash(value) + if value.is_a?(Array) + value.compact.map { |v| _to_hash(v) } + elsif value.is_a?(Hash) + {}.tap do |hash| + value.each { |k, v| hash[k] = _to_hash(v) } + end + elsif value.respond_to?(:to_hash) + value.to_hash + else + value + end + end + + end + + end +end diff --git a/lib/algolia/models/composition/widgets.rb b/lib/algolia/models/composition/widgets.rb new file mode 100644 index 00000000..74eafe67 --- /dev/null +++ b/lib/algolia/models/composition/widgets.rb @@ -0,0 +1,209 @@ +# frozen_string_literal: true + +# Code generated by OpenAPI Generator (https://openapi-generator.tech), manual changes will be lost - read more on https://github.com/algolia/api-clients-automation. DO NOT EDIT. + +require "date" +require "time" + +module Algolia + module Composition + # Widgets returned from any rules that are applied to the current search. + class Widgets + # Banners defined in the Merchandising Studio for a given search. + attr_accessor :banners + + # Attribute mapping from ruby-style variable name to JSON key. + def self.attribute_map + { + :banners => :banners + } + end + + # Attribute type mapping. + def self.types_mapping + { + :banners => :"Array" + } + end + + # List of attributes with nullable: true + def self.openapi_nullable + Set.new( + [] + ) + end + + # Initializes the object + # @param [Hash] attributes Model attributes in the form of hash + def initialize(attributes = {}) + if (!attributes.is_a?(Hash)) + raise ArgumentError, "The input argument (attributes) must be a hash in `Algolia::Widgets` initialize method" + end + + # check to see if the attribute exists and convert string to symbol for hash key + attributes = attributes.each_with_object({}) { |(k, v), h| + if (!self.class.attribute_map.key?(k.to_sym)) + raise( + ArgumentError, + "`#{k}` is not a valid attribute in `Algolia::Widgets`. Please check the name to make sure it's valid. List of attributes: " + + self.class.attribute_map.keys.inspect + ) + end + + h[k.to_sym] = v + } + + if attributes.key?(:banners) + if (value = attributes[:banners]).is_a?(Array) + self.banners = value + end + end + end + + # Checks equality by comparing each attribute. + # @param [Object] Object to be compared + def ==(other) + return true if self.equal?(other) + self.class == other.class && + banners == other.banners + end + + # @see the `==` method + # @param [Object] Object to be compared + def eql?(other) + self == other + end + + # Calculates hash code according to all attributes. + # @return [Integer] Hash code + def hash + [banners].hash + end + + # Builds the object from hash + # @param [Hash] attributes Model attributes in the form of hash + # @return [Object] Returns the model itself + def self.build_from_hash(attributes) + return nil unless attributes.is_a?(Hash) + attributes = attributes.transform_keys(&:to_sym) + transformed_hash = {} + types_mapping.each_pair do |key, type| + if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + transformed_hash[key.to_sym] = nil + elsif type =~ /\AArray<(.*)>/i + # check to ensure the input is an array given that the attribute + # is documented as an array but the input is not + if attributes[attribute_map[key]].is_a?(Array) + transformed_hash[key.to_sym] = attributes[attribute_map[key]].map { |v| + _deserialize(::Regexp.last_match(1), v) + } + end + elsif !attributes[attribute_map[key]].nil? + transformed_hash[key.to_sym] = _deserialize(type, attributes[attribute_map[key]]) + end + end + + new(transformed_hash) + end + + # Deserializes the data based on type + # @param string type Data type + # @param string value Value to be deserialized + # @return [Object] Deserialized data + def self._deserialize(type, value) + case type.to_sym + when :Time + Time.parse(value) + when :Date + Date.parse(value) + when :String + value.to_s + when :Integer + value.to_i + when :Float + value.to_f + when :Boolean + if value.to_s =~ /\A(true|t|yes|y|1)\z/i + true + else + false + end + + when :Object + # generic object (usually a Hash), return directly + value + when /\AArray<(?.+)>\z/ + inner_type = Regexp.last_match[:inner_type] + value.map { |v| _deserialize(inner_type, v) } + when /\AHash<(?.+?), (?.+)>\z/ + k_type = Regexp.last_match[:k_type] + v_type = Regexp.last_match[:v_type] + {}.tap do |hash| + value.each do |k, v| + hash[_deserialize(k_type, k)] = _deserialize(v_type, v) + end + end + # model + else + # models (e.g. Pet) or oneOf + klass = Algolia::Composition.const_get(type) + klass.respond_to?(:openapi_any_of) || klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass + .build_from_hash(value) + end + end + + # Returns the string representation of the object + # @return [String] String presentation of the object + def to_s + to_hash.to_s + end + + # to_body is an alias to to_hash (backward compatibility) + # @return [Hash] Returns the object in the form of hash + def to_body + to_hash + end + + def to_json(*_args) + to_hash.to_json + end + + # Returns the object in the form of hash + # @return [Hash] Returns the object in the form of hash + def to_hash + hash = {} + self.class.attribute_map.each_pair do |attr, param| + value = send(attr) + if value.nil? + is_nullable = self.class.openapi_nullable.include?(attr) + next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) + end + + hash[param] = _to_hash(value) + end + + hash + end + + # Outputs non-array value in the form of hash + # For object, use to_hash. Otherwise, just return the value + # @param [Object] value Any valid value + # @return [Hash] Returns the value in the form of hash + def _to_hash(value) + if value.is_a?(Array) + value.compact.map { |v| _to_hash(v) } + elsif value.is_a?(Hash) + {}.tap do |hash| + value.each { |k, v| hash[k] = _to_hash(v) } + end + elsif value.respond_to?(:to_hash) + value.to_hash + else + value + end + end + + end + + end +end