-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add generated files from splitted specs #6
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 = | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we should remove those |
||
this.basePath + | ||
'/1/indexes/{indexName}/batch'.replace( | ||
'{' + 'indexName' + '}', | ||
encodeURIComponent(String(indexName)) | ||
); | ||
Comment on lines
+95
to
+98
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Was this generated or you did it manually? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok it's generated, we should see how it's done so we can maybe use it for the init method. |
||
let localVarQueryParameters: any = {}; | ||
let localVarHeaderParams: any = (<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' | ||
); | ||
(<any>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) { | ||
(<any>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<MultipleQueries>, | ||
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<MultipleQueries>'), | ||
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 = (<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' | ||
); | ||
(<any>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) { | ||
(<any>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)); | ||
} | ||
} | ||
}); | ||
} | ||
); | ||
}); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { RequestFile } from './models'; | ||
import { Operation } from './operation'; | ||
|
||
export class BatchObject { | ||
'requests'?: Array<Operation>; | ||
|
||
static discriminator: string | undefined = undefined; | ||
|
||
static attributeTypeMap: Array<{ name: string; baseName: string; type: string }> = [ | ||
{ | ||
name: 'requests', | ||
baseName: 'requests', | ||
type: 'Array<Operation>', | ||
}, | ||
]; | ||
|
||
static getAttributeTypeMap() { | ||
return BatchObject.attributeTypeMap; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should put those in a .env