Exclude internal API
kozickikarol opened this issue · 2 comments
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.
@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" %}
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 contextThen call this view directly in your urls.
# urls.py
from .views import DRFDocsCustomView
urlpatterns = [
url(r'^api/docs/', DRFDocsCustomView.as_view()),
# ...
]