manosim / manosim/django-rest-framework-docs

An idea to support per-method serializer in a Viewset

Open
#112 1 comment 0 reactions 0 assignees View on GitHub

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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.