diff --git a/app.ts b/app.ts index 538d806c7ed..66532f09e92 100644 --- a/app.ts +++ b/app.ts @@ -5,16 +5,14 @@ const client = new SearchApi(); async function testClient() { // test openapi gen try { - const res = await client.search( - [ + const res = await client.multipleQueries('R2IYF7ETH7', 'e1e920e59f457ec70473486171c1d3b6', { + requests: [ { indexName: 'docsearch', query: 'crawler', }, ], - 'R2IYF7ETH7', - 'e1e920e59f457ec70473486171c1d3b6' - ); + }); console.log('[1-RESPONSE]', res); } catch (e) { diff --git a/openapi_spec/paths/indexes/batch.yml b/openapi_spec/paths/indexes/batch.yml index 2e64b8ecc91..d8b3a46ac73 100644 --- a/openapi_spec/paths/indexes/batch.yml +++ b/openapi_spec/paths/indexes/batch.yml @@ -12,6 +12,7 @@ post: content: application/json: schema: + title: batchObject type: object properties: requests: @@ -43,6 +44,7 @@ post: content: application/json: schema: + title: batchResponse type: object additionalProperties: false properties: diff --git a/openapi_spec/paths/indexes/multipleQueries.yml b/openapi_spec/paths/indexes/multipleQueries.yml index 743e6c92199..adccd85b2f7 100644 --- a/openapi_spec/paths/indexes/multipleQueries.yml +++ b/openapi_spec/paths/indexes/multipleQueries.yml @@ -11,6 +11,7 @@ post: content: application/json: schema: + title: multipleQueriesObject type: object additionalProperties: false properties: diff --git a/openapi_spec/paths/indexes/saveObject.yml b/openapi_spec/paths/indexes/saveObject.yml index 341f3031a58..a8018efa37b 100644 --- a/openapi_spec/paths/indexes/saveObject.yml +++ b/openapi_spec/paths/indexes/saveObject.yml @@ -1,6 +1,6 @@ post: tags: - - object + - search operationId: saveObject summary: Save object description: Add an object to the index, automatically assigning it an object ID @@ -21,6 +21,7 @@ post: content: application/json: schema: + title: saveObjectResponse type: object additionalProperties: false properties: diff --git a/output/client-search/searchApi.ts b/output/client-search/searchApi.ts index ff676b92a92..bcce3ced559 100644 --- a/output/client-search/searchApi.ts +++ b/output/client-search/searchApi.ts @@ -1,8 +1,11 @@ import localVarRequest from 'request'; import http from 'http'; -import { MultipleQueries } from '../model/multipleQueries'; +import { BatchObject } from '../model/batchObject'; +import { BatchResponse } from '../model/batchResponse'; +import { MultipleQueriesObject } from '../model/multipleQueriesObject'; import { MultipleQueriesResponse } from '../model/multipleQueriesResponse'; +import { SaveObjectResponse } from '../model/saveObjectResponse'; import { ObjectSerializer, Authentication, VoidAuth, Interceptor } from '../model/models'; @@ -72,17 +75,131 @@ export class SearchApi { this.interceptors.push(interceptor); } + /** + * + * @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: {} } + ): Promise<{ response: http.IncomingMessage; body: BatchResponse }> { + const localVarPath = + this.basePath + + '/1/indexes/{indexName}/batch'.replace( + '{' + 'indexName' + '}', + encodeURIComponent(String(indexName)) + ); + let localVarQueryParameters: any = {}; + let localVarHeaderParams: any = (Object).assign({}, this._defaultHeaders); + const produces = ['application/json']; + // give precedence to 'application/json' + if (produces.indexOf('application/json') >= 0) { + localVarHeaderParams.Accept = 'application/json'; + } else { + localVarHeaderParams.Accept = produces.join(','); + } + 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.'); + } + + // verify required parameter 'batchObject' is not null or undefined + if (batchObject === null || batchObject === undefined) { + 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; + + let localVarRequestOptions: localVarRequest.Options = { + method: 'POST', + qs: localVarQueryParameters, + headers: localVarHeaderParams, + uri: localVarPath, + useQuerystring: this._useQuerystring, + json: true, + body: ObjectSerializer.serialize(batchObject, 'BatchObject'), + }; + + let authenticationPromise = Promise.resolve(); + authenticationPromise = authenticationPromise.then(() => + this.authentications.default.applyToRequest(localVarRequestOptions) + ); + + let interceptorPromise = authenticationPromise; + for (const interceptor of this.interceptors) { + interceptorPromise = interceptorPromise.then(() => interceptor(localVarRequestOptions)); + } + + return interceptorPromise.then(() => { + if (Object.keys(localVarFormParams).length) { + if (localVarUseFormData) { + (localVarRequestOptions).formData = localVarFormParams; + } else { + localVarRequestOptions.form = localVarFormParams; + } + } + return new Promise<{ response: http.IncomingMessage; body: BatchResponse }>( + (resolve, reject) => { + localVarRequest(localVarRequestOptions, (error, response, body) => { + if (error) { + reject(error); + } else { + body = ObjectSerializer.deserialize(body, 'BatchResponse'); + if (response.statusCode && response.statusCode >= 200 && response.statusCode <= 299) { + resolve({ response: response, body: body }); + } else { + reject(new HttpError(response, body, response.statusCode)); + } + } + }); + } + ); + }); + } /** * * @summary Get search results for the given requests. - * @param multipleQueries * @param xAlgoliaApplicationId Algolia appID * @param xAlgoliaAPIKey Algolia API key + * @param multipleQueriesObject */ - public async search( - multipleQueries: Array, - xAlgoliaApplicationId?: string, - xAlgoliaAPIKey?: string, + public async multipleQueries( + xAlgoliaApplicationId: string, + xAlgoliaAPIKey: string, + multipleQueriesObject: MultipleQueriesObject, options: { headers: { [name: string]: string } } = { headers: {} } ): Promise<{ response: http.IncomingMessage; body: MultipleQueriesResponse }> { const localVarPath = this.basePath + '/1/indexes/*/queries'; @@ -97,10 +214,24 @@ export class SearchApi { } let localVarFormParams: any = {}; - // verify required parameter 'multipleQueries' is not null or undefined - if (multipleQueries === null || multipleQueries === undefined) { + // verify required parameter 'xAlgoliaApplicationId' is not null or undefined + if (xAlgoliaApplicationId === null || xAlgoliaApplicationId === undefined) { throw new Error( - 'Required parameter multipleQueries was null or undefined when calling search.' + '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( + 'Required parameter multipleQueriesObject was null or undefined when calling multipleQueries.' ); } @@ -123,7 +254,7 @@ export class SearchApi { uri: localVarPath, useQuerystring: this._useQuerystring, json: true, - body: ObjectSerializer.serialize(multipleQueries, 'Array'), + body: ObjectSerializer.serialize(multipleQueriesObject, 'MultipleQueriesObject'), }; let authenticationPromise = Promise.resolve(); @@ -162,4 +293,122 @@ 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: {} } + ): Promise<{ response: http.IncomingMessage; body: SaveObjectResponse }> { + const localVarPath = + this.basePath + + '/1/indexes/{indexName}'.replace( + '{' + 'indexName' + '}', + encodeURIComponent(String(indexName)) + ); + let localVarQueryParameters: any = {}; + let localVarHeaderParams: any = (Object).assign({}, this._defaultHeaders); + const produces = ['application/json']; + // give precedence to 'application/json' + if (produces.indexOf('application/json') >= 0) { + localVarHeaderParams.Accept = 'application/json'; + } else { + localVarHeaderParams.Accept = produces.join(','); + } + 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( + 'Required parameter indexName was null or undefined when calling saveObject.' + ); + } + + // verify required parameter 'requestBody' is not null or undefined + if (requestBody === null || requestBody === undefined) { + throw new Error( + 'Required parameter requestBody was null or undefined when calling saveObject.' + ); + } + + 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; + + let localVarRequestOptions: localVarRequest.Options = { + method: 'POST', + qs: localVarQueryParameters, + headers: localVarHeaderParams, + uri: localVarPath, + useQuerystring: this._useQuerystring, + json: true, + body: ObjectSerializer.serialize(requestBody, '{ [key: string]: object; }'), + }; + + let authenticationPromise = Promise.resolve(); + authenticationPromise = authenticationPromise.then(() => + this.authentications.default.applyToRequest(localVarRequestOptions) + ); + + let interceptorPromise = authenticationPromise; + for (const interceptor of this.interceptors) { + interceptorPromise = interceptorPromise.then(() => interceptor(localVarRequestOptions)); + } + + return interceptorPromise.then(() => { + if (Object.keys(localVarFormParams).length) { + if (localVarUseFormData) { + (localVarRequestOptions).formData = localVarFormParams; + } else { + localVarRequestOptions.form = localVarFormParams; + } + } + return new Promise<{ response: http.IncomingMessage; body: SaveObjectResponse }>( + (resolve, reject) => { + localVarRequest(localVarRequestOptions, (error, response, body) => { + if (error) { + reject(error); + } else { + body = ObjectSerializer.deserialize(body, 'SaveObjectResponse'); + if (response.statusCode && response.statusCode >= 200 && response.statusCode <= 299) { + resolve({ response: response, body: body }); + } else { + reject(new HttpError(response, body, response.statusCode)); + } + } + }); + } + ); + }); + } } diff --git a/output/model/batchObject.ts b/output/model/batchObject.ts new file mode 100644 index 00000000000..443d3201bb5 --- /dev/null +++ b/output/model/batchObject.ts @@ -0,0 +1,20 @@ +import { RequestFile } from './models'; +import { Operation } from './operation'; + +export class BatchObject { + 'requests'?: Array; + + static discriminator: string | undefined = undefined; + + static attributeTypeMap: Array<{ name: string; baseName: string; type: string }> = [ + { + name: 'requests', + baseName: 'requests', + type: 'Array', + }, + ]; + + static getAttributeTypeMap() { + return BatchObject.attributeTypeMap; + } +} diff --git a/output/model/batchResponse.ts b/output/model/batchResponse.ts new file mode 100644 index 00000000000..f4effb83765 --- /dev/null +++ b/output/model/batchResponse.ts @@ -0,0 +1,31 @@ +import { RequestFile } from './models'; + +export class BatchResponse { + /** + * taskID of the indexing task to wait for. + */ + 'taskID'?: number; + /** + * List of objectID + */ + 'objectIDs'?: Array; + + static discriminator: string | undefined = undefined; + + static attributeTypeMap: Array<{ name: string; baseName: string; type: string }> = [ + { + name: 'taskID', + baseName: 'taskID', + type: 'number', + }, + { + name: 'objectIDs', + baseName: 'objectIDs', + type: 'Array', + }, + ]; + + static getAttributeTypeMap() { + return BatchResponse.attributeTypeMap; + } +} diff --git a/output/model/modelError.ts b/output/model/modelError.ts new file mode 100644 index 00000000000..13fc1b89375 --- /dev/null +++ b/output/model/modelError.ts @@ -0,0 +1,22 @@ +import { RequestFile } from './models'; + +/** + * Error + */ +export class ModelError extends null { + 'message'?: string; + + static discriminator: string | undefined = undefined; + + static attributeTypeMap: Array<{ name: string; baseName: string; type: string }> = [ + { + name: 'message', + baseName: 'message', + type: 'string', + }, + ]; + + static getAttributeTypeMap() { + return super.getAttributeTypeMap().concat(ModelError.attributeTypeMap); + } +} diff --git a/output/model/models.ts b/output/model/models.ts index f4038e56af5..dd7ce871f8a 100644 --- a/output/model/models.ts +++ b/output/model/models.ts @@ -1,8 +1,15 @@ import localVarRequest from 'request'; +export * from './batchObject'; +export * from './batchResponse'; +export * from './modelError'; export * from './multipleQueries'; +export * from './multipleQueriesObject'; export * from './multipleQueriesResponse'; +export * from './multipleQueriesResponseHits'; export * from './multipleQueriesResponseResults'; +export * from './operation'; +export * from './saveObjectResponse'; import * as fs from 'fs'; @@ -16,20 +23,36 @@ export interface RequestDetailedFile { export type RequestFile = string | Buffer | fs.ReadStream | RequestDetailedFile; +import { BatchObject } from './batchObject'; +import { BatchResponse } from './batchResponse'; +import { ModelError } from './modelError'; import { MultipleQueries } from './multipleQueries'; +import { MultipleQueriesObject } from './multipleQueriesObject'; import { MultipleQueriesResponse } from './multipleQueriesResponse'; +import { MultipleQueriesResponseHits } from './multipleQueriesResponseHits'; import { MultipleQueriesResponseResults } from './multipleQueriesResponseResults'; +import { Operation } from './operation'; +import { SaveObjectResponse } from './saveObjectResponse'; let primitives = ['string', 'boolean', 'double', 'integer', 'long', 'float', 'number', 'any']; let enumsMap: { [index: string]: any } = { 'MultipleQueries.TypeEnum': MultipleQueries.TypeEnum, + 'MultipleQueriesObject.StrategyEnum': MultipleQueriesObject.StrategyEnum, + 'Operation.ActionEnum': Operation.ActionEnum, }; let typeMap: { [index: string]: any } = { + BatchObject: BatchObject, + BatchResponse: BatchResponse, + ModelError: ModelError, MultipleQueries: MultipleQueries, + MultipleQueriesObject: MultipleQueriesObject, MultipleQueriesResponse: MultipleQueriesResponse, + MultipleQueriesResponseHits: MultipleQueriesResponseHits, MultipleQueriesResponseResults: MultipleQueriesResponseResults, + Operation: Operation, + SaveObjectResponse: SaveObjectResponse, }; export class ObjectSerializer { diff --git a/output/model/multipleQueries.ts b/output/model/multipleQueries.ts index f5d35273925..3842566ce64 100644 --- a/output/model/multipleQueries.ts +++ b/output/model/multipleQueries.ts @@ -18,9 +18,9 @@ export class MultipleQueries { */ 'facet'?: string; /** - * A key-value mapping of additional search parameters + * A query string of search parameters */ - 'params'?: { [key: string]: object }; + 'params'?: string; static discriminator: string | undefined = undefined; @@ -48,7 +48,7 @@ export class MultipleQueries { { name: 'params', baseName: 'params', - type: '{ [key: string]: object; }', + type: 'string', }, ]; diff --git a/output/model/multipleQueriesObject.ts b/output/model/multipleQueriesObject.ts new file mode 100644 index 00000000000..35d55da74dc --- /dev/null +++ b/output/model/multipleQueriesObject.ts @@ -0,0 +1,33 @@ +import { RequestFile } from './models'; +import { MultipleQueries } from './multipleQueries'; + +export class MultipleQueriesObject { + 'requests': Array; + 'strategy'?: MultipleQueriesObject.StrategyEnum; + + static discriminator: string | undefined = undefined; + + static attributeTypeMap: Array<{ name: string; baseName: string; type: string }> = [ + { + name: 'requests', + baseName: 'requests', + type: 'Array', + }, + { + name: 'strategy', + baseName: 'strategy', + type: 'MultipleQueriesObject.StrategyEnum', + }, + ]; + + static getAttributeTypeMap() { + return MultipleQueriesObject.attributeTypeMap; + } +} + +export namespace MultipleQueriesObject { + export enum StrategyEnum { + None = 'none', + StopIfEnoughMatches = 'stopIfEnoughMatches', + } +} diff --git a/output/model/multipleQueriesResponseHits.ts b/output/model/multipleQueriesResponseHits.ts new file mode 100644 index 00000000000..3e8178a67ac --- /dev/null +++ b/output/model/multipleQueriesResponseHits.ts @@ -0,0 +1,22 @@ +import { RequestFile } from './models'; + +export class MultipleQueriesResponseHits { + /** + * Unique identifier of the object + */ + 'objectID'?: string; + + static discriminator: string | undefined = undefined; + + static attributeTypeMap: Array<{ name: string; baseName: string; type: string }> = [ + { + name: 'objectID', + baseName: 'objectID', + type: 'string', + }, + ]; + + static getAttributeTypeMap() { + return MultipleQueriesResponseHits.attributeTypeMap; + } +} diff --git a/output/model/multipleQueriesResponseResults.ts b/output/model/multipleQueriesResponseResults.ts index ea61b77356f..b15174ff452 100644 --- a/output/model/multipleQueriesResponseResults.ts +++ b/output/model/multipleQueriesResponseResults.ts @@ -1,7 +1,8 @@ import { RequestFile } from './models'; +import { MultipleQueriesResponseHits } from './multipleQueriesResponseHits'; export class MultipleQueriesResponseResults { - 'hits'?: Array<{ [key: string]: any }>; + 'hits'?: Array; 'nbHits'?: number; 'queryID'?: string; @@ -11,7 +12,7 @@ export class MultipleQueriesResponseResults { { name: 'hits', baseName: 'hits', - type: 'Array<{ [key: string]: any; }>', + type: 'Array', }, { name: 'nbHits', diff --git a/output/model/operation.ts b/output/model/operation.ts new file mode 100644 index 00000000000..771fd8cd80a --- /dev/null +++ b/output/model/operation.ts @@ -0,0 +1,43 @@ +import { RequestFile } from './models'; + +export class Operation { + /** + * type of operation + */ + 'action'?: Operation.ActionEnum; + /** + * arguments to the operation (depends on the type of the operation) + */ + 'body'?: { [key: string]: object }; + + static discriminator: string | undefined = undefined; + + static attributeTypeMap: Array<{ name: string; baseName: string; type: string }> = [ + { + name: 'action', + baseName: 'action', + type: 'Operation.ActionEnum', + }, + { + name: 'body', + baseName: 'body', + type: '{ [key: string]: object; }', + }, + ]; + + static getAttributeTypeMap() { + return Operation.attributeTypeMap; + } +} + +export namespace Operation { + export enum ActionEnum { + AddObject = 'addObject', + UpdateObject = 'updateObject', + PartialUpdateObject = 'partialUpdateObject', + PartialUpdateObjectNoCreate = 'partialUpdateObjectNoCreate', + DeleteObject = 'deleteObject', + Delete = 'delete', + Clear = 'clear', + } +} diff --git a/output/model/saveObjectResponse.ts b/output/model/saveObjectResponse.ts new file mode 100644 index 00000000000..90020ef73aa --- /dev/null +++ b/output/model/saveObjectResponse.ts @@ -0,0 +1,37 @@ +import { RequestFile } from './models'; + +export class SaveObjectResponse { + 'createdAt'?: string; + /** + * taskID of the indexing task to wait for. + */ + 'taskID'?: number; + /** + * Unique identifier of the object + */ + 'objectID'?: string; + + static discriminator: string | undefined = undefined; + + static attributeTypeMap: Array<{ name: string; baseName: string; type: string }> = [ + { + name: 'createdAt', + baseName: 'createdAt', + type: 'string', + }, + { + name: 'taskID', + baseName: 'taskID', + type: 'number', + }, + { + name: 'objectID', + baseName: 'objectID', + type: 'string', + }, + ]; + + static getAttributeTypeMap() { + return SaveObjectResponse.attributeTypeMap; + } +} diff --git a/package.json b/package.json index 6756a922dc1..9b97c5c2b50 100644 --- a/package.json +++ b/package.json @@ -26,4 +26,4 @@ "dependencies": { "swagger-cli": "^4.0.4" } -} \ No newline at end of file +} diff --git a/yarn.lock b/yarn.lock index e0f0f6fae49..d0eced75353 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=eecce8&locator=%40algolia%2Fautomation-javascript-client%40workspace%3A." + resolution: "algoliasearch-client-javascript@file:output/#output/::hash=9f2500&locator=%40algolia%2Fautomation-javascript-client%40workspace%3A." dependencies: "@types/request": ^2.48.7 request: ^2.81.0 - checksum: f5c39500e1657e312edaccf3fab400ba3c648a0363230274bb435b3f8238996fbd256b31fe5711862dd959bc6d3e936145768e2c16a9f1acf03c1a3d18124a4d + checksum: 4a413d1bbbeeaf41a9e4f75a2e9f8be6b827439a80099c57ae0d2b2387da9563ff416133c028989fe17eaa95025e248f8f586d78a08f903819eacae536f73b0b languageName: node linkType: hard