Skip to content

Commit 1240d10

Browse files
authored
[Typescript]: add deprecated tags for attributes (#22108)
* Add deprecated annotation when attribute is deprecated * Generate samples
1 parent 42af4f9 commit 1240d10

File tree

10 files changed

+140
-1
lines changed

10 files changed

+140
-1
lines changed

modules/openapi-generator/src/main/resources/typescript/model/model.mustache

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ export class {{classname}} {{#parent}}extends {{{.}}} {{/parent}}{
2121
{{#description}}
2222
/**
2323
* {{{.}}}
24+
{{#deprecated}}
25+
* @deprecated
26+
{{/deprecated}}
2427
*/
2528
{{/description}}
2629
'{{name}}'{{^required}}?{{/required}}: {{#isEnum}}{{{datatypeWithEnum}}}{{/isEnum}}{{^isEnum}}{{{dataType}}}{{/isEnum}}{{#isNullable}} | null{{/isNullable}};

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

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,33 @@ public void testDeprecatedParameter() throws Exception {
266266
String content = Files.readString(file);
267267
assertEquals(1, TestUtils.countOccurrences(content, "@deprecated"));
268268
}
269-
269+
270+
@Test
271+
public void testDeprecatedAttribute() throws Exception {
272+
final File output = Files.createTempDirectory("typescriptnodeclient_").toFile();
273+
output.deleteOnExit();
274+
275+
final CodegenConfigurator configurator = new CodegenConfigurator()
276+
.setGeneratorName("typescript")
277+
.setInputSpec("src/test/resources/3_0/typescript/deprecated-attribute.yaml")
278+
.setOutputDir(output.getAbsolutePath().replace("\\", "/"));
279+
280+
final ClientOptInput clientOptInput = configurator.toClientOptInput();
281+
final DefaultGenerator generator = new DefaultGenerator();
282+
final List<File> files = generator.opts(clientOptInput).generate();
283+
files.forEach(File::deleteOnExit);
284+
285+
// verify operation is deprecated
286+
Path file = Paths.get(output + "/models/PetUpdateRequest.ts");
287+
TestUtils.assertFileContains(
288+
file,
289+
"* @deprecated"
290+
);
291+
292+
String content = Files.readString(file);
293+
assertEquals(1, TestUtils.countOccurrences(content, "@deprecated"));
294+
}
295+
270296
@Test(description = "Verify useErasableSyntax config parameter generates erasable code")
271297
public void testUseErasableSyntaxConfig() throws IOException {
272298
boolean[] options = {true, false};
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
openapi: 3.0.0
2+
info:
3+
description: test order parameters
4+
version: 1.0.0
5+
title: Test order parameters
6+
license:
7+
name: Apache-2.0
8+
url: 'https://www.apache.org/licenses/LICENSE-2.0.html'
9+
10+
paths:
11+
/pets:
12+
get:
13+
tags:
14+
- default
15+
summary: Finds Pets
16+
deprecated: true
17+
description: Find all pets
18+
operationId: findPets
19+
parameters:
20+
- name: type
21+
in: query
22+
description: type of pet
23+
style: form
24+
explode: false
25+
schema:
26+
type: string
27+
default: available
28+
- name: name
29+
in: query
30+
description: name of pet
31+
required: true
32+
schema:
33+
type: string
34+
- name: age
35+
in: query
36+
description: age of pet
37+
schema:
38+
type: number
39+
format: int32
40+
responses:
41+
'200':
42+
description: successful operation
43+
'400':
44+
description: Invalid status value
45+
46+
patch:
47+
tags:
48+
- default
49+
summary: Update a Pet
50+
description: Partially update an existing pet
51+
operationId: updatePet
52+
requestBody:
53+
required: true
54+
content:
55+
application/json:
56+
schema:
57+
$ref: '#/components/schemas/PetUpdateRequest'
58+
responses:
59+
'200':
60+
description: Pet updated successfully
61+
content:
62+
application/json:
63+
schema:
64+
$ref: '#/components/schemas/Pet'
65+
'400':
66+
description: Invalid input
67+
'404':
68+
description: Pet not found
69+
70+
components:
71+
schemas:
72+
PetUpdateRequest:
73+
type: object
74+
description: Payload for updating a pet
75+
properties:
76+
name:
77+
type: string
78+
description: New name for the pet
79+
age:
80+
type: integer
81+
format: int32
82+
description: Updated age
83+
deprecated: true
84+
type:
85+
type: string
86+
description: Type of pet
87+
required:
88+
- name
89+
90+
Pet:
91+
type: object
92+
description: Pet object
93+
properties:
94+
id:
95+
type: integer
96+
format: int64
97+
name:
98+
type: string
99+
age:
100+
type: integer
101+
format: int32
102+
type:
103+
type: string

samples/openapi3/client/petstore/typescript/builds/browser/models/Pet.ts

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

samples/openapi3/client/petstore/typescript/builds/default/models/Pet.ts

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

samples/openapi3/client/petstore/typescript/builds/deno/models/Pet.ts

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

samples/openapi3/client/petstore/typescript/builds/deno_object_params/models/Pet.ts

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

samples/openapi3/client/petstore/typescript/builds/inversify/models/Pet.ts

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

samples/openapi3/client/petstore/typescript/builds/jquery/models/Pet.ts

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

samples/openapi3/client/petstore/typescript/builds/object_params/models/Pet.ts

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)