Skip to content

Commit 277ee3f

Browse files
committed
fix(service): object instead of any in case of nested properties in response
1 parent 4443ac3 commit 277ee3f

File tree

5 files changed

+11
-6
lines changed

5 files changed

+11
-6
lines changed

src/parser.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -591,6 +591,11 @@ function determineResponseType(
591591
return { name: type, type };
592592
}
593593

594+
if (schema.properties) {
595+
const type = nullable ? 'object | null' : 'object';
596+
return { name: type, type };
597+
}
598+
594599
return { name: 'any', type: 'any' };
595600
}
596601

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ export interface APIClientInterface {
8484
*/
8585
getRandomModel(
8686
requestHttpOptions?: HttpOptions
87-
): Observable<any>;
87+
): Observable<object>;
8888

8989
/**
9090
* Response generated for [ 200 ] HTTP response code.

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,14 +197,14 @@ export class APIClient implements APIClientInterface {
197197
*/
198198
getRandomModel(
199199
requestHttpOptions?: HttpOptions
200-
): Observable<any> {
200+
): Observable<object> {
201201
const path = `/randomModel`;
202202
const options: APIHttpOptions = {
203203
...this.options,
204204
...requestHttpOptions,
205205
};
206206

207-
return this.sendRequest<any>('GET', path, options);
207+
return this.sendRequest<object>('GET', path, options);
208208
}
209209

210210
/**

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,9 @@ export class GuardedAPIClient extends APIClient {
8787

8888
getRandomModel(
8989
requestHttpOptions?: HttpOptions
90-
): Observable<any> {
90+
): Observable<object> {
9191
return super.getRandomModel(requestHttpOptions)
92-
.pipe(tap((res: any) => guards.isAny(res) || console.error(`TypeGuard for response 'Any' caught inconsistency.`, res)));
92+
.pipe(tap((res: any) => guards.isobject(res) || console.error(`TypeGuard for response 'object' caught inconsistency.`, res)));
9393
}
9494

9595
getRandomString(

tests/custom/swagger.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ paths:
132132
get:
133133
responses:
134134
200:
135-
description: This returns any
135+
description: This returns object
136136
schema:
137137
properties:
138138
key:

0 commit comments

Comments
 (0)