Closed
Description
Checklist
- I have verified that that issue exists against the
master
branch of Django REST framework. - I have searched for similar issues in both open and closed tickets and cannot find a duplicate.
- This is not a usage question. (It sort of isn't...)
- This cannot be dealt with as a third party library.
- I have reduced the issue to the simplest possible case.
- I have included a failing test as a pull request. (If you are unable to do so we can still accept the issue.)
Description
Following an upgrade DRF 3.11.2 -> 3.12.2, in order to avoid the warning about duplicate OpenAPI Operation IDs (implemented in #7207), I had to refactor extra ViewSet actions such as
@action(methods=['PATCH', 'DELETE'], url_path='members', detail=True)
def members(self, request):
# ...
that generates two OpenAPI operations, both called SomethingMembers
, to
@action(methods=['PATCH'], url_path='members', detail=True)
def edit_member(self, request, **kwargs):
return self._handle_members(request)
@action(methods=['DELETE'], url_path='members', detail=True)
def delete_member(self, request, **kwargs):
return self._handle_members(request)
def _handle_members(self, request):
that generates two OpenAPI operations, called SomethingEditMember
and SomethingDeleteMember
and doesn't warn about things.
However, this screws up routing, since both views have the same URL path, and as such one of them gets selected by Django when dispatching the request, which naturally leads to Method Not Alloweds when attempting to use the one not selected.
Resolutions
- I suppose it could be possible to rework the Router to have an internal per-method dispatch when it notices an URL regex is used by two "destinations" with different methods? (This admittedly sounds brittle and complex.)
- The easier way might be to somehow easily allow setting an
operation_id
for@action
s too (which is what I'll be looking into next, probably by way of hacking the Schema generator somehow since there's no official support I can see).
Metadata
Metadata
Assignees
Labels
No labels