-
Notifications
You must be signed in to change notification settings - Fork 248
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
How to remove/prevent parameters inherited" from ViewSet #399
Comments
hi, thats a lot to process 😄 technically the @action(
methods=['post'], detail=False, permission_classes=[IsAdminUser], serializer_class=AcceptedRiskSerializer,
filterset_class=None, pagination_class=None
)
def accept_risks(self, request): same goes for the pagination. you invoke the lurking pagination in the view by forcing the the reason this is implemented like that is that it would be very hard to get the reverse situation on purpose, i.e. getting a paginated/filtered action response. second option is to use |
one more thing. parameter are additive as this is the most common use-case. you can however remove parameters by force with drf-spectacular/tests/test_regressions.py Line 1306 in f58bbb0
so 3 options but the first would be preferable. if i understood you correctly, this is indeed the intended behavior. the solution from |
Thanks for the quick and elaborate response. Looks like it's This works:
|
yes that makes sense. i wrote that example from memory. django-filter depends on both classes. perfect! |
Small tweak to use empty list needed as
|
closing this issue for now. feel free to comment if anything is missing or not working and we will follow-up. |
I am migrating from
drf_yasg
todrf-spectacular
and I think the below is not answered yet anywhere. I did read the docs :-)I have some ViewSets to handle models via DRF, for example:
As you can see there is a custom Mixin
ra.api.AcceptedRisksMixin
to provides an extra action method:For
drf-yasg
it works as expected/desired, getting two parameters theid
and request body in the schema:For
drf-spectacular
I am getting a lot more parameters. I think these are "inherited" or discovered from the EngagementViewset where there is a filter backend that accepts all these parameters.I also notice pagination related schema elements in the response:
Is the expected / intended behaviour? Without stating which one is correct, I think the
drf-yasg
scheme is what I was expecting / looks the most intuitive.I tried using
@extend_schema
, but it looks like that can only be used to add extra parameters, not to remove superfluous ones.Is there anyway to prevent this "inheritance" of parameters and other elemens into the method from the MixIn?
I am not seeing all these "extra parameters" on @action methods declared directly in the ViewSet, such as
close
in the above example.Full code is at: https://github.com/valentijnscholten/django-DefectDojo/blob/cd89dac2d92f5734c7c717edce39130caf6278f3/dojo/api_v2/views.py#L115
The text was updated successfully, but these errors were encountered: