diff --git a/app.ts b/app.ts index 66532f09e9..3fe458f717 100644 --- a/app.ts +++ b/app.ts @@ -1,11 +1,14 @@ -import { SearchApi } from 'algoliasearch-client-javascript'; +import { searchClient } from './searchClient'; -const client = new SearchApi(); +const appId = process.env.ALGOLIA_APPLICATION_ID_1 || '**** APP_ID *****'; +const apiKey = process.env.ALGOLIA_ADMIN_KEY_1 || '**** API_KEY *****'; +// Init client with appId and apiKey +const client = new searchClient(appId, apiKey); async function testClient() { // test openapi gen try { - const res = await client.multipleQueries('R2IYF7ETH7', 'e1e920e59f457ec70473486171c1d3b6', { + const res = await client.multipleQueries({ requests: [ { indexName: 'docsearch', diff --git a/openapi_spec/paths/indexes/batch.yml b/openapi_spec/paths/indexes/batch.yml index d8b3a46ac7..5a06b1aab7 100644 --- a/openapi_spec/paths/indexes/batch.yml +++ b/openapi_spec/paths/indexes/batch.yml @@ -4,8 +4,6 @@ post: operationId: batch summary: Performs multiple write operations in a single API call parameters: - - $ref: '../../parameters.yml#/AppId' - - $ref: '../../parameters.yml#/ApiKey' - $ref: '../../parameters.yml#/IndexName' requestBody: required: true diff --git a/openapi_spec/paths/indexes/multipleQueries.yml b/openapi_spec/paths/indexes/multipleQueries.yml index adccd85b2f..1b64bfb047 100644 --- a/openapi_spec/paths/indexes/multipleQueries.yml +++ b/openapi_spec/paths/indexes/multipleQueries.yml @@ -3,9 +3,6 @@ post: - search operationId: multipleQueries summary: Get search results for the given requests. - parameters: - - $ref: '../../parameters.yml#/AppId' - - $ref: '../../parameters.yml#/ApiKey' requestBody: required: true content: diff --git a/openapi_spec/paths/indexes/saveObject.yml b/openapi_spec/paths/indexes/saveObject.yml index a8018efa37..947ef11dc6 100644 --- a/openapi_spec/paths/indexes/saveObject.yml +++ b/openapi_spec/paths/indexes/saveObject.yml @@ -5,8 +5,6 @@ post: summary: Save object description: Add an object to the index, automatically assigning it an object ID parameters: - - $ref: '../../parameters.yml#/AppId' - - $ref: '../../parameters.yml#/ApiKey' - $ref: '../../parameters.yml#/IndexName' requestBody: required: true diff --git a/openapi_spec/paths/indexes/search.yml b/openapi_spec/paths/indexes/search.yml index 28008eb7f6..a8b7b0d5d3 100644 --- a/openapi_spec/paths/indexes/search.yml +++ b/openapi_spec/paths/indexes/search.yml @@ -4,8 +4,6 @@ post: operationId: search summary: Get search results parameters: - - $ref: '../../parameters.yml#/AppId' - - $ref: '../../parameters.yml#/ApiKey' - $ref: '../../parameters.yml#/IndexName' requestBody: $ref: '../../schemas/SearchParams.yml' diff --git a/output/client-search/searchApi.ts b/output/client-search/searchApi.ts index bcce3ced55..1f89cfabd8 100644 --- a/output/client-search/searchApi.ts +++ b/output/client-search/searchApi.ts @@ -78,14 +78,10 @@ export class SearchApi { /** * * @summary Performs multiple write operations in a single API call - * @param xAlgoliaApplicationId Algolia appID - * @param xAlgoliaAPIKey Algolia API key * @param indexName The index in which to perform the request * @param batchObject */ public async batch( - xAlgoliaApplicationId: string, - xAlgoliaAPIKey: string, indexName: string, batchObject: BatchObject, options: { headers: { [name: string]: string } } = { headers: {} } @@ -107,20 +103,6 @@ export class SearchApi { } let localVarFormParams: any = {}; - // verify required parameter 'xAlgoliaApplicationId' is not null or undefined - if (xAlgoliaApplicationId === null || xAlgoliaApplicationId === undefined) { - throw new Error( - 'Required parameter xAlgoliaApplicationId was null or undefined when calling batch.' - ); - } - - // verify required parameter 'xAlgoliaAPIKey' is not null or undefined - if (xAlgoliaAPIKey === null || xAlgoliaAPIKey === undefined) { - throw new Error( - 'Required parameter xAlgoliaAPIKey was null or undefined when calling batch.' - ); - } - // verify required parameter 'indexName' is not null or undefined if (indexName === null || indexName === undefined) { throw new Error('Required parameter indexName was null or undefined when calling batch.'); @@ -131,14 +113,6 @@ export class SearchApi { throw new Error('Required parameter batchObject was null or undefined when calling batch.'); } - localVarHeaderParams['X-Algolia-Application-Id'] = ObjectSerializer.serialize( - xAlgoliaApplicationId, - 'string' - ); - localVarHeaderParams['X-Algolia-API-Key'] = ObjectSerializer.serialize( - xAlgoliaAPIKey, - 'string' - ); (Object).assign(localVarHeaderParams, options.headers); let localVarUseFormData = false; @@ -192,13 +166,9 @@ export class SearchApi { /** * * @summary Get search results for the given requests. - * @param xAlgoliaApplicationId Algolia appID - * @param xAlgoliaAPIKey Algolia API key * @param multipleQueriesObject */ public async multipleQueries( - xAlgoliaApplicationId: string, - xAlgoliaAPIKey: string, multipleQueriesObject: MultipleQueriesObject, options: { headers: { [name: string]: string } } = { headers: {} } ): Promise<{ response: http.IncomingMessage; body: MultipleQueriesResponse }> { @@ -214,20 +184,6 @@ export class SearchApi { } let localVarFormParams: any = {}; - // verify required parameter 'xAlgoliaApplicationId' is not null or undefined - if (xAlgoliaApplicationId === null || xAlgoliaApplicationId === undefined) { - throw new Error( - 'Required parameter xAlgoliaApplicationId was null or undefined when calling multipleQueries.' - ); - } - - // verify required parameter 'xAlgoliaAPIKey' is not null or undefined - if (xAlgoliaAPIKey === null || xAlgoliaAPIKey === undefined) { - throw new Error( - 'Required parameter xAlgoliaAPIKey was null or undefined when calling multipleQueries.' - ); - } - // verify required parameter 'multipleQueriesObject' is not null or undefined if (multipleQueriesObject === null || multipleQueriesObject === undefined) { throw new Error( @@ -235,14 +191,6 @@ export class SearchApi { ); } - localVarHeaderParams['X-Algolia-Application-Id'] = ObjectSerializer.serialize( - xAlgoliaApplicationId, - 'string' - ); - localVarHeaderParams['X-Algolia-API-Key'] = ObjectSerializer.serialize( - xAlgoliaAPIKey, - 'string' - ); (Object).assign(localVarHeaderParams, options.headers); let localVarUseFormData = false; @@ -296,14 +244,10 @@ export class SearchApi { /** * Add an object to the index, automatically assigning it an object ID * @summary Save object - * @param xAlgoliaApplicationId Algolia appID - * @param xAlgoliaAPIKey Algolia API key * @param indexName The index in which to perform the request * @param requestBody */ public async saveObject( - xAlgoliaApplicationId: string, - xAlgoliaAPIKey: string, indexName: string, requestBody: { [key: string]: object }, options: { headers: { [name: string]: string } } = { headers: {} } @@ -325,20 +269,6 @@ export class SearchApi { } let localVarFormParams: any = {}; - // verify required parameter 'xAlgoliaApplicationId' is not null or undefined - if (xAlgoliaApplicationId === null || xAlgoliaApplicationId === undefined) { - throw new Error( - 'Required parameter xAlgoliaApplicationId was null or undefined when calling saveObject.' - ); - } - - // verify required parameter 'xAlgoliaAPIKey' is not null or undefined - if (xAlgoliaAPIKey === null || xAlgoliaAPIKey === undefined) { - throw new Error( - 'Required parameter xAlgoliaAPIKey was null or undefined when calling saveObject.' - ); - } - // verify required parameter 'indexName' is not null or undefined if (indexName === null || indexName === undefined) { throw new Error( @@ -353,14 +283,6 @@ export class SearchApi { ); } - localVarHeaderParams['X-Algolia-Application-Id'] = ObjectSerializer.serialize( - xAlgoliaApplicationId, - 'string' - ); - localVarHeaderParams['X-Algolia-API-Key'] = ObjectSerializer.serialize( - xAlgoliaAPIKey, - 'string' - ); (Object).assign(localVarHeaderParams, options.headers); let localVarUseFormData = false; diff --git a/searchClient.ts b/searchClient.ts new file mode 100644 index 0000000000..8675b44ca0 --- /dev/null +++ b/searchClient.ts @@ -0,0 +1,11 @@ +import { SearchApi } from 'algoliasearch-client-javascript'; + +export class searchClient extends SearchApi { + public constructor(appId: string, apiKey: string) { + super(); + + this.defaultHeaders['X-Algolia-Application-Id'] = appId; + this.defaultHeaders['X-Algolia-API-Key'] = apiKey; + this.basePath = 'https://' + appId + '-1.algolianet.com'; + } +} diff --git a/tsconfig.json b/tsconfig.json index 2c3762b922..3d69106454 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -16,5 +16,5 @@ "outDir": "dist", "typeRoots": ["node_modules/@types"] }, - "include": ["app.ts"] + "include": ["searchClient.ts", "app.ts"] } diff --git a/yarn.lock b/yarn.lock index d0eced7535..00f88c9b07 100644 --- a/yarn.lock +++ b/yarn.lock @@ -226,11 +226,11 @@ __metadata: "algoliasearch-client-javascript@file:output/::locator=%40algolia%2Fautomation-javascript-client%40workspace%3A.": version: 5.0.0 - resolution: "algoliasearch-client-javascript@file:output/#output/::hash=9f2500&locator=%40algolia%2Fautomation-javascript-client%40workspace%3A." + resolution: "algoliasearch-client-javascript@file:output/#output/::hash=5e44d1&locator=%40algolia%2Fautomation-javascript-client%40workspace%3A." dependencies: "@types/request": ^2.48.7 request: ^2.81.0 - checksum: 4a413d1bbbeeaf41a9e4f75a2e9f8be6b827439a80099c57ae0d2b2387da9563ff416133c028989fe17eaa95025e248f8f586d78a08f903819eacae536f73b0b + checksum: 324b24f6828b13f4d863425274de41987bcd006e3950379d01fb822308ef0cab02ca07e21297697fccd1b6aa5b3784f92f5f4f74550da0f4a61921d1fe18e7b0 languageName: node linkType: hard