2017-03-03 18:24:37 +03:00
|
|
|
from django.conf.urls import include, url
|
|
|
|
|
|
|
|
from rest_framework.renderers import (
|
|
|
|
CoreJSONRenderer, DocumentationRenderer, SchemaJSRenderer
|
|
|
|
)
|
2017-04-18 13:44:43 +03:00
|
|
|
from rest_framework.schemas import SchemaGenerator, get_schema_view
|
2017-09-25 17:17:25 +03:00
|
|
|
from rest_framework.settings import api_settings
|
2017-03-03 18:24:37 +03:00
|
|
|
|
|
|
|
|
2017-04-19 08:56:39 +03:00
|
|
|
def get_docs_view(
|
2019-07-23 14:06:03 +03:00
|
|
|
title=None, description=None, schema_url=None, urlconf=None,
|
|
|
|
public=True, patterns=None, generator_class=SchemaGenerator,
|
2017-09-25 17:17:25 +03:00
|
|
|
authentication_classes=api_settings.DEFAULT_AUTHENTICATION_CLASSES,
|
2018-01-25 11:39:03 +03:00
|
|
|
permission_classes=api_settings.DEFAULT_PERMISSION_CLASSES,
|
|
|
|
renderer_classes=None):
|
|
|
|
|
|
|
|
if renderer_classes is None:
|
|
|
|
renderer_classes = [DocumentationRenderer, CoreJSONRenderer]
|
2017-03-03 18:24:37 +03:00
|
|
|
|
|
|
|
return get_schema_view(
|
|
|
|
title=title,
|
|
|
|
url=schema_url,
|
2019-07-23 14:06:03 +03:00
|
|
|
urlconf=urlconf,
|
2017-03-03 18:24:37 +03:00
|
|
|
description=description,
|
|
|
|
renderer_classes=renderer_classes,
|
2017-03-15 10:07:12 +03:00
|
|
|
public=public,
|
|
|
|
patterns=patterns,
|
2017-04-18 13:44:43 +03:00
|
|
|
generator_class=generator_class,
|
2017-09-25 17:17:25 +03:00
|
|
|
authentication_classes=authentication_classes,
|
|
|
|
permission_classes=permission_classes,
|
2017-03-03 18:24:37 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
|
2017-04-19 08:56:39 +03:00
|
|
|
def get_schemajs_view(
|
2019-07-23 14:06:03 +03:00
|
|
|
title=None, description=None, schema_url=None, urlconf=None,
|
|
|
|
public=True, patterns=None, generator_class=SchemaGenerator,
|
2017-09-25 17:17:25 +03:00
|
|
|
authentication_classes=api_settings.DEFAULT_AUTHENTICATION_CLASSES,
|
|
|
|
permission_classes=api_settings.DEFAULT_PERMISSION_CLASSES):
|
2017-03-03 18:24:37 +03:00
|
|
|
renderer_classes = [SchemaJSRenderer]
|
|
|
|
|
|
|
|
return get_schema_view(
|
|
|
|
title=title,
|
|
|
|
url=schema_url,
|
2019-07-23 14:06:03 +03:00
|
|
|
urlconf=urlconf,
|
2017-03-03 18:24:37 +03:00
|
|
|
description=description,
|
|
|
|
renderer_classes=renderer_classes,
|
2017-03-15 10:07:12 +03:00
|
|
|
public=public,
|
|
|
|
patterns=patterns,
|
2017-04-18 13:44:43 +03:00
|
|
|
generator_class=generator_class,
|
2017-09-25 17:17:25 +03:00
|
|
|
authentication_classes=authentication_classes,
|
|
|
|
permission_classes=permission_classes,
|
2017-03-03 18:24:37 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
|
2017-04-19 08:56:39 +03:00
|
|
|
def include_docs_urls(
|
2019-07-23 14:06:03 +03:00
|
|
|
title=None, description=None, schema_url=None, urlconf=None,
|
|
|
|
public=True, patterns=None, generator_class=SchemaGenerator,
|
2017-09-25 17:17:25 +03:00
|
|
|
authentication_classes=api_settings.DEFAULT_AUTHENTICATION_CLASSES,
|
2018-01-25 11:39:03 +03:00
|
|
|
permission_classes=api_settings.DEFAULT_PERMISSION_CLASSES,
|
|
|
|
renderer_classes=None):
|
2017-03-03 18:24:37 +03:00
|
|
|
docs_view = get_docs_view(
|
|
|
|
title=title,
|
|
|
|
description=description,
|
|
|
|
schema_url=schema_url,
|
2019-07-23 14:06:03 +03:00
|
|
|
urlconf=urlconf,
|
2017-03-15 10:07:12 +03:00
|
|
|
public=public,
|
|
|
|
patterns=patterns,
|
2017-04-18 13:44:43 +03:00
|
|
|
generator_class=generator_class,
|
2017-09-25 17:17:25 +03:00
|
|
|
authentication_classes=authentication_classes,
|
2018-01-25 11:39:03 +03:00
|
|
|
renderer_classes=renderer_classes,
|
2017-09-25 17:17:25 +03:00
|
|
|
permission_classes=permission_classes,
|
2017-03-03 18:24:37 +03:00
|
|
|
)
|
|
|
|
schema_js_view = get_schemajs_view(
|
|
|
|
title=title,
|
|
|
|
description=description,
|
|
|
|
schema_url=schema_url,
|
2019-07-23 14:06:03 +03:00
|
|
|
urlconf=urlconf,
|
2017-03-15 10:07:12 +03:00
|
|
|
public=public,
|
|
|
|
patterns=patterns,
|
2017-04-18 13:44:43 +03:00
|
|
|
generator_class=generator_class,
|
2017-09-25 17:17:25 +03:00
|
|
|
authentication_classes=authentication_classes,
|
|
|
|
permission_classes=permission_classes,
|
2017-03-03 18:24:37 +03:00
|
|
|
)
|
|
|
|
urls = [
|
|
|
|
url(r'^$', docs_view, name='docs-index'),
|
|
|
|
url(r'^schema.js$', schema_js_view, name='schema-js')
|
|
|
|
]
|
2017-10-16 12:31:13 +03:00
|
|
|
return include((urls, 'api-docs'), namespace='api-docs')
|