Skip to content

Commit 0e24050

Browse files
committed
fix: spec shape, handle reserved word queryParameters
1 parent 8458a29 commit 0e24050

File tree

7 files changed

+74
-51
lines changed

7 files changed

+74
-51
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { RecommendationRequest } from './recommendationRequest';
2+
3+
export type GetRecommendations = {
4+
requests: Array<RecommendationRequest>;
5+
};

clients/algoliasearch-client-javascript/recommend/model/models.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ export * from './baseSearchParams';
44
export * from './baseSearchResponse';
55
export * from './baseSearchResponseFacetsStats';
66
export * from './errorBase';
7+
export * from './getRecommendations';
78
export * from './getRecommendationsResponse';
89
export * from './highlightResult';
910
export * from './indexSettingsAsSearchParams';

clients/algoliasearch-client-javascript/recommend/model/recommendationRequest.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,13 @@ export type RecommendationRequest = {
2222
* The max number of recommendations to retrieve. If it’s set to 0, all the recommendations of the objectID may be returned.
2323
*/
2424
maxRecommendations?: number;
25-
_queryParameters?: (BaseSearchParams & IndexSettingsAsSearchParams) | null;
25+
/**
26+
* The Algolia search parameters.
27+
*/
28+
queryParameters?: (BaseSearchParams & IndexSettingsAsSearchParams) | null;
29+
/**
30+
* The Algolia search parameters when there are no recommendations.
31+
*/
2632
fallbackParameters?: (BaseSearchParams & IndexSettingsAsSearchParams) | null;
2733
};
2834

clients/algoliasearch-client-javascript/recommend/src/recommendApi.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import { Headers, Host, Request, RequestOptions } from '../utils/types';
44
import { Requester } from '../utils/Requester';
55

66
import { ErrorBase } from '../model/errorBase';
7+
import { GetRecommendations } from '../model/getRecommendations';
78
import { GetRecommendationsResponse } from '../model/getRecommendationsResponse';
8-
import { RecommendationRequest } from '../model/recommendationRequest';
99
import { ApiKeyAuth } from '../model/models';
1010

1111
export enum RecommendApiKeys {
@@ -70,25 +70,25 @@ export class RecommendApi {
7070
/**
7171
*
7272
* @summary Returns recommendations for a specific model and objectID
73-
* @param recommendationRequest
73+
* @param getRecommendations
7474
*/
7575
public async getRecommendations(
76-
recommendationRequest: Array<RecommendationRequest>
76+
getRecommendations: GetRecommendations
7777
): Promise<GetRecommendationsResponse> {
7878
const path = '/1/indexes/*/recommendations';
7979
let headers: Headers = { Accept: 'application/json' };
8080
let queryParameters: Record<string, string> = {};
8181

82-
if (recommendationRequest === null || recommendationRequest === undefined) {
82+
if (getRecommendations === null || getRecommendations === undefined) {
8383
throw new Error(
84-
'Required parameter recommendationRequest was null or undefined when calling getRecommendations.'
84+
'Required parameter getRecommendations was null or undefined when calling getRecommendations.'
8585
);
8686
}
8787

8888
const request: Request = {
8989
method: 'POST',
9090
path,
91-
data: recommendationRequest,
91+
data: getRecommendations,
9292
};
9393

9494
const requestOptions: RequestOptions = {

openapitools.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
"gitHost": "algolia",
3131
"gitUserId": "algolia",
3232
"gitRepoId": "algoliasearch-client-javascript",
33+
"reservedWordsMappings": "queryParameters=queryParameters",
3334
"additionalProperties": {
3435
"modelPropertyNaming": "original",
3536
"supportsES6": true,

playground/javascript/recommend.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,16 @@ const client = new RecommendApiClient(appId, apiKey);
1414

1515
async function testRecommend() {
1616
try {
17-
const res = await client.getRecommendations([
18-
{
19-
indexName: searchIndex,
20-
model: RecommendationRequest.ModelEnum['BoughtTogether'],
21-
objectID: searchQuery,
22-
threshold: 0,
23-
},
24-
]);
17+
const res = await client.getRecommendations({
18+
requests: [
19+
{
20+
indexName: searchIndex,
21+
model: RecommendationRequest.ModelEnum['BoughtTogether'],
22+
objectID: searchQuery,
23+
threshold: 0,
24+
},
25+
],
26+
});
2527

2628
console.log(`[OK]`, res);
2729
} catch (e) {

specs/recommend/paths/getRecommendations.yml

Lines changed: 44 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -9,42 +9,50 @@ post:
99
application/json:
1010
schema:
1111
title: getRecommendations
12-
type: array
13-
items:
14-
title: recommendationRequest
15-
type: object
16-
additionalProperties: false
17-
properties:
18-
indexName:
19-
$ref: '../../common/parameters.yml#/indexName'
20-
objectID:
21-
$ref: '../../common/parameters.yml#/objectID'
22-
model:
23-
description: The recommendation model to use.
24-
type: string
25-
enum: ['related-products', 'bought-together']
26-
threshold:
27-
type: integer
28-
minimum: 0
29-
maximum: 100
30-
description: The threshold to use when filtering recommendations by their score.
31-
maxRecommendations:
32-
type: integer
33-
default: 0
34-
description: The max number of recommendations to retrieve. If it’s set to 0, all the recommendations of the objectID may be returned.
35-
queryParameters:
36-
allOf:
37-
- $ref: '../../search/common/schemas/SearchParams.yml#/baseSearchParams'
38-
- $ref: '../../search/common/schemas/IndexSettings.yml#/indexSettingsAsSearchParams'
39-
fallbackParameters:
40-
allOf:
41-
- $ref: '../../search/common/schemas/SearchParams.yml#/baseSearchParams'
42-
- $ref: '../../search/common/schemas/IndexSettings.yml#/indexSettingsAsSearchParams'
43-
required:
44-
- model
45-
- indexName
46-
- objectID
47-
- threshold
12+
type: object
13+
additionalProperties: false
14+
properties:
15+
requests:
16+
type: array
17+
items:
18+
title: recommendationRequest
19+
type: object
20+
additionalProperties: false
21+
properties:
22+
indexName:
23+
$ref: '../../common/parameters.yml#/indexName'
24+
objectID:
25+
$ref: '../../common/parameters.yml#/objectID'
26+
model:
27+
description: The recommendation model to use.
28+
type: string
29+
enum: ['related-products', 'bought-together']
30+
threshold:
31+
type: integer
32+
minimum: 0
33+
maximum: 100
34+
description: The threshold to use when filtering recommendations by their score.
35+
maxRecommendations:
36+
type: integer
37+
default: 0
38+
description: The max number of recommendations to retrieve. If it’s set to 0, all the recommendations of the objectID may be returned.
39+
queryParameters:
40+
description: The Algolia search parameters.
41+
allOf:
42+
- $ref: '../../search/common/schemas/SearchParams.yml#/baseSearchParams'
43+
- $ref: '../../search/common/schemas/IndexSettings.yml#/indexSettingsAsSearchParams'
44+
fallbackParameters:
45+
description: The Algolia search parameters when there are no recommendations.
46+
allOf:
47+
- $ref: '../../search/common/schemas/SearchParams.yml#/baseSearchParams'
48+
- $ref: '../../search/common/schemas/IndexSettings.yml#/indexSettingsAsSearchParams'
49+
required:
50+
- model
51+
- indexName
52+
- objectID
53+
- threshold
54+
required:
55+
- requests
4856
responses:
4957
'200':
5058
description: OK

0 commit comments

Comments
 (0)