Skip to content

Commit 043e255

Browse files
committed
#3 support additional fetch-parameters in BaseAPI constructor - bugfix
* Remember to include basePath in URLs * Each requestOption parameter is optional
1 parent 7af2ede commit 043e255

File tree

11 files changed

+53
-41
lines changed

11 files changed

+53
-41
lines changed

snapshotTests/snapshot/example/base.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@
1616
export class BaseAPI {
1717

1818
constructor(protected basePath: string = window.location.origin, protected requestOptions?: {
19-
credentials: RequestCredentials,
20-
headers: Record<string, string>,
21-
mode: RequestMode
19+
credentials?: RequestCredentials,
20+
headers?: Record<string, string>,
21+
mode?: RequestMode
2222
} | undefined) {}
2323

2424
protected async GET(
@@ -128,7 +128,9 @@ export class BaseAPI {
128128
queryOptions?: QueryOptions
129129
): string {
130130
return (
131-
this.expandPathTemplate(pathTemplate, params) + this.query(queryParams, queryOptions)
131+
this.basePath +
132+
this.expandPathTemplate(pathTemplate, params) +
133+
this.query(queryParams, queryOptions)
132134
);
133135
}
134136

snapshotTests/snapshot/infectionTracker/api.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ export class CaseWorkersApi extends BaseAPI implements CaseWorkersApiInterface {
6060
*/
6161
public async listCaseWorkers(): Promise<CaseWorkerDto> {
6262
return await this.GET(
63-
"/api/caseWorkers",
63+
this.basePath + "/api/caseWorkers",
6464
undefined,
6565
{}
6666
);
@@ -74,7 +74,7 @@ export class CaseWorkersApi extends BaseAPI implements CaseWorkersApiInterface {
7474
caseWorkerDto?: CaseWorkerDto;
7575
}): Promise<void> {
7676
return await this.POST(
77-
"/api/caseWorkers",
77+
this.basePath + "/api/caseWorkers",
7878
JSON.stringify(params.caseWorkerDto),
7979
{
8080
"Content-Type": "application/json",
@@ -148,7 +148,7 @@ export class CasesApi extends BaseAPI implements CasesApiInterface {
148148
*/
149149
public async listCases(): Promise<InfectionDto> {
150150
return await this.GET(
151-
"/api/cases",
151+
this.basePath + "/api/cases",
152152
undefined,
153153
{}
154154
);
@@ -162,7 +162,7 @@ export class CasesApi extends BaseAPI implements CasesApiInterface {
162162
infectionInformationDto?: InfectionInformationDto;
163163
}): Promise<void> {
164164
return await this.POST(
165-
"/api/cases",
165+
this.basePath + "/api/cases",
166166
JSON.stringify(params.infectionInformationDto),
167167
{
168168
"Content-Type": "application/json",
@@ -221,7 +221,7 @@ export class ExposuresApi extends BaseAPI implements ExposuresApiInterface {
221221
*/
222222
public async listExposures(): Promise<ExposureDto> {
223223
return await this.GET(
224-
"/api/exposures",
224+
this.basePath + "/api/exposures",
225225
undefined,
226226
{}
227227
);

snapshotTests/snapshot/infectionTracker/base.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@
1616
export class BaseAPI {
1717

1818
constructor(protected basePath: string = window.location.origin, protected requestOptions?: {
19-
credentials: RequestCredentials,
20-
headers: Record<string, string>,
21-
mode: RequestMode
19+
credentials?: RequestCredentials,
20+
headers?: Record<string, string>,
21+
mode?: RequestMode
2222
} | undefined) {}
2323

2424
protected async GET(
@@ -128,7 +128,9 @@ export class BaseAPI {
128128
queryOptions?: QueryOptions
129129
): string {
130130
return (
131-
this.expandPathTemplate(pathTemplate, params) + this.query(queryParams, queryOptions)
131+
this.basePath +
132+
this.expandPathTemplate(pathTemplate, params) +
133+
this.query(queryParams, queryOptions)
132134
);
133135
}
134136

snapshotTests/snapshot/petstore/api.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ export class PetApi extends BaseAPI implements PetApiInterface {
141141
security: petstore_auth;
142142
}): Promise<void> {
143143
return await this.POST(
144-
"/pet",
144+
this.basePath + "/pet",
145145
JSON.stringify(params.petDto),
146146
{
147147
...params.security?.headers(),
@@ -230,7 +230,7 @@ export class PetApi extends BaseAPI implements PetApiInterface {
230230
security: petstore_auth;
231231
}): Promise<void> {
232232
return await this.PUT(
233-
"/pet",
233+
this.basePath + "/pet",
234234
JSON.stringify(params.petDto),
235235
{
236236
...params.security?.headers(),
@@ -354,7 +354,7 @@ export class StoreApi extends BaseAPI implements StoreApiInterface {
354354
security: api_key;
355355
}): Promise<{ [key: string]: number; }> {
356356
return await this.GET(
357-
"/store/inventory",
357+
this.basePath + "/store/inventory",
358358
undefined,
359359
{
360360
...params.security?.headers(),}
@@ -385,7 +385,7 @@ export class StoreApi extends BaseAPI implements StoreApiInterface {
385385
orderDto?: OrderDto;
386386
}): Promise<OrderDto> {
387387
return await this.POST(
388-
"/store/order",
388+
this.basePath + "/store/order",
389389
JSON.stringify(params.orderDto),
390390
{
391391
"Content-Type": "application/json",
@@ -492,7 +492,7 @@ export class UserApi extends BaseAPI implements UserApiInterface {
492492
userDto?: UserDto;
493493
}): Promise<void> {
494494
return await this.POST(
495-
"/user",
495+
this.basePath + "/user",
496496
JSON.stringify(params.userDto),
497497
{
498498
"Content-Type": "application/json",
@@ -509,7 +509,7 @@ export class UserApi extends BaseAPI implements UserApiInterface {
509509
userDto?: Array<UserDto>;
510510
}): Promise<void> {
511511
return await this.POST(
512-
"/user/createWithArray",
512+
this.basePath + "/user/createWithArray",
513513
JSON.stringify(params.userDto),
514514
{
515515
"Content-Type": "application/json",
@@ -526,7 +526,7 @@ export class UserApi extends BaseAPI implements UserApiInterface {
526526
userDto?: Array<UserDto>;
527527
}): Promise<void> {
528528
return await this.POST(
529-
"/user/createWithList",
529+
this.basePath + "/user/createWithList",
530530
JSON.stringify(params.userDto),
531531
{
532532
"Content-Type": "application/json",
@@ -586,7 +586,7 @@ export class UserApi extends BaseAPI implements UserApiInterface {
586586
*/
587587
public async logoutUser(): Promise<void> {
588588
return await this.GET(
589-
"/user/logout",
589+
this.basePath + "/user/logout",
590590
undefined,
591591
{}
592592
);

snapshotTests/snapshot/petstore/base.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@
1616
export class BaseAPI {
1717

1818
constructor(protected basePath: string = window.location.origin, protected requestOptions?: {
19-
credentials: RequestCredentials,
20-
headers: Record<string, string>,
21-
mode: RequestMode
19+
credentials?: RequestCredentials,
20+
headers?: Record<string, string>,
21+
mode?: RequestMode
2222
} | undefined) {}
2323

2424
protected async GET(
@@ -128,7 +128,9 @@ export class BaseAPI {
128128
queryOptions?: QueryOptions
129129
): string {
130130
return (
131-
this.expandPathTemplate(pathTemplate, params) + this.query(queryParams, queryOptions)
131+
this.basePath +
132+
this.expandPathTemplate(pathTemplate, params) +
133+
this.query(queryParams, queryOptions)
132134
);
133135
}
134136

snapshotTests/snapshot/poly/api.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ export class DefaultApi extends BaseAPI implements DefaultApiInterface {
7272
*/
7373
public async partiesGet(): Promise<AnyPartyDto> {
7474
return await this.GET(
75-
"/parties",
75+
this.basePath + "/parties",
7676
undefined,
7777
{}
7878
);
@@ -103,7 +103,7 @@ export class DefaultApi extends BaseAPI implements DefaultApiInterface {
103103
anyPartyDto?: AnyPartyDto;
104104
}): Promise<void> {
105105
return await this.POST(
106-
"/parties",
106+
this.basePath + "/parties",
107107
JSON.stringify(params.anyPartyDto),
108108
{
109109
"Content-Type": "application/json",

snapshotTests/snapshot/poly/base.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@
1616
export class BaseAPI {
1717

1818
constructor(protected basePath: string = window.location.origin, protected requestOptions?: {
19-
credentials: RequestCredentials,
20-
headers: Record<string, string>,
21-
mode: RequestMode
19+
credentials?: RequestCredentials,
20+
headers?: Record<string, string>,
21+
mode?: RequestMode
2222
} | undefined) {}
2323

2424
protected async GET(
@@ -128,7 +128,9 @@ export class BaseAPI {
128128
queryOptions?: QueryOptions
129129
): string {
130130
return (
131-
this.expandPathTemplate(pathTemplate, params) + this.query(queryParams, queryOptions)
131+
this.basePath +
132+
this.expandPathTemplate(pathTemplate, params) +
133+
this.query(queryParams, queryOptions)
132134
);
133135
}
134136

snapshotTests/snapshot/typeHierarchy/api.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ export class DefaultApi extends BaseAPI implements DefaultApiInterface {
5454
anyPetDto?: AnyPetDto;
5555
}): Promise<void> {
5656
return await this.PATCH(
57-
"/pets",
57+
this.basePath + "/pets",
5858
JSON.stringify(params.anyPetDto),
5959
{
6060
"Content-Type": "application/json",

snapshotTests/snapshot/typeHierarchy/base.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@
1616
export class BaseAPI {
1717

1818
constructor(protected basePath: string = window.location.origin, protected requestOptions?: {
19-
credentials: RequestCredentials,
20-
headers: Record<string, string>,
21-
mode: RequestMode
19+
credentials?: RequestCredentials,
20+
headers?: Record<string, string>,
21+
mode?: RequestMode
2222
} | undefined) {}
2323

2424
protected async GET(
@@ -128,7 +128,9 @@ export class BaseAPI {
128128
queryOptions?: QueryOptions
129129
): string {
130130
return (
131-
this.expandPathTemplate(pathTemplate, params) + this.query(queryParams, queryOptions)
131+
this.basePath +
132+
this.expandPathTemplate(pathTemplate, params) +
133+
this.query(queryParams, queryOptions)
132134
);
133135
}
134136

src/main/resources/typescript-fetch-api/apiInner.handlebars

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ export class {{classname}} extends BaseAPI {
7373
{{baseName}}: { delimiter: "{{#if (eq style "spaceDelimited")}} {{else if (eq style "pipeDelimited")}}|{{else}},{{/if}}" },
7474
{{else if (not isExplode)}}
7575
{{baseName}}: { explode: false },
76-
{{/if}}{{/queryParams~}} }{{/if}}){{else}}"{{{path}}}"{{/if}},
76+
{{/if}}{{/queryParams~}} }{{/if}}){{else}}this.basePath + "{{{path}}}"{{/if}},
7777
{{~#if bodyParam}}
7878
JSON.stringify(params.{{bodyParam.paramName}})
7979
{{~else if hasFormParams}}

0 commit comments

Comments
 (0)