Skip to content

Commit 53f3015

Browse files
committed
feat(api-client): methods params extracted to separate property in api client interface
This will avoid repetition and allow us to have nicer method overloading for implementation of #91
1 parent c7f7d6f commit 53f3015

File tree

82 files changed

+6807
-8678
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

82 files changed

+6807
-8678
lines changed

templates/ngx-guarded-service.handlebars

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,15 @@ import { Observable } from 'rxjs';
66
import { tap } from 'rxjs/operators';
77
import { DefaultHttpOptions, HttpOptions } from '{{#if serviceTag}}../.{{/if}}./types';
88
import { USE_DOMAIN, USE_HTTP_OPTIONS, {{&serviceName}} } from './{{&serviceFileName}}';
9+
import { {{&interfaceName}} } from './{{&interfaceFileName}}';
910

1011
{{#if definitions.length}}
1112
import * as models from '.{{#if swaggerTag}}./..{{/if}}/models';
1213
import * as guards from '.{{#if swaggerTag}}./..{{/if}}/guards';
1314
{{/if}}
1415

1516
@Injectable()
16-
export class Guarded{{&serviceName}} extends {{&serviceName}} {
17+
export class Guarded{{&serviceName}} extends {{&serviceName}} implements {{&interfaceName}} {
1718

1819
constructor(readonly httpClient: HttpClient,
1920
@Optional() @Inject(USE_DOMAIN) domain?: string,
@@ -24,11 +25,7 @@ export class Guarded{{&serviceName}} extends {{&serviceName}} {
2425
{{#methods}}
2526
{{#if responseGuard}} {{&methodName}}(
2627
{{#if parameters.length}}
27-
args: {
28-
{{#each parameters}}
29-
{{camelCase name}}{{^isRequired}}?{{/isRequired}}: {{&type}},{{#if description}} //{{#unless isRequired}} (optional){{/unless}} {{&description}}{{/if}}
30-
{{/each}}
31-
},
28+
args: Exclude<{{&../interfaceName}}['{{&methodName}}Params'], undefined>,
3229
{{/if}}
3330
requestHttpOptions?: HttpOptions
3431
): Observable<{{&responseTypeSchema.type}}> {

templates/ngx-service.handlebars

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,18 +47,22 @@ export class {{&serviceName}} implements {{&interfaceName}}{{/if}}{{#if (templat
4747
}
4848

4949
{{/if}}
50-
{{#methods}}
51-
{{#description}}
52-
/**
50+
{{#methods}}{{#if (templateType 'interface')}}{{#if parameters.length}} /**
51+
* Arguments object for method `{{&methodName}}`.
52+
*/
53+
{{&methodName}}Params?: {
54+
{{#each parameters}}
55+
{{#if description}}/** {{#unless isRequired}} (optional){{/unless}} {{&description}} */
56+
{{/if}}{{camelCase name}}{{^isRequired}}?{{/isRequired}}: {{&type}},
57+
{{/each}}
58+
};
59+
60+
{{/if}}{{/if}}{{#description}} /**
5361
* {{&.}}
5462
*/
5563
{{/description}} {{&methodName}}(
5664
{{#if parameters.length}}
57-
args: {
58-
{{#each parameters}}
59-
{{camelCase name}}{{^isRequired}}?{{/isRequired}}: {{&type}},{{#if description}} //{{#unless isRequired}} (optional){{/unless}} {{&description}}{{/if}}
60-
{{/each}}
61-
},
65+
args: Exclude<{{&../interfaceName}}['{{&methodName}}Params'], undefined>,
6266
{{/if}}
6367
requestHttpOptions?: HttpOptions
6468
): Observable<{{&responseTypeSchema.type}}>{{#if (templateType 'service')}} {

tests/custom/api/api-client.interface.ts

Lines changed: 97 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -16,45 +16,67 @@ import * as models from './models';
1616

1717
export interface APIClientInterface {
1818

19+
/**
20+
* Arguments object for method `getItems`.
21+
*/
22+
getItemsParams?: {
23+
pageSize: number,
24+
/** page number */
25+
page: number,
26+
};
27+
1928
/**
2029
* Response generated for [ 200 ] HTTP response code.
2130
*/
2231
getItems(
23-
args: {
24-
pageSize: number,
25-
page: number, // page number
26-
},
32+
args: Exclude<APIClientInterface['getItemsParams'], undefined>,
2733
requestHttpOptions?: HttpOptions
2834
): Observable<models.ItemList>;
2935

36+
/**
37+
* Arguments object for method `getItemModels`.
38+
*/
39+
getItemModelsParams?: {
40+
pageSize: number,
41+
/** page number */
42+
page: number,
43+
};
44+
3045
/**
3146
* Response generated for [ 200 ] HTTP response code.
3247
*/
3348
getItemModels(
34-
args: {
35-
pageSize: number,
36-
page: number, // page number
37-
},
49+
args: Exclude<APIClientInterface['getItemModelsParams'], undefined>,
3850
requestHttpOptions?: HttpOptions
3951
): Observable<object>;
4052

53+
/**
54+
* Arguments object for method `getPetsId`.
55+
*/
56+
getPetsIdParams?: {
57+
id: string,
58+
};
59+
4160
/**
4261
* Response generated for [ 200 ] HTTP response code.
4362
*/
4463
getPetsId(
45-
args: {
46-
id: string,
47-
},
64+
args: Exclude<APIClientInterface['getPetsIdParams'], undefined>,
4865
requestHttpOptions?: HttpOptions
4966
): Observable<models.Pet[]>;
5067

68+
/**
69+
* Arguments object for method `deletePetsId`.
70+
*/
71+
deletePetsIdParams?: {
72+
id: string,
73+
};
74+
5175
/**
5276
* Response generated for [ 200 ] HTTP response code.
5377
*/
5478
deletePetsId(
55-
args: {
56-
id: string,
57-
},
79+
args: Exclude<APIClientInterface['deletePetsIdParams'], undefined>,
5880
requestHttpOptions?: HttpOptions
5981
): Observable<void>;
6082

@@ -72,13 +94,18 @@ export interface APIClientInterface {
7294
requestHttpOptions?: HttpOptions
7395
): Observable<models.Dictionary>;
7496

97+
/**
98+
* Arguments object for method `getFileId`.
99+
*/
100+
getFileIdParams?: {
101+
id: string,
102+
};
103+
75104
/**
76105
* Response generated for [ 200 ] HTTP response code.
77106
*/
78107
getFileId(
79-
args: {
80-
id: string,
81-
},
108+
args: Exclude<APIClientInterface['getFileIdParams'], undefined>,
82109
requestHttpOptions?: HttpOptions
83110
): Observable<File>;
84111

@@ -117,51 +144,80 @@ export interface APIClientInterface {
117144
requestHttpOptions?: HttpOptions
118145
): Observable<{ [key: string]: number }[]>;
119146

147+
/**
148+
* Arguments object for method `firestoreProjectsDatabasesDocumentsCommit`.
149+
*/
150+
firestoreProjectsDatabasesDocumentsCommitParams?: {
151+
/** (optional) - error format - 1 V1 - 2 V2 */
152+
wololo?: models.NumberEnumParam,
153+
/** (optional) Data format for response. */
154+
alt?: models.StringEnumParam,
155+
/** (optional) OAuth access token. */
156+
accessToken?: string,
157+
/** (optional) Pretty-print response. */
158+
pp?: boolean,
159+
/** (optional) should pretty print */
160+
prettyPrint?: boolean,
161+
simpleQueryParam?: string,
162+
simpleArrayQueryParam?: number[],
163+
body?: models.Data,
164+
/** The database name. In the format `database:{{name}}` */
165+
database: string,
166+
};
167+
120168
/**
121169
* Commits a transaction, while optionally updating documents.
122170
* Response generated for [ 200 ] HTTP response code.
123171
*/
124172
firestoreProjectsDatabasesDocumentsCommit(
125-
args: {
126-
wololo?: models.NumberEnumParam, // (optional) - error format - 1 V1 - 2 V2
127-
alt?: models.StringEnumParam, // (optional) Data format for response.
128-
accessToken?: string, // (optional) OAuth access token.
129-
pp?: boolean, // (optional) Pretty-print response.
130-
prettyPrint?: boolean, // (optional) should pretty print
131-
simpleQueryParam?: string,
132-
simpleArrayQueryParam?: number[],
133-
body?: models.Data,
134-
database: string, // The database name. In the format `database:{{name}}`
135-
},
173+
args: Exclude<APIClientInterface['firestoreProjectsDatabasesDocumentsCommitParams'], undefined>,
136174
requestHttpOptions?: HttpOptions
137175
): Observable<models.Dictionary>;
138176

177+
/**
178+
* Arguments object for method `postReposOwnerRepoGitBlobs`.
179+
*/
180+
postReposOwnerRepoGitBlobsParams?: {
181+
/** Name of repository owner. */
182+
owner: string,
183+
/** Name of repository. */
184+
repo: string,
185+
/** (optional) Is used to set specified media type. */
186+
accept?: string,
187+
/** Custom blob (should be imported from models) */
188+
body: models.Blob,
189+
};
190+
139191
/**
140192
* Create a custom Blob.
141193
* Response generated for [ 201 ] HTTP response code.
142194
*/
143195
postReposOwnerRepoGitBlobs(
144-
args: {
145-
owner: string, // Name of repository owner.
146-
repo: string, // Name of repository.
147-
accept?: string, // (optional) Is used to set specified media type.
148-
body: models.Blob, // Custom blob (should be imported from models)
149-
},
196+
args: Exclude<APIClientInterface['postReposOwnerRepoGitBlobsParams'], undefined>,
150197
requestHttpOptions?: HttpOptions
151198
): Observable<models.Blob[]>;
152199

200+
/**
201+
* Arguments object for method `getReposOwnerRepoGitBlobsShaCode`.
202+
*/
203+
getReposOwnerRepoGitBlobsShaCodeParams?: {
204+
body?: models.ModelParam,
205+
/** Name of repository owner. */
206+
owner: string,
207+
/** Name of repository. */
208+
repo: string,
209+
/** SHA-1 code. */
210+
shaCode: string,
211+
/** (optional) Is used to set specified media type. */
212+
accept?: string,
213+
};
214+
153215
/**
154216
* Get standard File
155217
* Response generated for [ 200 ] HTTP response code.
156218
*/
157219
getReposOwnerRepoGitBlobsShaCode(
158-
args: {
159-
body?: models.ModelParam,
160-
owner: string, // Name of repository owner.
161-
repo: string, // Name of repository.
162-
shaCode: string, // SHA-1 code.
163-
accept?: string, // (optional) Is used to set specified media type.
164-
},
220+
args: Exclude<APIClientInterface['getReposOwnerRepoGitBlobsShaCodeParams'], undefined>,
165221
requestHttpOptions?: HttpOptions
166222
): Observable<File>;
167223

tests/custom/api/api-client.service.ts

Lines changed: 8 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,7 @@ export class APIClient implements APIClientInterface {
5454
* Response generated for [ 200 ] HTTP response code.
5555
*/
5656
getItems(
57-
args: {
58-
pageSize: number,
59-
page: number, // page number
60-
},
57+
args: Exclude<APIClientInterface['getItemsParams'], undefined>,
6158
requestHttpOptions?: HttpOptions
6259
): Observable<models.ItemList> {
6360
const path = `/items`;
@@ -79,10 +76,7 @@ export class APIClient implements APIClientInterface {
7976
* Response generated for [ 200 ] HTTP response code.
8077
*/
8178
getItemModels(
82-
args: {
83-
pageSize: number,
84-
page: number, // page number
85-
},
79+
args: Exclude<APIClientInterface['getItemModelsParams'], undefined>,
8680
requestHttpOptions?: HttpOptions
8781
): Observable<object> {
8882
const path = `/itemModels`;
@@ -104,9 +98,7 @@ export class APIClient implements APIClientInterface {
10498
* Response generated for [ 200 ] HTTP response code.
10599
*/
106100
getPetsId(
107-
args: {
108-
id: string,
109-
},
101+
args: Exclude<APIClientInterface['getPetsIdParams'], undefined>,
110102
requestHttpOptions?: HttpOptions
111103
): Observable<models.Pet[]> {
112104
const path = `/pets/${args.id}`;
@@ -122,9 +114,7 @@ export class APIClient implements APIClientInterface {
122114
* Response generated for [ 200 ] HTTP response code.
123115
*/
124116
deletePetsId(
125-
args: {
126-
id: string,
127-
},
117+
args: Exclude<APIClientInterface['deletePetsIdParams'], undefined>,
128118
requestHttpOptions?: HttpOptions
129119
): Observable<void> {
130120
const path = `/pets/${args.id}`;
@@ -170,9 +160,7 @@ export class APIClient implements APIClientInterface {
170160
* Response generated for [ 200 ] HTTP response code.
171161
*/
172162
getFileId(
173-
args: {
174-
id: string,
175-
},
163+
args: Exclude<APIClientInterface['getFileIdParams'], undefined>,
176164
requestHttpOptions?: HttpOptions
177165
): Observable<File> {
178166
const path = `/file/${args.id}`;
@@ -265,17 +253,7 @@ export class APIClient implements APIClientInterface {
265253
* Response generated for [ 200 ] HTTP response code.
266254
*/
267255
firestoreProjectsDatabasesDocumentsCommit(
268-
args: {
269-
wololo?: models.NumberEnumParam, // (optional) - error format - 1 V1 - 2 V2
270-
alt?: models.StringEnumParam, // (optional) Data format for response.
271-
accessToken?: string, // (optional) OAuth access token.
272-
pp?: boolean, // (optional) Pretty-print response.
273-
prettyPrint?: boolean, // (optional) should pretty print
274-
simpleQueryParam?: string,
275-
simpleArrayQueryParam?: number[],
276-
body?: models.Data,
277-
database: string, // The database name. In the format `database:{{name}}`
278-
},
256+
args: Exclude<APIClientInterface['firestoreProjectsDatabasesDocumentsCommitParams'], undefined>,
279257
requestHttpOptions?: HttpOptions
280258
): Observable<models.Dictionary> {
281259
const path = `/${args.database}/write`;
@@ -313,12 +291,7 @@ export class APIClient implements APIClientInterface {
313291
* Response generated for [ 201 ] HTTP response code.
314292
*/
315293
postReposOwnerRepoGitBlobs(
316-
args: {
317-
owner: string, // Name of repository owner.
318-
repo: string, // Name of repository.
319-
accept?: string, // (optional) Is used to set specified media type.
320-
body: models.Blob, // Custom blob (should be imported from models)
321-
},
294+
args: Exclude<APIClientInterface['postReposOwnerRepoGitBlobsParams'], undefined>,
322295
requestHttpOptions?: HttpOptions
323296
): Observable<models.Blob[]> {
324297
const path = `/repos/${args.owner}/${args.repo}/git/blobs`;
@@ -338,13 +311,7 @@ export class APIClient implements APIClientInterface {
338311
* Response generated for [ 200 ] HTTP response code.
339312
*/
340313
getReposOwnerRepoGitBlobsShaCode(
341-
args: {
342-
body?: models.ModelParam,
343-
owner: string, // Name of repository owner.
344-
repo: string, // Name of repository.
345-
shaCode: string, // SHA-1 code.
346-
accept?: string, // (optional) Is used to set specified media type.
347-
},
314+
args: Exclude<APIClientInterface['getReposOwnerRepoGitBlobsShaCodeParams'], undefined>,
348315
requestHttpOptions?: HttpOptions
349316
): Observable<File> {
350317
const path = `/repos/${args.owner}/${args.repo}/git/blobs/${args.shaCode}`;

0 commit comments

Comments
 (0)