From 67942aa47871b89679641e21c33579b6c090e62a Mon Sep 17 00:00:00 2001 From: Beppe Catanese <1771700+gcatanese@users.noreply.github.com> Date: Thu, 3 Oct 2024 17:45:04 +0200 Subject: [PATCH] [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 * Correct indentation * Regenerate samples --------- Co-authored-by: Joscha Feth --- .../typescript-node/api-single.mustache | 4 ++++ .../TypeScriptNodeClientCodegenTest.java | 20 +++++++++++++++++++ .../3_0/typescript-node/SampleProject.yaml | 1 + .../typescript-node/3_0/api/defaultApi.ts | 2 ++ .../typescript-node/default/api/petApi.ts | 2 ++ .../typescript-node/npm/api/petApi.ts | 2 ++ 6 files changed, 31 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..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 @@ -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}} 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..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 @@ -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"); + } + 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 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..1c324466d47f 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..45e173378a54 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..45e173378a54 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';