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

Exclude internal API #129

Open
kozickikarol opened this issue Aug 16, 2016 · 2 comments
Open

Exclude internal API #129

kozickikarol opened this issue Aug 16, 2016 · 2 comments

Comments

@kozickikarol
Copy link

I don't see any possibility to exclude some views from docs. Is this feature implemented ?

Problem: I have internal API which is in 'internal' namespace and external one in 'api'. I would like to show only endpoints from external API.

Documentation does not say anything about it and I don't see place in code where I could filter or exclude endpoints by namespace or by app.

@heyyeah
Copy link

heyyeah commented Aug 18, 2016

@Kari94 I did this in my project by adding home.html to the templates folder in my project (see the Templates documentation) and then filtering after the for loop to exclude the groups I didn't want (in my case endpoints not in a group):
{% for group in endpoints_grouped %}
{% if group.grouper|lower != "none" %}

@hobbes7878
Copy link

Another way is to subclass DRFDocsView and use your DRF viewsets as a filter to override the endpoints used in the template context.

# views.py
from rest_framework import viewsets
from rest_framework_docs.views import DRFDocsView

class SomeViewSet(viewsets.ModelViewSet):
    queryset = SomeModel.objects.all()
    # ...

class DRFDocsCustomView(DRFDocsView):
    def get_context_data(self, **kwargs):
        context = super(DRFDocsCustomView, self).get_context_data(**kwargs)
        context['endpoints'] = [
            endpoint for endpoint in
            context['endpoints'] if endpoint.callback.cls in (
                SomeViewSet, SomeOtherViewSet
            )
        ]
        return context

Then call this view directly in your urls.

# urls.py
from .views import DRFDocsCustomView

urlpatterns = [
     url(r'^api/docs/', DRFDocsCustomView.as_view()),
    # ...
]

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

3 participants