[Typescript]: add deprecated tags for attributes (#22108)

* Add deprecated annotation when attribute is deprecated

* Generate samples
This commit is contained in:
Beppe Catanese
2025-10-13 08:44:35 +02:00
committed by GitHub
parent 42af4f9529
commit 1240d103ff
10 changed files with 140 additions and 1 deletions

View File

@@ -21,6 +21,9 @@ export class {{classname}} {{#parent}}extends {{{.}}} {{/parent}}{
{{#description}}
/**
* {{{.}}}
{{#deprecated}}
* @deprecated
{{/deprecated}}
*/
{{/description}}
'{{name}}'{{^required}}?{{/required}}: {{#isEnum}}{{{datatypeWithEnum}}}{{/isEnum}}{{^isEnum}}{{{dataType}}}{{/isEnum}}{{#isNullable}} | null{{/isNullable}};

View File

@@ -266,7 +266,33 @@ public class TypeScriptClientCodegenTest {
String content = Files.readString(file);
assertEquals(1, TestUtils.countOccurrences(content, "@deprecated"));
}
@Test
public void testDeprecatedAttribute() throws Exception {
final File output = Files.createTempDirectory("typescriptnodeclient_").toFile();
output.deleteOnExit();
final CodegenConfigurator configurator = new CodegenConfigurator()
.setGeneratorName("typescript")
.setInputSpec("src/test/resources/3_0/typescript/deprecated-attribute.yaml")
.setOutputDir(output.getAbsolutePath().replace("\\", "/"));
final ClientOptInput clientOptInput = configurator.toClientOptInput();
final DefaultGenerator generator = new DefaultGenerator();
final List<File> files = generator.opts(clientOptInput).generate();
files.forEach(File::deleteOnExit);
// verify operation is deprecated
Path file = Paths.get(output + "/models/PetUpdateRequest.ts");
TestUtils.assertFileContains(
file,
"* @deprecated"
);
String content = Files.readString(file);
assertEquals(1, TestUtils.countOccurrences(content, "@deprecated"));
}
@Test(description = "Verify useErasableSyntax config parameter generates erasable code")
public void testUseErasableSyntaxConfig() throws IOException {
boolean[] options = {true, false};

View File

@@ -0,0 +1,103 @@
openapi: 3.0.0
info:
description: test order parameters
version: 1.0.0
title: Test order parameters
license:
name: Apache-2.0
url: 'https://www.apache.org/licenses/LICENSE-2.0.html'
paths:
/pets:
get:
tags:
- default
summary: Finds Pets
deprecated: true
description: Find all pets
operationId: findPets
parameters:
- name: type
in: query
description: type of pet
style: form
explode: false
schema:
type: string
default: available
- name: name
in: query
description: name of pet
required: true
schema:
type: string
- name: age
in: query
description: age of pet
schema:
type: number
format: int32
responses:
'200':
description: successful operation
'400':
description: Invalid status value
patch:
tags:
- default
summary: Update a Pet
description: Partially update an existing pet
operationId: updatePet
requestBody:
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/PetUpdateRequest'
responses:
'200':
description: Pet updated successfully
content:
application/json:
schema:
$ref: '#/components/schemas/Pet'
'400':
description: Invalid input
'404':
description: Pet not found
components:
schemas:
PetUpdateRequest:
type: object
description: Payload for updating a pet
properties:
name:
type: string
description: New name for the pet
age:
type: integer
format: int32
description: Updated age
deprecated: true
type:
type: string
description: Type of pet
required:
- name
Pet:
type: object
description: Pet object
properties:
id:
type: integer
format: int64
name:
type: string
age:
type: integer
format: int32
type:
type: string

View File

@@ -25,6 +25,7 @@ export class Pet {
'tags'?: Array<Tag>;
/**
* pet status in the store
* @deprecated
*/
'status'?: PetStatusEnum;

View File

@@ -25,6 +25,7 @@ export class Pet {
'tags'?: Array<Tag>;
/**
* pet status in the store
* @deprecated
*/
'status'?: PetStatusEnum;

View File

@@ -25,6 +25,7 @@ export class Pet {
'tags'?: Array<Tag>;
/**
* pet status in the store
* @deprecated
*/
'status'?: PetStatusEnum;

View File

@@ -25,6 +25,7 @@ export class Pet {
'tags'?: Array<Tag>;
/**
* pet status in the store
* @deprecated
*/
'status'?: PetStatusEnum;

View File

@@ -25,6 +25,7 @@ export class Pet {
'tags'?: Array<Tag>;
/**
* pet status in the store
* @deprecated
*/
'status'?: PetStatusEnum;

View File

@@ -25,6 +25,7 @@ export class Pet {
'tags'?: Array<Tag>;
/**
* pet status in the store
* @deprecated
*/
'status'?: PetStatusEnum;

View File

@@ -25,6 +25,7 @@ export class Pet {
'tags'?: Array<Tag>;
/**
* pet status in the store
* @deprecated
*/
'status'?: PetStatusEnum;