Skip to content

Commit 67942aa

Browse files
gcatanesejoscha
andauthored
[Typescript-Node] Mark deprecated endpoints (#19770)
* Add @deprecated tag for deprecated operations * Add test helper to verify a given line * Add test to verify deprecated method * Regenerate samples * Delete tmp files after test * Remove assertFileContains on specific line * Update modules/openapi-generator/src/main/resources/typescript-node/api-single.mustache Co-authored-by: Joscha Feth <joscha@feth.com> * Correct indentation * Regenerate samples --------- Co-authored-by: Joscha Feth <joscha@feth.com>
1 parent 06d914d commit 67942aa

File tree

6 files changed

+31
-0
lines changed

6 files changed

+31
-0
lines changed

modules/openapi-generator/src/main/resources/typescript-node/api-single.mustache

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,10 @@ export class {{classname}} {
153153
{{#allParams}}
154154
* @param {{paramName}} {{description}}
155155
{{/allParams}}
156+
{{#isDeprecated}}
157+
*
158+
* @deprecated
159+
{{/isDeprecated}}
156160
*/
157161
public async {{nickname}} ({{#allParams}}{{paramName}}{{^required}}?{{/required}}: {{{dataType}}}, {{/allParams}}options: {headers: {[name: string]: string}} = {headers: {}}) : Promise<{ response: http.IncomingMessage; {{#returnType}}body: {{{.}}}; {{/returnType}}{{^returnType}}body?: any; {{/returnType}} }> {
158162
const localVarPath = this.basePath + '{{{path}}}'{{#pathParams}}

modules/openapi-generator/src/test/java/org/openapitools/codegen/typescript/typescriptnode/TypeScriptNodeClientCodegenTest.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,26 @@ public void testDeprecatedAttribute() throws IOException {
296296
"* @deprecated");
297297
}
298298

299+
@Test
300+
public void testDeprecatedOperation() throws IOException {
301+
302+
File output = Files.createTempDirectory("typescriptnodeclient_").toFile();
303+
output.deleteOnExit();
304+
305+
final CodegenConfigurator configurator = new CodegenConfigurator()
306+
.setGeneratorName("typescript-node")
307+
.setInputSpec("src/test/resources/3_0/typescript-node/SampleProject.yaml")
308+
.setOutputDir(output.getAbsolutePath().replace("\\", "/"));
309+
310+
final ClientOptInput clientOptInput = configurator.toClientOptInput();
311+
DefaultGenerator generator = new DefaultGenerator();
312+
List<File> files = generator.opts(clientOptInput).generate();
313+
files.forEach(File::deleteOnExit);
314+
315+
TestUtils.assertFileContains(Paths.get(output + "/api/defaultApi.ts"),
316+
"* @deprecated");
317+
}
318+
299319
private OperationsMap createPostProcessOperationsMapWithImportName(String importName) {
300320
OperationMap operations = new OperationMap();
301321
operations.setClassname("Pet");

modules/openapi-generator/src/test/resources/3_0/typescript-node/SampleProject.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ paths:
147147
patch:
148148
summary: Update User Information
149149
operationId: patch-users-userId
150+
deprecated: true
150151
responses:
151152
'200':
152153
description: User Updated

samples/client/petstore/typescript-node/3_0/api/defaultApi.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,8 @@ export class DefaultApi {
114114
* @param strCode Code as header
115115
* @param strCode2 Code as header2
116116
* @param patchUsersUserIdRequest Patch user properties to update.
117+
*
118+
* @deprecated
117119
*/
118120
public async patchUsersUserId (userId: number, strCode?: string, strCode2?: string, patchUsersUserIdRequest?: PatchUsersUserIdRequest, options: {headers: {[name: string]: string}} = {headers: {}}) : Promise<{ response: http.IncomingMessage; body: User; }> {
119121
const localVarPath = this.basePath + '/users/{userId}'

samples/client/petstore/typescript-node/default/api/petApi.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,8 @@ export class PetApi {
304304
* Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.
305305
* @summary Finds Pets by tags
306306
* @param tags Tags to filter by
307+
*
308+
* @deprecated
307309
*/
308310
public async findPetsByTags (tags: Array<string>, options: {headers: {[name: string]: string}} = {headers: {}}) : Promise<{ response: http.IncomingMessage; body: Array<Pet>; }> {
309311
const localVarPath = this.basePath + '/pet/findByTags';

samples/client/petstore/typescript-node/npm/api/petApi.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,8 @@ export class PetApi {
304304
* Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.
305305
* @summary Finds Pets by tags
306306
* @param tags Tags to filter by
307+
*
308+
* @deprecated
307309
*/
308310
public async findPetsByTags (tags: Array<string>, options: {headers: {[name: string]: string}} = {headers: {}}) : Promise<{ response: http.IncomingMessage; body: Array<Pet>; }> {
309311
const localVarPath = this.basePath + '/pet/findByTags';

0 commit comments

Comments
 (0)