manosim / manosim/django-rest-framework-docs
An idea to support per-method serializer in a Viewset
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 641
- Forks
- 178
- PR merge metrics
- No merged PRs in 30d
Description
I've implemented something like this on my fork
```
from my_serializers import PasswordSerializer
from rest_framework_docs.utils import func_serializer
class UserViewSet(viewsets.ViewSet):
@func_serializer(serializer_class=PasswordSerializer)
@detail_route(methods=['post'])
def set_password(self, request, pk=None):
serializer = PasswordSerializer(data=request.data)
```
I wonder if you are keen on extending your library with something like this? I think it's a handy feature.
The downside of this is that we have to change application code to support documentation generation. Another approach is to use docstring, something like
```
class UserViewSet(viewsets.ViewSet):
@detail_route(methods=['post'])
def set_password(self, request, pk=None):
"""
:func_serializer: my_serializers.PasswordSerializer
"""
serializer = PasswordSerializer(data=request.data)
```
I think I like the first approach better.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reviewing the library's current documentation-generation entry points for ViewSet methods and how serializers are discovered. Compare the proposed decorator and docstring approaches, then define the supported per-method behavior and verify that generated API documentation uses the selected serializer for each method.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- django, python
- Domain
- api, documentation
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100