Skip to content
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 extend_schema without a wrapper? #1364

Open
legitYosal opened this issue Jan 13, 2025 · 0 comments
Open

How to extend_schema without a wrapper? #1364

legitYosal opened this issue Jan 13, 2025 · 0 comments

Comments

@legitYosal
Copy link

Describe the bug
Using extend_schema wrapper, limits me to only use this wrapper in my final API, class, for example if I have 100 APIs I can not just create a abstract class which does this:
class BaseAPI(
mixins.ListModelMixin,
mixins.CreateModelMixin,
generics.GenericAPIView):

swagger_tags = []

def dispatch(self, request, *args, **kwargs):
    if self.swagger_tags:
        extend_schema(tags=self.swagger_tags)(self.get)
        extend_schema(tags=self.swagger_tags)(self.post)

    return super().dispatch(request, *args, **kwargs)

This won't work and I am forced to use extend schema in all of my API class methods across all these 100 APIs, which is against Django DRY and it seems much more code than it really needs.

As I am not very professional python programmer I have used many solutions which I have found in internet to over come this issue, for example overriding new function and none works, so I was thinking is there anyway to extend schema of a function without using a wrapper? so I can add an abstraction class???

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant