Skip to content

Commit 4da7d8b

Browse files
committed
fix: include API client class name to the operation deprecation error message
1 parent e5d70f4 commit 4da7d8b

File tree

5 files changed

+25
-2
lines changed

5 files changed

+25
-2
lines changed

docs/interfaces/openapi_client.CommonHttpClientOptions.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ Options for the common HTTP client.
1010

1111
### Properties
1212

13+
- [apiClientClassName](openapi_client.CommonHttpClientOptions.md#apiclientclassname)
1314
- [baseUrl](openapi_client.CommonHttpClientOptions.md#baseurl)
1415
- [binaryResponseType](openapi_client.CommonHttpClientOptions.md#binaryresponsetype)
1516
- [deprecatedOperations](openapi_client.CommonHttpClientOptions.md#deprecatedoperations)
@@ -27,6 +28,14 @@ Options for the common HTTP client.
2728

2829
## Properties
2930

31+
### apiClientClassName
32+
33+
**apiClientClassName**: `string`
34+
35+
Class name of the API client.
36+
37+
___
38+
3039
### baseUrl
3140

3241
**baseUrl**: `string`

src/schema-to-typescript/common/client.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
identifier,
1414
importDeclaration,
1515
importNamespaceSpecifier,
16+
logicalExpression,
1617
memberExpression,
1718
newExpression,
1819
objectExpression,
@@ -170,6 +171,14 @@ export function generateClient({
170171
});
171172

172173
const clientConstructorOptionsObject = objectExpression([
174+
objectProperty(
175+
identifier('apiClientClassName'),
176+
logicalExpression(
177+
'??',
178+
memberExpression(memberExpression(thisExpression(), identifier('constructor')), identifier('name')),
179+
stringLiteral('name')
180+
)
181+
),
173182
objectProperty(identifier('baseUrl'), stringLiteral(baseUrl ?? servers[0]?.url ?? defaultServerUrl)),
174183
objectProperty(identifier('binaryResponseType'), stringLiteral(responseBinaryType)),
175184
objectProperty(identifier('errorClass'), identifier(errorTypeName))

src/schema-to-typescript/common/core/common-http-client.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ export interface CommonHttpClientOptions {
1818
message: string
1919
): Error;
2020
};
21+
/**
22+
* Class name of the API client.
23+
*/
24+
apiClientClassName: string;
2125
/**
2226
* Default headers to be sent with each request.
2327
*/
@@ -666,7 +670,7 @@ export class CommonHttpClient {
666670
this.options.logDeprecationWarning({method: params.method, path: params.path, operationName});
667671
} else {
668672
console.warn(
669-
`Deprecated API call ${this.constructor.name ?? 'ApiClient'}.${operationName}: ${methodAndPath}`
673+
`Deprecated API call ${this.options.apiClientClassName}.${operationName}: ${methodAndPath}`
670674
);
671675
}
672676
}

test/pet-store/common-http-client.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ describe('CommonHttpClient', () => {
1212
async function getRequestUrl(request: CommonHttpClientRequest): Promise<string> {
1313
let resultUrl = '';
1414
const client = new CommonHttpClient({
15+
apiClientClassName: 'ApiClient',
1516
baseUrl,
1617
errorClass: CommonHttpClientError,
1718
binaryResponseType: 'blob',

test/pet-store/pet-service.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ describe('pet-service', () => {
1414
client.pet.findPetsByTags({tags: ['tag']});
1515
expect(warn).toHaveBeenCalledTimes(1);
1616
expect(warn).toHaveBeenCalledWith(
17-
'Deprecated API call CommonHttpClient.pet.findPetsByTags: GET /pet/findByTags'
17+
'Deprecated API call PetStoreApiClient.pet.findPetsByTags: GET /pet/findByTags'
1818
);
1919
});
2020

0 commit comments

Comments
 (0)