Notification texts go here Contact Us Buy Now!

How to hide Some API in django rest swagger?

Sure, here's the HTML content for a comprehensive blog post about hiding some APIs in Django REST Swagger:

In this technical blog post, we'll tackle an intriguing topic: how to conceal specific APIs from the watchful eyes of Swagger in Django REST. Swagger, a formidable tool for documenting APIs, can sometimes pose challenges when you want to keep certain endpoints hidden.

Excluding Views from Schema Generation

One effective approach to hiding APIs is to leverage the swagger_schema = None parameter. This simple yet powerful trick instructs Swagger to exclude a particular view from the schema generation process, effectively making it invisible to Swagger's prying eyes.

# views.py
from rest_framework import viewsets
from rest_framework.decorators import action
from drf_yasg.utils import swagger_auto_schema

class MyViewSet(viewsets.ModelViewSet):
    @swagger_auto_schema(auto_schema=None)
    @action(methods=['GET'], detail=False)
    def hidden_api(self, request):
        pass

By incorporating the swagger_auto_schema decorator with the auto_schema=None argument, you've successfully rendered the hidden_api method invisible to Swagger's documentation. This technique allows you to maintain a clean and organized API documentation, showcasing only the endpoints you want to expose.

Conclusion

With this newfound knowledge, you now possess the power to selectively conceal APIs from Swagger's watchful gaze. This newfound ability empowers you to create a streamlined and purposeful API documentation, catering specifically to the needs of your project. May your APIs flourish, and may your documentation remain pristine!

Post a Comment

Cookie Consent
We serve cookies on this site to analyze traffic, remember your preferences, and optimize your experience.
Oops!
It seems there is something wrong with your internet connection. Please connect to the internet and start browsing again.
AdBlock Detected!
We have detected that you are using adblocking plugin in your browser.
The revenue we earn by the advertisements is used to manage this website, we request you to whitelist our website in your adblocking plugin.
Site is Blocked
Sorry! This site is not available in your country.