HackSoftware / Django-Styleguide

Django styleguide used in HackSoft projects

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Browsable API

dakzh opened this issue · comments

commented

Hello,

How we can setup builtin rest framework documentation features?
For example Browsable API. Overriding get_serializer in every APIView sounds boring.

Thank you

@dakzh That's a great question.

We have the following mixin in some of our projects:

from rest_framework.schemas import AutoSchema


class ApiDocsMixin():
    schema = AutoSchema()

    def get_serializer(self):
        if hasattr(self, 'InputSerializer'):
            return self.InputSerializer()

        if hasattr(self, 'OutputSerializer'):
            return self.OutputSerializer()

This handles some basic cases, but it can be done quite better. Once we have resolutions there, we'll be adding examples.

Again, a general rule of thumb is - if you need to create a "framework-like" abstraction, to make your life easier, do so.

Also - you should check the latest 3.10+ changes in DRF, for the API documentation

Closing this in favor of #82