Skip to content

feat(javascript): legacy getRecommendations signature #3241

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions specs/recommend/paths/getRecommendations.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ post:
x-cacheable: true
x-acl:
- search
x-legacy-signature-recommend: true
summary: Retrieve recommendations
description: |
Retrieves recommendations from selected AI models.
Expand Down
4 changes: 4 additions & 0 deletions templates/javascript/clients/api-single.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ export function create{{#lambda.titlecase}}{{apiName}}{{/lambda.titlecase}}({
{{> client/api/operation/legacySearchCompatible/implementation}}
{{/vendorExtensions.x-legacy-signature}}

{{#vendorExtensions.x-legacy-signature-recommend}}
{{> client/api/operation/legacyGetRecommendationsCompatible/implementation}}
{{/vendorExtensions.x-legacy-signature-recommend}}

{{#allParams}}
{{#required}}
if ({{#isBoolean}}{{paramName}} === null || {{paramName}} === undefined{{/isBoolean}}{{^isBoolean}}!{{paramName}}{{/isBoolean}}) {
Expand Down
3 changes: 3 additions & 0 deletions templates/javascript/clients/client/api/imports.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ import type {
{{#x-legacy-signature}}
LegacySearchMethodProps,
{{/x-legacy-signature}}
{{#x-legacy-signature-recommend}}
LegacyGetRecommendationsParams,
{{/x-legacy-signature-recommend}}
{{/vendorExtensions}}
{{/operation}}
} from '../model/clientMethodProps';
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
if (getRecommendationsParams && Array.isArray(getRecommendationsParams)) {
const newSignatureRequest: GetRecommendationsParams = {
requests: getRecommendationsParams,
};

// eslint-disable-next-line no-param-reassign
getRecommendationsParams = newSignatureRequest;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import type { RecommendationsRequest } from './recommendationsRequest';
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/**
* Recommend method signature compatible with the `algoliasearch` v4 package. When using this signature, extra computation will be required to make it match the new signature.
*
* @deprecated This signature will be removed from the next major version, we recommend using the `GetRecommendationsParams` type for performances and future proof reasons.
*/
export type LegacyGetRecommendationsParams = RecommendationsRequest[];
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
{{/x-create-wrapping-object}}
{{#x-is-single-body-param}}
{{#bodyParams}}
{{paramName}}: {{{dataType}}} {{#x-legacy-signature}} | LegacySearchMethodProps{{/x-legacy-signature}},
{{paramName}}: {{{dataType}}} {{#x-legacy-signature}} | LegacySearchMethodProps{{/x-legacy-signature}} {{#x-legacy-signature-recommend}} | LegacyGetRecommendationsParams{{/x-legacy-signature-recommend}},
{{/bodyParams}}
{{/x-is-single-body-param}}
{{/vendorExtensions}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ import { {{classname}} } from '{{filename}}';
{{/imports}}

{{! Imports for the legacy search method signature }}
{{#operations}}{{#operation}}{{#vendorExtensions.x-legacy-signature}}{{> client/api/operation/legacySearchCompatible/imports}}{{/vendorExtensions.x-legacy-signature}}{{/operation}}{{/operations}}
{{#operations}}
{{#operation}}{{#vendorExtensions.x-legacy-signature}}{{> client/api/operation/legacySearchCompatible/imports}}{{/vendorExtensions.x-legacy-signature}}{{/operation}}
{{#operation}}{{#vendorExtensions.x-legacy-signature-recommend}}{{> client/api/operation/legacyGetRecommendationsCompatible/imports}}{{/vendorExtensions.x-legacy-signature-recommend}}{{/operation}}
{{/operations}}

{{! Imports for the helpers method of the search client }}
{{#isSearchClient}}
Expand Down Expand Up @@ -36,6 +39,7 @@ export type {{#lambda.titlecase}}{{nickname}}{{/lambda.titlecase}}Props = {
{{/x-create-wrapping-object}}

{{#x-legacy-signature}}{{> client/api/operation/legacySearchCompatible/model}}{{/x-legacy-signature}}
{{#x-legacy-signature-recommend}}{{> client/api/operation/legacyGetRecommendationsCompatible/model}}{{/x-legacy-signature-recommend}}

{{/vendorExtensions}}

Expand Down
Loading