Skip to content

Commit b63e845

Browse files
committed
add async to api interfaces, and change some any to clearly types
1 parent 9b58fa3 commit b63e845

File tree

3 files changed

+14
-14
lines changed

3 files changed

+14
-14
lines changed

src/main/resources/handlebars/typescript-axios/apiInner.mustache

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
/* eslint-disable */
33
{{>licenseInfo}}
44

5-
import globalAxios, { AxiosPromise, AxiosInstance } from 'axios';
5+
import globalAxios, { AxiosResponse, AxiosInstance, AxiosRequestConfig } from 'axios';
66
import { Configuration } from '{{apiRelativeToRoot}}configuration';
77
// Some imports not used depending on template conditions
88
// @ts-ignore
@@ -31,7 +31,7 @@ export const {{classname}}AxiosParamCreator = function (configuration?: Configur
3131
* @param {*} [options] Override http request option.
3232
* @throws {RequiredError}
3333
*/
34-
{{nickname}}: async ({{#parameters}}{{paramName}}{{^required}}?{{/required}}: {{{dataType}}}, {{/parameters}}options: any = {}): Promise<RequestArgs> => {
34+
{{nickname}}: async ({{#parameters}}{{paramName}}{{^required}}?{{/required}}: {{{dataType}}}, {{/parameters}}options: AxiosRequestConfig = {}): Promise<RequestArgs> => {
3535
{{#parameters}}
3636
{{#required}}
3737
// verify required parameter '{{paramName}}' is not null or undefined
@@ -48,7 +48,7 @@ export const {{classname}}AxiosParamCreator = function (configuration?: Configur
4848
if (configuration) {
4949
baseOptions = configuration.baseOptions;
5050
}
51-
const localVarRequestOptions = { method: '{{httpMethod}}', ...baseOptions, ...options};
51+
const localVarRequestOptions :AxiosRequestConfig = { method: '{{httpMethod}}', ...baseOptions, ...options};
5252
const localVarHeaderParameter = {} as any;
5353
const localVarQueryParameter = {} as any;{{#vendorExtensions}}{{#hasFormParams}}
5454
const localVarFormParams = new {{^multipartFormData}}URLSearchParams(){{/multipartFormData}}{{#multipartFormData}}FormData(){{/multipartFormData}};{{/hasFormParams}}{{/vendorExtensions}}
@@ -187,9 +187,9 @@ export const {{classname}}AxiosParamCreator = function (configuration?: Configur
187187
const query = new URLSearchParams(localVarUrlObj.search);
188188
for (const key in localVarQueryParameter) {
189189
query.set(key, localVarQueryParameter[key]);
190-
}
191-
for (const key in options.query) {
192-
query.set(key, options.query[key]);
190+
191+
for (const key in options.params) {
192+
query.set(key, options.params[key]);
193193
}
194194
localVarUrlObj.search = (new URLSearchParams(query)).toString();
195195
let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {};
@@ -232,10 +232,10 @@ export const {{classname}}Fp = function(configuration?: Configuration) {
232232
* @param {*} [options] Override http request option.
233233
* @throws {RequiredError}
234234
*/
235-
async {{nickname}}({{#parameters}}{{paramName}}{{^required}}?{{/required}}: {{{dataType}}}, {{/parameters}}options?: any): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise<{{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}void{{/returnType}}>> {
235+
async {{nickname}}({{#parameters}}{{paramName}}{{^required}}?{{/required}}: {{{dataType}}}, {{/parameters}}options?: AxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => Promise<AxiosResponse<{{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}void{{/returnType}}>>> {
236236
const localVarAxiosArgs = await {{classname}}AxiosParamCreator(configuration).{{nickname}}({{#parameters}}{{paramName}}, {{/parameters}}options);
237237
return (axios: AxiosInstance = globalAxios, basePath: string = BASE_PATH) => {
238-
const axiosRequestArgs = {...localVarAxiosArgs.options, url: basePath + localVarAxiosArgs.url};
238+
const axiosRequestArgs :AxiosRequestConfig = {...localVarAxiosArgs.options, url: basePath + localVarAxiosArgs.url};
239239
return axios.request(axiosRequestArgs);
240240
};
241241
},
@@ -264,7 +264,7 @@ export const {{classname}}Factory = function (configuration?: Configuration, bas
264264
* @param {*} [options] Override http request option.
265265
* @throws {RequiredError}
266266
*/
267-
{{nickname}}({{#parameters}}{{paramName}}{{^required}}?{{/required}}: {{{dataType}}}, {{/parameters}}options?: any): AxiosPromise<{{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}void{{/returnType}}> {
267+
async {{nickname}}({{#parameters}}{{paramName}}{{^required}}?{{/required}}: {{{dataType}}}, {{/parameters}}options?: AxiosRequestConfig): Promise<AxiosResponse<{{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}void{{/returnType}}>> {
268268
return {{classname}}Fp(configuration).{{nickname}}({{#parameters}}{{paramName}}, {{/parameters}}options).then((request) => request(axios, basePath));
269269
},
270270
{{/contents}}
@@ -294,7 +294,7 @@ export interface {{classname}}Interface {
294294
* @throws {RequiredError}
295295
* @memberof {{classname}}Interface
296296
*/
297-
{{nickname}}({{#parameters}}{{paramName}}{{^required}}?{{/required}}: {{{dataType}}}, {{/parameters}}options?: any): AxiosPromise<{{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}void{{/returnType}}>;
297+
async {{nickname}}({{#parameters}}{{paramName}}{{^required}}?{{/required}}: {{{dataType}}}, {{/parameters}}options?: AxiosRequestConfig): Promise<AxiosResponse<{{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}void{{/returnType}}>>;
298298

299299
{{/contents}}
300300
{{/operation}}
@@ -328,7 +328,7 @@ export class {{classname}} extends BaseAPI {
328328
* @throws {RequiredError}
329329
* @memberof {{classname}}
330330
*/
331-
public {{nickname}}({{#parameters}}{{paramName}}{{^required}}?{{/required}}: {{{dataType}}}, {{/parameters}}options?: any) {
331+
public async {{nickname}}({{#parameters}}{{paramName}}{{^required}}?{{/required}}: {{{dataType}}}, {{/parameters}}options?: AxiosRequestConfig) : Promise<AxiosResponse<{{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}void{{/returnType}}>> {
332332
return {{classname}}Fp(this.configuration).{{nickname}}({{#parameters}}{{paramName}}, {{/parameters}}options).then((request) => request(this.axios, this.basePath));
333333
}
334334
{{^@last}}

src/main/resources/handlebars/typescript-axios/baseApi.mustache

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import { Configuration } from "./configuration";
66
// Some imports not used depending on template conditions
77
// @ts-ignore
8-
import globalAxios, { AxiosPromise, AxiosInstance } from 'axios';
8+
import globalAxios, { AxiosRequestConfig, AxiosInstance } from 'axios';
99

1010
export const BASE_PATH = "{{{basePath}}}".replace(/\/+$/, "");
1111

@@ -27,7 +27,7 @@ export const COLLECTION_FORMATS = {
2727
*/
2828
export interface RequestArgs {
2929
url: string;
30-
options: any;
30+
options: AxiosRequestConfig;
3131
}
3232

3333
/**

src/main/resources/handlebars/typescript-axios/package.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"prepublishOnly": "npm run build"
1919
},
2020
"dependencies": {
21-
"axios": "^0.19.2"
21+
"axios": "^0.21.1"
2222
},
2323
"devDependencies": {
2424
"@types/node": "^12.11.5",

0 commit comments

Comments
 (0)