Skip to content

Commit fcffd5a

Browse files
authored
Merge pull request #7 from algolia/feat/API-157/remove-params
2 parents 0919f25 + 03503ff commit fcffd5a

File tree

11 files changed

+77
-124
lines changed

11 files changed

+77
-124
lines changed

algolia-typescript-template/api-all.mustache

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,7 @@ export class HttpError extends Error {
1919

2020
export { RequestFile } from '../model/models';
2121

22+
export class searchClient extends SearchApi{}
23+
2224
export const APIS = [{{#apis}}{{#operations}}{{ classname }}{{/operations}}{{^-last}}, {{/-last}}{{/apis}}];
2325
{{/apiInfo}}

algolia-typescript-template/api-single.mustache

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -59,27 +59,14 @@ export class {{classname}} {
5959

6060
protected interceptors: Interceptor[] = [];
6161

62-
constructor(basePath?: string);
63-
{{#authMethods}}
64-
{{#isBasicBasic}}
65-
constructor(username: string, password: string, basePath?: string);
66-
{{/isBasicBasic}}
67-
{{/authMethods}}
68-
constructor(basePathOrUsername: string, password?: string, basePath?: string) {
69-
if (password) {
70-
{{#authMethods}}
71-
{{#isBasicBasic}}
72-
this.username = basePathOrUsername;
73-
this.password = password
74-
{{/isBasicBasic}}
75-
{{/authMethods}}
76-
if (basePath) {
77-
this.basePath = basePath;
78-
}
79-
} else {
80-
if (basePathOrUsername) {
81-
this.basePath = basePathOrUsername
82-
}
62+
constructor(appId: string, apiKey: string, basePath?: string) {
63+
64+
this.setApiKey(SearchApiApiKeys.appId, appId);
65+
this.setApiKey(SearchApiApiKeys.apiKey, apiKey);
66+
this.basePath = 'https://' + appId + '-1.algolianet.com';
67+
68+
if (basePath) {
69+
this.basePath = basePath;
8370
}
8471
}
8572

app.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
1-
import { SearchApi } from 'algoliasearch-client-javascript';
1+
import { searchClient } from 'algoliasearch-client-javascript';
22

3-
const client = new SearchApi();
3+
const appId = process.env.ALGOLIA_APPLICATION_ID_1 || '**** APP_ID *****';
4+
const apiKey = process.env.ALGOLIA_ADMIN_KEY_1 || '**** API_KEY *****';
5+
// Init client with appId and apiKey
6+
const client = new searchClient(appId, apiKey);
47

58
async function testClient() {
69
// test openapi gen
710
try {
8-
const res = await client.multipleQueries('R2IYF7ETH7', 'e1e920e59f457ec70473486171c1d3b6', {
11+
const res = await client.multipleQueries({
912
requests: [
1013
{
1114
indexName: 'docsearch',

openapi_spec/paths/indexes/batch.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ post:
44
operationId: batch
55
summary: Performs multiple write operations in a single API call
66
parameters:
7-
- $ref: '../../parameters.yml#/AppId'
8-
- $ref: '../../parameters.yml#/ApiKey'
97
- $ref: '../../parameters.yml#/IndexName'
108
requestBody:
119
required: true

openapi_spec/paths/indexes/multipleQueries.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@ post:
33
- search
44
operationId: multipleQueries
55
summary: Get search results for the given requests.
6-
parameters:
7-
- $ref: '../../parameters.yml#/AppId'
8-
- $ref: '../../parameters.yml#/ApiKey'
96
requestBody:
107
required: true
118
content:

openapi_spec/paths/indexes/saveObject.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ post:
55
summary: Save object
66
description: Add an object to the index, automatically assigning it an object ID
77
parameters:
8-
- $ref: '../../parameters.yml#/AppId'
9-
- $ref: '../../parameters.yml#/ApiKey'
108
- $ref: '../../parameters.yml#/IndexName'
119
requestBody:
1210
required: true

openapi_spec/paths/indexes/search.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ post:
44
operationId: search
55
summary: Get search results
66
parameters:
7-
- $ref: '../../parameters.yml#/AppId'
8-
- $ref: '../../parameters.yml#/ApiKey'
97
- $ref: '../../parameters.yml#/IndexName'
108
requestBody:
119
$ref: '../../schemas/SearchParams.yml'

openapi_spec/spec.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,19 @@ servers:
2020
variables:
2121
appId:
2222
default: test
23+
components:
24+
securitySchemes:
25+
appId:
26+
type: apiKey
27+
in: header
28+
name: X-Algolia-Application-Id
29+
apiKey:
30+
type: apiKey
31+
in: header
32+
name: X-Algolia-API-Key
33+
security:
34+
- appId: []
35+
apiKey: []
2336
paths:
2437
# We can add this one later, as it requires the init method
2538
# /1/indexes/{indexName}/query:

output/client-search/apis.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,6 @@ export class HttpError extends Error {
1111

1212
export { RequestFile } from '../model/models';
1313

14+
export class searchClient extends SearchApi {}
15+
1416
export const APIS = [SearchApi];

output/client-search/searchApi.ts

Lines changed: 44 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { MultipleQueriesResponse } from '../model/multipleQueriesResponse';
88
import { SaveObjectResponse } from '../model/saveObjectResponse';
99

1010
import { ObjectSerializer, Authentication, VoidAuth, Interceptor } from '../model/models';
11+
import { HttpBasicAuth, HttpBearerAuth, ApiKeyAuth, OAuth } from '../model/models';
1112

1213
import { HttpError, RequestFile } from './apis';
1314

@@ -17,7 +18,10 @@ let defaultBasePath = 'https://test-1.algolianet.com';
1718
// This file is autogenerated - Please do not edit
1819
// ===============================================
1920

20-
export enum SearchApiApiKeys {}
21+
export enum SearchApiApiKeys {
22+
apiKey,
23+
appId,
24+
}
2125

2226
export class SearchApi {
2327
protected _basePath = defaultBasePath;
@@ -26,20 +30,19 @@ export class SearchApi {
2630

2731
protected authentications = {
2832
default: <Authentication>new VoidAuth(),
33+
apiKey: new ApiKeyAuth('header', 'X-Algolia-API-Key'),
34+
appId: new ApiKeyAuth('header', 'X-Algolia-Application-Id'),
2935
};
3036

3137
protected interceptors: Interceptor[] = [];
3238

33-
constructor(basePath?: string);
34-
constructor(basePathOrUsername: string, password?: string, basePath?: string) {
35-
if (password) {
36-
if (basePath) {
37-
this.basePath = basePath;
38-
}
39-
} else {
40-
if (basePathOrUsername) {
41-
this.basePath = basePathOrUsername;
42-
}
39+
constructor(appId: string, apiKey: string, basePath?: string) {
40+
this.setApiKey(SearchApiApiKeys.appId, appId);
41+
this.setApiKey(SearchApiApiKeys.apiKey, apiKey);
42+
this.basePath = 'https://' + appId + '-1.algolianet.com';
43+
44+
if (basePath) {
45+
this.basePath = basePath;
4346
}
4447
}
4548

@@ -78,14 +81,10 @@ export class SearchApi {
7881
/**
7982
*
8083
* @summary Performs multiple write operations in a single API call
81-
* @param xAlgoliaApplicationId Algolia appID
82-
* @param xAlgoliaAPIKey Algolia API key
8384
* @param indexName The index in which to perform the request
8485
* @param batchObject
8586
*/
8687
public async batch(
87-
xAlgoliaApplicationId: string,
88-
xAlgoliaAPIKey: string,
8988
indexName: string,
9089
batchObject: BatchObject,
9190
options: { headers: { [name: string]: string } } = { headers: {} }
@@ -107,20 +106,6 @@ export class SearchApi {
107106
}
108107
let localVarFormParams: any = {};
109108

110-
// verify required parameter 'xAlgoliaApplicationId' is not null or undefined
111-
if (xAlgoliaApplicationId === null || xAlgoliaApplicationId === undefined) {
112-
throw new Error(
113-
'Required parameter xAlgoliaApplicationId was null or undefined when calling batch.'
114-
);
115-
}
116-
117-
// verify required parameter 'xAlgoliaAPIKey' is not null or undefined
118-
if (xAlgoliaAPIKey === null || xAlgoliaAPIKey === undefined) {
119-
throw new Error(
120-
'Required parameter xAlgoliaAPIKey was null or undefined when calling batch.'
121-
);
122-
}
123-
124109
// verify required parameter 'indexName' is not null or undefined
125110
if (indexName === null || indexName === undefined) {
126111
throw new Error('Required parameter indexName was null or undefined when calling batch.');
@@ -131,14 +116,6 @@ export class SearchApi {
131116
throw new Error('Required parameter batchObject was null or undefined when calling batch.');
132117
}
133118

134-
localVarHeaderParams['X-Algolia-Application-Id'] = ObjectSerializer.serialize(
135-
xAlgoliaApplicationId,
136-
'string'
137-
);
138-
localVarHeaderParams['X-Algolia-API-Key'] = ObjectSerializer.serialize(
139-
xAlgoliaAPIKey,
140-
'string'
141-
);
142119
(<any>Object).assign(localVarHeaderParams, options.headers);
143120

144121
let localVarUseFormData = false;
@@ -154,6 +131,16 @@ export class SearchApi {
154131
};
155132

156133
let authenticationPromise = Promise.resolve();
134+
if (this.authentications.apiKey.apiKey) {
135+
authenticationPromise = authenticationPromise.then(() =>
136+
this.authentications.apiKey.applyToRequest(localVarRequestOptions)
137+
);
138+
}
139+
if (this.authentications.appId.apiKey) {
140+
authenticationPromise = authenticationPromise.then(() =>
141+
this.authentications.appId.applyToRequest(localVarRequestOptions)
142+
);
143+
}
157144
authenticationPromise = authenticationPromise.then(() =>
158145
this.authentications.default.applyToRequest(localVarRequestOptions)
159146
);
@@ -192,13 +179,9 @@ export class SearchApi {
192179
/**
193180
*
194181
* @summary Get search results for the given requests.
195-
* @param xAlgoliaApplicationId Algolia appID
196-
* @param xAlgoliaAPIKey Algolia API key
197182
* @param multipleQueriesObject
198183
*/
199184
public async multipleQueries(
200-
xAlgoliaApplicationId: string,
201-
xAlgoliaAPIKey: string,
202185
multipleQueriesObject: MultipleQueriesObject,
203186
options: { headers: { [name: string]: string } } = { headers: {} }
204187
): Promise<{ response: http.IncomingMessage; body: MultipleQueriesResponse }> {
@@ -214,35 +197,13 @@ export class SearchApi {
214197
}
215198
let localVarFormParams: any = {};
216199

217-
// verify required parameter 'xAlgoliaApplicationId' is not null or undefined
218-
if (xAlgoliaApplicationId === null || xAlgoliaApplicationId === undefined) {
219-
throw new Error(
220-
'Required parameter xAlgoliaApplicationId was null or undefined when calling multipleQueries.'
221-
);
222-
}
223-
224-
// verify required parameter 'xAlgoliaAPIKey' is not null or undefined
225-
if (xAlgoliaAPIKey === null || xAlgoliaAPIKey === undefined) {
226-
throw new Error(
227-
'Required parameter xAlgoliaAPIKey was null or undefined when calling multipleQueries.'
228-
);
229-
}
230-
231200
// verify required parameter 'multipleQueriesObject' is not null or undefined
232201
if (multipleQueriesObject === null || multipleQueriesObject === undefined) {
233202
throw new Error(
234203
'Required parameter multipleQueriesObject was null or undefined when calling multipleQueries.'
235204
);
236205
}
237206

238-
localVarHeaderParams['X-Algolia-Application-Id'] = ObjectSerializer.serialize(
239-
xAlgoliaApplicationId,
240-
'string'
241-
);
242-
localVarHeaderParams['X-Algolia-API-Key'] = ObjectSerializer.serialize(
243-
xAlgoliaAPIKey,
244-
'string'
245-
);
246207
(<any>Object).assign(localVarHeaderParams, options.headers);
247208

248209
let localVarUseFormData = false;
@@ -258,6 +219,16 @@ export class SearchApi {
258219
};
259220

260221
let authenticationPromise = Promise.resolve();
222+
if (this.authentications.apiKey.apiKey) {
223+
authenticationPromise = authenticationPromise.then(() =>
224+
this.authentications.apiKey.applyToRequest(localVarRequestOptions)
225+
);
226+
}
227+
if (this.authentications.appId.apiKey) {
228+
authenticationPromise = authenticationPromise.then(() =>
229+
this.authentications.appId.applyToRequest(localVarRequestOptions)
230+
);
231+
}
261232
authenticationPromise = authenticationPromise.then(() =>
262233
this.authentications.default.applyToRequest(localVarRequestOptions)
263234
);
@@ -296,14 +267,10 @@ export class SearchApi {
296267
/**
297268
* Add an object to the index, automatically assigning it an object ID
298269
* @summary Save object
299-
* @param xAlgoliaApplicationId Algolia appID
300-
* @param xAlgoliaAPIKey Algolia API key
301270
* @param indexName The index in which to perform the request
302271
* @param requestBody
303272
*/
304273
public async saveObject(
305-
xAlgoliaApplicationId: string,
306-
xAlgoliaAPIKey: string,
307274
indexName: string,
308275
requestBody: { [key: string]: object },
309276
options: { headers: { [name: string]: string } } = { headers: {} }
@@ -325,20 +292,6 @@ export class SearchApi {
325292
}
326293
let localVarFormParams: any = {};
327294

328-
// verify required parameter 'xAlgoliaApplicationId' is not null or undefined
329-
if (xAlgoliaApplicationId === null || xAlgoliaApplicationId === undefined) {
330-
throw new Error(
331-
'Required parameter xAlgoliaApplicationId was null or undefined when calling saveObject.'
332-
);
333-
}
334-
335-
// verify required parameter 'xAlgoliaAPIKey' is not null or undefined
336-
if (xAlgoliaAPIKey === null || xAlgoliaAPIKey === undefined) {
337-
throw new Error(
338-
'Required parameter xAlgoliaAPIKey was null or undefined when calling saveObject.'
339-
);
340-
}
341-
342295
// verify required parameter 'indexName' is not null or undefined
343296
if (indexName === null || indexName === undefined) {
344297
throw new Error(
@@ -353,14 +306,6 @@ export class SearchApi {
353306
);
354307
}
355308

356-
localVarHeaderParams['X-Algolia-Application-Id'] = ObjectSerializer.serialize(
357-
xAlgoliaApplicationId,
358-
'string'
359-
);
360-
localVarHeaderParams['X-Algolia-API-Key'] = ObjectSerializer.serialize(
361-
xAlgoliaAPIKey,
362-
'string'
363-
);
364309
(<any>Object).assign(localVarHeaderParams, options.headers);
365310

366311
let localVarUseFormData = false;
@@ -376,6 +321,16 @@ export class SearchApi {
376321
};
377322

378323
let authenticationPromise = Promise.resolve();
324+
if (this.authentications.apiKey.apiKey) {
325+
authenticationPromise = authenticationPromise.then(() =>
326+
this.authentications.apiKey.applyToRequest(localVarRequestOptions)
327+
);
328+
}
329+
if (this.authentications.appId.apiKey) {
330+
authenticationPromise = authenticationPromise.then(() =>
331+
this.authentications.appId.applyToRequest(localVarRequestOptions)
332+
);
333+
}
379334
authenticationPromise = authenticationPromise.then(() =>
380335
this.authentications.default.applyToRequest(localVarRequestOptions)
381336
);

yarn.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,11 +226,11 @@ __metadata:
226226

227227
"algoliasearch-client-javascript@file:output/::locator=%40algolia%2Fautomation-javascript-client%40workspace%3A.":
228228
version: 5.0.0
229-
resolution: "algoliasearch-client-javascript@file:output/#output/::hash=9f2500&locator=%40algolia%2Fautomation-javascript-client%40workspace%3A."
229+
resolution: "algoliasearch-client-javascript@file:output/#output/::hash=342434&locator=%40algolia%2Fautomation-javascript-client%40workspace%3A."
230230
dependencies:
231231
"@types/request": ^2.48.7
232232
request: ^2.81.0
233-
checksum: 4a413d1bbbeeaf41a9e4f75a2e9f8be6b827439a80099c57ae0d2b2387da9563ff416133c028989fe17eaa95025e248f8f586d78a08f903819eacae536f73b0b
233+
checksum: 79ae2881a4d93698d4600f7710ea07512df105e9faf61982acc2cc8327d1666fe39f7e83c4a4d471b1876c321b932850a49923a49d22d474bacdf16dfaa81e71
234234
languageName: node
235235
linkType: hard
236236

0 commit comments

Comments
 (0)