Skip to content

Commit

Permalink
Use drf_yasg to provide api documentation
Browse files Browse the repository at this point in the history
The drf_yasg package provides much more information in the swagger documents. This allows to use code generators like openapi-generator to automatically generate a api wrapper.
  • Loading branch information
alles-klar committed Nov 25, 2019
1 parent bad8495 commit d2b1f63
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
1 change: 1 addition & 0 deletions dojo/settings/settings.dist.py
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,7 @@ def generate_url(scheme, double_slashes, user, password, host, port, path):
# 'axes'
'django_celery_results',
'social_django',
'drf_yasg',
)

# ------------------------------------------------------------------------------
Expand Down
18 changes: 15 additions & 3 deletions dojo/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@
from django.conf.urls import include, url
from django.conf.urls.static import static
from django.contrib import admin
from rest_framework_swagger.views import get_swagger_view
from tastypie.api import Api
from tastypie_swagger.views import SwaggerView, ResourcesView, SchemaView
from rest_framework.routers import DefaultRouter
from rest_framework.authtoken import views as tokenviews
from rest_framework import permissions
from drf_yasg.views import get_schema_view
from drf_yasg import openapi
from django.http import HttpResponse
from defectDojo_engagement_survey.urls import urlpatterns as survey_urls

Expand Down Expand Up @@ -150,7 +152,17 @@
url(r'^schema/$', SchemaView.as_view(), name='schema'),
]

schema_view = get_swagger_view(title='Defect Dojo API v2')
schema_view = get_schema_view(
openapi.Info(
title="Defect Dojo API",
default_version='v2',
description="To use the API you need be authorized.",
),
# if public=False, includes only endpoints the current user has access to
public=True,
# The API of a OpenSource project should be public accessible
permission_classes=(permissions.AllowAny),
)

urlpatterns = [
# tastypie api
Expand All @@ -169,7 +181,7 @@
name='action_history'),
url(r'^%s' % get_system_setting('url_prefix'), include(ur)),
url(r'^api/v2/api-token-auth/', tokenviews.obtain_auth_token),
url(r'^api/v2/doc/', schema_view, name="api_v2_schema"),
url(r'^api/v2/doc/', schema_view.with_ui('swagger', cache_timeout=0), name='api_v2_schema'),
url(r'^robots.txt', lambda x: HttpResponse("User-Agent: *\nDisallow: /", content_type="text/plain"), name="robots_file"),
]

Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,4 @@ ptvsd>=4.2.7
google-api-python-client==1.7.11
google-auth==1.6.3
google-auth-oauthlib==0.3.0
drf_yasg==1.17.0

0 comments on commit d2b1f63

Please sign in to comment.