lib/algolia/models/search/search_synonyms_params.rb in algolia-3.0.0.alpha.5 vs lib/algolia/models/search/search_synonyms_params.rb in algolia-3.0.0.alpha.6

- old
+ new

@@ -7,14 +7,47 @@ module Search class SearchSynonymsParams # Text to search for in an index. attr_accessor :query + attr_accessor :type + + # Page to retrieve (the first page is `0`, not `1`). + attr_accessor :page + + # Number of hits per page. + attr_accessor :hits_per_page + + class EnumAttributeValidator + attr_reader :datatype + attr_reader :allowable_values + + def initialize(datatype, allowable_values) + @allowable_values = allowable_values.map do |value| + case datatype.to_s + when /Integer/i + value.to_i + when /Float/i + value.to_f + else + value + end + end + end + + def valid?(value) + !value || allowable_values.include?(value) + end + end + # Attribute mapping from ruby-style variable name to JSON key. def self.attribute_map { - :query => :query + :query => :query, + :type => :type, + :page => :page, + :hits_per_page => :hitsPerPage } end # Returns all the JSON keys this model knows about def self.acceptable_attributes @@ -22,11 +55,14 @@ end # Attribute type mapping. def self.types_mapping { - :query => :String + :query => :String, + :type => :SynonymType, + :page => :Integer, + :hits_per_page => :Integer } end # List of attributes with nullable: true def self.openapi_nullable @@ -51,19 +87,52 @@ end if attributes.key?(:query) self.query = attributes[:query] end + + if attributes.key?(:type) + self.type = attributes[:type] + end + + if attributes.key?(:page) + self.page = attributes[:page] + end + + if attributes.key?(:hits_per_page) + self.hits_per_page = attributes[:hits_per_page] + end end + # Custom attribute writer method with validation + # @param [Object] hits_per_page Value to be assigned + def hits_per_page=(hits_per_page) + if hits_per_page.nil? + raise ArgumentError, 'hits_per_page cannot be nil' + end + + if hits_per_page > 1000 + raise ArgumentError, 'invalid value for "hits_per_page", must be smaller than or equal to 1000.' + end + + if hits_per_page < 1 + raise ArgumentError, 'invalid value for "hits_per_page", must be greater than or equal to 1.' + end + + @hits_per_page = hits_per_page + end + # Checks equality by comparing each attribute. # @param [Object] Object to be compared def ==(other) return true if equal?(other) self.class == other.class && - query == other.query + query == other.query && + type == other.type && + page == other.page && + hits_per_page == other.hits_per_page end # @see the `==` method # @param [Object] Object to be compared def eql?(other) @@ -71,11 +140,11 @@ end # Calculates hash code according to all attributes. # @return [Integer] Hash code def hash - [query].hash + [query, type, page, hits_per_page].hash end # Builds the object from hash # @param [Hash] attributes Model attributes in the form of hash # @return [Object] Returns the model itself @@ -84,19 +153,19 @@ 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_s] = 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_s] = attributes[attribute_map[key]].map { |v| _deserialize(::Regexp.last_match(1), v) } + 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_s] = _deserialize(type, attributes[attribute_map[key]]) + transformed_hash[key.to_sym] = _deserialize(type, attributes[attribute_map[key]]) end end new(transformed_hash) end @@ -151,9 +220,13 @@ # 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