From 80e9aa8fba3fa27693e034ef5638454a762deeea Mon Sep 17 00:00:00 2001 From: Beppe Catanese Date: Thu, 3 Oct 2024 12:02:38 +0200 Subject: [PATCH 1/9] Add @deprecated tag for deprecated operations --- .../src/main/resources/typescript-node/api-single.mustache | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/modules/openapi-generator/src/main/resources/typescript-node/api-single.mustache b/modules/openapi-generator/src/main/resources/typescript-node/api-single.mustache index 43b9f074069e..3e84ca76e571 100644 --- a/modules/openapi-generator/src/main/resources/typescript-node/api-single.mustache +++ b/modules/openapi-generator/src/main/resources/typescript-node/api-single.mustache @@ -153,6 +153,10 @@ export class {{classname}} { {{#allParams}} * @param {{paramName}} {{description}} {{/allParams}} + {{#isDeprecated}} + * + * @deprecated + {{/isDeprecated}} */ 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}} }> { const localVarPath = this.basePath + '{{{path}}}'{{#pathParams}} From 545be334ab6505888a83b99e90247add67e2b606 Mon Sep 17 00:00:00 2001 From: Beppe Catanese Date: Thu, 3 Oct 2024 12:03:05 +0200 Subject: [PATCH 2/9] Add test helper to verify a given line --- .../java/org/openapitools/codegen/TestUtils.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/modules/openapi-generator/src/test/java/org/openapitools/codegen/TestUtils.java b/modules/openapi-generator/src/test/java/org/openapitools/codegen/TestUtils.java index 72288ac05af9..fe823283cd57 100644 --- a/modules/openapi-generator/src/test/java/org/openapitools/codegen/TestUtils.java +++ b/modules/openapi-generator/src/test/java/org/openapitools/codegen/TestUtils.java @@ -173,6 +173,18 @@ public static void assertFileContains(Path path, String... lines) { } } + public static void assertFileContains(Path path, String line, int lineNumber) { + try { + List lines = Files.readAllLines(path); + assertNotNull(lines); + + String target = lines.get(lineNumber - 1); + assertTrue(target.contains(line), "File does not contain line [" + line + "] at lineNumber [" + lineNumber + "]"); + } catch (IOException e) { + fail("Unable to evaluate file " + path); + } + } + public static String linearize(String target) { return target.replaceAll("\r?\n", "").replaceAll("\\s+", "\\s"); } From 32593b12cf57e3071a754e292b8bf7c962b0f54a Mon Sep 17 00:00:00 2001 From: Beppe Catanese Date: Thu, 3 Oct 2024 12:03:31 +0200 Subject: [PATCH 3/9] Add test to verify deprecated method --- .../TypeScriptNodeClientCodegenTest.java | 20 +++++++++++++++++++ .../3_0/typescript-node/SampleProject.yaml | 1 + 2 files changed, 21 insertions(+) diff --git a/modules/openapi-generator/src/test/java/org/openapitools/codegen/typescript/typescriptnode/TypeScriptNodeClientCodegenTest.java b/modules/openapi-generator/src/test/java/org/openapitools/codegen/typescript/typescriptnode/TypeScriptNodeClientCodegenTest.java index 108d12c0917b..b4ee9ce25fe3 100644 --- a/modules/openapi-generator/src/test/java/org/openapitools/codegen/typescript/typescriptnode/TypeScriptNodeClientCodegenTest.java +++ b/modules/openapi-generator/src/test/java/org/openapitools/codegen/typescript/typescriptnode/TypeScriptNodeClientCodegenTest.java @@ -296,6 +296,26 @@ public void testDeprecatedAttribute() throws IOException { "* @deprecated"); } + @Test + public void testDeprecatedOperation() throws IOException { + + File output = Files.createTempDirectory("typescriptnodeclient_").toFile(); + output.deleteOnExit(); + + final CodegenConfigurator configurator = new CodegenConfigurator() + .setGeneratorName("typescript-node") + .setInputSpec("src/test/resources/3_0/typescript-node/SampleProject.yaml") + .setOutputDir(output.getAbsolutePath().replace("\\", "/")); + + final ClientOptInput clientOptInput = configurator.toClientOptInput(); + DefaultGenerator generator = new DefaultGenerator(); + List files = generator.opts(clientOptInput).generate(); + //files.forEach(File::deleteOnExit); + + TestUtils.assertFileContains(Paths.get(output + "/api/defaultApi.ts"), + "* @deprecated", 118); + } + private OperationsMap createPostProcessOperationsMapWithImportName(String importName) { OperationMap operations = new OperationMap(); operations.setClassname("Pet"); diff --git a/modules/openapi-generator/src/test/resources/3_0/typescript-node/SampleProject.yaml b/modules/openapi-generator/src/test/resources/3_0/typescript-node/SampleProject.yaml index a9cb17fada33..90de51babe5a 100644 --- a/modules/openapi-generator/src/test/resources/3_0/typescript-node/SampleProject.yaml +++ b/modules/openapi-generator/src/test/resources/3_0/typescript-node/SampleProject.yaml @@ -147,6 +147,7 @@ paths: patch: summary: Update User Information operationId: patch-users-userId + deprecated: true responses: '200': description: User Updated From 189438221de26267d9c963823f06cef067c16e84 Mon Sep 17 00:00:00 2001 From: Beppe Catanese Date: Thu, 3 Oct 2024 13:06:13 +0200 Subject: [PATCH 4/9] Regenerate samples --- samples/client/petstore/typescript-node/3_0/api/defaultApi.ts | 2 ++ samples/client/petstore/typescript-node/default/api/petApi.ts | 2 ++ samples/client/petstore/typescript-node/npm/api/petApi.ts | 2 ++ 3 files changed, 6 insertions(+) diff --git a/samples/client/petstore/typescript-node/3_0/api/defaultApi.ts b/samples/client/petstore/typescript-node/3_0/api/defaultApi.ts index 9786eacce900..66187774b87d 100644 --- a/samples/client/petstore/typescript-node/3_0/api/defaultApi.ts +++ b/samples/client/petstore/typescript-node/3_0/api/defaultApi.ts @@ -114,6 +114,8 @@ export class DefaultApi { * @param strCode Code as header * @param strCode2 Code as header2 * @param patchUsersUserIdRequest Patch user properties to update. + * + * @deprecated */ public async patchUsersUserId (userId: number, strCode?: string, strCode2?: string, patchUsersUserIdRequest?: PatchUsersUserIdRequest, options: {headers: {[name: string]: string}} = {headers: {}}) : Promise<{ response: http.IncomingMessage; body: User; }> { const localVarPath = this.basePath + '/users/{userId}' diff --git a/samples/client/petstore/typescript-node/default/api/petApi.ts b/samples/client/petstore/typescript-node/default/api/petApi.ts index f755d42f4daf..7cc65e6fbcea 100644 --- a/samples/client/petstore/typescript-node/default/api/petApi.ts +++ b/samples/client/petstore/typescript-node/default/api/petApi.ts @@ -304,6 +304,8 @@ export class PetApi { * Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing. * @summary Finds Pets by tags * @param tags Tags to filter by + * + * @deprecated */ public async findPetsByTags (tags: Array, options: {headers: {[name: string]: string}} = {headers: {}}) : Promise<{ response: http.IncomingMessage; body: Array; }> { const localVarPath = this.basePath + '/pet/findByTags'; diff --git a/samples/client/petstore/typescript-node/npm/api/petApi.ts b/samples/client/petstore/typescript-node/npm/api/petApi.ts index f755d42f4daf..7cc65e6fbcea 100644 --- a/samples/client/petstore/typescript-node/npm/api/petApi.ts +++ b/samples/client/petstore/typescript-node/npm/api/petApi.ts @@ -304,6 +304,8 @@ export class PetApi { * Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing. * @summary Finds Pets by tags * @param tags Tags to filter by + * + * @deprecated */ public async findPetsByTags (tags: Array, options: {headers: {[name: string]: string}} = {headers: {}}) : Promise<{ response: http.IncomingMessage; body: Array; }> { const localVarPath = this.basePath + '/pet/findByTags'; From 2453686ce4c9a2768f7c8d4784c4da2ef064cebf Mon Sep 17 00:00:00 2001 From: Beppe Catanese Date: Thu, 3 Oct 2024 13:27:14 +0200 Subject: [PATCH 5/9] Delete tmp files after test --- .../typescriptnode/TypeScriptNodeClientCodegenTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/openapi-generator/src/test/java/org/openapitools/codegen/typescript/typescriptnode/TypeScriptNodeClientCodegenTest.java b/modules/openapi-generator/src/test/java/org/openapitools/codegen/typescript/typescriptnode/TypeScriptNodeClientCodegenTest.java index b4ee9ce25fe3..8a6c062bad21 100644 --- a/modules/openapi-generator/src/test/java/org/openapitools/codegen/typescript/typescriptnode/TypeScriptNodeClientCodegenTest.java +++ b/modules/openapi-generator/src/test/java/org/openapitools/codegen/typescript/typescriptnode/TypeScriptNodeClientCodegenTest.java @@ -310,7 +310,7 @@ public void testDeprecatedOperation() throws IOException { final ClientOptInput clientOptInput = configurator.toClientOptInput(); DefaultGenerator generator = new DefaultGenerator(); List files = generator.opts(clientOptInput).generate(); - //files.forEach(File::deleteOnExit); + files.forEach(File::deleteOnExit); TestUtils.assertFileContains(Paths.get(output + "/api/defaultApi.ts"), "* @deprecated", 118); From 297ed4faab3fd8a09af63d6c1b7de0386ea77be8 Mon Sep 17 00:00:00 2001 From: Beppe Catanese Date: Thu, 3 Oct 2024 13:28:51 +0200 Subject: [PATCH 6/9] Remove assertFileContains on specific line --- .../java/org/openapitools/codegen/TestUtils.java | 12 ------------ .../TypeScriptNodeClientCodegenTest.java | 2 +- 2 files changed, 1 insertion(+), 13 deletions(-) diff --git a/modules/openapi-generator/src/test/java/org/openapitools/codegen/TestUtils.java b/modules/openapi-generator/src/test/java/org/openapitools/codegen/TestUtils.java index fe823283cd57..72288ac05af9 100644 --- a/modules/openapi-generator/src/test/java/org/openapitools/codegen/TestUtils.java +++ b/modules/openapi-generator/src/test/java/org/openapitools/codegen/TestUtils.java @@ -173,18 +173,6 @@ public static void assertFileContains(Path path, String... lines) { } } - public static void assertFileContains(Path path, String line, int lineNumber) { - try { - List lines = Files.readAllLines(path); - assertNotNull(lines); - - String target = lines.get(lineNumber - 1); - assertTrue(target.contains(line), "File does not contain line [" + line + "] at lineNumber [" + lineNumber + "]"); - } catch (IOException e) { - fail("Unable to evaluate file " + path); - } - } - public static String linearize(String target) { return target.replaceAll("\r?\n", "").replaceAll("\\s+", "\\s"); } diff --git a/modules/openapi-generator/src/test/java/org/openapitools/codegen/typescript/typescriptnode/TypeScriptNodeClientCodegenTest.java b/modules/openapi-generator/src/test/java/org/openapitools/codegen/typescript/typescriptnode/TypeScriptNodeClientCodegenTest.java index 8a6c062bad21..38a0bcf2cb96 100644 --- a/modules/openapi-generator/src/test/java/org/openapitools/codegen/typescript/typescriptnode/TypeScriptNodeClientCodegenTest.java +++ b/modules/openapi-generator/src/test/java/org/openapitools/codegen/typescript/typescriptnode/TypeScriptNodeClientCodegenTest.java @@ -313,7 +313,7 @@ public void testDeprecatedOperation() throws IOException { files.forEach(File::deleteOnExit); TestUtils.assertFileContains(Paths.get(output + "/api/defaultApi.ts"), - "* @deprecated", 118); + "* @deprecated"); } private OperationsMap createPostProcessOperationsMapWithImportName(String importName) { From 2e4124734b9ec94786b5dbf9d87e209064273afa Mon Sep 17 00:00:00 2001 From: Beppe Catanese <1771700+gcatanese@users.noreply.github.com> Date: Thu, 3 Oct 2024 13:31:19 +0200 Subject: [PATCH 7/9] Update modules/openapi-generator/src/main/resources/typescript-node/api-single.mustache Co-authored-by: Joscha Feth --- .../src/main/resources/typescript-node/api-single.mustache | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/openapi-generator/src/main/resources/typescript-node/api-single.mustache b/modules/openapi-generator/src/main/resources/typescript-node/api-single.mustache index 3e84ca76e571..424cef896cdd 100644 --- a/modules/openapi-generator/src/main/resources/typescript-node/api-single.mustache +++ b/modules/openapi-generator/src/main/resources/typescript-node/api-single.mustache @@ -155,7 +155,7 @@ export class {{classname}} { {{/allParams}} {{#isDeprecated}} * - * @deprecated + * @deprecated {{/isDeprecated}} */ 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}} }> { From e4029a8e9600c878c3697c4a801f94075b56265b Mon Sep 17 00:00:00 2001 From: Beppe Catanese Date: Thu, 3 Oct 2024 15:01:50 +0200 Subject: [PATCH 8/9] Correct indentation --- .../src/main/resources/typescript-node/api-single.mustache | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/openapi-generator/src/main/resources/typescript-node/api-single.mustache b/modules/openapi-generator/src/main/resources/typescript-node/api-single.mustache index 424cef896cdd..99c84a6fbb41 100644 --- a/modules/openapi-generator/src/main/resources/typescript-node/api-single.mustache +++ b/modules/openapi-generator/src/main/resources/typescript-node/api-single.mustache @@ -155,7 +155,7 @@ export class {{classname}} { {{/allParams}} {{#isDeprecated}} * - * @deprecated + * @deprecated {{/isDeprecated}} */ 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}} }> { From d68656a89160a1f0ca9925f851f17646be1fdf09 Mon Sep 17 00:00:00 2001 From: Beppe Catanese Date: Thu, 3 Oct 2024 15:02:07 +0200 Subject: [PATCH 9/9] Regenerate samples --- samples/client/petstore/typescript-node/3_0/api/defaultApi.ts | 2 +- samples/client/petstore/typescript-node/default/api/petApi.ts | 2 +- samples/client/petstore/typescript-node/npm/api/petApi.ts | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/samples/client/petstore/typescript-node/3_0/api/defaultApi.ts b/samples/client/petstore/typescript-node/3_0/api/defaultApi.ts index 66187774b87d..1c324466d47f 100644 --- a/samples/client/petstore/typescript-node/3_0/api/defaultApi.ts +++ b/samples/client/petstore/typescript-node/3_0/api/defaultApi.ts @@ -115,7 +115,7 @@ export class DefaultApi { * @param strCode2 Code as header2 * @param patchUsersUserIdRequest Patch user properties to update. * - * @deprecated + * @deprecated */ public async patchUsersUserId (userId: number, strCode?: string, strCode2?: string, patchUsersUserIdRequest?: PatchUsersUserIdRequest, options: {headers: {[name: string]: string}} = {headers: {}}) : Promise<{ response: http.IncomingMessage; body: User; }> { const localVarPath = this.basePath + '/users/{userId}' diff --git a/samples/client/petstore/typescript-node/default/api/petApi.ts b/samples/client/petstore/typescript-node/default/api/petApi.ts index 7cc65e6fbcea..45e173378a54 100644 --- a/samples/client/petstore/typescript-node/default/api/petApi.ts +++ b/samples/client/petstore/typescript-node/default/api/petApi.ts @@ -305,7 +305,7 @@ export class PetApi { * @summary Finds Pets by tags * @param tags Tags to filter by * - * @deprecated + * @deprecated */ public async findPetsByTags (tags: Array, options: {headers: {[name: string]: string}} = {headers: {}}) : Promise<{ response: http.IncomingMessage; body: Array; }> { const localVarPath = this.basePath + '/pet/findByTags'; diff --git a/samples/client/petstore/typescript-node/npm/api/petApi.ts b/samples/client/petstore/typescript-node/npm/api/petApi.ts index 7cc65e6fbcea..45e173378a54 100644 --- a/samples/client/petstore/typescript-node/npm/api/petApi.ts +++ b/samples/client/petstore/typescript-node/npm/api/petApi.ts @@ -305,7 +305,7 @@ export class PetApi { * @summary Finds Pets by tags * @param tags Tags to filter by * - * @deprecated + * @deprecated */ public async findPetsByTags (tags: Array, options: {headers: {[name: string]: string}} = {headers: {}}) : Promise<{ response: http.IncomingMessage; body: Array; }> { const localVarPath = this.basePath + '/pet/findByTags';