Open kiblik opened 2 years ago
detail=True
only determines where the endpoint is mounted. irrelevant for the endpoint schema itself.pagination_class
present on that view/action. The pagination logic gets activated by doing Serializer(many=True)
.spectacular
and yasg
decorators at the same time. your mileage may vary.Check 'default'
and suffix
@swagger_auto_schema(
method='get',
responses={'default': serializers.DeletePreviewSerializer(many=True)}
)
@action(detail=True, methods=["get"], filter_backends=[], suffix='List')
Hi @tfranzel,
detail=True
only determines where the endpoint is mounted. irrelevant for the endpoint schema itself. (please check the analysis below)pagination_class
I did a quite deep dive. I was trying to find out, why yasg
doesn't evaluate my definition as I expect.
False
https://github.com/axnsan12/drf-yasg/blob/d9700dbf8cc80d725a7db485c2d4446c19c29840/src/drf_yasg/inspectors/view.py#L216-L217
Actually, I found out, that these lines are not even executed. Moreover, the whole function get_default_responses
is not executed.get_response_serializers
(which calls get_default_responses
). I found out that get_default_responses
is not called because I used status.HTTP_200_OK
in responses
(which is one of the "success responses").
https://github.com/axnsan12/drf-yasg/blob/d9700dbf8cc80d725a7db485c2d4446c19c29840/src/drf_yasg/inspectors/view.py#L230-L235
So I used 'default'
as HTTP response code.get_default_responses
is executed right now. But my feeling from point 1. is right,
self.should_page
is returning False
because it calls self.has_list_response
and it is returning False
as well.self.has_list_response
is returning False
because it calls self.is_list_view
and it is returning False
as well.self.is_list_view
is returning False
because it calls utils.is_list_view
and it is returning False
as well.@action(default=True)
, the result shouldn't be listed. 😢
a detail action is surely not a list route
So, because I'm not able to change the action
name and detail
has to be True
, I decided to use a "dirty hack" and set suffix = 'List'
. Thankfully there is not any side effect.
@kiblik I can't comment on the other things but detail
works 100% like I said, trust me :smiley:
/x/ # list
/x/{id}/ # retrieve
/x/action # action with detail=False
/x/{id}/action # action with detail=True
DRF does not specify what comes out of the action endpoint, i.e. if it is a list or not. Spectacular defaults to non-list with actions and you need to provide many=True
if you want your action to be a list.
Bug Report
Description
In our project, I was trying to write the definition of a new API endpoint that combines
Serializer(many=True)
anddetail=True
.I was able to write the expected definition for
drf_spectacular
butdrf_yasg
has a different result.Response for
drf_spectacular
Response for
drf_yasg
Is it a bug or did I miss something in the documentation?
Is this a regression?
I don't know, I'm writing a new implementation
Minimal Reproduction
Your Environment
Full context
https://github.com/DefectDojo/django-DefectDojo/pull/5612