ModuleSpecHandler autogenerated operation ID by concatenating the endpoint's HTTP verb and handler class. However, this result in odd names when the handler class already starts with the verb, as noted in T425428#11973782 which lists examples such as getGetRevisionSource. It would be nice to avoid doing that to keep the IDs more readable. Docs at https://www.mediawiki.org/wiki/Documentation/API_documentation/Reference#Operation_identifier should be updated when this is done, too.
Description
Details
| Subject | Author | Repo | Branch | Lines +/- | |
|---|---|---|---|---|---|
| Rest: Avoid repeating HTTP verb in autogenerated operation IDs | Gkm563 | mediawiki/core | master | +28 -3 |
Related Objects
Event Timeline
Change #1345352 had a related patch set uploaded (by Gkm563; author: Gkm563):
[mediawiki/core@master] Rest: Avoid repeating HTTP verb in autogenerated operation IDs
I have investigated the autogenerated operation IDs and submitted a patch: https://gerrit.wikimedia.org/r/c/mediawiki/core/+/1345352
It checks case-insensitively whether the leading word from the operation summary (or route path) matches the HTTP verb, avoiding duplicate prefixes like getGetRevisionSource -> getRevisionSource. Added unit tests for GET, POST, DELETE, PUT, and path fallbacks in ModuleSpecHandlerTest.
@Gkm563: Thanks for the patch. There is no need to add a comment here; see the automated patch notification four minutes earlier above your comment. Thanks.
@HCoplin-WMF , may you look at this task along with the thread that @daniel tagged you in, with @MHorsey-WMF , Moriel, and Alex, to let us know your thoughts?
Thanks for the patch, @Gkm563 ! Appreciate the consideration and contribution, as well as your patience for me getting back to you.
Another approach that we might want to consider is simply removing the HTTP verb prefix entirely. @BPirkle made a good point here: https://phabricator.wikimedia.org/T425428#11973782 where including the prefix could be slightly confusing in some cases. Additionally, it could result in somewhat confusing generated client method names, like "getSearchPages" being a little more opaque than "searchPages", since the first reads as if "search pages" was an entity instead of the endpoint operation.
The exception is when we do go through the route fallback where there is no summary defined in the spec, in which case including the verb would likely be preferable (eg: if GET /page/{title}/history had no summary, it would fall back to getPageTitleHistory).
One trade-off with that approach is that we will need to be a little more diligent about making sure people have good summaries that follow @KBach's style guide for summaries: https://www.mediawiki.org/wiki/Documentation/API_documentation/Reference#Summary
That is much easier with the linter, but it will also require that we start enforcing linting for new APIs (which wouldn't be a bad thing either :) ).
The other trade-off with using the endpoint summaries in general is that they are more likely to change than the path names themselves, especially if future people don't realize that the summary is directly tied to the operation ID. That could result in generated clients being broken. I think that is a relatively minor concern, and I think it's generally worth the trade-off for the improved names, but it's worth calling out as a general risk to the generated approach, including with any potential logic changes like this in the future.
Change #1345352 abandoned by Gkm563:
[mediawiki/core@master] Rest: Avoid repeating HTTP verb in autogenerated operation IDs
Reason:
Superseded by change 1369051 (T443917 / T439285), which derives operationIds directly from HTTP method and path.