From 6b11b8c9b6b5b51fd4208353ea9facded9967468 Mon Sep 17 00:00:00 2001 From: Emmanuel Date: Tue, 14 Jan 2025 11:41:23 +0100 Subject: [PATCH 01/31] feat: rename composition to composition-full (private) and add composition (public) --- config/clients.config.json | 19 +++- .../common/parameters.yml | 0 .../common/schemas/Batch.yml | 0 .../common/schemas/GetTaskResponse.yml | 0 .../common/schemas/Hit.yml | 0 .../schemas/SearchForFacetValuesResponse.yml | 0 .../common/schemas/SearchParams.yml | 0 .../common/schemas/SearchResponse.yml | 0 .../common/schemas/batchCompositionAction.yml | 0 .../common/schemas/compositionBehavior.yml | 0 .../common/schemas/compositionRule.yml | 0 .../schemas/listCompositionsResponse.yml | 0 .../schemas/rulesBatchCompositionAction.yml | 0 .../helpers/waitForCompositionTask.yml | 0 .../paths/advanced/getTask.yml | 0 .../manage_compositions/listCompositions.yml | 0 .../paths/objects/multipleBatch.yml | 0 .../paths/objects/objects.yml | 0 .../paths/rules/parameters.yml | 0 .../paths/rules/rule.yml | 0 .../paths/rules/saveRules.yml | 0 .../paths/rules/searchRules.yml | 0 .../paths/search/search.yml | 0 .../paths/search/searchForFacetValues.yml | 0 specs/composition-full/spec.yml | 101 ++++++++++++++++++ specs/composition/spec.yml | 49 +-------- .../javascript/clients/api-single.mustache | 4 +- .../clients/client/api/imports.mustache | 8 +- .../clients/client/builds/browser.mustache | 2 +- .../client/model/clientMethodProps.mustache | 4 +- templates/javascript/snippets/init.mustache | 2 +- .../javascript/tests/client/client.mustache | 16 +-- .../tests/client/createClient.mustache | 2 +- templates/javascript/tests/e2e/e2e.mustache | 10 +- .../tests/requests/requests.mustache | 12 +-- 35 files changed, 151 insertions(+), 78 deletions(-) rename specs/{composition => composition-full}/common/parameters.yml (100%) rename specs/{composition => composition-full}/common/schemas/Batch.yml (100%) rename specs/{composition => composition-full}/common/schemas/GetTaskResponse.yml (100%) rename specs/{composition => composition-full}/common/schemas/Hit.yml (100%) rename specs/{composition => composition-full}/common/schemas/SearchForFacetValuesResponse.yml (100%) rename specs/{composition => composition-full}/common/schemas/SearchParams.yml (100%) rename specs/{composition => composition-full}/common/schemas/SearchResponse.yml (100%) rename specs/{composition => composition-full}/common/schemas/batchCompositionAction.yml (100%) rename specs/{composition => composition-full}/common/schemas/compositionBehavior.yml (100%) rename specs/{composition => composition-full}/common/schemas/compositionRule.yml (100%) rename specs/{composition => composition-full}/common/schemas/listCompositionsResponse.yml (100%) rename specs/{composition => composition-full}/common/schemas/rulesBatchCompositionAction.yml (100%) rename specs/{composition => composition-full}/helpers/waitForCompositionTask.yml (100%) rename specs/{composition => composition-full}/paths/advanced/getTask.yml (100%) rename specs/{composition => composition-full}/paths/manage_compositions/listCompositions.yml (100%) rename specs/{composition => composition-full}/paths/objects/multipleBatch.yml (100%) rename specs/{composition => composition-full}/paths/objects/objects.yml (100%) rename specs/{composition => composition-full}/paths/rules/parameters.yml (100%) rename specs/{composition => composition-full}/paths/rules/rule.yml (100%) rename specs/{composition => composition-full}/paths/rules/saveRules.yml (100%) rename specs/{composition => composition-full}/paths/rules/searchRules.yml (100%) rename specs/{composition => composition-full}/paths/search/search.yml (100%) rename specs/{composition => composition-full}/paths/search/searchForFacetValues.yml (100%) create mode 100644 specs/composition-full/spec.yml diff --git a/config/clients.config.json b/config/clients.config.json index 015ff8a19c..3d48ea8fbb 100644 --- a/config/clients.config.json +++ b/config/clients.config.json @@ -3,6 +3,7 @@ "clients": [ "abtesting", "analytics", + "composition", "ingestion", "insights", "monitoring", @@ -32,6 +33,10 @@ "name": "algoliasearch", "output": "clients/algoliasearch-client-dart/packages/algoliasearch" }, + { + "name": "composition", + "output": "clients/algoliasearch-client-dart/packages/client_composition" + }, { "name": "insights", "output": "clients/algoliasearch-client-dart/packages/client_insights" @@ -64,6 +69,7 @@ "clients": [ "abtesting", "analytics", + "composition", "ingestion", "insights", "monitoring", @@ -91,6 +97,7 @@ "clients": [ "abtesting", "analytics", + "composition", "ingestion", "insights", "monitoring", @@ -134,6 +141,10 @@ "name": "analytics", "output": "clients/algoliasearch-client-javascript/packages/client-analytics" }, + { + "name": "composition", + "output": "clients/algoliasearch-client-javascript/packages/composition" + }, { "name": "ingestion", "output": "clients/algoliasearch-client-javascript/packages/ingestion" @@ -163,7 +174,7 @@ "output": "clients/algoliasearch-client-javascript/packages/client-search" }, { - "name": "composition", + "name": "composition-full", "output": "clients/algoliasearch-client-javascript/packages/client-composition" } ], @@ -185,6 +196,7 @@ "clients": [ "abtesting", "analytics", + "composition", "ingestion", "insights", "monitoring", @@ -212,6 +224,7 @@ "clients": [ "abtesting", "analytics", + "composition", "ingestion", "insights", "monitoring", @@ -239,6 +252,7 @@ "clients": [ "abtesting", "analytics", + "composition", "ingestion", "insights", "monitoring", @@ -273,6 +287,7 @@ "clients": [ "abtesting", "analytics", + "composition", "ingestion", "insights", "monitoring", @@ -300,6 +315,7 @@ "clients": [ "abtesting", "analytics", + "composition", "ingestion", "insights", "monitoring", @@ -327,6 +343,7 @@ "clients": [ "abtesting", "analytics", + "composition", "ingestion", "insights", "monitoring", diff --git a/specs/composition/common/parameters.yml b/specs/composition-full/common/parameters.yml similarity index 100% rename from specs/composition/common/parameters.yml rename to specs/composition-full/common/parameters.yml diff --git a/specs/composition/common/schemas/Batch.yml b/specs/composition-full/common/schemas/Batch.yml similarity index 100% rename from specs/composition/common/schemas/Batch.yml rename to specs/composition-full/common/schemas/Batch.yml diff --git a/specs/composition/common/schemas/GetTaskResponse.yml b/specs/composition-full/common/schemas/GetTaskResponse.yml similarity index 100% rename from specs/composition/common/schemas/GetTaskResponse.yml rename to specs/composition-full/common/schemas/GetTaskResponse.yml diff --git a/specs/composition/common/schemas/Hit.yml b/specs/composition-full/common/schemas/Hit.yml similarity index 100% rename from specs/composition/common/schemas/Hit.yml rename to specs/composition-full/common/schemas/Hit.yml diff --git a/specs/composition/common/schemas/SearchForFacetValuesResponse.yml b/specs/composition-full/common/schemas/SearchForFacetValuesResponse.yml similarity index 100% rename from specs/composition/common/schemas/SearchForFacetValuesResponse.yml rename to specs/composition-full/common/schemas/SearchForFacetValuesResponse.yml diff --git a/specs/composition/common/schemas/SearchParams.yml b/specs/composition-full/common/schemas/SearchParams.yml similarity index 100% rename from specs/composition/common/schemas/SearchParams.yml rename to specs/composition-full/common/schemas/SearchParams.yml diff --git a/specs/composition/common/schemas/SearchResponse.yml b/specs/composition-full/common/schemas/SearchResponse.yml similarity index 100% rename from specs/composition/common/schemas/SearchResponse.yml rename to specs/composition-full/common/schemas/SearchResponse.yml diff --git a/specs/composition/common/schemas/batchCompositionAction.yml b/specs/composition-full/common/schemas/batchCompositionAction.yml similarity index 100% rename from specs/composition/common/schemas/batchCompositionAction.yml rename to specs/composition-full/common/schemas/batchCompositionAction.yml diff --git a/specs/composition/common/schemas/compositionBehavior.yml b/specs/composition-full/common/schemas/compositionBehavior.yml similarity index 100% rename from specs/composition/common/schemas/compositionBehavior.yml rename to specs/composition-full/common/schemas/compositionBehavior.yml diff --git a/specs/composition/common/schemas/compositionRule.yml b/specs/composition-full/common/schemas/compositionRule.yml similarity index 100% rename from specs/composition/common/schemas/compositionRule.yml rename to specs/composition-full/common/schemas/compositionRule.yml diff --git a/specs/composition/common/schemas/listCompositionsResponse.yml b/specs/composition-full/common/schemas/listCompositionsResponse.yml similarity index 100% rename from specs/composition/common/schemas/listCompositionsResponse.yml rename to specs/composition-full/common/schemas/listCompositionsResponse.yml diff --git a/specs/composition/common/schemas/rulesBatchCompositionAction.yml b/specs/composition-full/common/schemas/rulesBatchCompositionAction.yml similarity index 100% rename from specs/composition/common/schemas/rulesBatchCompositionAction.yml rename to specs/composition-full/common/schemas/rulesBatchCompositionAction.yml diff --git a/specs/composition/helpers/waitForCompositionTask.yml b/specs/composition-full/helpers/waitForCompositionTask.yml similarity index 100% rename from specs/composition/helpers/waitForCompositionTask.yml rename to specs/composition-full/helpers/waitForCompositionTask.yml diff --git a/specs/composition/paths/advanced/getTask.yml b/specs/composition-full/paths/advanced/getTask.yml similarity index 100% rename from specs/composition/paths/advanced/getTask.yml rename to specs/composition-full/paths/advanced/getTask.yml diff --git a/specs/composition/paths/manage_compositions/listCompositions.yml b/specs/composition-full/paths/manage_compositions/listCompositions.yml similarity index 100% rename from specs/composition/paths/manage_compositions/listCompositions.yml rename to specs/composition-full/paths/manage_compositions/listCompositions.yml diff --git a/specs/composition/paths/objects/multipleBatch.yml b/specs/composition-full/paths/objects/multipleBatch.yml similarity index 100% rename from specs/composition/paths/objects/multipleBatch.yml rename to specs/composition-full/paths/objects/multipleBatch.yml diff --git a/specs/composition/paths/objects/objects.yml b/specs/composition-full/paths/objects/objects.yml similarity index 100% rename from specs/composition/paths/objects/objects.yml rename to specs/composition-full/paths/objects/objects.yml diff --git a/specs/composition/paths/rules/parameters.yml b/specs/composition-full/paths/rules/parameters.yml similarity index 100% rename from specs/composition/paths/rules/parameters.yml rename to specs/composition-full/paths/rules/parameters.yml diff --git a/specs/composition/paths/rules/rule.yml b/specs/composition-full/paths/rules/rule.yml similarity index 100% rename from specs/composition/paths/rules/rule.yml rename to specs/composition-full/paths/rules/rule.yml diff --git a/specs/composition/paths/rules/saveRules.yml b/specs/composition-full/paths/rules/saveRules.yml similarity index 100% rename from specs/composition/paths/rules/saveRules.yml rename to specs/composition-full/paths/rules/saveRules.yml diff --git a/specs/composition/paths/rules/searchRules.yml b/specs/composition-full/paths/rules/searchRules.yml similarity index 100% rename from specs/composition/paths/rules/searchRules.yml rename to specs/composition-full/paths/rules/searchRules.yml diff --git a/specs/composition/paths/search/search.yml b/specs/composition-full/paths/search/search.yml similarity index 100% rename from specs/composition/paths/search/search.yml rename to specs/composition-full/paths/search/search.yml diff --git a/specs/composition/paths/search/searchForFacetValues.yml b/specs/composition-full/paths/search/searchForFacetValues.yml similarity index 100% rename from specs/composition/paths/search/searchForFacetValues.yml rename to specs/composition-full/paths/search/searchForFacetValues.yml diff --git a/specs/composition-full/spec.yml b/specs/composition-full/spec.yml new file mode 100644 index 0000000000..65553cf1e4 --- /dev/null +++ b/specs/composition-full/spec.yml @@ -0,0 +1,101 @@ +openapi: 3.0.2 +info: + title: Composition API + description: Composition API. + version: 1.0.0 +components: + securitySchemes: + appId: + $ref: '../common/securitySchemes.yml#/appId' + apiKey: + $ref: '../common/securitySchemes.yml#/apiKey' +servers: + - url: https://{appId}.algolia.net + variables: + appId: + default: ALGOLIA_APPLICATION_ID + - url: https://{appId}-1.algolianet.com + variables: + appId: + default: ALGOLIA_APPLICATION_ID + - url: https://{appId}-2.algolianet.com + variables: + appId: + default: ALGOLIA_APPLICATION_ID + - url: https://{appId}-3.algolianet.com + variables: + appId: + default: ALGOLIA_APPLICATION_ID + - url: https://{appId}-dsn.algolia.net + variables: + appId: + default: ALGOLIA_APPLICATION_ID +security: + - appId: [] + apiKey: [] +tags: + - name: Compositions + description: | + Manage your compositions and composition settings. + - name: Rules + description: | + Manage your compositions rules. + - name: Search + description: Search one or more indices for matching records or facet values. +x-tagGroups: + - name: Search + tags: + - Compositions +paths: + # ###################### + # ### Custom request ### + # ###################### + /{path}: + $ref: '../common/paths/customRequest.yml' + + # ######################## + # ### Search Endpoints ### + # ######################## + /1/compositions/{compositionID}/run: + $ref: 'paths/search/search.yml' + /1/compositions/{compositionID}/facets/{facetName}/query: + $ref: 'paths/search/searchForFacetValues.yml' + + # ######################### + # ### Objects Endpoints ### + # ######################### + /1/compositions/{compositionID}: + $ref: 'paths/objects/objects.yml' + /1/compositions/*/batch: + $ref: 'paths/objects/multipleBatch.yml' + + # ####################### + # ### Rules Endpoints ### + # ####################### + /1/compositions/{compositionID}/rules/{objectID}: + $ref: 'paths/rules/rule.yml' + /1/compositions/{compositionID}/rules/batch: + $ref: 'paths/rules/saveRules.yml' + /1/compositions/{compositionID}/rules/search: + $ref: 'paths/rules/searchRules.yml' + + # ########################## + # ### Advanced Endpoints ### + # ########################## + /1/compositions/{compositionID}/task/{taskID}: + $ref: 'paths/advanced/getTask.yml' + + # ##################################### + # ### Manage Compositions Endpoints ### + # ##################################### + /1/compositions: + $ref: 'paths/manage_compositions/listCompositions.yml' + + # ############### + # ### Helpers ### + # ############### + /setClientApiKey: + $ref: '../common/helpers/setClientApiKey.yml#/method' + + /waitForCompositionTask: + $ref: 'helpers/waitForCompositionTask.yml#/method' diff --git a/specs/composition/spec.yml b/specs/composition/spec.yml index 65553cf1e4..f2feb9814e 100644 --- a/specs/composition/spec.yml +++ b/specs/composition/spec.yml @@ -47,55 +47,10 @@ x-tagGroups: tags: - Compositions paths: - # ###################### - # ### Custom request ### - # ###################### - /{path}: - $ref: '../common/paths/customRequest.yml' - # ######################## # ### Search Endpoints ### # ######################## /1/compositions/{compositionID}/run: - $ref: 'paths/search/search.yml' + $ref: '../composition-full/paths/search/search.yml' /1/compositions/{compositionID}/facets/{facetName}/query: - $ref: 'paths/search/searchForFacetValues.yml' - - # ######################### - # ### Objects Endpoints ### - # ######################### - /1/compositions/{compositionID}: - $ref: 'paths/objects/objects.yml' - /1/compositions/*/batch: - $ref: 'paths/objects/multipleBatch.yml' - - # ####################### - # ### Rules Endpoints ### - # ####################### - /1/compositions/{compositionID}/rules/{objectID}: - $ref: 'paths/rules/rule.yml' - /1/compositions/{compositionID}/rules/batch: - $ref: 'paths/rules/saveRules.yml' - /1/compositions/{compositionID}/rules/search: - $ref: 'paths/rules/searchRules.yml' - - # ########################## - # ### Advanced Endpoints ### - # ########################## - /1/compositions/{compositionID}/task/{taskID}: - $ref: 'paths/advanced/getTask.yml' - - # ##################################### - # ### Manage Compositions Endpoints ### - # ##################################### - /1/compositions: - $ref: 'paths/manage_compositions/listCompositions.yml' - - # ############### - # ### Helpers ### - # ############### - /setClientApiKey: - $ref: '../common/helpers/setClientApiKey.yml#/method' - - /waitForCompositionTask: - $ref: 'helpers/waitForCompositionTask.yml#/method' + $ref: '../composition-full/paths/search/searchForFacetValues.yml' diff --git a/templates/javascript/clients/api-single.mustache b/templates/javascript/clients/api-single.mustache index f1e6b0b77c..ae8a3babe7 100644 --- a/templates/javascript/clients/api-single.mustache +++ b/templates/javascript/clients/api-single.mustache @@ -96,9 +96,9 @@ export function create{{#lambda.titlecase}}{{clientName}}{{/lambda.titlecase}}({ {{#isSearchClient}} {{> client/api/helpers}} {{/isSearchClient}} - {{#isCompositionClient}} + {{#isCompositionFullClient}} {{> client/api/compositionHelpers}} - {{/isCompositionClient}} + {{/isCompositionFullClient}} {{#operation}} {{> client/api/operation/jsdoc}} {{nickname}}{{#vendorExtensions.x-is-generic}}{{/vendorExtensions.x-is-generic}}( {{> client/api/operation/parameters}} ) : Promise<{{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}void{{/returnType}}{{#vendorExtensions.x-is-generic}}{{/vendorExtensions.x-is-generic}}> { diff --git a/templates/javascript/clients/client/api/imports.mustache b/templates/javascript/clients/client/api/imports.mustache index 6f39b0255b..e26313348d 100644 --- a/templates/javascript/clients/client/api/imports.mustache +++ b/templates/javascript/clients/client/api/imports.mustache @@ -9,9 +9,9 @@ import { serializeQueryParameters, createIterablePromise, {{/isSearchClient}} - {{#isCompositionClient}} + {{#isCompositionFullClient}} createIterablePromise, - {{/isCompositionClient}} + {{/isCompositionFullClient}} } from '@algolia/client-common'; import type { CreateClientOptions, @@ -42,9 +42,9 @@ import type { WaitForAppTaskOptions, WaitForTaskOptions, {{/isSearchClient}} - {{#isCompositionClient}} + {{#isCompositionFullClient}} WaitForCompositionTaskOptions, - {{/isCompositionClient}} + {{/isCompositionFullClient}} {{#operation}} {{#vendorExtensions}} {{#x-create-wrapping-object}} diff --git a/templates/javascript/clients/client/builds/browser.mustache b/templates/javascript/clients/client/builds/browser.mustache index 0bde1bd8df..96d46575ba 100644 --- a/templates/javascript/clients/client/builds/browser.mustache +++ b/templates/javascript/clients/client/builds/browser.mustache @@ -12,7 +12,7 @@ logger: createNullLogger(), requester: createXhrRequester(), algoliaAgents: [{ segment: 'Browser' }], - authMode: 'Within{{#isCompositionClient}}Headers{{/isCompositionClient}}{{^isCompositionClient}}QueryParameters{{/isCompositionClient}}', + authMode: 'Within{{#isCompositionClient}}Headers{{/isCompositionClient}}{{^isCompositionClient}}{{#isCompositionFullClient}}Headers{{/isCompositionFullClient}}{{^isCompositionFullClient}}QueryParameters{{/isCompositionFullClient}}{{/isCompositionClient}}', responsesCache: createMemoryCache(), requestsCache: createMemoryCache({ serializable: false }), hostsCache: createFallbackableCache({ diff --git a/templates/javascript/clients/client/model/clientMethodProps.mustache b/templates/javascript/clients/client/model/clientMethodProps.mustache index c836f22995..4ec998600f 100644 --- a/templates/javascript/clients/client/model/clientMethodProps.mustache +++ b/templates/javascript/clients/client/model/clientMethodProps.mustache @@ -189,7 +189,7 @@ export type ReplaceAllObjectsOptions = { } {{/isAlgoliasearchClient}} {{/isSearchClient}} -{{#isCompositionClient}} +{{#isCompositionFullClient}} export type WaitForCompositionTaskOptions = { /** * The maximum number of retries. 50 by default. @@ -211,6 +211,6 @@ export type WaitForCompositionTaskOptions = { */ compositionID: string; }; -{{/isCompositionClient}} +{{/isCompositionFullClient}} {{/apiInfo.apis.0}} \ No newline at end of file diff --git a/templates/javascript/snippets/init.mustache b/templates/javascript/snippets/init.mustache index ed3c1a63ac..62c7f55e00 100644 --- a/templates/javascript/snippets/init.mustache +++ b/templates/javascript/snippets/init.mustache @@ -1 +1 @@ -const client = {{{clientName}}}("ALGOLIA_APPLICATION_ID", "ALGOLIA_API_KEY"){{^isSearchClient}}{{^isCompositionClient}}.{{{initMethod}}}({{#hasRegionalHost}} {region: '{{defaultRegion}}'} {{/hasRegionalHost}}){{/isCompositionClient}}{{/isSearchClient}}; \ No newline at end of file +const client = {{{clientName}}}("ALGOLIA_APPLICATION_ID", "ALGOLIA_API_KEY"){{^isSearchClient}}{{^isCompositionClient}}{{^isCompositionFullClient}}.{{{initMethod}}}({{#hasRegionalHost}} {region: '{{defaultRegion}}'} {{/hasRegionalHost}}){{/isCompositionFullClient}}{{/isCompositionClient}}{{/isSearchClient}}; \ No newline at end of file diff --git a/templates/javascript/tests/client/client.mustache b/templates/javascript/tests/client/client.mustache index 47c559c017..34a153a5c3 100644 --- a/templates/javascript/tests/client/client.mustache +++ b/templates/javascript/tests/client/client.mustache @@ -2,12 +2,12 @@ /* eslint-disable eslint/no-unused-vars */ import { describe, test, expect } from 'vitest'; -{{^isCompositionClient}} +{{^isCompositionFullClient}} import { {{{clientName}}} } from '{{{importPackage}}}'; -{{/isCompositionClient}} -{{#isCompositionClient}} -import { compositionClient } from '@algolia/client-composition'; -{{/isCompositionClient}} +{{/isCompositionFullClient}} +{{#isCompositionFullClient}} +import { compositionFullClient } from '@algolia/client-composition'; +{{/isCompositionFullClient}} import { nodeEchoRequester } from '@algolia/requester-testing'; import type { EchoResponse } from '@algolia/requester-testing'; @@ -15,7 +15,7 @@ const appId = 'test-app-id'; const apiKey = 'test-api-key'; function createClient() { - return {{^isCompositionClient}}{{{clientName}}}{{/isCompositionClient}}{{#isCompositionClient}}compositionClient{{/isCompositionClient}}(appId, apiKey{{#isStandaloneClient}}, { requester: nodeEchoRequester() }{{/isStandaloneClient}}){{^isStandaloneClient}}.{{{initMethod}}}({ options: { requester: nodeEchoRequester() }, {{#hasRegionalHost}} region:'{{{defaultRegion}}}' {{/hasRegionalHost}} });{{/isStandaloneClient}}; + return {{^isCompositionFullClient}}{{{clientName}}}{{/isCompositionFullClient}}{{#isCompositionFullClient}}compositionFullClient{{/isCompositionFullClient}}(appId, apiKey{{#isStandaloneClient}}, { requester: nodeEchoRequester() }{{/isStandaloneClient}}){{^isStandaloneClient}}.{{{initMethod}}}({ options: { requester: nodeEchoRequester() }, {{#hasRegionalHost}} region:'{{{defaultRegion}}}' {{/hasRegionalHost}} });{{/isStandaloneClient}}; } {{#blocksClient}} @@ -24,8 +24,8 @@ function createClient() { describe('init', () => { test('sets authMode', async () => { - const qpClient = {{^isCompositionClient}}{{{clientName}}}{{/isCompositionClient}}{{#isCompositionClient}}compositionClient{{/isCompositionClient}}('foo', 'bar'{{#isStandaloneClient}}, { requester: nodeEchoRequester(), authMode: 'WithinQueryParameters' }{{/isStandaloneClient}}){{^isStandaloneClient}}.{{{initMethod}}}({ options: { requester: nodeEchoRequester(), authMode: 'WithinQueryParameters' }, {{#hasRegionalHost}} region:'{{{defaultRegion}}}' {{/hasRegionalHost}} });{{/isStandaloneClient}}; - const headerClient = {{^isCompositionClient}}{{{clientName}}}{{/isCompositionClient}}{{#isCompositionClient}}compositionClient{{/isCompositionClient}}('foo', 'bar'{{#isStandaloneClient}}, { requester: nodeEchoRequester(), authMode: 'WithinHeaders' }{{/isStandaloneClient}}){{^isStandaloneClient}}.{{{initMethod}}}({ options: { requester: nodeEchoRequester(), authMode: 'WithinHeaders' }, {{#hasRegionalHost}} region:'{{{defaultRegion}}}' {{/hasRegionalHost}} });{{/isStandaloneClient}}; + const qpClient = {{^isCompositionFullClient}}{{{clientName}}}{{/isCompositionFullClient}}{{#isCompositionFullClient}}compositionFullClient{{/isCompositionFullClient}}('foo', 'bar'{{#isStandaloneClient}}, { requester: nodeEchoRequester(), authMode: 'WithinQueryParameters' }{{/isStandaloneClient}}){{^isStandaloneClient}}.{{{initMethod}}}({ options: { requester: nodeEchoRequester(), authMode: 'WithinQueryParameters' }, {{#hasRegionalHost}} region:'{{{defaultRegion}}}' {{/hasRegionalHost}} });{{/isStandaloneClient}}; + const headerClient = {{^isCompositionFullClient}}{{{clientName}}}{{/isCompositionFullClient}}{{#isCompositionFullClient}}compositionFullClient{{/isCompositionFullClient}}('foo', 'bar'{{#isStandaloneClient}}, { requester: nodeEchoRequester(), authMode: 'WithinHeaders' }{{/isStandaloneClient}}){{^isStandaloneClient}}.{{{initMethod}}}({ options: { requester: nodeEchoRequester(), authMode: 'WithinHeaders' }, {{#hasRegionalHost}} region:'{{{defaultRegion}}}' {{/hasRegionalHost}} });{{/isStandaloneClient}}; const qpResult = (await qpClient.customGet({ path: '1/foo', diff --git a/templates/javascript/tests/client/createClient.mustache b/templates/javascript/tests/client/createClient.mustache index 1bbb0eca9b..dacf87c0d2 100644 --- a/templates/javascript/tests/client/createClient.mustache +++ b/templates/javascript/tests/client/createClient.mustache @@ -1,4 +1,4 @@ -{{^autoCreateClient}}const client = {{/autoCreateClient}}{{^isCompositionClient}}{{{clientName}}}{{/isCompositionClient}}{{#isCompositionClient}}compositionClient{{/isCompositionClient}}( +{{^autoCreateClient}}const client = {{/autoCreateClient}}{{^isCompositionFullClient}}{{{clientName}}}{{/isCompositionFullClient}}{{#isCompositionFullClient}}compositionFullClient{{/isCompositionFullClient}}( '{{parametersWithDataTypeMap.appId.value}}', '{{parametersWithDataTypeMap.apiKey.value}}' {{#isStandaloneClient}}, diff --git a/templates/javascript/tests/e2e/e2e.mustache b/templates/javascript/tests/e2e/e2e.mustache index 867f8a2fd1..3f59053088 100644 --- a/templates/javascript/tests/e2e/e2e.mustache +++ b/templates/javascript/tests/e2e/e2e.mustache @@ -6,12 +6,12 @@ import { union } from '../helpers.js'; import * as dotenv from 'dotenv'; dotenv.config({path:'../../.env'}); -{{^isCompositionClient}} +{{^isCompositionFullClient}} import { {{{clientName}}} } from '{{{importPackage}}}'; -{{/isCompositionClient}} -{{#isCompositionClient}} +{{/isCompositionFullClient}} +{{#isCompositionFullClient}} import { compositionClient } from '@algolia/client-composition'; -{{/isCompositionClient}} +{{/isCompositionFullClient}} import type { RequestOptions } from '@algolia/client-common'; if (!process.env.{{e2eAppID}}) { @@ -22,7 +22,7 @@ if (!process.env.{{e2eApiKey}}) { throw new Error("please provide an `{{e2eApiKey}}` env var for e2e tests"); } -const client = {{^isCompositionClient}}{{{clientName}}}{{/isCompositionClient}}{{#isCompositionClient}}compositionClient{{/isCompositionClient}}(process.env.{{e2eAppID}}, process.env.{{e2eApiKey}}){{^isStandaloneClient}}.{{{initMethod}}}({{#hasRegionalHost}} {region:'{{{defaultRegion}}}'} {{/hasRegionalHost}}){{/isStandaloneClient}}; +const client = {{^isCompositionFullClient}}{{{clientName}}}{{/isCompositionFullClient}}{{#isCompositionFullClient}}compositionFullClient{{/isCompositionFullClient}}(process.env.{{e2eAppID}}, process.env.{{e2eApiKey}}){{^isStandaloneClient}}.{{{initMethod}}}({{#hasRegionalHost}} {region:'{{{defaultRegion}}}'} {{/hasRegionalHost}}){{/isStandaloneClient}}; {{#blocksE2E}} describe('{{operationId}}', () => { diff --git a/templates/javascript/tests/requests/requests.mustache b/templates/javascript/tests/requests/requests.mustache index 96de0298f5..4871801702 100644 --- a/templates/javascript/tests/requests/requests.mustache +++ b/templates/javascript/tests/requests/requests.mustache @@ -1,12 +1,12 @@ // {{generationBanner}} import { describe, test, expect } from 'vitest'; -{{^isCompositionClient}} +{{^isCompositionFullClient}} import { {{{clientName}}} } from '{{{importPackage}}}'; -{{/isCompositionClient}} -{{#isCompositionClient}} -import { compositionClient } from '@algolia/client-composition'; -{{/isCompositionClient}} +{{/isCompositionFullClient}} +{{#isCompositionFullClient}} +import { compositionFullClient } from '@algolia/client-composition'; +{{/isCompositionFullClient}} import { nodeEchoRequester } from '@algolia/requester-testing'; import type { EchoResponse } from '@algolia/requester-testing'; import type { ClientOptions } from '@algolia/client-common'; @@ -15,7 +15,7 @@ const appId = process.env.ALGOLIA_APPLICATION_ID || 'test_app_id'; const apiKey = process.env.ALGOLIA_SEARCH_KEY || 'test_api_key'; const clientOptions: ClientOptions = { requester: nodeEchoRequester() }; // this makes sure the types are correctly exported -const client = {{^isCompositionClient}}{{{clientName}}}{{/isCompositionClient}}{{#isCompositionClient}}compositionClient{{/isCompositionClient}}(appId, apiKey{{#isStandaloneClient}}, { requester: nodeEchoRequester() }{{/isStandaloneClient}}){{^isStandaloneClient}}.{{{initMethod}}}({ options: clientOptions, {{#hasRegionalHost}} region:'{{{defaultRegion}}}' {{/hasRegionalHost}} });{{/isStandaloneClient}}; +const client = {{^isCompositionFullClient}}{{{clientName}}}{{/isCompositionFullClient}}{{#isCompositionFullClient}}compositionFullClient{{/isCompositionFullClient}}(appId, apiKey{{#isStandaloneClient}}, { requester: nodeEchoRequester() }{{/isStandaloneClient}}){{^isStandaloneClient}}.{{{initMethod}}}({ options: clientOptions, {{#hasRegionalHost}} region:'{{{defaultRegion}}}' {{/hasRegionalHost}} });{{/isStandaloneClient}}; {{#blocksRequests}} describe('{{operationId}}', () => { From d9a9d10688e016f2a785e3c30fa3688c9b04a3c1 Mon Sep 17 00:00:00 2001 From: shortcuts Date: Tue, 14 Jan 2025 12:16:22 +0100 Subject: [PATCH 02/31] fix: add custom paths --- specs/composition/spec.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/specs/composition/spec.yml b/specs/composition/spec.yml index f2feb9814e..22b8007435 100644 --- a/specs/composition/spec.yml +++ b/specs/composition/spec.yml @@ -47,6 +47,12 @@ x-tagGroups: tags: - Compositions paths: + # ###################### + # ### Custom request ### + # ###################### + /{path}: + $ref: '../common/paths/customRequest.yml' + # ######################## # ### Search Endpoints ### # ######################## From 93ef4eba3389ac86ca04e921e7c4c5a8aa330843 Mon Sep 17 00:00:00 2001 From: shortcuts Date: Tue, 14 Jan 2025 13:21:08 +0100 Subject: [PATCH 03/31] fix: skip custom tests --- .../java/com/algolia/codegen/cts/tests/TestsClient.java | 5 +++++ specs/composition/spec.yml | 6 ------ 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/generators/src/main/java/com/algolia/codegen/cts/tests/TestsClient.java b/generators/src/main/java/com/algolia/codegen/cts/tests/TestsClient.java index a6e4c68445..da0eaa08fd 100644 --- a/generators/src/main/java/com/algolia/codegen/cts/tests/TestsClient.java +++ b/generators/src/main/java/com/algolia/codegen/cts/tests/TestsClient.java @@ -107,6 +107,11 @@ public void run(Map models, Map } else if (step.type.equals("method")) { ope = operations.get(step.method); if (ope == null) { + // some clients don't have custom methods + if (step.method.startsWith("custom") && client.equals("composition")) { + continue skipTest; + } + throw new CTSException("Cannot find operation for method: " + step.method, test.testName); } stepOut.put("stepTemplate", "tests/client/method.mustache"); diff --git a/specs/composition/spec.yml b/specs/composition/spec.yml index 22b8007435..f2feb9814e 100644 --- a/specs/composition/spec.yml +++ b/specs/composition/spec.yml @@ -47,12 +47,6 @@ x-tagGroups: tags: - Compositions paths: - # ###################### - # ### Custom request ### - # ###################### - /{path}: - $ref: '../common/paths/customRequest.yml' - # ######################## # ### Search Endpoints ### # ######################## From f0900467e0f45ac722d4329791f8fe874a073a1c Mon Sep 17 00:00:00 2001 From: shortcuts Date: Tue, 14 Jan 2025 13:32:08 +0100 Subject: [PATCH 04/31] fix: algoliasearch cts --- .../packages/client_composition/build.yaml | 14 ++++++++++++++ .../codegen/AlgoliaJavascriptGenerator.java | 2 -- .../algolia/codegen/cts/AlgoliaCTSGenerator.java | 2 +- .../codegen/cts/manager/JavascriptCTSManager.java | 10 ++-------- .../algolia/codegen/cts/tests/TestsRequest.java | 4 ++-- 5 files changed, 19 insertions(+), 13 deletions(-) create mode 100644 clients/algoliasearch-client-dart/packages/client_composition/build.yaml diff --git a/clients/algoliasearch-client-dart/packages/client_composition/build.yaml b/clients/algoliasearch-client-dart/packages/client_composition/build.yaml new file mode 100644 index 0000000000..6d71b406a7 --- /dev/null +++ b/clients/algoliasearch-client-dart/packages/client_composition/build.yaml @@ -0,0 +1,14 @@ +targets: + $default: + builders: + json_serializable: + options: + any_map: false + checked: true + create_factory: true + create_to_json: true + disallow_unrecognized_keys: false + explicit_to_json: true + field_rename: none + ignore_unannotated: false + include_if_null: false diff --git a/generators/src/main/java/com/algolia/codegen/AlgoliaJavascriptGenerator.java b/generators/src/main/java/com/algolia/codegen/AlgoliaJavascriptGenerator.java index 47b8197195..07f4581381 100644 --- a/generators/src/main/java/com/algolia/codegen/AlgoliaJavascriptGenerator.java +++ b/generators/src/main/java/com/algolia/codegen/AlgoliaJavascriptGenerator.java @@ -18,7 +18,6 @@ public class AlgoliaJavascriptGenerator extends TypeScriptNodeClientCodegen { private String CLIENT; private boolean isAlgoliasearchClient; - private boolean isAlgoliaCompositionClient; @Override public String getName() { @@ -31,7 +30,6 @@ public void processOpts() { CLIENT = Helpers.camelize((String) additionalProperties.get("client")); isAlgoliasearchClient = CLIENT.equals("algoliasearch"); - isAlgoliaCompositionClient = CLIENT.equals("composition"); // generator specific options setSupportsES6(true); diff --git a/generators/src/main/java/com/algolia/codegen/cts/AlgoliaCTSGenerator.java b/generators/src/main/java/com/algolia/codegen/cts/AlgoliaCTSGenerator.java index b98a4d1dff..7a620cbc90 100644 --- a/generators/src/main/java/com/algolia/codegen/cts/AlgoliaCTSGenerator.java +++ b/generators/src/main/java/com/algolia/codegen/cts/AlgoliaCTSGenerator.java @@ -149,7 +149,7 @@ public Map postProcessSupportingFileData(Map obj // We can put whatever we want in the bundle, and it will be accessible in the template bundle.put("mode", mode); bundle.put("is" + Helpers.capitalize(client) + "Client", true); - bundle.put("isStandaloneClient", client.contains("search") || client.equals("composition")); + bundle.put("isStandaloneClient", client.contains("search")); bundle.put("isSearchClient", client.contains("search")); // just so algoliasearch is treated as a search client too bundle.put("client", Helpers.createClientName(importClientName, language) + "Client"); bundle.put("clientPrefix", Helpers.createClientName(importClientName, language)); diff --git a/generators/src/main/java/com/algolia/codegen/cts/manager/JavascriptCTSManager.java b/generators/src/main/java/com/algolia/codegen/cts/manager/JavascriptCTSManager.java index 2f81a9854f..b1be21a8d3 100644 --- a/generators/src/main/java/com/algolia/codegen/cts/manager/JavascriptCTSManager.java +++ b/generators/src/main/java/com/algolia/codegen/cts/manager/JavascriptCTSManager.java @@ -46,13 +46,7 @@ public void addDataToBundle(Map bundle) throws GeneratorExceptio bundle.put("utilsPackageVersion", Helpers.getPackageJsonVersion("client-common")); bundle.put("algoliasearchVersion", Helpers.getPackageJsonVersion("algoliasearch")); bundle.put("initMethod", "init" + Helpers.capitalize(Helpers.camelize(client))); - bundle.put( - "clientName", - client.equals("algoliasearch") ? "liteClient" : client.equals("composition") ? "compositionClient" : "algoliasearch" - ); - bundle.put( - "importPackage", - client.equals("algoliasearch") ? "algoliasearch/lite" : client.equals("composition") ? "@algolia/client-composition" : "algoliasearch" - ); + bundle.put("clientName", client.equals("algoliasearch") ? "liteClient" : "algoliasearch"); + bundle.put("importPackage", client.equals("algoliasearch") ? "algoliasearch/lite" : "algoliasearch"); } } diff --git a/generators/src/main/java/com/algolia/codegen/cts/tests/TestsRequest.java b/generators/src/main/java/com/algolia/codegen/cts/tests/TestsRequest.java index ed277a9938..7d4f63acfd 100644 --- a/generators/src/main/java/com/algolia/codegen/cts/tests/TestsRequest.java +++ b/generators/src/main/java/com/algolia/codegen/cts/tests/TestsRequest.java @@ -81,10 +81,10 @@ public void run(Map models, Map List blocksE2E = new ArrayList<>(); ParametersWithDataType paramsType = new ParametersWithDataType(models, language, client, false); - bundle.put("e2eAppID", client.equals("composition") ? "METIS_APPLICATION_ID" : "ALGOLIA_APPLICATION_ID"); + bundle.put("e2eAppID", client.startsWith("composition") ? "METIS_APPLICATION_ID" : "ALGOLIA_APPLICATION_ID"); bundle.put( "e2eApiKey", - client.equals("composition") ? "METIS_API_KEY" : (client.equals("monitoring") ? "MONITORING_API_KEY" : "ALGOLIA_ADMIN_KEY") + client.startsWith("composition") ? "METIS_API_KEY" : (client.equals("monitoring") ? "MONITORING_API_KEY" : "ALGOLIA_ADMIN_KEY") ); bundle.put("useEchoRequester", true); From 46fbfee83e95da7c9cce69cd3b87ed2c6cd86801 Mon Sep 17 00:00:00 2001 From: shortcuts Date: Tue, 14 Jan 2025 13:35:08 +0100 Subject: [PATCH 05/31] fix: cts --- .../algoliasearch-client-javascript/yarn.lock | 18 ++++ tests/CTS/client/composition-full/api.json | 89 +++++++++++++++++++ .../getComposition.json | 0 .../getRule.json | 0 .../getTask.json | 0 .../listCompositions.json | 0 .../multipleBatch.json | 0 .../saveRules.json | 0 .../CTS/requests/composition-full/search.json | 17 ++++ .../searchCompositionRules.json | 0 .../searchForFacetValues.json | 22 +++++ 11 files changed, 146 insertions(+) create mode 100644 tests/CTS/client/composition-full/api.json rename tests/CTS/requests/{composition => composition-full}/getComposition.json (100%) rename tests/CTS/requests/{composition => composition-full}/getRule.json (100%) rename tests/CTS/requests/{composition => composition-full}/getTask.json (100%) rename tests/CTS/requests/{composition => composition-full}/listCompositions.json (100%) rename tests/CTS/requests/{composition => composition-full}/multipleBatch.json (100%) rename tests/CTS/requests/{composition => composition-full}/saveRules.json (100%) create mode 100644 tests/CTS/requests/composition-full/search.json rename tests/CTS/requests/{composition => composition-full}/searchCompositionRules.json (100%) create mode 100644 tests/CTS/requests/composition-full/searchForFacetValues.json diff --git a/clients/algoliasearch-client-javascript/yarn.lock b/clients/algoliasearch-client-javascript/yarn.lock index c114e05f3d..e2b66193c4 100644 --- a/clients/algoliasearch-client-javascript/yarn.lock +++ b/clients/algoliasearch-client-javascript/yarn.lock @@ -139,6 +139,23 @@ __metadata: languageName: unknown linkType: soft +"@algolia/composition@npm:0.0.1, @algolia/composition@workspace:packages/composition": + version: 0.0.0-use.local + resolution: "@algolia/composition@workspace:packages/composition" + dependencies: + "@algolia/client-common": "npm:5.19.0" + "@algolia/requester-browser-xhr": "npm:5.19.0" + "@algolia/requester-fetch": "npm:5.19.0" + "@algolia/requester-node-http": "npm:5.19.0" + "@arethetypeswrong/cli": "npm:0.17.3" + "@types/node": "npm:22.10.5" + publint: "npm:0.3.1" + rollup: "npm:4.30.1" + tsup: "npm:8.3.5" + typescript: "npm:5.7.3" + languageName: unknown + linkType: soft + "@algolia/ingestion@npm:1.19.0, @algolia/ingestion@workspace:packages/ingestion": version: 0.0.0-use.local resolution: "@algolia/ingestion@workspace:packages/ingestion" @@ -2419,6 +2436,7 @@ __metadata: "@algolia/client-personalization": "npm:5.19.0" "@algolia/client-query-suggestions": "npm:5.19.0" "@algolia/client-search": "npm:5.19.0" + "@algolia/composition": "npm:0.0.1" "@algolia/ingestion": "npm:1.19.0" "@algolia/monitoring": "npm:1.19.0" "@algolia/recommend": "npm:5.19.0" diff --git a/tests/CTS/client/composition-full/api.json b/tests/CTS/client/composition-full/api.json new file mode 100644 index 0000000000..71170ea471 --- /dev/null +++ b/tests/CTS/client/composition-full/api.json @@ -0,0 +1,89 @@ +[ + { + "testName": "calls api with correct read host", + "autoCreateClient": false, + "steps": [ + { + "type": "createClient", + "parameters": { + "appId": "test-app-id", + "apiKey": "test-api-key" + } + }, + { + "type": "method", + "method": "customGet", + "parameters": { + "path": "test" + }, + "expected": { + "type": "host", + "match": "test-app-id-dsn.algolia.net" + } + } + ] + }, + { + "testName": "calls api with correct write host", + "autoCreateClient": false, + "steps": [ + { + "type": "createClient", + "parameters": { + "appId": "test-app-id", + "apiKey": "test-api-key" + } + }, + { + "type": "method", + "method": "customPost", + "parameters": { + "path": "test" + }, + "expected": { + "type": "host", + "match": "test-app-id.algolia.net" + } + } + ] + }, + { + "testName": "test the compression strategy", + "autoCreateClient": false, + "steps": [ + { + "type": "createClient", + "parameters": { + "appId": "test-app-id", + "apiKey": "test-api-key", + "customHosts": [ + { + "port": 6678 + } + ], + "gzip": true + } + }, + { + "type": "method", + "method": "customPost", + "parameters": { + "path": "1/test/gzip", + "parameters": {}, + "body": { + "message": "this is a compressed body" + } + }, + "expected": { + "type": "response", + "match": { + "message": "ok compression test server response", + "body": { + "message": "this is a compressed body" + } + } + } + } + ] + } +] diff --git a/tests/CTS/requests/composition/getComposition.json b/tests/CTS/requests/composition-full/getComposition.json similarity index 100% rename from tests/CTS/requests/composition/getComposition.json rename to tests/CTS/requests/composition-full/getComposition.json diff --git a/tests/CTS/requests/composition/getRule.json b/tests/CTS/requests/composition-full/getRule.json similarity index 100% rename from tests/CTS/requests/composition/getRule.json rename to tests/CTS/requests/composition-full/getRule.json diff --git a/tests/CTS/requests/composition/getTask.json b/tests/CTS/requests/composition-full/getTask.json similarity index 100% rename from tests/CTS/requests/composition/getTask.json rename to tests/CTS/requests/composition-full/getTask.json diff --git a/tests/CTS/requests/composition/listCompositions.json b/tests/CTS/requests/composition-full/listCompositions.json similarity index 100% rename from tests/CTS/requests/composition/listCompositions.json rename to tests/CTS/requests/composition-full/listCompositions.json diff --git a/tests/CTS/requests/composition/multipleBatch.json b/tests/CTS/requests/composition-full/multipleBatch.json similarity index 100% rename from tests/CTS/requests/composition/multipleBatch.json rename to tests/CTS/requests/composition-full/multipleBatch.json diff --git a/tests/CTS/requests/composition/saveRules.json b/tests/CTS/requests/composition-full/saveRules.json similarity index 100% rename from tests/CTS/requests/composition/saveRules.json rename to tests/CTS/requests/composition-full/saveRules.json diff --git a/tests/CTS/requests/composition-full/search.json b/tests/CTS/requests/composition-full/search.json new file mode 100644 index 0000000000..e8be0dcbf2 --- /dev/null +++ b/tests/CTS/requests/composition-full/search.json @@ -0,0 +1,17 @@ +[ + { + "parameters": { + "compositionID": "foo", + "requestBody": { + "params": { "query": "batman" } + } + }, + "request": { + "path": "/1/compositions/foo/run", + "method": "POST", + "body": { + "params": { "query": "batman" } + } + } + } +] diff --git a/tests/CTS/requests/composition/searchCompositionRules.json b/tests/CTS/requests/composition-full/searchCompositionRules.json similarity index 100% rename from tests/CTS/requests/composition/searchCompositionRules.json rename to tests/CTS/requests/composition-full/searchCompositionRules.json diff --git a/tests/CTS/requests/composition-full/searchForFacetValues.json b/tests/CTS/requests/composition-full/searchForFacetValues.json new file mode 100644 index 0000000000..a94217c83a --- /dev/null +++ b/tests/CTS/requests/composition-full/searchForFacetValues.json @@ -0,0 +1,22 @@ +[ + { + "parameters": { + "compositionID": "foo", + "facetName": "brand", + "searchForFacetValuesRequest": { + "params": { + "maxFacetHits": 10 + } + } + }, + "request": { + "path": "/1/compositions/foo/facets/brand/query", + "method": "POST", + "body": { + "params": { + "maxFacetHits": 10 + } + } + } + } +] From 6b961b06e57af24ccb33248f98ef8a797f217253 Mon Sep 17 00:00:00 2001 From: shortcuts Date: Tue, 14 Jan 2025 13:45:22 +0100 Subject: [PATCH 06/31] fix: algoliasearch --- .../codegen/AlgoliaJavascriptGenerator.java | 2 +- .../algoliasearch/builds/models.mustache | 30 ++++++++++++++----- tests/output/javascript/yarn.lock | 18 +++++------ 3 files changed, 32 insertions(+), 18 deletions(-) diff --git a/generators/src/main/java/com/algolia/codegen/AlgoliaJavascriptGenerator.java b/generators/src/main/java/com/algolia/codegen/AlgoliaJavascriptGenerator.java index 07f4581381..4cffef3da9 100644 --- a/generators/src/main/java/com/algolia/codegen/AlgoliaJavascriptGenerator.java +++ b/generators/src/main/java/com/algolia/codegen/AlgoliaJavascriptGenerator.java @@ -184,7 +184,7 @@ private void setDefaultGeneratorOptions() { dependency.put("withInitMethod", !name.contains("search")); dependency.put( "dependencyHasRegionalHosts", - !name.contains("search") && !name.contains("recommend") && !name.contains("monitoring") + !name.contains("search") && !name.contains("recommend") && !name.contains("monitoring") && !name.startsWith("composition") ); dependencies.add(dependency); diff --git a/templates/javascript/clients/algoliasearch/builds/models.mustache b/templates/javascript/clients/algoliasearch/builds/models.mustache index 0c683c0b2f..6309a55841 100644 --- a/templates/javascript/clients/algoliasearch/builds/models.mustache +++ b/templates/javascript/clients/algoliasearch/builds/models.mustache @@ -40,8 +40,8 @@ import type { CustomGetProps, CustomPostProps, CustomPutProps, - DeletedAtResponse, DeleteSourceProps, + DeletedAtResponse, Distinct, Edit, EditType, @@ -49,18 +49,20 @@ import type { ExactOnSingleWordQuery, Exhaustive, FacetFilters, + FacetHits, FacetOrdering, - Facets, FacetStats, + Facets, GetTaskProps, HighlightResult, HighlightResultOption, + Hit, IgnorePlurals, IndexSettingsAsSearchParams, InsideBoundingBox, Languages, - MatchedGeoLocation, MatchLevel, + MatchedGeoLocation, Mode, NumericFilters, OptionalFilters, @@ -73,6 +75,7 @@ import type { QueryType, Range, RankingInfo, + ReRankingApplyFilter, Redirect, RedirectRuleIndexData, RedirectRuleIndexMetadata, @@ -80,11 +83,15 @@ import type { RemoveStopWords, RemoveWordsIfNoResults, RenderingContent, - ReRankingApplyFilter, + SearchForFacetValuesProps, + SearchForFacetValuesRequest, + SearchForFacetValuesResponse, + SearchHits, SearchPagination, SearchParams, SearchParamsObject, SearchParamsQuery, + SearchResponse, SemanticSearch, SnippetResult, SnippetResultOption, @@ -155,8 +162,8 @@ export type { CustomGetProps, CustomPostProps, CustomPutProps, - DeletedAtResponse, DeleteSourceProps, + DeletedAtResponse, Distinct, Edit, EditType, @@ -164,18 +171,20 @@ export type { ExactOnSingleWordQuery, Exhaustive, FacetFilters, + FacetHits, FacetOrdering, - Facets, FacetStats, + Facets, GetTaskProps, HighlightResult, HighlightResultOption, + Hit, IgnorePlurals, IndexSettingsAsSearchParams, InsideBoundingBox, Languages, - MatchedGeoLocation, MatchLevel, + MatchedGeoLocation, Mode, NumericFilters, OptionalFilters, @@ -188,6 +197,7 @@ export type { QueryType, Range, RankingInfo, + ReRankingApplyFilter, Redirect, RedirectRuleIndexData, RedirectRuleIndexMetadata, @@ -195,11 +205,15 @@ export type { RemoveStopWords, RemoveWordsIfNoResults, RenderingContent, - ReRankingApplyFilter, + SearchForFacetValuesProps, + SearchForFacetValuesRequest, + SearchForFacetValuesResponse, + SearchHits, SearchPagination, SearchParams, SearchParamsObject, SearchParamsQuery, + SearchResponse, SemanticSearch, SnippetResult, SnippetResultOption, diff --git a/tests/output/javascript/yarn.lock b/tests/output/javascript/yarn.lock index 73d15f4a79..7fca00df6a 100644 --- a/tests/output/javascript/yarn.lock +++ b/tests/output/javascript/yarn.lock @@ -984,7 +984,7 @@ __metadata: "@types/node": "npm:22.10.5" algoliasearch: "link:../../../clients/algoliasearch-client-javascript/packages/algoliasearch" dotenv: "npm:16.4.7" - typescript: "npm:5.7.2" + typescript: "npm:5.7.3" vitest: "npm:2.1.8" languageName: unknown linkType: soft @@ -1553,23 +1553,23 @@ __metadata: languageName: node linkType: hard -"typescript@npm:5.7.2": - version: 5.7.2 - resolution: "typescript@npm:5.7.2" +"typescript@npm:5.7.3": + version: 5.7.3 + resolution: "typescript@npm:5.7.3" bin: tsc: bin/tsc tsserver: bin/tsserver - checksum: 10/4caa3904df69db9d4a8bedc31bafc1e19ffb7b24fbde2997a1633ae1398d0de5bdbf8daf602ccf3b23faddf1aeeb9b795223a2ed9c9a4fdcaf07bfde114a401a + checksum: 10/6a7e556de91db3d34dc51cd2600e8e91f4c312acd8e52792f243c7818dfadb27bae677175fad6947f9c81efb6c57eb6b2d0c736f196a6ee2f1f7d57b74fc92fa languageName: node linkType: hard -"typescript@patch:typescript@npm%3A5.7.2#optional!builtin": - version: 5.7.2 - resolution: "typescript@patch:typescript@npm%3A5.7.2#optional!builtin::version=5.7.2&hash=5786d5" +"typescript@patch:typescript@npm%3A5.7.3#optional!builtin": + version: 5.7.3 + resolution: "typescript@patch:typescript@npm%3A5.7.3#optional!builtin::version=5.7.3&hash=5786d5" bin: tsc: bin/tsc tsserver: bin/tsserver - checksum: 10/d75ca10141afc64fd3474b41a8b082b640555bed388d237558aed64e5827ddadb48f90932c7f4205883f18f5bcab8b6a739a2cfac95855604b0dfeb34bc2f3eb + checksum: 10/dc58d777eb4c01973f7fbf1fd808aad49a0efdf545528dab9b07d94fdcb65b8751742804c3057e9619a4627f2d9cc85547fdd49d9f4326992ad0181b49e61d81 languageName: node linkType: hard From ef94e827a902ffb9c1c18d76e99607cb80be64fe Mon Sep 17 00:00:00 2001 From: shortcuts Date: Tue, 14 Jan 2025 14:24:42 +0100 Subject: [PATCH 07/31] fix: javascript playground --- playground/javascript/node/compositionFull.ts | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 playground/javascript/node/compositionFull.ts diff --git a/playground/javascript/node/compositionFull.ts b/playground/javascript/node/compositionFull.ts new file mode 100644 index 0000000000..8aba1975b1 --- /dev/null +++ b/playground/javascript/node/compositionFull.ts @@ -0,0 +1,50 @@ +import { ApiError } from '@algolia/client-common'; +import { compositionClient } from '@algolia/client-composition'; + +const appId = process.env.METIS_APPLICATION_ID || '**** APP_ID *****'; +const apiKey = process.env.METIS_API_KEY || '**** ADMIN_KEY *****'; + +// Init client with appId and apiKey +const client = compositionClient(appId, apiKey); + +async function testComposition() { + try { + console.log(appId, apiKey) + // create a new composition + // const res = await client.multipleBatch({ + // requests: [ + // { + // action: 'upsert', + // body: { + // objectID: 'id1', + // name: 'my first composition', + // description: 'the first ever composition from the client', + // behavior: { + // injection: { + // main: { + // source: { + // search: { + // index: 'cts_e2e_small', + // }, + // }, + // }, + // }, + // }, + // }, + // }, + // ], + // }); + // console.log(`[OK]`, res); + + console.log(await client.listCompositions()) + + } catch (e) { + if (e instanceof ApiError) { + return console.log(`[${e.status}] ${e.message}`, e.stackTrace, e); + } + + console.log('[ERROR]', e); + } +} + +testComposition(); From ab3896f5aff117aa66a7fdf12c0076844533e79f Mon Sep 17 00:00:00 2001 From: shortcuts Date: Tue, 14 Jan 2025 14:25:52 +0100 Subject: [PATCH 08/31] fix: swift duplicates --- .../java/com/algolia/codegen/AlgoliaSwiftGenerator.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/generators/src/main/java/com/algolia/codegen/AlgoliaSwiftGenerator.java b/generators/src/main/java/com/algolia/codegen/AlgoliaSwiftGenerator.java index aac6aebfe2..c760861be0 100644 --- a/generators/src/main/java/com/algolia/codegen/AlgoliaSwiftGenerator.java +++ b/generators/src/main/java/com/algolia/codegen/AlgoliaSwiftGenerator.java @@ -67,12 +67,14 @@ public class AlgoliaSwiftGenerator extends Swift5ClientCodegen { "exactonsinglewordquery", "exhaustive", "facetfilters", + "facethits", "facetordering", "facets", "facetstats", "forbidden", "highlightresult", "highlightresultoption", + "hit", "ignoreplurals", "indexsettingsassearchparams", "insideboundingbox", @@ -102,10 +104,14 @@ public class AlgoliaSwiftGenerator extends Swift5ClientCodegen { "removewordsifnoresults", "renderingcontent", "rerankingapplyfilter", + "searchforfacetvaluesrequest", + "searchforfacetvaluesresponse", + "searchhits", "searchpagination", "searchparams", "searchparamsobject", "searchparamsquery", + "searchresponse", "semanticsearch", "snippetresult", "snippetresultoption", From 899dc05f01b925b22fdf311094becfd828a159d8 Mon Sep 17 00:00:00 2001 From: Emmanuel Date: Wed, 15 Jan 2025 11:00:46 +0100 Subject: [PATCH 09/31] fix: playground --- playground/javascript/node/composition.ts | 4 ++-- playground/javascript/node/compositionFull.ts | 4 ++-- playground/javascript/node/package.json | 1 + 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/playground/javascript/node/composition.ts b/playground/javascript/node/composition.ts index 8aba1975b1..71320fff8b 100644 --- a/playground/javascript/node/composition.ts +++ b/playground/javascript/node/composition.ts @@ -1,5 +1,5 @@ import { ApiError } from '@algolia/client-common'; -import { compositionClient } from '@algolia/client-composition'; +import { compositionClient } from '@algolia/composition'; const appId = process.env.METIS_APPLICATION_ID || '**** APP_ID *****'; const apiKey = process.env.METIS_API_KEY || '**** ADMIN_KEY *****'; @@ -36,7 +36,7 @@ async function testComposition() { // }); // console.log(`[OK]`, res); - console.log(await client.listCompositions()) + console.log(await client.search({ compositionID: 'id1', requestBody: {} })) } catch (e) { if (e instanceof ApiError) { diff --git a/playground/javascript/node/compositionFull.ts b/playground/javascript/node/compositionFull.ts index 8aba1975b1..e7f88ad7ac 100644 --- a/playground/javascript/node/compositionFull.ts +++ b/playground/javascript/node/compositionFull.ts @@ -1,11 +1,11 @@ import { ApiError } from '@algolia/client-common'; -import { compositionClient } from '@algolia/client-composition'; +import { compositionFullClient } from '@algolia/client-composition'; const appId = process.env.METIS_APPLICATION_ID || '**** APP_ID *****'; const apiKey = process.env.METIS_API_KEY || '**** ADMIN_KEY *****'; // Init client with appId and apiKey -const client = compositionClient(appId, apiKey); +const client = compositionFullClient(appId, apiKey); async function testComposition() { try { diff --git a/playground/javascript/node/package.json b/playground/javascript/node/package.json index 62a70dee5e..920c189572 100644 --- a/playground/javascript/node/package.json +++ b/playground/javascript/node/package.json @@ -15,6 +15,7 @@ "@algolia/client-personalization": "link:../../../clients/algoliasearch-client-javascript/packages/client-personalization", "@algolia/client-query-suggestions": "link:../../../clients/algoliasearch-client-javascript/packages/client-query-suggestions", "@algolia/client-search": "link:../../../clients/algoliasearch-client-javascript/packages/client-search", + "@algolia/composition": "link:../../../clients/algoliasearch-client-javascript/packages/composition", "@algolia/ingestion": "link:../../../clients/algoliasearch-client-javascript/packages/ingestion", "@algolia/monitoring": "link:../../../clients/algoliasearch-client-javascript/packages/monitoring", "@algolia/recommend": "link:../../../clients/algoliasearch-client-javascript/packages/recommend", From 6b777d6f9709bf9db45655d8b6e18ec24c9fde3b Mon Sep 17 00:00:00 2001 From: Emmanuel Date: Wed, 15 Jan 2025 12:13:51 +0100 Subject: [PATCH 10/31] fix: generate composition tests for JS --- .../codegen/cts/AlgoliaCTSGenerator.java | 2 +- .../cts/manager/JavascriptCTSManager.java | 16 ++++++++++++++-- scripts/cts/generate.ts | 5 ++++- .../javascript/tests/client/client.mustache | 15 ++++++--------- .../tests/client/createClient.mustache | 2 +- templates/javascript/tests/package.mustache | 1 + .../javascript/tests/requests/requests.mustache | 7 +------ tests/CTS/client/composition/api.json | 17 +++++++++++------ 8 files changed, 39 insertions(+), 26 deletions(-) diff --git a/generators/src/main/java/com/algolia/codegen/cts/AlgoliaCTSGenerator.java b/generators/src/main/java/com/algolia/codegen/cts/AlgoliaCTSGenerator.java index 7a620cbc90..fbd0d87944 100644 --- a/generators/src/main/java/com/algolia/codegen/cts/AlgoliaCTSGenerator.java +++ b/generators/src/main/java/com/algolia/codegen/cts/AlgoliaCTSGenerator.java @@ -149,7 +149,7 @@ public Map postProcessSupportingFileData(Map obj // We can put whatever we want in the bundle, and it will be accessible in the template bundle.put("mode", mode); bundle.put("is" + Helpers.capitalize(client) + "Client", true); - bundle.put("isStandaloneClient", client.contains("search")); + bundle.put("isStandaloneClient", client.contains("search") || client.contains("composition")); bundle.put("isSearchClient", client.contains("search")); // just so algoliasearch is treated as a search client too bundle.put("client", Helpers.createClientName(importClientName, language) + "Client"); bundle.put("clientPrefix", Helpers.createClientName(importClientName, language)); diff --git a/generators/src/main/java/com/algolia/codegen/cts/manager/JavascriptCTSManager.java b/generators/src/main/java/com/algolia/codegen/cts/manager/JavascriptCTSManager.java index b1be21a8d3..4569841ee0 100644 --- a/generators/src/main/java/com/algolia/codegen/cts/manager/JavascriptCTSManager.java +++ b/generators/src/main/java/com/algolia/codegen/cts/manager/JavascriptCTSManager.java @@ -46,7 +46,19 @@ public void addDataToBundle(Map bundle) throws GeneratorExceptio bundle.put("utilsPackageVersion", Helpers.getPackageJsonVersion("client-common")); bundle.put("algoliasearchVersion", Helpers.getPackageJsonVersion("algoliasearch")); bundle.put("initMethod", "init" + Helpers.capitalize(Helpers.camelize(client))); - bundle.put("clientName", client.equals("algoliasearch") ? "liteClient" : "algoliasearch"); - bundle.put("importPackage", client.equals("algoliasearch") ? "algoliasearch/lite" : "algoliasearch"); + bundle.put( + "clientName", + client.equals("algoliasearch") + ? "liteClient" + : client.equals("composition") ? "compositionClient" : client.equals("composition-full") ? "compositionFullClient" : "algoliasearch" + ); + bundle.put( + "importPackage", + client.equals("algoliasearch") + ? "algoliasearch/lite" + : client.equals("composition") + ? "@algolia/composition" + : client.equals("composition-full") ? "@algolia/client-composition" : "algoliasearch" + ); } } diff --git a/scripts/cts/generate.ts b/scripts/cts/generate.ts index c165fef65d..5eba3fa837 100644 --- a/scripts/cts/generate.ts +++ b/scripts/cts/generate.ts @@ -1,4 +1,4 @@ -import { callGenerator, run, setupAndGen } from '../common.ts'; +import { callGenerator, isWSL, run, setupAndGen } from '../common.ts'; import { getTestOutputFolder } from '../config.ts'; import { formatter } from '../formatter.ts'; import type { Generator } from '../types.ts'; @@ -36,6 +36,9 @@ export async function ctsGenerateMany(generators: Generator[], languageVersion = }); } + if (isWSL()) { + await run(`sudo chmod 777 -R tests/output/${lang}`); + } await formatter(lang, `tests/output/${lang}`); } } diff --git a/templates/javascript/tests/client/client.mustache b/templates/javascript/tests/client/client.mustache index 34a153a5c3..a2fbd5e209 100644 --- a/templates/javascript/tests/client/client.mustache +++ b/templates/javascript/tests/client/client.mustache @@ -2,12 +2,7 @@ /* eslint-disable eslint/no-unused-vars */ import { describe, test, expect } from 'vitest'; -{{^isCompositionFullClient}} import { {{{clientName}}} } from '{{{importPackage}}}'; -{{/isCompositionFullClient}} -{{#isCompositionFullClient}} -import { compositionFullClient } from '@algolia/client-composition'; -{{/isCompositionFullClient}} import { nodeEchoRequester } from '@algolia/requester-testing'; import type { EchoResponse } from '@algolia/requester-testing'; @@ -15,17 +10,18 @@ const appId = 'test-app-id'; const apiKey = 'test-api-key'; function createClient() { - return {{^isCompositionFullClient}}{{{clientName}}}{{/isCompositionFullClient}}{{#isCompositionFullClient}}compositionFullClient{{/isCompositionFullClient}}(appId, apiKey{{#isStandaloneClient}}, { requester: nodeEchoRequester() }{{/isStandaloneClient}}){{^isStandaloneClient}}.{{{initMethod}}}({ options: { requester: nodeEchoRequester() }, {{#hasRegionalHost}} region:'{{{defaultRegion}}}' {{/hasRegionalHost}} });{{/isStandaloneClient}}; + return {{{clientName}}}(appId, apiKey{{#isStandaloneClient}}, { requester: nodeEchoRequester() }{{/isStandaloneClient}}){{^isStandaloneClient}}.{{{initMethod}}}({ options: { requester: nodeEchoRequester() }, {{#hasRegionalHost}} region:'{{{defaultRegion}}}' {{/hasRegionalHost}} });{{/isStandaloneClient}}; } {{#blocksClient}} {{> tests/client/tests}} {{/blocksClient}} +{{^isCompositionClient}} describe('init', () => { test('sets authMode', async () => { - const qpClient = {{^isCompositionFullClient}}{{{clientName}}}{{/isCompositionFullClient}}{{#isCompositionFullClient}}compositionFullClient{{/isCompositionFullClient}}('foo', 'bar'{{#isStandaloneClient}}, { requester: nodeEchoRequester(), authMode: 'WithinQueryParameters' }{{/isStandaloneClient}}){{^isStandaloneClient}}.{{{initMethod}}}({ options: { requester: nodeEchoRequester(), authMode: 'WithinQueryParameters' }, {{#hasRegionalHost}} region:'{{{defaultRegion}}}' {{/hasRegionalHost}} });{{/isStandaloneClient}}; - const headerClient = {{^isCompositionFullClient}}{{{clientName}}}{{/isCompositionFullClient}}{{#isCompositionFullClient}}compositionFullClient{{/isCompositionFullClient}}('foo', 'bar'{{#isStandaloneClient}}, { requester: nodeEchoRequester(), authMode: 'WithinHeaders' }{{/isStandaloneClient}}){{^isStandaloneClient}}.{{{initMethod}}}({ options: { requester: nodeEchoRequester(), authMode: 'WithinHeaders' }, {{#hasRegionalHost}} region:'{{{defaultRegion}}}' {{/hasRegionalHost}} });{{/isStandaloneClient}}; + const qpClient = {{{clientName}}}('foo', 'bar'{{#isStandaloneClient}}, { requester: nodeEchoRequester(), authMode: 'WithinQueryParameters' }{{/isStandaloneClient}}){{^isStandaloneClient}}.{{{initMethod}}}({ options: { requester: nodeEchoRequester(), authMode: 'WithinQueryParameters' }, {{#hasRegionalHost}} region:'{{{defaultRegion}}}' {{/hasRegionalHost}} });{{/isStandaloneClient}}; + const headerClient = {{{clientName}}}('foo', 'bar'{{#isStandaloneClient}}, { requester: nodeEchoRequester(), authMode: 'WithinHeaders' }{{/isStandaloneClient}}){{^isStandaloneClient}}.{{{initMethod}}}({ options: { requester: nodeEchoRequester(), authMode: 'WithinHeaders' }, {{#hasRegionalHost}} region:'{{{defaultRegion}}}' {{/hasRegionalHost}} });{{/isStandaloneClient}}; const qpResult = (await qpClient.customGet({ path: '1/foo', @@ -45,4 +41,5 @@ describe('init', () => { 'x-algolia-application-id': 'foo', }); }); -}); \ No newline at end of file +}); +{{/isCompositionClient}} \ No newline at end of file diff --git a/templates/javascript/tests/client/createClient.mustache b/templates/javascript/tests/client/createClient.mustache index dacf87c0d2..3c79e0c9c4 100644 --- a/templates/javascript/tests/client/createClient.mustache +++ b/templates/javascript/tests/client/createClient.mustache @@ -1,4 +1,4 @@ -{{^autoCreateClient}}const client = {{/autoCreateClient}}{{^isCompositionFullClient}}{{{clientName}}}{{/isCompositionFullClient}}{{#isCompositionFullClient}}compositionFullClient{{/isCompositionFullClient}}( +{{^autoCreateClient}}const client = {{/autoCreateClient}}{{{clientName}}}( '{{parametersWithDataTypeMap.appId.value}}', '{{parametersWithDataTypeMap.apiKey.value}}' {{#isStandaloneClient}}, diff --git a/templates/javascript/tests/package.mustache b/templates/javascript/tests/package.mustache index 721cbec021..00d5ef512f 100644 --- a/templates/javascript/tests/package.mustache +++ b/templates/javascript/tests/package.mustache @@ -8,6 +8,7 @@ "dependencies": { "algoliasearch": "link:../../../clients/algoliasearch-client-javascript/packages/algoliasearch", "@algolia/client-composition": "link:../../../clients/algoliasearch-client-javascript/packages/client-composition", + "@algolia/composition": "link:../../../clients/algoliasearch-client-javascript/packages/composition", "@algolia/requester-testing": "link:../../../clients/algoliasearch-client-javascript/packages/requester-testing" }, "devDependencies": { diff --git a/templates/javascript/tests/requests/requests.mustache b/templates/javascript/tests/requests/requests.mustache index 4871801702..7c247fa5f6 100644 --- a/templates/javascript/tests/requests/requests.mustache +++ b/templates/javascript/tests/requests/requests.mustache @@ -1,12 +1,7 @@ // {{generationBanner}} import { describe, test, expect } from 'vitest'; -{{^isCompositionFullClient}} import { {{{clientName}}} } from '{{{importPackage}}}'; -{{/isCompositionFullClient}} -{{#isCompositionFullClient}} -import { compositionFullClient } from '@algolia/client-composition'; -{{/isCompositionFullClient}} import { nodeEchoRequester } from '@algolia/requester-testing'; import type { EchoResponse } from '@algolia/requester-testing'; import type { ClientOptions } from '@algolia/client-common'; @@ -15,7 +10,7 @@ const appId = process.env.ALGOLIA_APPLICATION_ID || 'test_app_id'; const apiKey = process.env.ALGOLIA_SEARCH_KEY || 'test_api_key'; const clientOptions: ClientOptions = { requester: nodeEchoRequester() }; // this makes sure the types are correctly exported -const client = {{^isCompositionFullClient}}{{{clientName}}}{{/isCompositionFullClient}}{{#isCompositionFullClient}}compositionFullClient{{/isCompositionFullClient}}(appId, apiKey{{#isStandaloneClient}}, { requester: nodeEchoRequester() }{{/isStandaloneClient}}){{^isStandaloneClient}}.{{{initMethod}}}({ options: clientOptions, {{#hasRegionalHost}} region:'{{{defaultRegion}}}' {{/hasRegionalHost}} });{{/isStandaloneClient}}; +const client = {{{clientName}}}(appId, apiKey{{#isStandaloneClient}}, { requester: nodeEchoRequester() }{{/isStandaloneClient}}){{^isStandaloneClient}}.{{{initMethod}}}({ options: clientOptions, {{#hasRegionalHost}} region:'{{{defaultRegion}}}' {{/hasRegionalHost}} });{{/isStandaloneClient}}; {{#blocksRequests}} describe('{{operationId}}', () => { diff --git a/tests/CTS/client/composition/api.json b/tests/CTS/client/composition/api.json index 71170ea471..e09ad312bb 100644 --- a/tests/CTS/client/composition/api.json +++ b/tests/CTS/client/composition/api.json @@ -12,9 +12,10 @@ }, { "type": "method", - "method": "customGet", + "method": "search", "parameters": { - "path": "test" + "compositionID": "test-composition-id", + "requestBody": {} }, "expected": { "type": "host", @@ -36,9 +37,10 @@ }, { "type": "method", - "method": "customPost", + "method": "search", "parameters": { - "path": "test" + "compositionID": "test-composition-id", + "requestBody": {} }, "expected": { "type": "host", @@ -66,10 +68,13 @@ }, { "type": "method", - "method": "customPost", + "method": "search", "parameters": { "path": "1/test/gzip", - "parameters": {}, + "parameters": { + "compositionID": "test-composition-id", + "requestBody": {} + }, "body": { "message": "this is a compressed body" } From 57886331b6bb56b059a1820dc6ee431c865f0aab Mon Sep 17 00:00:00 2001 From: Emmanuel Date: Wed, 15 Jan 2025 12:40:25 +0100 Subject: [PATCH 11/31] fix: more fix for javascript --- .../main/java/com/algolia/codegen/cts/tests/TestsClient.java | 5 ++++- tests/CTS/client/composition/api.json | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/generators/src/main/java/com/algolia/codegen/cts/tests/TestsClient.java b/generators/src/main/java/com/algolia/codegen/cts/tests/TestsClient.java index da0eaa08fd..20ac523ac0 100644 --- a/generators/src/main/java/com/algolia/codegen/cts/tests/TestsClient.java +++ b/generators/src/main/java/com/algolia/codegen/cts/tests/TestsClient.java @@ -108,7 +108,10 @@ public void run(Map models, Map ope = operations.get(step.method); if (ope == null) { // some clients don't have custom methods - if (step.method.startsWith("custom") && client.equals("composition")) { + if ( + (step.method.startsWith("custom") || step.method.equals("commonAPI") || step.method.equals("setClientApiKey")) && + client.equals("composition") + ) { continue skipTest; } diff --git a/tests/CTS/client/composition/api.json b/tests/CTS/client/composition/api.json index e09ad312bb..9332b825dc 100644 --- a/tests/CTS/client/composition/api.json +++ b/tests/CTS/client/composition/api.json @@ -44,7 +44,7 @@ }, "expected": { "type": "host", - "match": "test-app-id.algolia.net" + "match": "test-app-id-dsn.algolia.net" } } ] From 7f13d4d52ee861d4f8b264ab71648d949d6720b6 Mon Sep 17 00:00:00 2001 From: Emmanuel Date: Wed, 15 Jan 2025 13:05:24 +0100 Subject: [PATCH 12/31] fix: more JS fix --- .../java/com/algolia/codegen/cts/tests/TestsClient.java | 5 +---- .../com/algolia/codegen/cts/tests/TestsGenerator.java | 9 +++++++-- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/generators/src/main/java/com/algolia/codegen/cts/tests/TestsClient.java b/generators/src/main/java/com/algolia/codegen/cts/tests/TestsClient.java index 20ac523ac0..da0eaa08fd 100644 --- a/generators/src/main/java/com/algolia/codegen/cts/tests/TestsClient.java +++ b/generators/src/main/java/com/algolia/codegen/cts/tests/TestsClient.java @@ -108,10 +108,7 @@ public void run(Map models, Map ope = operations.get(step.method); if (ope == null) { // some clients don't have custom methods - if ( - (step.method.startsWith("custom") || step.method.equals("commonAPI") || step.method.equals("setClientApiKey")) && - client.equals("composition") - ) { + if (step.method.startsWith("custom") && client.equals("composition")) { continue skipTest; } diff --git a/generators/src/main/java/com/algolia/codegen/cts/tests/TestsGenerator.java b/generators/src/main/java/com/algolia/codegen/cts/tests/TestsGenerator.java index de8fb6ce7f..ee3d0b43c6 100644 --- a/generators/src/main/java/com/algolia/codegen/cts/tests/TestsGenerator.java +++ b/generators/src/main/java/com/algolia/codegen/cts/tests/TestsGenerator.java @@ -51,10 +51,15 @@ protected Map loadCTS(String path, String clientName, Class js Map cts = new TreeMap<>(); - for (File f : allTests) { + skipFile: for (File f : allTests) { String json = new String(Files.readAllBytes(Paths.get(f.getAbsolutePath()))); json = injectVariables(json); - cts.put(f.getName().replace(".json", ""), Json.mapper().readValue(json, jsonType)); + String key = f.getName().replace(".json", ""); + // some clients don't have custom methods + if (clientName.equals("composition") && (key.equals("commonApi") || key.equals("setClientApiKey"))) { + continue skipFile; + } + cts.put(key, Json.mapper().readValue(json, jsonType)); } return cts; } From 48f48250097ea605ef3316972a1ade8a43fb23c1 Mon Sep 17 00:00:00 2001 From: Emmanuel Date: Wed, 15 Jan 2025 16:25:18 +0100 Subject: [PATCH 13/31] fix: JS snippets generations --- scripts/docs/generate.ts | 5 ++++- templates/javascript/snippets/init.mustache | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/scripts/docs/generate.ts b/scripts/docs/generate.ts index 326ab71904..00849c61fb 100644 --- a/scripts/docs/generate.ts +++ b/scripts/docs/generate.ts @@ -1,4 +1,4 @@ -import { callGenerator, exists, run, setupAndGen, toAbsolutePath } from '../common.ts'; +import { callGenerator, exists, isWSL, run, setupAndGen, toAbsolutePath } from '../common.ts'; import { getTestOutputFolder } from '../config.ts'; import { formatter } from '../formatter.ts'; import type { Generator } from '../types.ts'; @@ -32,6 +32,9 @@ export async function docsGenerateMany(generators: Generator[], scope: 'guides' } if (await exists(toAbsolutePath(docsPath))) { + if (isWSL()) { + await run(`sudo chmod 777 -R ${docsPath}`); + } await formatter(lang, docsPath); } } diff --git a/templates/javascript/snippets/init.mustache b/templates/javascript/snippets/init.mustache index 62c7f55e00..c84fe09357 100644 --- a/templates/javascript/snippets/init.mustache +++ b/templates/javascript/snippets/init.mustache @@ -1 +1 @@ -const client = {{{clientName}}}("ALGOLIA_APPLICATION_ID", "ALGOLIA_API_KEY"){{^isSearchClient}}{{^isCompositionClient}}{{^isCompositionFullClient}}.{{{initMethod}}}({{#hasRegionalHost}} {region: '{{defaultRegion}}'} {{/hasRegionalHost}}){{/isCompositionFullClient}}{{/isCompositionClient}}{{/isSearchClient}}; \ No newline at end of file +const client = {{{clientName}}}("ALGOLIA_APPLICATION_ID", "ALGOLIA_API_KEY"){{^isSearchClient}}{{^isCompositionClient}}{{^isComposition-fullClient}}.{{{initMethod}}}({{#hasRegionalHost}} {region: '{{defaultRegion}}'} {{/hasRegionalHost}}){{/isComposition-fullClient}}{{/isCompositionClient}}{{/isSearchClient}}; \ No newline at end of file From afb8e9fbe393559a79179f90150ff6b7ee3ff40c Mon Sep 17 00:00:00 2001 From: Emmanuel Date: Wed, 15 Jan 2025 16:48:59 +0100 Subject: [PATCH 14/31] fix: remove test that doesn't make sense without custom methods --- tests/CTS/client/composition/api.json | 42 --------------------------- 1 file changed, 42 deletions(-) diff --git a/tests/CTS/client/composition/api.json b/tests/CTS/client/composition/api.json index 9332b825dc..dca4607da0 100644 --- a/tests/CTS/client/composition/api.json +++ b/tests/CTS/client/composition/api.json @@ -48,47 +48,5 @@ } } ] - }, - { - "testName": "test the compression strategy", - "autoCreateClient": false, - "steps": [ - { - "type": "createClient", - "parameters": { - "appId": "test-app-id", - "apiKey": "test-api-key", - "customHosts": [ - { - "port": 6678 - } - ], - "gzip": true - } - }, - { - "type": "method", - "method": "search", - "parameters": { - "path": "1/test/gzip", - "parameters": { - "compositionID": "test-composition-id", - "requestBody": {} - }, - "body": { - "message": "this is a compressed body" - } - }, - "expected": { - "type": "response", - "match": { - "message": "ok compression test server response", - "body": { - "message": "this is a compressed body" - } - } - } - } - ] } ] From fede5cb6fb2a124420dc38ccee9cc9a97b742fa3 Mon Sep 17 00:00:00 2001 From: Emmanuel Date: Wed, 15 Jan 2025 17:37:55 +0100 Subject: [PATCH 15/31] fix: dart generation --- .../main/java/com/algolia/codegen/AlgoliaDartGenerator.java | 1 + templates/dart/api.mustache | 2 ++ templates/dart/lib.mustache | 4 +++- 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/generators/src/main/java/com/algolia/codegen/AlgoliaDartGenerator.java b/generators/src/main/java/com/algolia/codegen/AlgoliaDartGenerator.java index 9e49549038..ea42a2fd78 100644 --- a/generators/src/main/java/com/algolia/codegen/AlgoliaDartGenerator.java +++ b/generators/src/main/java/com/algolia/codegen/AlgoliaDartGenerator.java @@ -36,6 +36,7 @@ public void processOpts() { isAlgoliasearchClient = client.equals("algoliasearch"); String version = Helpers.getClientConfigField("dart", "packageVersion"); additionalProperties.put("isAlgoliasearchClient", isAlgoliasearchClient); + additionalProperties.put("isCompositionClient", client.equals("composition")); // pubspec.yaml setPubAuthor("Algolia"); diff --git a/templates/dart/api.mustache b/templates/dart/api.mustache index bc07f28dcf..9c0ce01f49 100644 --- a/templates/dart/api.mustache +++ b/templates/dart/api.mustache @@ -177,6 +177,7 @@ final class {{classname}} implements ApiClient { } {{/operation}} +{{^isCompositionClient}} @Deprecated('This operation has been deprecated, use `customPost` instead') Future post({ required String path, @@ -214,6 +215,7 @@ final class {{classname}} implements ApiClient { return this.customDelete(path: path, parameters: parameters, requestOptions: requestOptions); } {{/isAlgoliasearchClient}} +{{/isCompositionClient}} @override void dispose() => _retryStrategy.dispose(); diff --git a/templates/dart/lib.mustache b/templates/dart/lib.mustache index c9108ef2fe..6a02bfd826 100644 --- a/templates/dart/lib.mustache +++ b/templates/dart/lib.mustache @@ -7,4 +7,6 @@ export 'package:algolia_client_core/algolia_client_core.dart'; {{/apis}}{{/apiInfo}} {{#models}}{{#model}}export '{{sourceFolder}}/{{modelPackage}}/{{classFilename}}.dart'; {{/model}}{{/models}} -export 'src/extension.dart'; \ No newline at end of file +{{^isCompositionClient}} +export 'src/extension.dart'; +{{/isCompositionClient}} \ No newline at end of file From c45a50aa5343d8b84b0ae7960d1cace3d3aa902d Mon Sep 17 00:00:00 2001 From: shortcuts Date: Thu, 16 Jan 2025 23:27:42 +0100 Subject: [PATCH 16/31] fix: dart --- templates/dart/pubspec.mustache | 2 +- templates/dart/snippets/pubspec.mustache | 1 + templates/dart/snippets/pubspec_overrides.mustache | 4 +++- tests/output/dart/lib/src/run.dart | 1 + tests/output/dart/pubspec.yaml | 1 + tests/output/dart/pubspec_overrides.yaml | 2 ++ 6 files changed, 9 insertions(+), 2 deletions(-) diff --git a/templates/dart/pubspec.mustache b/templates/dart/pubspec.mustache index 37292fb56c..adbd9121c1 100644 --- a/templates/dart/pubspec.mustache +++ b/templates/dart/pubspec.mustache @@ -29,4 +29,4 @@ dev_dependencies: json_serializable: ^6.7.0 lints: ^5.0.0 logging: ^1.2.0 - test: ^1.25.8 + test: ^1.25.8 \ No newline at end of file diff --git a/templates/dart/snippets/pubspec.mustache b/templates/dart/snippets/pubspec.mustache index 7cad2f8667..e6f1320bfa 100644 --- a/templates/dart/snippets/pubspec.mustache +++ b/templates/dart/snippets/pubspec.mustache @@ -9,6 +9,7 @@ dependencies: algolia_client_search: ^1.0.0 algolia_client_insights: ^1.0.0 algolia_client_recommend: ^1.0.0 + algolia_client_composition: ^1.0.0 dotenv: ^4.1.0 http: ^1.2.2 diff --git a/templates/dart/snippets/pubspec_overrides.mustache b/templates/dart/snippets/pubspec_overrides.mustache index 8186223507..cd0eba1efa 100644 --- a/templates/dart/snippets/pubspec_overrides.mustache +++ b/templates/dart/snippets/pubspec_overrides.mustache @@ -8,4 +8,6 @@ dependency_overrides: algolia_client_insights: path: ../../../clients/algoliasearch-client-dart/packages/client_insights algolia_client_recommend: - path: ../../../clients/algoliasearch-client-dart/packages/client_recommend \ No newline at end of file + path: ../../../clients/algoliasearch-client-dart/packages/client_recommend + algolia_client_composition: + path: ../../../clients/algoliasearch-client-dart/packages/client_composition \ No newline at end of file diff --git a/tests/output/dart/lib/src/run.dart b/tests/output/dart/lib/src/run.dart index 2f433a4ace..695e6a0a98 100644 --- a/tests/output/dart/lib/src/run.dart +++ b/tests/output/dart/lib/src/run.dart @@ -25,6 +25,7 @@ Future runTest({ /// Uses provided function to intercept HTTP requests. class RequestInterceptor extends Requester { String apiKey = "fake"; + @override Duration connectTimeout = Duration(seconds: 30); Function(HttpRequest) onRequest = (_) {}; diff --git a/tests/output/dart/pubspec.yaml b/tests/output/dart/pubspec.yaml index 5395163846..bca1bd7b07 100644 --- a/tests/output/dart/pubspec.yaml +++ b/tests/output/dart/pubspec.yaml @@ -9,6 +9,7 @@ dependencies: algolia_client_search: ^1.0.0 algolia_client_insights: ^1.0.0 algolia_client_recommend: ^1.0.0 + algolia_client_composition: ^1.0.0 test: ^1.25.8 collection: ^1.17.2 test_api: ^0.7.3 diff --git a/tests/output/dart/pubspec_overrides.yaml b/tests/output/dart/pubspec_overrides.yaml index 0587f0ba0e..8d82f4fd7a 100644 --- a/tests/output/dart/pubspec_overrides.yaml +++ b/tests/output/dart/pubspec_overrides.yaml @@ -9,3 +9,5 @@ dependency_overrides: path: ../../../clients/algoliasearch-client-dart/packages/client_insights algolia_client_recommend: path: ../../../clients/algoliasearch-client-dart/packages/client_recommend + algolia_client_composition: + path: ../../../clients/algoliasearch-client-dart/packages/client_composition From f95b503658af11a4d428cb7ad9f1bf9506e0b470 Mon Sep 17 00:00:00 2001 From: shortcuts Date: Fri, 17 Jan 2025 09:12:21 +0100 Subject: [PATCH 17/31] fix: kotlin --- .../main/java/com/algolia/codegen/AlgoliaCSharpGenerator.java | 2 +- .../main/java/com/algolia/codegen/AlgoliaDartGenerator.java | 2 +- .../src/main/java/com/algolia/codegen/AlgoliaGoGenerator.java | 2 +- .../main/java/com/algolia/codegen/AlgoliaJavaGenerator.java | 2 +- .../java/com/algolia/codegen/AlgoliaJavascriptGenerator.java | 2 +- .../main/java/com/algolia/codegen/AlgoliaKotlinGenerator.java | 2 +- .../main/java/com/algolia/codegen/AlgoliaPhpGenerator.java | 2 +- .../main/java/com/algolia/codegen/AlgoliaPythonGenerator.java | 2 +- .../main/java/com/algolia/codegen/AlgoliaRubyGenerator.java | 2 +- .../main/java/com/algolia/codegen/AlgoliaScalaGenerator.java | 2 +- .../main/java/com/algolia/codegen/AlgoliaSwiftGenerator.java | 2 +- templates/kotlin/api.mustache | 4 ++++ 12 files changed, 15 insertions(+), 11 deletions(-) diff --git a/generators/src/main/java/com/algolia/codegen/AlgoliaCSharpGenerator.java b/generators/src/main/java/com/algolia/codegen/AlgoliaCSharpGenerator.java index f0223f142d..ab48ae3f71 100644 --- a/generators/src/main/java/com/algolia/codegen/AlgoliaCSharpGenerator.java +++ b/generators/src/main/java/com/algolia/codegen/AlgoliaCSharpGenerator.java @@ -45,7 +45,7 @@ public void processOpts() { additionalProperties.put("sourceFolder", ""); additionalProperties.put("netCoreProjectFile", true); additionalProperties.put("targetFramework", "netstandard2.1;netstandard2.0"); - additionalProperties.put("isSearchClient", client.equals("search")); + additionalProperties.put("is" + Helpers.capitalize(Helpers.camelize((String) additionalProperties.get("client"))) + "Client", true); additionalProperties.put("apiPackageName", getClientName(client)); additionalProperties.put("equatable", false); additionalProperties.put("disallowAdditionalPropertiesIfNotPresent", true); diff --git a/generators/src/main/java/com/algolia/codegen/AlgoliaDartGenerator.java b/generators/src/main/java/com/algolia/codegen/AlgoliaDartGenerator.java index ea42a2fd78..04a88154f8 100644 --- a/generators/src/main/java/com/algolia/codegen/AlgoliaDartGenerator.java +++ b/generators/src/main/java/com/algolia/codegen/AlgoliaDartGenerator.java @@ -36,7 +36,7 @@ public void processOpts() { isAlgoliasearchClient = client.equals("algoliasearch"); String version = Helpers.getClientConfigField("dart", "packageVersion"); additionalProperties.put("isAlgoliasearchClient", isAlgoliasearchClient); - additionalProperties.put("isCompositionClient", client.equals("composition")); + additionalProperties.put("is" + Helpers.capitalize(Helpers.camelize((String) additionalProperties.get("client"))) + "Client", true); // pubspec.yaml setPubAuthor("Algolia"); diff --git a/generators/src/main/java/com/algolia/codegen/AlgoliaGoGenerator.java b/generators/src/main/java/com/algolia/codegen/AlgoliaGoGenerator.java index 80364e7e35..8e060a731c 100644 --- a/generators/src/main/java/com/algolia/codegen/AlgoliaGoGenerator.java +++ b/generators/src/main/java/com/algolia/codegen/AlgoliaGoGenerator.java @@ -30,7 +30,7 @@ public void processOpts() { additionalProperties.put("packageName", client.equals("query-suggestions") ? "suggestions" : client); additionalProperties.put("enumClassPrefix", true); - additionalProperties.put("isSearchClient", client.equals("search")); + additionalProperties.put("is" + Helpers.capitalize(Helpers.camelize((String) additionalProperties.get("client"))) + "Client", true); String outputFolder = "algolia" + File.separator + client; setOutputDir(getOutputDir() + File.separator + outputFolder); diff --git a/generators/src/main/java/com/algolia/codegen/AlgoliaJavaGenerator.java b/generators/src/main/java/com/algolia/codegen/AlgoliaJavaGenerator.java index 3034b10b14..6b69aef9ba 100644 --- a/generators/src/main/java/com/algolia/codegen/AlgoliaJavaGenerator.java +++ b/generators/src/main/java/com/algolia/codegen/AlgoliaJavaGenerator.java @@ -53,7 +53,7 @@ public void processOpts() { final String invokerFolder = (sourceFolder + '/' + invokerPackage).replace(".", "/"); supportingFiles.add(new SupportingFile("build_config.mustache", invokerFolder, "BuildConfig.java")); supportingFiles.add(new SupportingFile("gradle.properties.mustache", "", "gradle.properties")); - additionalProperties.put("isSearchClient", client.equals("search")); + additionalProperties.put("is" + Helpers.capitalize(Helpers.camelize((String) additionalProperties.get("client"))) + "Client", true); Helpers.addCommonSupportingFiles(supportingFiles, ""); diff --git a/generators/src/main/java/com/algolia/codegen/AlgoliaJavascriptGenerator.java b/generators/src/main/java/com/algolia/codegen/AlgoliaJavascriptGenerator.java index 4cffef3da9..ede53d941e 100644 --- a/generators/src/main/java/com/algolia/codegen/AlgoliaJavascriptGenerator.java +++ b/generators/src/main/java/com/algolia/codegen/AlgoliaJavascriptGenerator.java @@ -154,7 +154,7 @@ private void setDefaultGeneratorOptions() { additionalProperties.put("apiName", CLIENT); additionalProperties.put("clientName", clientName); additionalProperties.put("algoliaAgent", Helpers.capitalize(CLIENT)); - additionalProperties.put("is" + Helpers.capitalize(CLIENT) + "Client", true); + additionalProperties.put("is" + Helpers.capitalize(Helpers.camelize((String) additionalProperties.get("client"))) + "Client", true); additionalProperties.put("isSearchClient", CLIENT.equals("search") || isAlgoliasearchClient); additionalProperties.put("isAlgoliasearchClient", isAlgoliasearchClient); additionalProperties.put("packageVersion", Helpers.getPackageJsonVersion(packageName)); diff --git a/generators/src/main/java/com/algolia/codegen/AlgoliaKotlinGenerator.java b/generators/src/main/java/com/algolia/codegen/AlgoliaKotlinGenerator.java index d181c47683..d7fe82fbbe 100644 --- a/generators/src/main/java/com/algolia/codegen/AlgoliaKotlinGenerator.java +++ b/generators/src/main/java/com/algolia/codegen/AlgoliaKotlinGenerator.java @@ -48,7 +48,7 @@ public void processOpts() { supportingFiles.removeIf(file -> file.getTemplateFile().contains("auth")); // Search config - additionalProperties.put("isSearchClient", client.equals("search")); + additionalProperties.put("is" + Helpers.capitalize(Helpers.camelize((String) additionalProperties.get("client"))) + "Client", true); // We don't extend hashmap propertyAdditionalKeywords.clear(); diff --git a/generators/src/main/java/com/algolia/codegen/AlgoliaPhpGenerator.java b/generators/src/main/java/com/algolia/codegen/AlgoliaPhpGenerator.java index 4abf6a623c..30636c16ae 100644 --- a/generators/src/main/java/com/algolia/codegen/AlgoliaPhpGenerator.java +++ b/generators/src/main/java/com/algolia/codegen/AlgoliaPhpGenerator.java @@ -56,7 +56,7 @@ public void processOpts() { Helpers.addCommonSupportingFiles(supportingFiles, ""); - additionalProperties.put("isSearchClient", client.equals("search")); + additionalProperties.put("is" + Helpers.capitalize(Helpers.camelize((String) additionalProperties.get("client"))) + "Client", true); additionalProperties.put("configClassname", getClientName(client) + "Config"); try { diff --git a/generators/src/main/java/com/algolia/codegen/AlgoliaPythonGenerator.java b/generators/src/main/java/com/algolia/codegen/AlgoliaPythonGenerator.java index c4c6a220f0..d435564462 100644 --- a/generators/src/main/java/com/algolia/codegen/AlgoliaPythonGenerator.java +++ b/generators/src/main/java/com/algolia/codegen/AlgoliaPythonGenerator.java @@ -26,7 +26,7 @@ public String getName() { public void processOpts() { CLIENT = (String) additionalProperties.get("client"); - additionalProperties.put("isSearchClient", CLIENT.equals("search")); + additionalProperties.put("is" + Helpers.capitalize(Helpers.camelize((String) additionalProperties.get("client"))) + "Client", true); additionalProperties.put("packageVersion", Helpers.getClientConfigField("python", "packageVersion")); additionalProperties.put(CodegenConstants.EXCLUDE_TESTS, true); diff --git a/generators/src/main/java/com/algolia/codegen/AlgoliaRubyGenerator.java b/generators/src/main/java/com/algolia/codegen/AlgoliaRubyGenerator.java index 22f0a4fe4c..949bcd464d 100644 --- a/generators/src/main/java/com/algolia/codegen/AlgoliaRubyGenerator.java +++ b/generators/src/main/java/com/algolia/codegen/AlgoliaRubyGenerator.java @@ -25,7 +25,7 @@ public String getName() { public void processOpts() { CLIENT = (String) additionalProperties.get("client"); - additionalProperties.put("isSearchClient", CLIENT.equals("search")); + additionalProperties.put("is" + Helpers.capitalize(Helpers.camelize((String) additionalProperties.get("client"))) + "Client", true); additionalProperties.put("packageVersion", Helpers.getClientConfigField("ruby", "packageVersion")); setGemName("algolia"); additionalProperties.put("modelModule", Helpers.capitalize(Helpers.camelize(CLIENT))); diff --git a/generators/src/main/java/com/algolia/codegen/AlgoliaScalaGenerator.java b/generators/src/main/java/com/algolia/codegen/AlgoliaScalaGenerator.java index ec1265231d..f4cb1434c4 100644 --- a/generators/src/main/java/com/algolia/codegen/AlgoliaScalaGenerator.java +++ b/generators/src/main/java/com/algolia/codegen/AlgoliaScalaGenerator.java @@ -78,7 +78,7 @@ public void processOpts() { Helpers.addCommonSupportingFiles(supportingFiles, ""); - additionalProperties.put("isSearchClient", client.equals("search")); + additionalProperties.put("is" + Helpers.capitalize(Helpers.camelize((String) additionalProperties.get("client"))) + "Client", true); typeMapping.put("AnyType", "Any"); nameMapping.putAll(NAME_MAPPING); diff --git a/generators/src/main/java/com/algolia/codegen/AlgoliaSwiftGenerator.java b/generators/src/main/java/com/algolia/codegen/AlgoliaSwiftGenerator.java index c760861be0..7a04b1ad3b 100644 --- a/generators/src/main/java/com/algolia/codegen/AlgoliaSwiftGenerator.java +++ b/generators/src/main/java/com/algolia/codegen/AlgoliaSwiftGenerator.java @@ -185,7 +185,7 @@ public void processOpts() { System.exit(1); } - additionalProperties.put("isSearchClient", CLIENT.equals("search")); + additionalProperties.put("is" + Helpers.capitalize(Helpers.camelize((String) additionalProperties.get("client"))) + "Client", true); additionalProperties.put(CodegenConstants.EXCLUDE_TESTS, true); additionalProperties.put(RESPONSE_AS, new String[] { RESPONSE_LIBRARY_ASYNC_AWAIT }); diff --git a/templates/kotlin/api.mustache b/templates/kotlin/api.mustache index 165cba8d6f..50bdde51e0 100644 --- a/templates/kotlin/api.mustache +++ b/templates/kotlin/api.mustache @@ -10,6 +10,10 @@ import {{packageName}}.transport.internal.* import kotlinx.serialization.json.* import kotlin.time.Duration.Companion.milliseconds +{{#isCompositionClient}} +import {{modelPackage}}.RequestBody +{{/isCompositionClient}} + {{#operations}} public class {{classname}}( override val appId: String, From c275a136fd687de7a7adebbac64e78f0ab47e690 Mon Sep 17 00:00:00 2001 From: shortcuts Date: Fri, 17 Jan 2025 09:24:09 +0100 Subject: [PATCH 18/31] fix: templates --- .../main/java/com/algolia/codegen/cts/tests/TestsGenerator.java | 2 +- templates/javascript/clients/client/builds/browser.mustache | 2 +- templates/javascript/snippets/init.mustache | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/generators/src/main/java/com/algolia/codegen/cts/tests/TestsGenerator.java b/generators/src/main/java/com/algolia/codegen/cts/tests/TestsGenerator.java index ee3d0b43c6..2fc7d32ba1 100644 --- a/generators/src/main/java/com/algolia/codegen/cts/tests/TestsGenerator.java +++ b/generators/src/main/java/com/algolia/codegen/cts/tests/TestsGenerator.java @@ -56,7 +56,7 @@ protected Map loadCTS(String path, String clientName, Class js json = injectVariables(json); String key = f.getName().replace(".json", ""); // some clients don't have custom methods - if (clientName.equals("composition") && (key.equals("commonApi") || key.equals("setClientApiKey"))) { + if (clientName.equals("composition") && key.equals("commonApi")) { continue skipFile; } cts.put(key, Json.mapper().readValue(json, jsonType)); diff --git a/templates/javascript/clients/client/builds/browser.mustache b/templates/javascript/clients/client/builds/browser.mustache index 96d46575ba..cfb91b0fc8 100644 --- a/templates/javascript/clients/client/builds/browser.mustache +++ b/templates/javascript/clients/client/builds/browser.mustache @@ -12,7 +12,7 @@ logger: createNullLogger(), requester: createXhrRequester(), algoliaAgents: [{ segment: 'Browser' }], - authMode: 'Within{{#isCompositionClient}}Headers{{/isCompositionClient}}{{^isCompositionClient}}{{#isCompositionFullClient}}Headers{{/isCompositionFullClient}}{{^isCompositionFullClient}}QueryParameters{{/isCompositionFullClient}}{{/isCompositionClient}}', + authMode: 'Within{{#isCompositionClient}}Headers{{/isCompositionClient}}{{#isCompositionFullClient}}Headers{{/isCompositionFullClient}}{{^isCompositionClient}}{{^isCompositionFullClient}}QueryParameters{{/isCompositionFullClient}}{{/isCompositionClient}}', responsesCache: createMemoryCache(), requestsCache: createMemoryCache({ serializable: false }), hostsCache: createFallbackableCache({ diff --git a/templates/javascript/snippets/init.mustache b/templates/javascript/snippets/init.mustache index c84fe09357..62c7f55e00 100644 --- a/templates/javascript/snippets/init.mustache +++ b/templates/javascript/snippets/init.mustache @@ -1 +1 @@ -const client = {{{clientName}}}("ALGOLIA_APPLICATION_ID", "ALGOLIA_API_KEY"){{^isSearchClient}}{{^isCompositionClient}}{{^isComposition-fullClient}}.{{{initMethod}}}({{#hasRegionalHost}} {region: '{{defaultRegion}}'} {{/hasRegionalHost}}){{/isComposition-fullClient}}{{/isCompositionClient}}{{/isSearchClient}}; \ No newline at end of file +const client = {{{clientName}}}("ALGOLIA_APPLICATION_ID", "ALGOLIA_API_KEY"){{^isSearchClient}}{{^isCompositionClient}}{{^isCompositionFullClient}}.{{{initMethod}}}({{#hasRegionalHost}} {region: '{{defaultRegion}}'} {{/hasRegionalHost}}){{/isCompositionFullClient}}{{/isCompositionClient}}{{/isSearchClient}}; \ No newline at end of file From 22a28d326d72f1dcb8a1cb95efee880bd66adca6 Mon Sep 17 00:00:00 2001 From: shortcuts Date: Fri, 17 Jan 2025 09:26:23 +0100 Subject: [PATCH 19/31] fix: is variable --- .../main/java/com/algolia/codegen/cts/AlgoliaCTSGenerator.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/generators/src/main/java/com/algolia/codegen/cts/AlgoliaCTSGenerator.java b/generators/src/main/java/com/algolia/codegen/cts/AlgoliaCTSGenerator.java index fbd0d87944..28aaf0117d 100644 --- a/generators/src/main/java/com/algolia/codegen/cts/AlgoliaCTSGenerator.java +++ b/generators/src/main/java/com/algolia/codegen/cts/AlgoliaCTSGenerator.java @@ -148,7 +148,7 @@ public Map postProcessSupportingFileData(Map obj // We can put whatever we want in the bundle, and it will be accessible in the template bundle.put("mode", mode); - bundle.put("is" + Helpers.capitalize(client) + "Client", true); + bundle.put("is" + Helpers.capitalize(Helpers.camelize(client)) + "Client", true); bundle.put("isStandaloneClient", client.contains("search") || client.contains("composition")); bundle.put("isSearchClient", client.contains("search")); // just so algoliasearch is treated as a search client too bundle.put("client", Helpers.createClientName(importClientName, language) + "Client"); From 606cbb69bac5089f642990ab4c7bc2ee31077764 Mon Sep 17 00:00:00 2001 From: shortcuts Date: Fri, 17 Jan 2025 09:57:38 +0100 Subject: [PATCH 20/31] fix: imports --- .../cts/manager/JavascriptCTSManager.java | 32 +++++++++++-------- tests/output/javascript/yarn.lock | 7 ++++ 2 files changed, 25 insertions(+), 14 deletions(-) diff --git a/generators/src/main/java/com/algolia/codegen/cts/manager/JavascriptCTSManager.java b/generators/src/main/java/com/algolia/codegen/cts/manager/JavascriptCTSManager.java index 4569841ee0..3abd4a76f3 100644 --- a/generators/src/main/java/com/algolia/codegen/cts/manager/JavascriptCTSManager.java +++ b/generators/src/main/java/com/algolia/codegen/cts/manager/JavascriptCTSManager.java @@ -46,19 +46,23 @@ public void addDataToBundle(Map bundle) throws GeneratorExceptio bundle.put("utilsPackageVersion", Helpers.getPackageJsonVersion("client-common")); bundle.put("algoliasearchVersion", Helpers.getPackageJsonVersion("algoliasearch")); bundle.put("initMethod", "init" + Helpers.capitalize(Helpers.camelize(client))); - bundle.put( - "clientName", - client.equals("algoliasearch") - ? "liteClient" - : client.equals("composition") ? "compositionClient" : client.equals("composition-full") ? "compositionFullClient" : "algoliasearch" - ); - bundle.put( - "importPackage", - client.equals("algoliasearch") - ? "algoliasearch/lite" - : client.equals("composition") - ? "@algolia/composition" - : client.equals("composition-full") ? "@algolia/client-composition" : "algoliasearch" - ); + + switch (client) { + case "composition": + bundle.put("clientName", "compositionClient"); + bundle.put("importPackage", "@algolia/composition"); + break; + case "composition-full": + bundle.put("clientName", "compositionFullClient"); + bundle.put("importPackage", "@algolia/composition-full"); + break; + case "algoliasearch": + bundle.put("clientName", "liteClient"); + bundle.put("importPackage", "algoliasearch/lite"); + break; + default: + bundle.put("clientName", "algoliasearch"); + bundle.put("importPackage", "algoliasearch"); + } } } diff --git a/tests/output/javascript/yarn.lock b/tests/output/javascript/yarn.lock index 7fca00df6a..6aaab175e5 100644 --- a/tests/output/javascript/yarn.lock +++ b/tests/output/javascript/yarn.lock @@ -11,6 +11,12 @@ __metadata: languageName: node linkType: soft +"@algolia/composition@link:../../../clients/algoliasearch-client-javascript/packages/composition::locator=javascript-tests%40workspace%3A.": + version: 0.0.0-use.local + resolution: "@algolia/composition@link:../../../clients/algoliasearch-client-javascript/packages/composition::locator=javascript-tests%40workspace%3A." + languageName: node + linkType: soft + "@algolia/requester-testing@link:../../../clients/algoliasearch-client-javascript/packages/requester-testing::locator=javascript-tests%40workspace%3A.": version: 0.0.0-use.local resolution: "@algolia/requester-testing@link:../../../clients/algoliasearch-client-javascript/packages/requester-testing::locator=javascript-tests%40workspace%3A." @@ -980,6 +986,7 @@ __metadata: resolution: "javascript-tests@workspace:." dependencies: "@algolia/client-composition": "link:../../../clients/algoliasearch-client-javascript/packages/client-composition" + "@algolia/composition": "link:../../../clients/algoliasearch-client-javascript/packages/composition" "@algolia/requester-testing": "link:../../../clients/algoliasearch-client-javascript/packages/requester-testing" "@types/node": "npm:22.10.5" algoliasearch: "link:../../../clients/algoliasearch-client-javascript/packages/algoliasearch" From bae83d0a0c7d8c61939c8924e491ea805c17ae58 Mon Sep 17 00:00:00 2001 From: shortcuts Date: Mon, 20 Jan 2025 08:39:21 +0100 Subject: [PATCH 21/31] fix: javascript tests --- .../algolia/codegen/cts/manager/JavascriptCTSManager.java | 2 +- templates/javascript/tests/e2e/e2e.mustache | 7 +------ 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/generators/src/main/java/com/algolia/codegen/cts/manager/JavascriptCTSManager.java b/generators/src/main/java/com/algolia/codegen/cts/manager/JavascriptCTSManager.java index 3abd4a76f3..4246eabeff 100644 --- a/generators/src/main/java/com/algolia/codegen/cts/manager/JavascriptCTSManager.java +++ b/generators/src/main/java/com/algolia/codegen/cts/manager/JavascriptCTSManager.java @@ -54,7 +54,7 @@ public void addDataToBundle(Map bundle) throws GeneratorExceptio break; case "composition-full": bundle.put("clientName", "compositionFullClient"); - bundle.put("importPackage", "@algolia/composition-full"); + bundle.put("importPackage", "@algolia/client-composition"); break; case "algoliasearch": bundle.put("clientName", "liteClient"); diff --git a/templates/javascript/tests/e2e/e2e.mustache b/templates/javascript/tests/e2e/e2e.mustache index 3f59053088..95bb834166 100644 --- a/templates/javascript/tests/e2e/e2e.mustache +++ b/templates/javascript/tests/e2e/e2e.mustache @@ -6,12 +6,7 @@ import { union } from '../helpers.js'; import * as dotenv from 'dotenv'; dotenv.config({path:'../../.env'}); -{{^isCompositionFullClient}} import { {{{clientName}}} } from '{{{importPackage}}}'; -{{/isCompositionFullClient}} -{{#isCompositionFullClient}} -import { compositionClient } from '@algolia/client-composition'; -{{/isCompositionFullClient}} import type { RequestOptions } from '@algolia/client-common'; if (!process.env.{{e2eAppID}}) { @@ -22,7 +17,7 @@ if (!process.env.{{e2eApiKey}}) { throw new Error("please provide an `{{e2eApiKey}}` env var for e2e tests"); } -const client = {{^isCompositionFullClient}}{{{clientName}}}{{/isCompositionFullClient}}{{#isCompositionFullClient}}compositionFullClient{{/isCompositionFullClient}}(process.env.{{e2eAppID}}, process.env.{{e2eApiKey}}){{^isStandaloneClient}}.{{{initMethod}}}({{#hasRegionalHost}} {region:'{{{defaultRegion}}}'} {{/hasRegionalHost}}){{/isStandaloneClient}}; +const client = {{{clientName}}}(process.env.{{e2eAppID}}, process.env.{{e2eApiKey}}){{^isStandaloneClient}}.{{{initMethod}}}({{#hasRegionalHost}} {region:'{{{defaultRegion}}}'} {{/hasRegionalHost}}){{/isStandaloneClient}}; {{#blocksE2E}} describe('{{operationId}}', () => { From c44e17e523e668a9e2d72ae9aaf93237be2eca4d Mon Sep 17 00:00:00 2001 From: shortcuts Date: Mon, 20 Jan 2025 08:46:16 +0100 Subject: [PATCH 22/31] fix: Full naming --- .../java/com/algolia/codegen/AlgoliaJavascriptGenerator.java | 3 ++- .../com/algolia/codegen/cts/manager/JavascriptCTSManager.java | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/generators/src/main/java/com/algolia/codegen/AlgoliaJavascriptGenerator.java b/generators/src/main/java/com/algolia/codegen/AlgoliaJavascriptGenerator.java index ede53d941e..938a9adf30 100644 --- a/generators/src/main/java/com/algolia/codegen/AlgoliaJavascriptGenerator.java +++ b/generators/src/main/java/com/algolia/codegen/AlgoliaJavascriptGenerator.java @@ -152,7 +152,8 @@ private void setDefaultGeneratorOptions() { String packageName = getPackageName((String) additionalProperties.get("client")); additionalProperties.put("apiName", CLIENT); - additionalProperties.put("clientName", clientName); + // Just so the full client doesn't have the weird Full naming + additionalProperties.put("clientName", CLIENT.contains("composition") ? "composition" + Helpers.API_SUFFIX : clientName); additionalProperties.put("algoliaAgent", Helpers.capitalize(CLIENT)); additionalProperties.put("is" + Helpers.capitalize(Helpers.camelize((String) additionalProperties.get("client"))) + "Client", true); additionalProperties.put("isSearchClient", CLIENT.equals("search") || isAlgoliasearchClient); diff --git a/generators/src/main/java/com/algolia/codegen/cts/manager/JavascriptCTSManager.java b/generators/src/main/java/com/algolia/codegen/cts/manager/JavascriptCTSManager.java index 4246eabeff..48782d2b66 100644 --- a/generators/src/main/java/com/algolia/codegen/cts/manager/JavascriptCTSManager.java +++ b/generators/src/main/java/com/algolia/codegen/cts/manager/JavascriptCTSManager.java @@ -53,7 +53,7 @@ public void addDataToBundle(Map bundle) throws GeneratorExceptio bundle.put("importPackage", "@algolia/composition"); break; case "composition-full": - bundle.put("clientName", "compositionFullClient"); + bundle.put("clientName", "compositionClient"); bundle.put("importPackage", "@algolia/client-composition"); break; case "algoliasearch": From 9178823b0ffe713f66bfe4afe43974ea9e5f738c Mon Sep 17 00:00:00 2001 From: shortcuts Date: Mon, 20 Jan 2025 08:49:48 +0100 Subject: [PATCH 23/31] fix: kotlin tests --- templates/kotlin/tests/client/benchmark.mustache | 4 ++++ templates/kotlin/tests/client/client.mustache | 4 ++++ templates/kotlin/tests/e2e/e2e.mustache | 4 ++++ templates/kotlin/tests/requests/requests.mustache | 4 ++++ 4 files changed, 16 insertions(+) diff --git a/templates/kotlin/tests/client/benchmark.mustache b/templates/kotlin/tests/client/benchmark.mustache index 816a603090..94f37c787d 100644 --- a/templates/kotlin/tests/client/benchmark.mustache +++ b/templates/kotlin/tests/client/benchmark.mustache @@ -14,6 +14,10 @@ import kotlinx.serialization.encodeToString import kotlin.test.* import kotlin.time.Duration.Companion.milliseconds +{{#isCompositionClient}} +import com.algolia.client.model.{{import}}.*RequestBody +{{/isCompositionClient}} + class {{clientPrefix}}Test { {{#blocksBenchmark}} diff --git a/templates/kotlin/tests/client/client.mustache b/templates/kotlin/tests/client/client.mustache index 3a2160df35..bc624eb440 100644 --- a/templates/kotlin/tests/client/client.mustache +++ b/templates/kotlin/tests/client/client.mustache @@ -16,6 +16,10 @@ import kotlinx.serialization.encodeToString import kotlin.test.* import kotlin.time.Duration.Companion.milliseconds +{{#isCompositionClient}} +import com.algolia.client.model.{{import}}.*RequestBody +{{/isCompositionClient}} + class {{clientPrefix}}Test { {{#blocksClient}} diff --git a/templates/kotlin/tests/e2e/e2e.mustache b/templates/kotlin/tests/e2e/e2e.mustache index 25d4c67f8e..78a9e39760 100644 --- a/templates/kotlin/tests/e2e/e2e.mustache +++ b/templates/kotlin/tests/e2e/e2e.mustache @@ -16,6 +16,10 @@ import kotlinx.serialization.encodeToString import kotlin.test.* import kotlin.time.Duration.Companion.milliseconds +{{#isCompositionClient}} +import com.algolia.client.model.{{import}}.*RequestBody +{{/isCompositionClient}} + class {{clientPrefix}}Test { var client: {{client}}; diff --git a/templates/kotlin/tests/requests/requests.mustache b/templates/kotlin/tests/requests/requests.mustache index dd528b8f79..e525a77a6e 100644 --- a/templates/kotlin/tests/requests/requests.mustache +++ b/templates/kotlin/tests/requests/requests.mustache @@ -12,6 +12,10 @@ import kotlinx.serialization.json.* import kotlin.test.* import kotlin.time.Duration.Companion.milliseconds +{{#isCompositionClient}} +import com.algolia.client.model.{{import}}.*RequestBody +{{/isCompositionClient}} + class {{clientPrefix}}Test { val client = {{client}}( From ad0fbcf6bb4980377b49ab2f91963af87843c746 Mon Sep 17 00:00:00 2001 From: shortcuts Date: Mon, 20 Jan 2025 09:06:59 +0100 Subject: [PATCH 24/31] fix: javascript --- templates/javascript/clients/client/builds/definition.mustache | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/javascript/clients/client/builds/definition.mustache b/templates/javascript/clients/client/builds/definition.mustache index 133497716c..075951ce6c 100644 --- a/templates/javascript/clients/client/builds/definition.mustache +++ b/templates/javascript/clients/client/builds/definition.mustache @@ -5,7 +5,7 @@ import { createNullLogger, createMemoryCache, createFallbackableCache, createBro import type { ClientOptions } from '@algolia/client-common'; -import { create{{#lambda.titlecase}}{{clientName}}{{/lambda.titlecase}}, apiClientVersion } from '../src/{{clientName}}'; +import { create{{#lambda.titlecase}}{{clientName}}{{/lambda.titlecase}}, apiClientVersion } from '../src/{{#isCompositionFullClient}}compositionFullClient{{/isCompositionFullClient}}{{^isCompositionFullClient}}{{clientName}}{{/isCompositionFullClient}}'; {{#hasRegionalHost}} import { REGIONS } from '../src/{{clientName}}'; From 5879c878bbad09081db2b9f44be353cc348a4a72 Mon Sep 17 00:00:00 2001 From: Emmanuel Date: Mon, 20 Jan 2025 14:53:59 +0100 Subject: [PATCH 25/31] fix: JS build --- templates/javascript/clients/client/builds/definition.mustache | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/javascript/clients/client/builds/definition.mustache b/templates/javascript/clients/client/builds/definition.mustache index 075951ce6c..3412ffeb9c 100644 --- a/templates/javascript/clients/client/builds/definition.mustache +++ b/templates/javascript/clients/client/builds/definition.mustache @@ -22,7 +22,7 @@ export { isScheduleTrigger, isSubscriptionTrigger, {{/isIngestionClient}} -} from '../src/{{clientName}}'; +} from '../src/{{#isCompositionFullClient}}compositionFullClient{{/isCompositionFullClient}}{{^isCompositionFullClient}}{{clientName}}{{/isCompositionFullClient}}'; export * from '../model'; From af4bf961986352331da4d9bcccc7c1c754a802e4 Mon Sep 17 00:00:00 2001 From: Emmanuel Date: Mon, 20 Jan 2025 15:18:05 +0100 Subject: [PATCH 26/31] fix: JS playground --- playground/javascript/node/compositionFull.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/playground/javascript/node/compositionFull.ts b/playground/javascript/node/compositionFull.ts index e7f88ad7ac..8aba1975b1 100644 --- a/playground/javascript/node/compositionFull.ts +++ b/playground/javascript/node/compositionFull.ts @@ -1,11 +1,11 @@ import { ApiError } from '@algolia/client-common'; -import { compositionFullClient } from '@algolia/client-composition'; +import { compositionClient } from '@algolia/client-composition'; const appId = process.env.METIS_APPLICATION_ID || '**** APP_ID *****'; const apiKey = process.env.METIS_API_KEY || '**** ADMIN_KEY *****'; // Init client with appId and apiKey -const client = compositionFullClient(appId, apiKey); +const client = compositionClient(appId, apiKey); async function testComposition() { try { From ca02d679bf406389f41fa6fa4dc5cee76963f40d Mon Sep 17 00:00:00 2001 From: Emmanuel Date: Mon, 20 Jan 2025 15:37:35 +0100 Subject: [PATCH 27/31] fix: JS CTS --- .../main/java/com/algolia/codegen/cts/tests/TestsGenerator.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/generators/src/main/java/com/algolia/codegen/cts/tests/TestsGenerator.java b/generators/src/main/java/com/algolia/codegen/cts/tests/TestsGenerator.java index 2fc7d32ba1..ee3d0b43c6 100644 --- a/generators/src/main/java/com/algolia/codegen/cts/tests/TestsGenerator.java +++ b/generators/src/main/java/com/algolia/codegen/cts/tests/TestsGenerator.java @@ -56,7 +56,7 @@ protected Map loadCTS(String path, String clientName, Class js json = injectVariables(json); String key = f.getName().replace(".json", ""); // some clients don't have custom methods - if (clientName.equals("composition") && key.equals("commonApi")) { + if (clientName.equals("composition") && (key.equals("commonApi") || key.equals("setClientApiKey"))) { continue skipFile; } cts.put(key, Json.mapper().readValue(json, jsonType)); From 45066edd2af34b057b3d7dc5d4f2ac5de933d131 Mon Sep 17 00:00:00 2001 From: Emmanuel Date: Mon, 20 Jan 2025 16:36:29 +0100 Subject: [PATCH 28/31] fix: kotlin CTS --- templates/kotlin/tests/client/benchmark.mustache | 2 +- templates/kotlin/tests/client/client.mustache | 2 +- templates/kotlin/tests/e2e/e2e.mustache | 2 +- templates/kotlin/tests/requests/requests.mustache | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/templates/kotlin/tests/client/benchmark.mustache b/templates/kotlin/tests/client/benchmark.mustache index 94f37c787d..1284acec04 100644 --- a/templates/kotlin/tests/client/benchmark.mustache +++ b/templates/kotlin/tests/client/benchmark.mustache @@ -15,7 +15,7 @@ import kotlin.test.* import kotlin.time.Duration.Companion.milliseconds {{#isCompositionClient}} -import com.algolia.client.model.{{import}}.*RequestBody +import com.algolia.client.model.{{import}}.RequestBody {{/isCompositionClient}} class {{clientPrefix}}Test { diff --git a/templates/kotlin/tests/client/client.mustache b/templates/kotlin/tests/client/client.mustache index bc624eb440..e50784b90e 100644 --- a/templates/kotlin/tests/client/client.mustache +++ b/templates/kotlin/tests/client/client.mustache @@ -17,7 +17,7 @@ import kotlin.test.* import kotlin.time.Duration.Companion.milliseconds {{#isCompositionClient}} -import com.algolia.client.model.{{import}}.*RequestBody +import com.algolia.client.model.{{import}}.RequestBody {{/isCompositionClient}} class {{clientPrefix}}Test { diff --git a/templates/kotlin/tests/e2e/e2e.mustache b/templates/kotlin/tests/e2e/e2e.mustache index 78a9e39760..1d02f27f59 100644 --- a/templates/kotlin/tests/e2e/e2e.mustache +++ b/templates/kotlin/tests/e2e/e2e.mustache @@ -17,7 +17,7 @@ import kotlin.test.* import kotlin.time.Duration.Companion.milliseconds {{#isCompositionClient}} -import com.algolia.client.model.{{import}}.*RequestBody +import com.algolia.client.model.{{import}}.RequestBody {{/isCompositionClient}} class {{clientPrefix}}Test { diff --git a/templates/kotlin/tests/requests/requests.mustache b/templates/kotlin/tests/requests/requests.mustache index e525a77a6e..5290d50c94 100644 --- a/templates/kotlin/tests/requests/requests.mustache +++ b/templates/kotlin/tests/requests/requests.mustache @@ -13,7 +13,7 @@ import kotlin.test.* import kotlin.time.Duration.Companion.milliseconds {{#isCompositionClient}} -import com.algolia.client.model.{{import}}.*RequestBody +import com.algolia.client.model.{{import}}.RequestBody {{/isCompositionClient}} class {{clientPrefix}}Test { From 1603ad72abe05f2f88655f3a89dadc8f74d27b67 Mon Sep 17 00:00:00 2001 From: Pierre Millot Date: Tue, 21 Jan 2025 18:45:57 +0100 Subject: [PATCH 29/31] fix generics --- .../codegen/AlgoliaSwiftGenerator.java | 4 +- .../codegen/utils/GenericPropagator.java | 104 +++++++++++------- specs/recommend/paths/batchRecommendRules.yml | 1 - .../client/model/types/isGeneric.mustache | 4 +- 4 files changed, 71 insertions(+), 42 deletions(-) diff --git a/generators/src/main/java/com/algolia/codegen/AlgoliaSwiftGenerator.java b/generators/src/main/java/com/algolia/codegen/AlgoliaSwiftGenerator.java index 7a04b1ad3b..461f12d574 100644 --- a/generators/src/main/java/com/algolia/codegen/AlgoliaSwiftGenerator.java +++ b/generators/src/main/java/com/algolia/codegen/AlgoliaSwiftGenerator.java @@ -310,14 +310,14 @@ public void processOpenAPI(OpenAPI openAPI) { public OperationsMap postProcessOperationsWithModels(OperationsMap objs, List models) { OperationsMap operations = super.postProcessOperationsWithModels(objs, models); Helpers.removeHelpers(operations); - GenericPropagator.propagateGenericsToOperations(operations, models); + GenericPropagator.propagateGenericsToOperations("swift", CLIENT, operations, models); return operations; } @Override public Map postProcessAllModels(Map objs) { Map models = super.postProcessAllModels(objs); - GenericPropagator.propagateGenericsToModels(models); + GenericPropagator.propagateGenericsToModels("swift", CLIENT, models); OneOf.updateModelsOneOf(models, modelPackage); OneOf.addOneOfMetadata(models); return models; diff --git a/generators/src/main/java/com/algolia/codegen/utils/GenericPropagator.java b/generators/src/main/java/com/algolia/codegen/utils/GenericPropagator.java index b2cfa40302..a70020f876 100644 --- a/generators/src/main/java/com/algolia/codegen/utils/GenericPropagator.java +++ b/generators/src/main/java/com/algolia/codegen/utils/GenericPropagator.java @@ -1,5 +1,6 @@ package com.algolia.codegen.utils; +import com.algolia.codegen.AlgoliaSwiftGenerator; import java.util.*; import java.util.function.Function; import org.openapitools.codegen.*; @@ -43,18 +44,19 @@ private static void setHasChildGeneric(IJsonSchemaValidationProperties property) * x-has-child-generic */ private static boolean hasGeneric(IJsonSchemaValidationProperties property) { - if (property instanceof CodegenModel) { - return ( - (boolean) ((CodegenModel) property).vendorExtensions.getOrDefault("x-propagated-generic", false) || - (boolean) ((CodegenModel) property).vendorExtensions.getOrDefault("x-has-child-generic", false) - ); - } else if (property instanceof CodegenProperty) { - return ( - (boolean) ((CodegenProperty) property).vendorExtensions.getOrDefault("x-propagated-generic", false) || - (boolean) ((CodegenProperty) property).vendorExtensions.getOrDefault("x-has-child-generic", false) - ); + Map vendorExtensions; + if (property instanceof CodegenModel model) { + vendorExtensions = model.vendorExtensions; + } else if (property instanceof CodegenProperty prop) { + vendorExtensions = prop.vendorExtensions; + } else { + return false; } - return false; + return ( + (boolean) vendorExtensions.getOrDefault("x-propagated-generic", false) || + (boolean) vendorExtensions.getOrDefault("x-has-child-generic", false) || + (boolean) vendorExtensions.getOrDefault("x-is-generic", false) + ); } private static CodegenModel propertyToModel(Map models, CodegenProperty prop) { @@ -78,16 +80,13 @@ private static boolean markPropagatedGeneric( } // if items itself isn't generic, we recurse on its items and properties until we reach the // end or find a generic property - if ( - items != null && - ((boolean) items.vendorExtensions.getOrDefault("x-is-generic", false) || markPropagatedGeneric(items, getVar, skipOneOf)) - ) { + if (items != null && (hasGeneric(items) || markPropagatedGeneric(items, getVar, skipOneOf))) { setPropagatedGeneric(model); return true; } for (CodegenProperty variable : getVar.apply(model)) { // same thing for the variable, if it's not a generic, we recurse on it until we find one - if ((boolean) variable.vendorExtensions.getOrDefault("x-is-generic", false) || markPropagatedGeneric(variable, getVar, skipOneOf)) { + if (hasGeneric(items) || markPropagatedGeneric(variable, getVar, skipOneOf)) { setPropagatedGeneric(model); return true; } @@ -122,12 +121,17 @@ private static boolean propagateGenericRecursive( return false; } - private static void setGenericToComposedSchema(Map models, List composedSchemas) { + private static void setGenericToComposedSchema( + Map models, + CodegenModel model, + List composedSchemas + ) { if (composedSchemas == null) { return; } for (CodegenProperty prop : composedSchemas) { - if (hasGeneric(propertyToModel(models, prop))) { + if (hasGeneric(prop) || hasGeneric(propertyToModel(models, prop))) { + setHasChildGeneric(model); setHasChildGeneric(prop); } } @@ -138,26 +142,34 @@ private static void propagateToComposedSchema(Map models, if (composedSchemas == null) { return; } - setGenericToComposedSchema(models, composedSchemas.getOneOf()); - setGenericToComposedSchema(models, composedSchemas.getAllOf()); - setGenericToComposedSchema(models, composedSchemas.getAnyOf()); + setGenericToComposedSchema(models, model, composedSchemas.getOneOf()); + setGenericToComposedSchema(models, model, composedSchemas.getAllOf()); + setGenericToComposedSchema(models, model, composedSchemas.getAnyOf()); } - private static Map convertToMap(Map models) { + private static Map convertToMap(String language, String client, Map models) { Map modelsMap = new TreeMap<>(String.CASE_INSENSITIVE_ORDER); for (ModelsMap modelMap : models.values()) { // modelContainers always have 1 and only 1 model in our specs CodegenModel model = modelMap.getModels().get(0).getModel(); - modelsMap.put(model.name, model); + String modelName = model.name; + if (language.equals("swift") && !client.equals("search")) { + modelName = AlgoliaSwiftGenerator.prefixReservedModelName(modelName, client); + } + modelsMap.put(modelName, model); } return modelsMap; } - private static Map convertToMap(List models) { + private static Map convertToMap(String language, String client, List models) { Map modelsMap = new TreeMap<>(String.CASE_INSENSITIVE_ORDER); for (ModelMap modelMap : models) { CodegenModel model = modelMap.getModel(); - modelsMap.put(model.name, model); + String modelName = model.name; + if (language.equals("swift") && !client.equals("search")) { + modelName = AlgoliaSwiftGenerator.prefixReservedModelName(modelName, client); + } + modelsMap.put(modelName, model); } return modelsMap; } @@ -165,25 +177,29 @@ private static Map convertToMap(List models) { /** * Models and their members will be marked with either x-propagated-generic or x-has-child-generic */ - public static void propagateGenericsToModels(Map modelsMap, boolean skipOneOf) { + public static void propagateGenericsToModels(String language, String client, Map modelsMap, boolean skipOneOf) { // We propagate generics in two phases: // 1. We mark the direct parent of the generic model to replace it with T // 2. We tell each parent with generic properties to pass that generic type all the way down - Map models = convertToMap(modelsMap); + Map models = convertToMap(language, client, modelsMap); - for (CodegenModel model : models.values()) { - markPropagatedGeneric(model, m -> m.getVars(), skipOneOf); - markPropagatedGeneric(model, m -> m.getRequiredVars(), skipOneOf); - } + // we don't know in which order the model will come, so we iterate multiple times to make sure + // models at any depth are propagated + for (int i = 0; i < 5; i++) { + for (CodegenModel model : models.values()) { + markPropagatedGeneric(model, m -> m.getVars(), skipOneOf); + markPropagatedGeneric(model, m -> m.getRequiredVars(), skipOneOf); + } - for (CodegenModel model : models.values()) { - propagateGenericRecursive(models, model, m -> m.getVars()); - propagateGenericRecursive(models, model, m -> m.getRequiredVars()); - } + for (CodegenModel model : models.values()) { + propagateGenericRecursive(models, model, m -> m.getVars()); + propagateGenericRecursive(models, model, m -> m.getRequiredVars()); + } - for (CodegenModel model : models.values()) { - propagateToComposedSchema(models, model); + for (CodegenModel model : models.values()) { + propagateToComposedSchema(models, model); + } } } @@ -191,9 +207,21 @@ public static void propagateGenericsToModels(Map modelsMap) { propagateGenericsToModels(modelsMap, false); } + public static void propagateGenericsToModels(Map modelsMap, boolean skipOneOf) { + propagateGenericsToModels("dontcare", "dontcare", modelsMap, false); + } + + public static void propagateGenericsToModels(String language, String client, Map modelsMap) { + propagateGenericsToModels(language, client, modelsMap, false); + } + /** Mark operations with a generic return type with x-is-generic */ public static void propagateGenericsToOperations(OperationsMap operations, List allModels) { - Map models = convertToMap(allModels); + propagateGenericsToOperations("dontcare", "dontcare", operations, allModels); + } + + public static void propagateGenericsToOperations(String language, String client, OperationsMap operations, List allModels) { + Map models = convertToMap(language, client, allModels); for (CodegenOperation ope : operations.getOperations().getOperation()) { if (ope.returnType == null) { continue; diff --git a/specs/recommend/paths/batchRecommendRules.yml b/specs/recommend/paths/batchRecommendRules.yml index 69ae5c45e9..9d2bd9dddf 100644 --- a/specs/recommend/paths/batchRecommendRules.yml +++ b/specs/recommend/paths/batchRecommendRules.yml @@ -27,7 +27,6 @@ post: title: rules type: array description: Recommend rules. - additionalProperties: false items: $ref: '../common/schemas/RecommendRule.yml#/RecommendRule' diff --git a/templates/javascript/clients/client/model/types/isGeneric.mustache b/templates/javascript/clients/client/model/types/isGeneric.mustache index e987e40d6b..59b1617fef 100644 --- a/templates/javascript/clients/client/model/types/isGeneric.mustache +++ b/templates/javascript/clients/client/model/types/isGeneric.mustache @@ -2,6 +2,8 @@ {{#vendorExtensions.x-has-child-generic}} > {{/vendorExtensions.x-has-child-generic}} +{{^vendorExtensions.x-has-child-generic}} {{#vendorExtensions.x-is-generic}} > -{{/vendorExtensions.x-is-generic}} \ No newline at end of file +{{/vendorExtensions.x-is-generic}} +{{/vendorExtensions.x-has-child-generic}} \ No newline at end of file From 7ec686c2e12e03253c56f1545b93b753e453923a Mon Sep 17 00:00:00 2001 From: Pierre Millot Date: Tue, 21 Jan 2025 18:54:24 +0100 Subject: [PATCH 30/31] dont gen for swift --- config/clients.config.json | 1 - .../java/com/algolia/codegen/AlgoliaSwiftGenerator.java | 6 ------ .../java/com/algolia/codegen/utils/GenericPropagator.java | 4 ++-- 3 files changed, 2 insertions(+), 9 deletions(-) diff --git a/config/clients.config.json b/config/clients.config.json index 3d48ea8fbb..5008edde1f 100644 --- a/config/clients.config.json +++ b/config/clients.config.json @@ -343,7 +343,6 @@ "clients": [ "abtesting", "analytics", - "composition", "ingestion", "insights", "monitoring", diff --git a/generators/src/main/java/com/algolia/codegen/AlgoliaSwiftGenerator.java b/generators/src/main/java/com/algolia/codegen/AlgoliaSwiftGenerator.java index 461f12d574..d466ec54ae 100644 --- a/generators/src/main/java/com/algolia/codegen/AlgoliaSwiftGenerator.java +++ b/generators/src/main/java/com/algolia/codegen/AlgoliaSwiftGenerator.java @@ -67,14 +67,12 @@ public class AlgoliaSwiftGenerator extends Swift5ClientCodegen { "exactonsinglewordquery", "exhaustive", "facetfilters", - "facethits", "facetordering", "facets", "facetstats", "forbidden", "highlightresult", "highlightresultoption", - "hit", "ignoreplurals", "indexsettingsassearchparams", "insideboundingbox", @@ -104,14 +102,10 @@ public class AlgoliaSwiftGenerator extends Swift5ClientCodegen { "removewordsifnoresults", "renderingcontent", "rerankingapplyfilter", - "searchforfacetvaluesrequest", - "searchforfacetvaluesresponse", - "searchhits", "searchpagination", "searchparams", "searchparamsobject", "searchparamsquery", - "searchresponse", "semanticsearch", "snippetresult", "snippetresultoption", diff --git a/generators/src/main/java/com/algolia/codegen/utils/GenericPropagator.java b/generators/src/main/java/com/algolia/codegen/utils/GenericPropagator.java index a70020f876..f1b7350ab5 100644 --- a/generators/src/main/java/com/algolia/codegen/utils/GenericPropagator.java +++ b/generators/src/main/java/com/algolia/codegen/utils/GenericPropagator.java @@ -153,7 +153,7 @@ private static Map convertToMap(String language, String cl // modelContainers always have 1 and only 1 model in our specs CodegenModel model = modelMap.getModels().get(0).getModel(); String modelName = model.name; - if (language.equals("swift") && !client.equals("search")) { + if (language.equals("swift")) { modelName = AlgoliaSwiftGenerator.prefixReservedModelName(modelName, client); } modelsMap.put(modelName, model); @@ -166,7 +166,7 @@ private static Map convertToMap(String language, String cl for (ModelMap modelMap : models) { CodegenModel model = modelMap.getModel(); String modelName = model.name; - if (language.equals("swift") && !client.equals("search")) { + if (language.equals("swift")) { modelName = AlgoliaSwiftGenerator.prefixReservedModelName(modelName, client); } modelsMap.put(modelName, model); From 660bea524b6654b7b8236f2b6b2b84a4c9881903 Mon Sep 17 00:00:00 2001 From: Pierre Millot Date: Tue, 21 Jan 2025 23:52:12 +0100 Subject: [PATCH 31/31] rollback a bit --- clients/algoliasearch-client-javascript/yarn.lock | 7 +++---- .../algolia/codegen/utils/GenericPropagator.java | 15 ++++++++------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/clients/algoliasearch-client-javascript/yarn.lock b/clients/algoliasearch-client-javascript/yarn.lock index d62dd17599..863a904016 100644 --- a/clients/algoliasearch-client-javascript/yarn.lock +++ b/clients/algoliasearch-client-javascript/yarn.lock @@ -139,7 +139,7 @@ __metadata: languageName: unknown linkType: soft -"@algolia/composition@npm:0.0.1, @algolia/composition@workspace:packages/composition": +"@algolia/composition@workspace:packages/composition": version: 0.0.0-use.local resolution: "@algolia/composition@workspace:packages/composition" dependencies: @@ -148,8 +148,8 @@ __metadata: "@algolia/requester-fetch": "npm:5.19.0" "@algolia/requester-node-http": "npm:5.19.0" "@arethetypeswrong/cli": "npm:0.17.3" - "@types/node": "npm:22.10.5" - publint: "npm:0.3.1" + "@types/node": "npm:22.10.7" + publint: "npm:0.3.2" rollup: "npm:4.30.1" tsup: "npm:8.3.5" typescript: "npm:5.7.3" @@ -2317,7 +2317,6 @@ __metadata: "@algolia/client-personalization": "npm:5.19.0" "@algolia/client-query-suggestions": "npm:5.19.0" "@algolia/client-search": "npm:5.19.0" - "@algolia/composition": "npm:0.0.1" "@algolia/ingestion": "npm:1.19.0" "@algolia/monitoring": "npm:1.19.0" "@algolia/recommend": "npm:5.19.0" diff --git a/generators/src/main/java/com/algolia/codegen/utils/GenericPropagator.java b/generators/src/main/java/com/algolia/codegen/utils/GenericPropagator.java index f1b7350ab5..5b145c938b 100644 --- a/generators/src/main/java/com/algolia/codegen/utils/GenericPropagator.java +++ b/generators/src/main/java/com/algolia/codegen/utils/GenericPropagator.java @@ -54,8 +54,7 @@ private static boolean hasGeneric(IJsonSchemaValidationProperties property) { } return ( (boolean) vendorExtensions.getOrDefault("x-propagated-generic", false) || - (boolean) vendorExtensions.getOrDefault("x-has-child-generic", false) || - (boolean) vendorExtensions.getOrDefault("x-is-generic", false) + (boolean) vendorExtensions.getOrDefault("x-has-child-generic", false) ); } @@ -80,13 +79,16 @@ private static boolean markPropagatedGeneric( } // if items itself isn't generic, we recurse on its items and properties until we reach the // end or find a generic property - if (items != null && (hasGeneric(items) || markPropagatedGeneric(items, getVar, skipOneOf))) { + if ( + items != null && + ((boolean) items.vendorExtensions.getOrDefault("x-is-generic", false) || markPropagatedGeneric(items, getVar, skipOneOf)) + ) { setPropagatedGeneric(model); return true; } for (CodegenProperty variable : getVar.apply(model)) { // same thing for the variable, if it's not a generic, we recurse on it until we find one - if (hasGeneric(items) || markPropagatedGeneric(variable, getVar, skipOneOf)) { + if ((boolean) variable.vendorExtensions.getOrDefault("x-is-generic", false) || markPropagatedGeneric(variable, getVar, skipOneOf)) { setPropagatedGeneric(model); return true; } @@ -130,8 +132,7 @@ private static void setGenericToComposedSchema( return; } for (CodegenProperty prop : composedSchemas) { - if (hasGeneric(prop) || hasGeneric(propertyToModel(models, prop))) { - setHasChildGeneric(model); + if (hasGeneric(propertyToModel(models, prop))) { setHasChildGeneric(prop); } } @@ -208,7 +209,7 @@ public static void propagateGenericsToModels(Map modelsMap) { } public static void propagateGenericsToModels(Map modelsMap, boolean skipOneOf) { - propagateGenericsToModels("dontcare", "dontcare", modelsMap, false); + propagateGenericsToModels("dontcare", "dontcare", modelsMap, skipOneOf); } public static void propagateGenericsToModels(String language, String client, Map modelsMap) {