Skip to content

Commit

Permalink
feat(specs): rename composition to composition-full (private) and add…
Browse files Browse the repository at this point in the history
… composition (public) (generated)

algolia/api-clients-automation#4357

Co-authored-by: algolia-bot <[email protected]>
Co-authored-by: Emmanuel Krebs <[email protected]>
Co-authored-by: shortcuts <[email protected]>
Co-authored-by: Pierre Millot <[email protected]>
  • Loading branch information
4 people committed Jan 22, 2025
1 parent 7e4c20d commit b23c822
Show file tree
Hide file tree
Showing 52 changed files with 10,818 additions and 0 deletions.
174 changes: 174 additions & 0 deletions lib/algolia/api/composition_client.rb
Original file line number Diff line number Diff line change
@@ -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
110 changes: 110 additions & 0 deletions lib/algolia/models/composition/around_precision.rb
Original file line number Diff line number Diff line change
@@ -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<Range>",
:"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<(?<sub_type>.+)>\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<String, (?<sub_type>.+)>\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
110 changes: 110 additions & 0 deletions lib/algolia/models/composition/around_radius.rb
Original file line number Diff line number Diff line change
@@ -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<(?<sub_type>.+)>\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<String, (?<sub_type>.+)>\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
Loading

0 comments on commit b23c822

Please sign in to comment.