[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>
This commit is contained in:
Beppe Catanese 2024-10-03 17:45:04 +02:00 committed by GitHub
parent 06d914dd0f
commit 67942aa478
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 31 additions and 0 deletions

View File

@ -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}}

View File

@ -296,6 +296,26 @@ public class TypeScriptNodeClientCodegenTest {
"* @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<File> 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");

View File

@ -147,6 +147,7 @@ paths:
patch:
summary: Update User Information
operationId: patch-users-userId
deprecated: true
responses:
'200':
description: User Updated

View File

@ -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}'

View File

@ -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<string>, options: {headers: {[name: string]: string}} = {headers: {}}) : Promise<{ response: http.IncomingMessage; body: Array<Pet>; }> {
const localVarPath = this.basePath + '/pet/findByTags';

View File

@ -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<string>, options: {headers: {[name: string]: string}} = {headers: {}}) : Promise<{ response: http.IncomingMessage; body: Array<Pet>; }> {
const localVarPath = this.basePath + '/pet/findByTags';