Skip to content

Commit 238c677

Browse files
authored
Merge pull request #6 from algolia/feat/API-157/generation-with-splitted-files
feat: add generated files from splitted specs
2 parents 277532e + 7ec58cb commit 238c677

17 files changed

+507
-24
lines changed

app.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,14 @@ const client = new SearchApi();
55
async function testClient() {
66
// test openapi gen
77
try {
8-
const res = await client.search(
9-
[
8+
const res = await client.multipleQueries('R2IYF7ETH7', 'e1e920e59f457ec70473486171c1d3b6', {
9+
requests: [
1010
{
1111
indexName: 'docsearch',
1212
query: 'crawler',
1313
},
1414
],
15-
'R2IYF7ETH7',
16-
'e1e920e59f457ec70473486171c1d3b6'
17-
);
15+
});
1816

1917
console.log('[1-RESPONSE]', res);
2018
} catch (e) {

openapi_spec/paths/indexes/batch.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ post:
1212
content:
1313
application/json:
1414
schema:
15+
title: batchObject
1516
type: object
1617
properties:
1718
requests:
@@ -43,6 +44,7 @@ post:
4344
content:
4445
application/json:
4546
schema:
47+
title: batchResponse
4648
type: object
4749
additionalProperties: false
4850
properties:

openapi_spec/paths/indexes/multipleQueries.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ post:
1111
content:
1212
application/json:
1313
schema:
14+
title: multipleQueriesObject
1415
type: object
1516
additionalProperties: false
1617
properties:

openapi_spec/paths/indexes/saveObject.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
post:
22
tags:
3-
- object
3+
- search
44
operationId: saveObject
55
summary: Save object
66
description: Add an object to the index, automatically assigning it an object ID
@@ -21,6 +21,7 @@ post:
2121
content:
2222
application/json:
2323
schema:
24+
title: saveObjectResponse
2425
type: object
2526
additionalProperties: false
2627
properties:

output/client-search/searchApi.ts

Lines changed: 259 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
import localVarRequest from 'request';
22
import http from 'http';
33

4-
import { MultipleQueries } from '../model/multipleQueries';
4+
import { BatchObject } from '../model/batchObject';
5+
import { BatchResponse } from '../model/batchResponse';
6+
import { MultipleQueriesObject } from '../model/multipleQueriesObject';
57
import { MultipleQueriesResponse } from '../model/multipleQueriesResponse';
8+
import { SaveObjectResponse } from '../model/saveObjectResponse';
69

710
import { ObjectSerializer, Authentication, VoidAuth, Interceptor } from '../model/models';
811

@@ -72,17 +75,131 @@ export class SearchApi {
7275
this.interceptors.push(interceptor);
7376
}
7477

78+
/**
79+
*
80+
* @summary Performs multiple write operations in a single API call
81+
* @param xAlgoliaApplicationId Algolia appID
82+
* @param xAlgoliaAPIKey Algolia API key
83+
* @param indexName The index in which to perform the request
84+
* @param batchObject
85+
*/
86+
public async batch(
87+
xAlgoliaApplicationId: string,
88+
xAlgoliaAPIKey: string,
89+
indexName: string,
90+
batchObject: BatchObject,
91+
options: { headers: { [name: string]: string } } = { headers: {} }
92+
): Promise<{ response: http.IncomingMessage; body: BatchResponse }> {
93+
const localVarPath =
94+
this.basePath +
95+
'/1/indexes/{indexName}/batch'.replace(
96+
'{' + 'indexName' + '}',
97+
encodeURIComponent(String(indexName))
98+
);
99+
let localVarQueryParameters: any = {};
100+
let localVarHeaderParams: any = (<any>Object).assign({}, this._defaultHeaders);
101+
const produces = ['application/json'];
102+
// give precedence to 'application/json'
103+
if (produces.indexOf('application/json') >= 0) {
104+
localVarHeaderParams.Accept = 'application/json';
105+
} else {
106+
localVarHeaderParams.Accept = produces.join(',');
107+
}
108+
let localVarFormParams: any = {};
109+
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+
124+
// verify required parameter 'indexName' is not null or undefined
125+
if (indexName === null || indexName === undefined) {
126+
throw new Error('Required parameter indexName was null or undefined when calling batch.');
127+
}
128+
129+
// verify required parameter 'batchObject' is not null or undefined
130+
if (batchObject === null || batchObject === undefined) {
131+
throw new Error('Required parameter batchObject was null or undefined when calling batch.');
132+
}
133+
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+
);
142+
(<any>Object).assign(localVarHeaderParams, options.headers);
143+
144+
let localVarUseFormData = false;
145+
146+
let localVarRequestOptions: localVarRequest.Options = {
147+
method: 'POST',
148+
qs: localVarQueryParameters,
149+
headers: localVarHeaderParams,
150+
uri: localVarPath,
151+
useQuerystring: this._useQuerystring,
152+
json: true,
153+
body: ObjectSerializer.serialize(batchObject, 'BatchObject'),
154+
};
155+
156+
let authenticationPromise = Promise.resolve();
157+
authenticationPromise = authenticationPromise.then(() =>
158+
this.authentications.default.applyToRequest(localVarRequestOptions)
159+
);
160+
161+
let interceptorPromise = authenticationPromise;
162+
for (const interceptor of this.interceptors) {
163+
interceptorPromise = interceptorPromise.then(() => interceptor(localVarRequestOptions));
164+
}
165+
166+
return interceptorPromise.then(() => {
167+
if (Object.keys(localVarFormParams).length) {
168+
if (localVarUseFormData) {
169+
(<any>localVarRequestOptions).formData = localVarFormParams;
170+
} else {
171+
localVarRequestOptions.form = localVarFormParams;
172+
}
173+
}
174+
return new Promise<{ response: http.IncomingMessage; body: BatchResponse }>(
175+
(resolve, reject) => {
176+
localVarRequest(localVarRequestOptions, (error, response, body) => {
177+
if (error) {
178+
reject(error);
179+
} else {
180+
body = ObjectSerializer.deserialize(body, 'BatchResponse');
181+
if (response.statusCode && response.statusCode >= 200 && response.statusCode <= 299) {
182+
resolve({ response: response, body: body });
183+
} else {
184+
reject(new HttpError(response, body, response.statusCode));
185+
}
186+
}
187+
});
188+
}
189+
);
190+
});
191+
}
75192
/**
76193
*
77194
* @summary Get search results for the given requests.
78-
* @param multipleQueries
79195
* @param xAlgoliaApplicationId Algolia appID
80196
* @param xAlgoliaAPIKey Algolia API key
197+
* @param multipleQueriesObject
81198
*/
82-
public async search(
83-
multipleQueries: Array<MultipleQueries>,
84-
xAlgoliaApplicationId?: string,
85-
xAlgoliaAPIKey?: string,
199+
public async multipleQueries(
200+
xAlgoliaApplicationId: string,
201+
xAlgoliaAPIKey: string,
202+
multipleQueriesObject: MultipleQueriesObject,
86203
options: { headers: { [name: string]: string } } = { headers: {} }
87204
): Promise<{ response: http.IncomingMessage; body: MultipleQueriesResponse }> {
88205
const localVarPath = this.basePath + '/1/indexes/*/queries';
@@ -97,10 +214,24 @@ export class SearchApi {
97214
}
98215
let localVarFormParams: any = {};
99216

100-
// verify required parameter 'multipleQueries' is not null or undefined
101-
if (multipleQueries === null || multipleQueries === undefined) {
217+
// verify required parameter 'xAlgoliaApplicationId' is not null or undefined
218+
if (xAlgoliaApplicationId === null || xAlgoliaApplicationId === undefined) {
102219
throw new Error(
103-
'Required parameter multipleQueries was null or undefined when calling search.'
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+
231+
// verify required parameter 'multipleQueriesObject' is not null or undefined
232+
if (multipleQueriesObject === null || multipleQueriesObject === undefined) {
233+
throw new Error(
234+
'Required parameter multipleQueriesObject was null or undefined when calling multipleQueries.'
104235
);
105236
}
106237

@@ -123,7 +254,7 @@ export class SearchApi {
123254
uri: localVarPath,
124255
useQuerystring: this._useQuerystring,
125256
json: true,
126-
body: ObjectSerializer.serialize(multipleQueries, 'Array<MultipleQueries>'),
257+
body: ObjectSerializer.serialize(multipleQueriesObject, 'MultipleQueriesObject'),
127258
};
128259

129260
let authenticationPromise = Promise.resolve();
@@ -162,4 +293,122 @@ export class SearchApi {
162293
);
163294
});
164295
}
296+
/**
297+
* Add an object to the index, automatically assigning it an object ID
298+
* @summary Save object
299+
* @param xAlgoliaApplicationId Algolia appID
300+
* @param xAlgoliaAPIKey Algolia API key
301+
* @param indexName The index in which to perform the request
302+
* @param requestBody
303+
*/
304+
public async saveObject(
305+
xAlgoliaApplicationId: string,
306+
xAlgoliaAPIKey: string,
307+
indexName: string,
308+
requestBody: { [key: string]: object },
309+
options: { headers: { [name: string]: string } } = { headers: {} }
310+
): Promise<{ response: http.IncomingMessage; body: SaveObjectResponse }> {
311+
const localVarPath =
312+
this.basePath +
313+
'/1/indexes/{indexName}'.replace(
314+
'{' + 'indexName' + '}',
315+
encodeURIComponent(String(indexName))
316+
);
317+
let localVarQueryParameters: any = {};
318+
let localVarHeaderParams: any = (<any>Object).assign({}, this._defaultHeaders);
319+
const produces = ['application/json'];
320+
// give precedence to 'application/json'
321+
if (produces.indexOf('application/json') >= 0) {
322+
localVarHeaderParams.Accept = 'application/json';
323+
} else {
324+
localVarHeaderParams.Accept = produces.join(',');
325+
}
326+
let localVarFormParams: any = {};
327+
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+
342+
// verify required parameter 'indexName' is not null or undefined
343+
if (indexName === null || indexName === undefined) {
344+
throw new Error(
345+
'Required parameter indexName was null or undefined when calling saveObject.'
346+
);
347+
}
348+
349+
// verify required parameter 'requestBody' is not null or undefined
350+
if (requestBody === null || requestBody === undefined) {
351+
throw new Error(
352+
'Required parameter requestBody was null or undefined when calling saveObject.'
353+
);
354+
}
355+
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+
);
364+
(<any>Object).assign(localVarHeaderParams, options.headers);
365+
366+
let localVarUseFormData = false;
367+
368+
let localVarRequestOptions: localVarRequest.Options = {
369+
method: 'POST',
370+
qs: localVarQueryParameters,
371+
headers: localVarHeaderParams,
372+
uri: localVarPath,
373+
useQuerystring: this._useQuerystring,
374+
json: true,
375+
body: ObjectSerializer.serialize(requestBody, '{ [key: string]: object; }'),
376+
};
377+
378+
let authenticationPromise = Promise.resolve();
379+
authenticationPromise = authenticationPromise.then(() =>
380+
this.authentications.default.applyToRequest(localVarRequestOptions)
381+
);
382+
383+
let interceptorPromise = authenticationPromise;
384+
for (const interceptor of this.interceptors) {
385+
interceptorPromise = interceptorPromise.then(() => interceptor(localVarRequestOptions));
386+
}
387+
388+
return interceptorPromise.then(() => {
389+
if (Object.keys(localVarFormParams).length) {
390+
if (localVarUseFormData) {
391+
(<any>localVarRequestOptions).formData = localVarFormParams;
392+
} else {
393+
localVarRequestOptions.form = localVarFormParams;
394+
}
395+
}
396+
return new Promise<{ response: http.IncomingMessage; body: SaveObjectResponse }>(
397+
(resolve, reject) => {
398+
localVarRequest(localVarRequestOptions, (error, response, body) => {
399+
if (error) {
400+
reject(error);
401+
} else {
402+
body = ObjectSerializer.deserialize(body, 'SaveObjectResponse');
403+
if (response.statusCode && response.statusCode >= 200 && response.statusCode <= 299) {
404+
resolve({ response: response, body: body });
405+
} else {
406+
reject(new HttpError(response, body, response.statusCode));
407+
}
408+
}
409+
});
410+
}
411+
);
412+
});
413+
}
165414
}

output/model/batchObject.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { RequestFile } from './models';
2+
import { Operation } from './operation';
3+
4+
export class BatchObject {
5+
'requests'?: Array<Operation>;
6+
7+
static discriminator: string | undefined = undefined;
8+
9+
static attributeTypeMap: Array<{ name: string; baseName: string; type: string }> = [
10+
{
11+
name: 'requests',
12+
baseName: 'requests',
13+
type: 'Array<Operation>',
14+
},
15+
];
16+
17+
static getAttributeTypeMap() {
18+
return BatchObject.attributeTypeMap;
19+
}
20+
}

0 commit comments

Comments
 (0)