Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Exclude URLs from Django REST Swagger

I have a few URLs that I want to exclude from my REST API documentation. I'm using Django REST Swagger and the only documentation I can find (https://github.com/marcgibbons/django-rest-swagger) doesn't really tell me much. There is the "exclude_namespaces" part of SWAGGER_SETTINGS in settings.py, but there is no real explanation or example of how to use this.

Simply put, I want to exclude any URLs from the docs that start with the following:

/api/jobs/status/
/api/jobs/parameters/

How could I go about doing this?

Thanks in advance for any help offered :P

like image 581
David Brown Avatar asked Apr 24 '14 08:04

David Brown


1 Answers

the namespaces to exclude are the one defined in your urls.py.

So for example, in your case:

urls.py:

internal_apis = patterns('',
                     url(r'^/api/jobs/status/',...),
                     url(r'^/api/jobs/parameters/',...),
                     )

urlpatterns = urlpatterns + patterns('',
              url(r'^', include(internal_apis, namespace="internal_apis")),
              ...
              )

and in your settings.py:

SWAGGER_SETTINGS = {
    "exclude_namespaces": ["internal_apis"],    #  List URL namespaces to ignore
}

This is well described in there

like image 94
Laurent Bristiel Avatar answered Oct 17 '22 00:10

Laurent Bristiel