Skip to content

Commit 7c30fe4

Browse files
fix(spec): fix wrong query parameters
algolia/api-clients-automation#330 Co-authored-by: Clément Vannicatte <[email protected]>
1 parent 772896f commit 7c30fe4

File tree

9 files changed

+673
-817
lines changed

9 files changed

+673
-817
lines changed

packages/client-abtesting/src/abtestingApi.ts

Lines changed: 47 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,6 @@ export function createAbtestingApi(
7474
addABTestsRequest: AddABTestsRequest,
7575
requestOptions?: RequestOptions
7676
): Promise<ABTestResponse> {
77-
const requestPath = '/2/abtests';
78-
const headers: Headers = {};
79-
const queryParameters: QueryParameters = {};
80-
8177
if (!addABTestsRequest) {
8278
throw new Error(
8379
'Parameter `addABTestsRequest` is required when calling `addABTests`.'
@@ -100,6 +96,10 @@ export function createAbtestingApi(
10096
);
10197
}
10298

99+
const requestPath = '/2/abtests';
100+
const headers: Headers = {};
101+
const queryParameters: QueryParameters = {};
102+
103103
const request: Request = {
104104
method: 'POST',
105105
path: requestPath,
@@ -122,24 +122,20 @@ export function createAbtestingApi(
122122
* @summary Send requests to the Algolia REST API.
123123
* @param del - The del object.
124124
* @param del.path - The path of the API endpoint to target, anything after the /1 needs to be specified.
125-
* @param del.parameters - URL-encoded query string. Force some query parameters to be applied for each query made with this API key.
125+
* @param del.parameters - Query parameters to be applied to the current query.
126126
* @param del.body - The parameters to send with the custom request.
127127
*/
128128
del(
129129
{ path, parameters, body }: DelProps,
130130
requestOptions?: RequestOptions
131131
): Promise<Record<string, any>> {
132-
const requestPath = '/1{path}'.replace('{path}', String(path));
133-
const headers: Headers = {};
134-
const queryParameters: QueryParameters = {};
135-
136132
if (!path) {
137133
throw new Error('Parameter `path` is required when calling `del`.');
138134
}
139135

140-
if (parameters !== undefined) {
141-
queryParameters.parameters = parameters.toString();
142-
}
136+
const requestPath = '/1{path}'.replace('{path}', path);
137+
const headers: Headers = {};
138+
const queryParameters: QueryParameters = parameters || {};
143139

144140
const request: Request = {
145141
method: 'DELETE',
@@ -168,19 +164,19 @@ export function createAbtestingApi(
168164
{ id }: DeleteABTestProps,
169165
requestOptions?: RequestOptions
170166
): Promise<ABTestResponse> {
171-
const requestPath = '/2/abtests/{id}'.replace(
172-
'{id}',
173-
encodeURIComponent(String(id))
174-
);
175-
const headers: Headers = {};
176-
const queryParameters: QueryParameters = {};
177-
178167
if (!id) {
179168
throw new Error(
180169
'Parameter `id` is required when calling `deleteABTest`.'
181170
);
182171
}
183172

173+
const requestPath = '/2/abtests/{id}'.replace(
174+
'{id}',
175+
encodeURIComponent(id)
176+
);
177+
const headers: Headers = {};
178+
const queryParameters: QueryParameters = {};
179+
184180
const request: Request = {
185181
method: 'DELETE',
186182
path: requestPath,
@@ -202,23 +198,19 @@ export function createAbtestingApi(
202198
* @summary Send requests to the Algolia REST API.
203199
* @param get - The get object.
204200
* @param get.path - The path of the API endpoint to target, anything after the /1 needs to be specified.
205-
* @param get.parameters - URL-encoded query string. Force some query parameters to be applied for each query made with this API key.
201+
* @param get.parameters - Query parameters to be applied to the current query.
206202
*/
207203
get(
208204
{ path, parameters }: GetProps,
209205
requestOptions?: RequestOptions
210206
): Promise<Record<string, any>> {
211-
const requestPath = '/1{path}'.replace('{path}', String(path));
212-
const headers: Headers = {};
213-
const queryParameters: QueryParameters = {};
214-
215207
if (!path) {
216208
throw new Error('Parameter `path` is required when calling `get`.');
217209
}
218210

219-
if (parameters !== undefined) {
220-
queryParameters.parameters = parameters.toString();
221-
}
211+
const requestPath = '/1{path}'.replace('{path}', path);
212+
const headers: Headers = {};
213+
const queryParameters: QueryParameters = parameters || {};
222214

223215
const request: Request = {
224216
method: 'GET',
@@ -246,17 +238,17 @@ export function createAbtestingApi(
246238
{ id }: GetABTestProps,
247239
requestOptions?: RequestOptions
248240
): Promise<ABTest> {
241+
if (!id) {
242+
throw new Error('Parameter `id` is required when calling `getABTest`.');
243+
}
244+
249245
const requestPath = '/2/abtests/{id}'.replace(
250246
'{id}',
251-
encodeURIComponent(String(id))
247+
encodeURIComponent(id)
252248
);
253249
const headers: Headers = {};
254250
const queryParameters: QueryParameters = {};
255251

256-
if (!id) {
257-
throw new Error('Parameter `id` is required when calling `getABTest`.');
258-
}
259-
260252
const request: Request = {
261253
method: 'GET',
262254
path: requestPath,
@@ -317,24 +309,20 @@ export function createAbtestingApi(
317309
* @summary Send requests to the Algolia REST API.
318310
* @param post - The post object.
319311
* @param post.path - The path of the API endpoint to target, anything after the /1 needs to be specified.
320-
* @param post.parameters - URL-encoded query string. Force some query parameters to be applied for each query made with this API key.
312+
* @param post.parameters - Query parameters to be applied to the current query.
321313
* @param post.body - The parameters to send with the custom request.
322314
*/
323315
post(
324316
{ path, parameters, body }: PostProps,
325317
requestOptions?: RequestOptions
326318
): Promise<Record<string, any>> {
327-
const requestPath = '/1{path}'.replace('{path}', String(path));
328-
const headers: Headers = {};
329-
const queryParameters: QueryParameters = {};
330-
331319
if (!path) {
332320
throw new Error('Parameter `path` is required when calling `post`.');
333321
}
334322

335-
if (parameters !== undefined) {
336-
queryParameters.parameters = parameters.toString();
337-
}
323+
const requestPath = '/1{path}'.replace('{path}', path);
324+
const headers: Headers = {};
325+
const queryParameters: QueryParameters = parameters || {};
338326

339327
const request: Request = {
340328
method: 'POST',
@@ -358,24 +346,20 @@ export function createAbtestingApi(
358346
* @summary Send requests to the Algolia REST API.
359347
* @param put - The put object.
360348
* @param put.path - The path of the API endpoint to target, anything after the /1 needs to be specified.
361-
* @param put.parameters - URL-encoded query string. Force some query parameters to be applied for each query made with this API key.
349+
* @param put.parameters - Query parameters to be applied to the current query.
362350
* @param put.body - The parameters to send with the custom request.
363351
*/
364352
put(
365353
{ path, parameters, body }: PutProps,
366354
requestOptions?: RequestOptions
367355
): Promise<Record<string, any>> {
368-
const requestPath = '/1{path}'.replace('{path}', String(path));
369-
const headers: Headers = {};
370-
const queryParameters: QueryParameters = {};
371-
372356
if (!path) {
373357
throw new Error('Parameter `path` is required when calling `put`.');
374358
}
375359

376-
if (parameters !== undefined) {
377-
queryParameters.parameters = parameters.toString();
378-
}
360+
const requestPath = '/1{path}'.replace('{path}', path);
361+
const headers: Headers = {};
362+
const queryParameters: QueryParameters = parameters || {};
379363

380364
const request: Request = {
381365
method: 'PUT',
@@ -404,19 +388,19 @@ export function createAbtestingApi(
404388
{ id }: StopABTestProps,
405389
requestOptions?: RequestOptions
406390
): Promise<ABTestResponse> {
407-
const requestPath = '/2/abtests/{id}/stop'.replace(
408-
'{id}',
409-
encodeURIComponent(String(id))
410-
);
411-
const headers: Headers = {};
412-
const queryParameters: QueryParameters = {};
413-
414391
if (!id) {
415392
throw new Error(
416393
'Parameter `id` is required when calling `stopABTest`.'
417394
);
418395
}
419396

397+
const requestPath = '/2/abtests/{id}/stop'.replace(
398+
'{id}',
399+
encodeURIComponent(id)
400+
);
401+
const headers: Headers = {};
402+
const queryParameters: QueryParameters = {};
403+
420404
const request: Request = {
421405
method: 'POST',
422406
path: requestPath,
@@ -442,9 +426,9 @@ export type DelProps = {
442426
*/
443427
path: string;
444428
/**
445-
* URL-encoded query string. Force some query parameters to be applied for each query made with this API key.
429+
* Query parameters to be applied to the current query.
446430
*/
447-
parameters?: string;
431+
parameters?: Record<string, any>;
448432
/**
449433
* The parameters to send with the custom request.
450434
*/
@@ -464,9 +448,9 @@ export type GetProps = {
464448
*/
465449
path: string;
466450
/**
467-
* URL-encoded query string. Force some query parameters to be applied for each query made with this API key.
451+
* Query parameters to be applied to the current query.
468452
*/
469-
parameters?: string;
453+
parameters?: Record<string, any>;
470454
};
471455

472456
export type GetABTestProps = {
@@ -493,9 +477,9 @@ export type PostProps = {
493477
*/
494478
path: string;
495479
/**
496-
* URL-encoded query string. Force some query parameters to be applied for each query made with this API key.
480+
* Query parameters to be applied to the current query.
497481
*/
498-
parameters?: string;
482+
parameters?: Record<string, any>;
499483
/**
500484
* The parameters to send with the custom request.
501485
*/
@@ -508,9 +492,9 @@ export type PutProps = {
508492
*/
509493
path: string;
510494
/**
511-
* URL-encoded query string. Force some query parameters to be applied for each query made with this API key.
495+
* Query parameters to be applied to the current query.
512496
*/
513-
parameters?: string;
497+
parameters?: Record<string, any>;
514498
/**
515499
* The parameters to send with the custom request.
516500
*/

0 commit comments

Comments
 (0)