Skip to content
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

Merged
merged 3 commits into from
Nov 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', {
Copy link
Collaborator

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

requests: [
{
indexName: 'docsearch',
query: 'crawler',
},
],
'R2IYF7ETH7',
'e1e920e59f457ec70473486171c1d3b6'
);
});

console.log('[1-RESPONSE]', res);
} catch (e) {
Expand Down
2 changes: 2 additions & 0 deletions openapi_spec/paths/indexes/batch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ post:
content:
application/json:
schema:
title: batchObject
type: object
properties:
requests:
Expand Down Expand Up @@ -43,6 +44,7 @@ post:
content:
application/json:
schema:
title: batchResponse
type: object
additionalProperties: false
properties:
Expand Down
1 change: 1 addition & 0 deletions openapi_spec/paths/indexes/multipleQueries.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ post:
content:
application/json:
schema:
title: multipleQueriesObject
type: object
additionalProperties: false
properties:
Expand Down
3 changes: 2 additions & 1 deletion openapi_spec/paths/indexes/saveObject.yml
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -21,6 +21,7 @@ post:
content:
application/json:
schema:
title: saveObjectResponse
type: object
additionalProperties: false
properties:
Expand Down
269 changes: 259 additions & 10 deletions output/client-search/searchApi.ts
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';

Expand Down Expand Up @@ -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 =
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should remove those localVar prefixes with the templates

this.basePath +
'/1/indexes/{indexName}/batch'.replace(
'{' + 'indexName' + '}',
encodeURIComponent(String(indexName))
);
Comment on lines +95 to +98
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was this generated or you did it manually?

Copy link
Member

Choose a reason for hiding this comment

The 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';
Expand All @@ -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.'
);
}

Expand All @@ -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();
Expand Down Expand Up @@ -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));
}
}
});
}
);
});
}
}
20 changes: 20 additions & 0 deletions output/model/batchObject.ts
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;
}
}
Loading