Skip to content

Commit b23c822

Browse files
algolia-bote-krebsshortcutsmillotp
committed
feat(specs): rename composition to composition-full (private) and add 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]>
1 parent 7e4c20d commit b23c822

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+10818
-0
lines changed

lib/algolia/api/composition_client.rb

Lines changed: 174 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,174 @@
1+
# frozen_string_literal: true
2+
3+
# 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.
4+
5+
module Algolia
6+
class CompositionClient
7+
attr_accessor :api_client
8+
9+
def initialize(config = nil)
10+
raise "`config` is missing." if config.nil?
11+
raise "`app_id` is missing." if config.app_id.nil? || config.app_id == ""
12+
raise "`api_key` is missing." if config.api_key.nil? || config.api_key == ""
13+
14+
@api_client = Algolia::ApiClient.new(config)
15+
end
16+
17+
def self.create(app_id, api_key, opts = {})
18+
hosts = []
19+
hosts << Transport::StatefulHost.new("#{app_id}-dsn.algolia.net", accept: CallType::READ)
20+
hosts << Transport::StatefulHost.new("#{app_id}.algolia.net", accept: CallType::WRITE)
21+
22+
hosts += 1
23+
.upto(3)
24+
.map do |i|
25+
Transport::StatefulHost.new("#{app_id}-#{i}.algolianet.com", accept: CallType::READ | CallType::WRITE)
26+
end
27+
.shuffle
28+
29+
config = Algolia::Configuration.new(app_id, api_key, hosts, "Composition", opts)
30+
create_with_config(config)
31+
end
32+
33+
def self.create_with_config(config)
34+
new(config)
35+
end
36+
37+
# Helper method to switch the API key used to authenticate the requests.
38+
#
39+
# @param api_key [String] the new API key to use.
40+
# @return [void]
41+
def set_client_api_key(api_key)
42+
@api_client.set_client_api_key(api_key)
43+
44+
self
45+
end
46+
47+
def add_user_agent_segment(segment, version = nil)
48+
@api_client.config.add_user_agent_segment(segment, version)
49+
50+
self
51+
end
52+
53+
# Runs a query on a single composition and returns matching results.
54+
#
55+
# Required API Key ACLs:
56+
# - search
57+
# @param composition_id [String] Unique Composition ObjectID. (required)
58+
# @param request_body [RequestBody] (required)
59+
# @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)
60+
# @return [Http::Response] the response
61+
def search_with_http_info(composition_id, request_body, request_options = {})
62+
# verify the required parameter 'composition_id' is set
63+
if @api_client.config.client_side_validation && composition_id.nil?
64+
raise ArgumentError, "Parameter `composition_id` is required when calling `search`."
65+
end
66+
# verify the required parameter 'request_body' is set
67+
if @api_client.config.client_side_validation && request_body.nil?
68+
raise ArgumentError, "Parameter `request_body` is required when calling `search`."
69+
end
70+
71+
path = "/1/compositions/{compositionID}/run".sub(
72+
"{" + "compositionID" + "}",
73+
Transport.encode_uri(composition_id.to_s)
74+
)
75+
query_params = {}
76+
query_params = query_params.merge(request_options[:query_params]) unless request_options[:query_params].nil?
77+
header_params = {}
78+
header_params = header_params.merge(request_options[:header_params]) unless request_options[:header_params].nil?
79+
80+
post_body = request_options[:debug_body] || @api_client.object_to_http_body(request_body)
81+
82+
new_options = request_options.merge(
83+
:operation => :"CompositionClient.search",
84+
:header_params => header_params,
85+
:query_params => query_params,
86+
:body => post_body,
87+
:use_read_transporter => true
88+
)
89+
90+
@api_client.call_api(:POST, path, new_options)
91+
end
92+
93+
# Runs a query on a single composition and returns matching results.
94+
#
95+
# Required API Key ACLs:
96+
# - search
97+
# @param composition_id [String] Unique Composition ObjectID. (required)
98+
# @param request_body [RequestBody] (required)
99+
# @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)
100+
# @return [SearchResponse]
101+
def search(composition_id, request_body, request_options = {})
102+
response = search_with_http_info(composition_id, request_body, request_options)
103+
@api_client.deserialize(response.body, request_options[:debug_return_type] || "Composition::SearchResponse")
104+
end
105+
106+
# 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**.
107+
#
108+
# Required API Key ACLs:
109+
# - search
110+
# @param composition_id [String] Unique Composition ObjectID. (required)
111+
# @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)
112+
# @param search_for_facet_values_request [SearchForFacetValuesRequest]
113+
# @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)
114+
# @return [Http::Response] the response
115+
def search_for_facet_values_with_http_info(
116+
composition_id,
117+
facet_name,
118+
search_for_facet_values_request = nil,
119+
request_options = {}
120+
)
121+
# verify the required parameter 'composition_id' is set
122+
if @api_client.config.client_side_validation && composition_id.nil?
123+
raise ArgumentError, "Parameter `composition_id` is required when calling `search_for_facet_values`."
124+
end
125+
# verify the required parameter 'facet_name' is set
126+
if @api_client.config.client_side_validation && facet_name.nil?
127+
raise ArgumentError, "Parameter `facet_name` is required when calling `search_for_facet_values`."
128+
end
129+
130+
path = "/1/compositions/{compositionID}/facets/{facetName}/query"
131+
.sub("{" + "compositionID" + "}", Transport.encode_uri(composition_id.to_s))
132+
.sub("{" + "facetName" + "}", Transport.encode_uri(facet_name.to_s))
133+
query_params = {}
134+
query_params = query_params.merge(request_options[:query_params]) unless request_options[:query_params].nil?
135+
header_params = {}
136+
header_params = header_params.merge(request_options[:header_params]) unless request_options[:header_params].nil?
137+
138+
post_body = request_options[:debug_body] || @api_client.object_to_http_body(search_for_facet_values_request)
139+
140+
new_options = request_options.merge(
141+
:operation => :"CompositionClient.search_for_facet_values",
142+
:header_params => header_params,
143+
:query_params => query_params,
144+
:body => post_body,
145+
:use_read_transporter => true
146+
)
147+
148+
@api_client.call_api(:POST, path, new_options)
149+
end
150+
151+
# 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**.
152+
#
153+
# Required API Key ACLs:
154+
# - search
155+
# @param composition_id [String] Unique Composition ObjectID. (required)
156+
# @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)
157+
# @param search_for_facet_values_request [SearchForFacetValuesRequest]
158+
# @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)
159+
# @return [SearchForFacetValuesResponse]
160+
def search_for_facet_values(composition_id, facet_name, search_for_facet_values_request = nil, request_options = {})
161+
response = search_for_facet_values_with_http_info(
162+
composition_id,
163+
facet_name,
164+
search_for_facet_values_request,
165+
request_options
166+
)
167+
@api_client.deserialize(
168+
response.body,
169+
request_options[:debug_return_type] || "Composition::SearchForFacetValuesResponse"
170+
)
171+
end
172+
173+
end
174+
end
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
# frozen_string_literal: true
2+
3+
# 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.
4+
5+
require "date"
6+
require "time"
7+
8+
module Algolia
9+
module Composition
10+
# 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.
11+
module AroundPrecision
12+
class << self
13+
# List of class defined in oneOf (OpenAPI v3)
14+
def openapi_one_of
15+
[
16+
:"Array<Range>",
17+
:"Integer"
18+
]
19+
end
20+
21+
# Builds the object
22+
# @param [Mixed] Data to be matched against the list of oneOf items
23+
# @return [Object] Returns the model or the data itself
24+
def build(data)
25+
# Go through the list of oneOf items and attempt to identify the appropriate one.
26+
# Note:
27+
# - We do not attempt to check whether exactly one item matches.
28+
# - No advanced validation of types in some cases (e.g. "x: { type: string }" will happily match { x: 123 })
29+
# due to the way the deserialization is made in the base_object template (it just casts without verifying).
30+
# - TODO: scalar values are de facto behaving as if they were nullable.
31+
# - TODO: logging when debugging is set.
32+
openapi_one_of.each do |klass|
33+
begin
34+
# "nullable: true"
35+
next if klass == :AnyType
36+
typed_data = find_and_cast_into_type(klass, data)
37+
return typed_data if typed_data
38+
# rescue all errors so we keep iterating even if the current item lookup raises
39+
rescue
40+
end
41+
end
42+
43+
openapi_one_of.include?(:AnyType) ? data : nil
44+
end
45+
46+
private
47+
48+
SchemaMismatchError = Class.new(StandardError)
49+
50+
def find_and_cast_into_type(klass, data)
51+
return if data.nil?
52+
53+
case klass.to_s
54+
when "Boolean"
55+
return data if data.instance_of?(TrueClass) || data.instance_of?(FalseClass)
56+
when "Float"
57+
return data if data.instance_of?(Float)
58+
when "Integer"
59+
return data if data.instance_of?(Integer)
60+
when "Time"
61+
return Time.parse(data)
62+
when "Date"
63+
return Date.parse(data)
64+
when "String"
65+
return data if data.instance_of?(String)
66+
# "type: object"
67+
when "Object"
68+
return data if data.instance_of?(Hash)
69+
# "type: array"
70+
when /\AArray<(?<sub_type>.+)>\z/
71+
if data.instance_of?(Array)
72+
sub_type = Regexp.last_match[:sub_type]
73+
return data.map { |item| find_and_cast_into_type(sub_type, item) }
74+
end
75+
# "type: object" with "additionalProperties: { ... }"
76+
when /\AHash<String, (?<sub_type>.+)>\z/
77+
if data.instance_of?(Hash) && data.keys.all? { |k| k.instance_of?(Symbol) || k.instance_of?(String) }
78+
sub_type = Regexp.last_match[:sub_type]
79+
return data.each_with_object({}) { |(k, v), hsh| hsh[k] = find_and_cast_into_type(sub_type, v) }
80+
end
81+
# model
82+
else
83+
const = Algolia::Composition.const_get(klass)
84+
if const
85+
if const.respond_to?(:openapi_one_of)
86+
# nested oneOf model
87+
model = const.build(data)
88+
elsif const.respond_to?(:discriminator_attributes)
89+
if const.discriminator_attributes.all? { |attr| data.key?(attr) }
90+
model = const.build_from_hash(data)
91+
end
92+
else
93+
# maybe it's an enum, or doens't have discriminators
94+
model = const.build_from_hash(data)
95+
end
96+
97+
return model if model
98+
end
99+
end
100+
101+
# if no match by now, raise
102+
raise
103+
rescue
104+
raise SchemaMismatchError, "#{data} doesn't match the #{klass} type"
105+
end
106+
end
107+
end
108+
109+
end
110+
end
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
# frozen_string_literal: true
2+
3+
# 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.
4+
5+
require "date"
6+
require "time"
7+
8+
module Algolia
9+
module Composition
10+
# 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.
11+
module AroundRadius
12+
class << self
13+
# List of class defined in oneOf (OpenAPI v3)
14+
def openapi_one_of
15+
[
16+
:"AroundRadiusAll",
17+
:"Integer"
18+
]
19+
end
20+
21+
# Builds the object
22+
# @param [Mixed] Data to be matched against the list of oneOf items
23+
# @return [Object] Returns the model or the data itself
24+
def build(data)
25+
# Go through the list of oneOf items and attempt to identify the appropriate one.
26+
# Note:
27+
# - We do not attempt to check whether exactly one item matches.
28+
# - No advanced validation of types in some cases (e.g. "x: { type: string }" will happily match { x: 123 })
29+
# due to the way the deserialization is made in the base_object template (it just casts without verifying).
30+
# - TODO: scalar values are de facto behaving as if they were nullable.
31+
# - TODO: logging when debugging is set.
32+
openapi_one_of.each do |klass|
33+
begin
34+
# "nullable: true"
35+
next if klass == :AnyType
36+
typed_data = find_and_cast_into_type(klass, data)
37+
return typed_data if typed_data
38+
# rescue all errors so we keep iterating even if the current item lookup raises
39+
rescue
40+
end
41+
end
42+
43+
openapi_one_of.include?(:AnyType) ? data : nil
44+
end
45+
46+
private
47+
48+
SchemaMismatchError = Class.new(StandardError)
49+
50+
def find_and_cast_into_type(klass, data)
51+
return if data.nil?
52+
53+
case klass.to_s
54+
when "Boolean"
55+
return data if data.instance_of?(TrueClass) || data.instance_of?(FalseClass)
56+
when "Float"
57+
return data if data.instance_of?(Float)
58+
when "Integer"
59+
return data if data.instance_of?(Integer)
60+
when "Time"
61+
return Time.parse(data)
62+
when "Date"
63+
return Date.parse(data)
64+
when "String"
65+
return data if data.instance_of?(String)
66+
# "type: object"
67+
when "Object"
68+
return data if data.instance_of?(Hash)
69+
# "type: array"
70+
when /\AArray<(?<sub_type>.+)>\z/
71+
if data.instance_of?(Array)
72+
sub_type = Regexp.last_match[:sub_type]
73+
return data.map { |item| find_and_cast_into_type(sub_type, item) }
74+
end
75+
# "type: object" with "additionalProperties: { ... }"
76+
when /\AHash<String, (?<sub_type>.+)>\z/
77+
if data.instance_of?(Hash) && data.keys.all? { |k| k.instance_of?(Symbol) || k.instance_of?(String) }
78+
sub_type = Regexp.last_match[:sub_type]
79+
return data.each_with_object({}) { |(k, v), hsh| hsh[k] = find_and_cast_into_type(sub_type, v) }
80+
end
81+
# model
82+
else
83+
const = Algolia::Composition.const_get(klass)
84+
if const
85+
if const.respond_to?(:openapi_one_of)
86+
# nested oneOf model
87+
model = const.build(data)
88+
elsif const.respond_to?(:discriminator_attributes)
89+
if const.discriminator_attributes.all? { |attr| data.key?(attr) }
90+
model = const.build_from_hash(data)
91+
end
92+
else
93+
# maybe it's an enum, or doens't have discriminators
94+
model = const.build_from_hash(data)
95+
end
96+
97+
return model if model
98+
end
99+
end
100+
101+
# if no match by now, raise
102+
raise
103+
rescue
104+
raise SchemaMismatchError, "#{data} doesn't match the #{klass} type"
105+
end
106+
end
107+
end
108+
109+
end
110+
end

0 commit comments

Comments
 (0)