[Typescript]: add deprecated tags#21436
Conversation
|
👏 first of all: great change I started reviewing this PR and then noticed that I am not completely sure I understand the rubric at which what tag gets added where;
Is that the current behavior? Because I can see some generated functions where a parameter is marked deprecated, but the function receiving the parameter is not, even though there is no alternative, as the parameter is not optional. Q: does marking an endpoint really "infect" all parameters? Cheers, |
Thanks for the feedback Joscha. The deprecation tags are independent:
I have implemented this approach because ultimately the OpenAPI definition is the source of truth. The API contract establishes what is deprecated, the generated source code just reflects that. |
That makes sense. Do the samples overlap? I feel like I'm the code I reviewed I saw at least one place where both the method and a parameter was deprecated. |
Do you mean:
|
sorry, yes, this one. So the effects of the change are clear - one change affects only the function, the other only the parameter |
|
Done. Thank you |
joscha
left a comment
There was a problem hiding this comment.
Thank you. Splitting them is much appreciated, however if we use the echo service, I still see an issue with the assertions. please let me know what you think.
| // verify operation is deprecated | ||
| TestUtils.assertFileContains( | ||
| Paths.get(output + "/apis/DefaultApi.ts"), | ||
| "* @deprecated" |
There was a problem hiding this comment.
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.:
- if the tag was added to the wrong operation it would still pass the assertion.
- if more than one tag was added in a different (incorrect) location in the same file, it would still pass the assertion.
- it does not ensure no other files are affected (i.e. a file that is not
DefaultApi.tscould have a deprecated tag on every method and every parameter and it would still pass
There was a problem hiding this comment.
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.
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.
Pls have a look at my last commit? what do you think? I have added a new method in TestUtils to assert a given text on a specific lineNumber. This might address/mitigate some of the concerns
There was a problem hiding this comment.
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.
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 👍
PR to add
@deprecationtags when endpoints or parameters are deprecatedPR checklist
Commit all changed files.
This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master.
These must match the expectations made by your contribution.
You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example
./bin/generate-samples.sh bin/configs/java*.IMPORTANT: Do NOT purge/delete any folders/files (e.g. tests) when regenerating the samples as manually written tests may be removed.
master(upcoming7.x.0minor release - breaking changes with fallbacks),8.0.x(breaking changes without fallbacks)@TiFu (2017/07) @taxpon (2017/07) @sebastianhaas (2017/07) @kenisteward (2017/07) @Vrolijkx (2017/09) @macjohnny (2018/01) @topce (2018/10) @akehir (2019/07) @petejohansonxo (2019/11) @amakhrov (2020/02) @davidgamero (2022/03) @mkusaka (2022/04) @joscha (2024/10)