-
-
Notifications
You must be signed in to change notification settings - Fork 7.5k
[Typescript]: add deprecated tags #21436
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
macjohnny
merged 7 commits into
OpenAPITools:master
from
gcatanese:typescript-deprecated-tags
Jun 27, 2025
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
5829fb7
Add deprecation markers
gcatanese a0c59fb
Move inputSpec (avoid sharing with other generators)
gcatanese 8fa6f33
Generate samples
gcatanese 78a0f3b
Refactor unit tests
gcatanese d3935e8
Add test helper method
gcatanese 6902833
Revert "Add test helper method"
gcatanese 063109e
Assert number of expected @deprecated
gcatanese File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
modules/openapi-generator/src/test/resources/3_0/typescript/deprecated-operation.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| 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 |
43 changes: 43 additions & 0 deletions
43
modules/openapi-generator/src/test/resources/3_0/typescript/deprecated-parameter.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| 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 | ||
| 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 | ||
| deprecated: true | ||
| 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 |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see two issues with these assertions (of this test and the next): They don't assert that the deprecated tag is only put on the expected locations
I.e.:
DefaultApi.tscould have a deprecated tag on every method and every parameter and it would still passThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know, it is not great, but this is the testing approach used in most generators. There are fundamental limitations with
TestUtils(maybe there are helpers that can be used instead?) that only verifies a given content is found.A better approach is to test the samples, using Python or Node scripts, to have the flexibility to check specific lines, for example. But this is a major effort at this stage.
I think the testing framework should improve, but not as part of this PR IMO. I can add few more assertions (if those add more value!?), but without a different approach we would still cover partially the scenarios we want to verify.
My suggestion is to move on with this PR (deprecation tags are very valuable in the generated code) and look at improving testing in a way that would benefit all generators and guide better all contributors.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe we can an add another assertion about the max number of expected
@deprecateds in the file, so at least we identify if there's more than expected; won't help with asserting their location, but better than nothing.Agree with the test env not being an issue of this PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pls have a look at my last commit? what do you think? I have added a new method in
TestUtilsto assert a given text on a specific lineNumber. This might address/mitigate some of the concernsThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whilst being a good idea, I think this is too fragile. We had this come up a few times as it is fairly simple to implement, but it breaks easily when the general file context changes, independently from the asserted code. I.e. let's say someone adds an empty line somewhere in the generator, then loads of tests will fail that use line based assertions. They are tricky to fix, as you need to look at the echo response, etc.
Thus, whilst I appreciate your effort, I think longterm a line-based assertion is onerous for future changes and extremely fragile.
An assertion that applies a diff with context or similar would possibly work. So would a snapshot test with a proper diff.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess it is a trade-off between thorough testing and maintainability. It could work if the tests are independent and don't share the same specs or data.
Anyway, I will revert the last commit and improve the existing tests as suggested 👍