Skip to content

Commit

Permalink
fix: spec shape, handle reserved word queryParameters
Browse files Browse the repository at this point in the history
  • Loading branch information
shortcuts committed Nov 29, 2021
1 parent 459e628 commit 36749c2
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 51 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { RecommendationRequest } from './recommendationRequest';

export type GetRecommendations = {
requests: Array<RecommendationRequest>;
};
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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<RecommendationRequest>
getRecommendations: GetRecommendations
): Promise<GetRecommendationsResponse> {
const path = '/1/indexes/*/recommendations';
let headers: Headers = { Accept: 'application/json' };
let queryParameters: Record<string, string> = {};

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 = {
Expand Down
1 change: 1 addition & 0 deletions openapitools.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"gitHost": "algolia",
"gitUserId": "algolia",
"gitRepoId": "algoliasearch-client-javascript",
"reservedWordsMappings": "queryParameters=queryParameters",
"additionalProperties": {
"modelPropertyNaming": "original",
"supportsES6": true,
Expand Down
18 changes: 10 additions & 8 deletions playground/javascript/recommend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
80 changes: 44 additions & 36 deletions specs/recommend/paths/getRecommendations.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 36749c2

Please sign in to comment.