[Django]-How to tag whole ViewSet in drf_yasg?

18๐Ÿ‘

โœ…

I ended up using something like this:

first creating a custom auto schema

class CustomAutoSchema(SwaggerAutoSchema):

    def get_tags(self, operation_keys=None):
        tags = self.overrides.get('tags', None) or getattr(self.view, 'my_tags', [])
        if not tags:
            tags = [operation_keys[0]]

        return tags

in your settings file add:

SWAGGER_SETTINGS = {"DEFAULT_AUTO_SCHEMA_CLASS":"path.to.CustomAutoSchema"}

and in your View:

class AuthorViewSet(viewsets.ModelViewSet):
    queryset = Author.objects.all()
    serializer_class = AuthorSerializer
    permission_classes = [permissions.AllowAny]
    my_tags = ["Authors"]
๐Ÿ‘คAprimus

Leave a comment