diff --git a/clients/algoliasearch-client-javascript/recommend/model/getRecommendations.ts b/clients/algoliasearch-client-javascript/recommend/model/getRecommendations.ts new file mode 100644 index 00000000000..61f717e73a4 --- /dev/null +++ b/clients/algoliasearch-client-javascript/recommend/model/getRecommendations.ts @@ -0,0 +1,5 @@ +import { RecommendationRequest } from './recommendationRequest'; + +export type GetRecommendations = { + requests: Array; +}; diff --git a/clients/algoliasearch-client-javascript/recommend/model/models.ts b/clients/algoliasearch-client-javascript/recommend/model/models.ts index 3610262bf61..a8cf01e6c33 100644 --- a/clients/algoliasearch-client-javascript/recommend/model/models.ts +++ b/clients/algoliasearch-client-javascript/recommend/model/models.ts @@ -4,6 +4,7 @@ export * from './baseSearchParams'; export * from './baseSearchResponse'; export * from './baseSearchResponseFacetsStats'; export * from './errorBase'; +export * from './getRecommendations'; export * from './getRecommendationsResponse'; export * from './highlightResult'; export * from './indexSettingsAsSearchParams'; diff --git a/clients/algoliasearch-client-javascript/recommend/model/recommendationRequest.ts b/clients/algoliasearch-client-javascript/recommend/model/recommendationRequest.ts index eb9b7ab6b2e..de88f00ea7f 100644 --- a/clients/algoliasearch-client-javascript/recommend/model/recommendationRequest.ts +++ b/clients/algoliasearch-client-javascript/recommend/model/recommendationRequest.ts @@ -22,7 +22,13 @@ export type RecommendationRequest = { * The max number of recommendations to retrieve. If it’s set to 0, all the recommendations of the objectID may be returned. */ maxRecommendations?: number; - _queryParameters?: (BaseSearchParams & IndexSettingsAsSearchParams) | null; + /** + * The Algolia search parameters. + */ + queryParameters?: (BaseSearchParams & IndexSettingsAsSearchParams) | null; + /** + * The Algolia search parameters when there are no recommendations. + */ fallbackParameters?: (BaseSearchParams & IndexSettingsAsSearchParams) | null; }; diff --git a/clients/algoliasearch-client-javascript/recommend/src/recommendApi.ts b/clients/algoliasearch-client-javascript/recommend/src/recommendApi.ts index a475c50d6b5..af6fa636500 100644 --- a/clients/algoliasearch-client-javascript/recommend/src/recommendApi.ts +++ b/clients/algoliasearch-client-javascript/recommend/src/recommendApi.ts @@ -4,8 +4,8 @@ import { Headers, Host, Request, RequestOptions } from '../utils/types'; import { Requester } from '../utils/Requester'; import { ErrorBase } from '../model/errorBase'; +import { GetRecommendations } from '../model/getRecommendations'; import { GetRecommendationsResponse } from '../model/getRecommendationsResponse'; -import { RecommendationRequest } from '../model/recommendationRequest'; import { ApiKeyAuth } from '../model/models'; export enum RecommendApiKeys { @@ -70,25 +70,25 @@ export class RecommendApi { /** * * @summary Returns recommendations for a specific model and objectID - * @param recommendationRequest + * @param getRecommendations */ public async getRecommendations( - recommendationRequest: Array + getRecommendations: GetRecommendations ): Promise { const path = '/1/indexes/*/recommendations'; let headers: Headers = { Accept: 'application/json' }; let queryParameters: Record = {}; - if (recommendationRequest === null || recommendationRequest === undefined) { + if (getRecommendations === null || getRecommendations === undefined) { throw new Error( - 'Required parameter recommendationRequest was null or undefined when calling getRecommendations.' + 'Required parameter getRecommendations was null or undefined when calling getRecommendations.' ); } const request: Request = { method: 'POST', path, - data: recommendationRequest, + data: getRecommendations, }; const requestOptions: RequestOptions = { diff --git a/openapitools.json b/openapitools.json index af88ab629a5..7363c129304 100644 --- a/openapitools.json +++ b/openapitools.json @@ -30,6 +30,7 @@ "gitHost": "algolia", "gitUserId": "algolia", "gitRepoId": "algoliasearch-client-javascript", + "reservedWordsMappings": "queryParameters=queryParameters", "additionalProperties": { "modelPropertyNaming": "original", "supportsES6": true, diff --git a/playground/javascript/recommend.ts b/playground/javascript/recommend.ts index 66bf7b3f3e5..38c837d506b 100644 --- a/playground/javascript/recommend.ts +++ b/playground/javascript/recommend.ts @@ -14,14 +14,16 @@ const client = new RecommendApiClient(appId, apiKey); async function testRecommend() { try { - const res = await client.getRecommendations([ - { - indexName: searchIndex, - model: RecommendationRequest.ModelEnum['BoughtTogether'], - objectID: searchQuery, - threshold: 0, - }, - ]); + const res = await client.getRecommendations({ + requests: [ + { + indexName: searchIndex, + model: RecommendationRequest.ModelEnum['BoughtTogether'], + objectID: searchQuery, + threshold: 0, + }, + ], + }); console.log(`[OK]`, res); } catch (e) { diff --git a/specs/recommend/paths/getRecommendations.yml b/specs/recommend/paths/getRecommendations.yml index 4fbe9cfde4c..41cc7ca7348 100644 --- a/specs/recommend/paths/getRecommendations.yml +++ b/specs/recommend/paths/getRecommendations.yml @@ -9,42 +9,50 @@ post: application/json: schema: title: getRecommendations - type: array - items: - title: recommendationRequest - type: object - additionalProperties: false - properties: - indexName: - $ref: '../../common/parameters.yml#/indexName' - objectID: - $ref: '../../common/parameters.yml#/objectID' - model: - description: The recommendation model to use. - type: string - enum: ['related-products', 'bought-together'] - threshold: - type: integer - minimum: 0 - maximum: 100 - description: The threshold to use when filtering recommendations by their score. - maxRecommendations: - type: integer - default: 0 - description: The max number of recommendations to retrieve. If it’s set to 0, all the recommendations of the objectID may be returned. - queryParameters: - allOf: - - $ref: '../../search/common/schemas/SearchParams.yml#/baseSearchParams' - - $ref: '../../search/common/schemas/IndexSettings.yml#/indexSettingsAsSearchParams' - fallbackParameters: - allOf: - - $ref: '../../search/common/schemas/SearchParams.yml#/baseSearchParams' - - $ref: '../../search/common/schemas/IndexSettings.yml#/indexSettingsAsSearchParams' - required: - - model - - indexName - - objectID - - threshold + type: object + additionalProperties: false + properties: + requests: + type: array + items: + title: recommendationRequest + type: object + additionalProperties: false + properties: + indexName: + $ref: '../../common/parameters.yml#/indexName' + objectID: + $ref: '../../common/parameters.yml#/objectID' + model: + description: The recommendation model to use. + type: string + enum: ['related-products', 'bought-together'] + threshold: + type: integer + minimum: 0 + maximum: 100 + description: The threshold to use when filtering recommendations by their score. + maxRecommendations: + type: integer + default: 0 + description: The max number of recommendations to retrieve. If it’s set to 0, all the recommendations of the objectID may be returned. + queryParameters: + description: The Algolia search parameters. + allOf: + - $ref: '../../search/common/schemas/SearchParams.yml#/baseSearchParams' + - $ref: '../../search/common/schemas/IndexSettings.yml#/indexSettingsAsSearchParams' + fallbackParameters: + description: The Algolia search parameters when there are no recommendations. + allOf: + - $ref: '../../search/common/schemas/SearchParams.yml#/baseSearchParams' + - $ref: '../../search/common/schemas/IndexSettings.yml#/indexSettingsAsSearchParams' + required: + - model + - indexName + - objectID + - threshold + required: + - requests responses: '200': description: OK