Skip to content

Commit a68b192

Browse files
committed
feat: more changes
1 parent 0a71476 commit a68b192

File tree

8 files changed

+29
-5
lines changed

8 files changed

+29
-5
lines changed

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/templates/core/CustomConfig.hbs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ type DefaultIntervals = {
66
}
77

88
export type CustomConfig = {
9+
readonly BASE: string;
910
readonly method: 'GET' | 'PUT' | 'POST' | 'DELETE' | 'OPTIONS' | 'HEAD' | 'PATCH';
1011
readonly retryStatuses?: number[];
1112
readonly retryIntervals?: DefaultIntervals;
@@ -17,4 +18,5 @@ export type CustomConfig = {
1718
readonly retryOn4xx?: boolean;
1819
readonly headers?: Record<string, any>;
1920
readonly url?: string;
21+
readonly token?: string;
2022
};

src/templates/core/custom/request.hbs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ import type { OpenAPIConfig } from './OpenAPI';
3535
{{>functions/getQueryString}}
3636

3737

38-
{{>functions/getUrl}}
38+
{{>functions/customGetUrl}}
3939

4040

4141
{{>functions/getFormData}}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
const getUrl = (serviceRequestConfig: CustomConfig, options: ApiRequestOptions): string => {
2+
const path = options.url
3+
.replace(/{(.*?)}/g, (substring: string, group: string) => {
4+
if (options.path?.hasOwnProperty(group)) {
5+
return encoder(String(options.path[group]));
6+
}
7+
return substring;
8+
});
9+
10+
const url = `${serviceRequestConfig.BASE}${path}`;
11+
if (options.query) {
12+
return `${url}${getQueryString(options.query)}`;
13+
}
14+
return url;
15+
};

src/utils/getHttpRequestName.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,7 @@ export const getHttpRequestName = (httpClient: HttpClient): string => {
1616
return 'AxiosHttpRequest';
1717
case HttpClient.ANGULAR:
1818
return 'AngularHttpRequest';
19+
case HttpClient.CUSTOM:
20+
return 'CustomHttpRequest';
1921
}
2022
};

src/utils/registerHandlebarTemplates.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import angularRequest from '../templates/core/angular/request.hbs';
1010
import angularSendRequest from '../templates/core/angular/sendRequest.hbs';
1111
import templateCoreApiError from '../templates/core/ApiError.hbs';
1212
import templateCoreApiRequestOptions from '../templates/core/ApiRequestOptions.hbs';
13-
import templateCoreCustomConfig from '../templates/core/CustomConfig.hbs';
1413
import templateCoreCustomApiError from '../templates/core/custom/ApiError.hbs';
1514
import templateCoreApiResult from '../templates/core/ApiResult.hbs';
1615
import axiosGetHeaders from '../templates/core/axios/getHeaders.hbs';
@@ -32,6 +31,7 @@ import functionCatchErrorCodes from '../templates/core/functions/catchErrorCodes
3231
import functionGetFormData from '../templates/core/functions/getFormData.hbs';
3332
import functionGetQueryString from '../templates/core/functions/getQueryString.hbs';
3433
import functionGetUrl from '../templates/core/functions/getUrl.hbs';
34+
import functionCustomGetUrl from '../templates/core/functions/customGetUrl.hbs';
3535
import functionIsBlob from '../templates/core/functions/isBlob.hbs';
3636
import functionIsDefined from '../templates/core/functions/isDefined.hbs';
3737
import functionIsFormData from '../templates/core/functions/isFormData.hbs';
@@ -54,6 +54,7 @@ import xhrGetResponseBody from '../templates/core/xhr/getResponseBody.hbs';
5454
import xhrGetResponseHeader from '../templates/core/xhr/getResponseHeader.hbs';
5555
import xhrRequest from '../templates/core/xhr/request.hbs';
5656
import xhrSendRequest from '../templates/core/xhr/sendRequest.hbs';
57+
import templateCoreCustomConfig from '../templates/core/CustomConfig.hbs';
5758
import customGetHeaders from '../templates/core/custom/getHeaders.hbs';
5859
import customGetRequestBody from '../templates/core/custom/getRequestBody.hbs';
5960
import customGetResponseBody from '../templates/core/custom/getResponseBody.hbs';
@@ -184,6 +185,7 @@ export const registerHandlebarTemplates = (root: {
184185
Handlebars.registerPartial('functions/getFormData', Handlebars.template(functionGetFormData));
185186
Handlebars.registerPartial('functions/getQueryString', Handlebars.template(functionGetQueryString));
186187
Handlebars.registerPartial('functions/getUrl', Handlebars.template(functionGetUrl));
188+
Handlebars.registerPartial('functions/customGetUrl', Handlebars.template(functionCustomGetUrl));
187189
Handlebars.registerPartial('functions/isBlob', Handlebars.template(functionIsBlob));
188190
Handlebars.registerPartial('functions/isDefined', Handlebars.template(functionIsDefined));
189191
Handlebars.registerPartial('functions/isFormData', Handlebars.template(functionIsFormData));
@@ -240,5 +242,6 @@ export const registerHandlebarTemplates = (root: {
240242
Handlebars.registerPartial('custom/getResponseHeader', Handlebars.template(customGetResponseHeader));
241243
Handlebars.registerPartial('custom/sendRequest', Handlebars.template(customSendRequest));
242244
Handlebars.registerPartial('custom/request', Handlebars.template(customRequest));
245+
Handlebars.registerPartial('custom/getUrl', Handlebars.template(templateCoreCustomApiError));
243246
return templates;
244247
};

src/utils/writeClient.spec.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ describe('writeClient', () => {
3333
request: () => 'request',
3434
baseHttpRequest: () => 'baseHttpRequest',
3535
httpRequest: () => 'httpRequest',
36+
customConfig: () => 'customConfig',
37+
customApiError: () => 'customApiError',
3638
},
3739
};
3840

src/utils/writeClientCore.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ export const writeClientCore = async (
4646
await writeFile(resolve(outputPath, 'request.ts'), i(templates.core.request(context), indent));
4747
if (httpClient === HttpClientValues.CUSTOM) {
4848
await writeFile(resolve(outputPath, 'CustomConfig.ts'), i(templates.core.customConfig(context), indent));
49-
await writeFile(resolve(outputPath, 'CustomApiError.ts'), i(templates.core.customApiError(context), indent));
49+
await writeFile(resolve(outputPath, 'ApiError.ts'), i(templates.core.customApiError(context), indent));
5050
}
5151
if (isDefined(clientName)) {
5252
await writeFile(resolve(outputPath, 'BaseHttpRequest.ts'), i(templates.core.baseHttpRequest(context), indent));

0 commit comments

Comments
 (0)